Skip to content

Commit 56d2262

Browse files
authored
[CIR][Lowering][TBAA] distinct C and C++ (#1406)
1 parent 5a75305 commit 56d2262

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace direct {
1414

1515
class CIRToLLVMTBAAAttrLowering {
1616
public:
17-
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext)
18-
: mlirContext(mlirContext) {}
17+
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext, bool isCPlusPlus)
18+
: mlirContext(mlirContext), isCPlusPlus(isCPlusPlus) {}
1919

2020
mlir::LLVM::TBAATypeDescriptorAttr
2121
lowerCIRTBAAAttrToLLVMTBAAAttr(mlir::Attribute tbaa) {
@@ -44,6 +44,9 @@ class CIRToLLVMTBAAAttrLowering {
4444

4545
private:
4646
mlir::LLVM::TBAARootAttr getRoot() {
47+
if (isCPlusPlus)
48+
return createTBAARoot("Simple C++ TBAA");
49+
4750
return createTBAARoot("Simple C/C++ TBAA");
4851
}
4952

@@ -67,13 +70,16 @@ class CIRToLLVMTBAAAttrLowering {
6770
}
6871

6972
mlir::MLIRContext *mlirContext;
73+
bool isCPlusPlus;
7074
};
7175

7276
mlir::ArrayAttr lowerCIRTBAAAttr(mlir::Attribute tbaa,
7377
mlir::ConversionPatternRewriter &rewriter,
7478
cir::LowerModule *lowerMod) {
7579
auto *ctx = rewriter.getContext();
76-
CIRToLLVMTBAAAttrLowering lower(ctx);
80+
auto langAttr = mlir::cast<cir::LangAttr>(
81+
lowerMod->getModule()->getAttr(cir::CIRDialect::getLangAttrName()));
82+
CIRToLLVMTBAAAttrLowering lower(ctx, langAttr.isCXX());
7783
if (auto tbaaTag = mlir::dyn_cast<cir::TBAATagAttr>(tbaa)) {
7884
mlir::LLVM::TBAATypeDescriptorAttr accessType =
7985
lower.lowerCIRTBAAAttrToLLVMTBAAAttr(tbaaTag.getAccess());

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4742,8 +4742,6 @@ void ConvertCIRToLLVMPass::runOnOperation() {
47424742
// Allow operations that will be lowered directly to LLVM IR.
47434743
target.addLegalOp<mlir::LLVM::ZeroOp>();
47444744

4745-
processCIRAttrs(module);
4746-
47474745
llvm::SmallVector<mlir::Operation *> ops;
47484746
ops.push_back(module);
47494747
collect_unreachable(module, ops);
@@ -4770,6 +4768,8 @@ void ConvertCIRToLLVMPass::runOnOperation() {
47704768
dtorAttr.getPriority());
47714769
});
47724770
buildGlobalAnnotationsVar(stringGlobalsMap, argStringGlobalsMap, argsVarMap);
4771+
4772+
processCIRAttrs(module);
47734773
}
47744774

47754775
std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass() {

clang/test/CIR/CodeGen/tbaa-struct.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) {
380380
// OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
381381
// OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
382382
// OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
383-
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
383+
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
384384
// OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
385385
// OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
386386
// OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]

0 commit comments

Comments
 (0)