diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp index 83a63ee38d11..09d5c2042bbd 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp @@ -14,8 +14,8 @@ namespace direct { class CIRToLLVMTBAAAttrLowering { public: - CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext) - : mlirContext(mlirContext) {} + CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext, bool isCPlusPlus) + : mlirContext(mlirContext), isCPlusPlus(isCPlusPlus) {} mlir::LLVM::TBAATypeDescriptorAttr lowerCIRTBAAAttrToLLVMTBAAAttr(mlir::Attribute tbaa) { @@ -44,6 +44,9 @@ class CIRToLLVMTBAAAttrLowering { private: mlir::LLVM::TBAARootAttr getRoot() { + if (isCPlusPlus) + return createTBAARoot("Simple C++ TBAA"); + return createTBAARoot("Simple C/C++ TBAA"); } @@ -67,13 +70,16 @@ class CIRToLLVMTBAAAttrLowering { } mlir::MLIRContext *mlirContext; + bool isCPlusPlus; }; mlir::ArrayAttr lowerCIRTBAAAttr(mlir::Attribute tbaa, mlir::ConversionPatternRewriter &rewriter, cir::LowerModule *lowerMod) { auto *ctx = rewriter.getContext(); - CIRToLLVMTBAAAttrLowering lower(ctx); + auto langAttr = mlir::cast( + lowerMod->getModule()->getAttr(cir::CIRDialect::getLangAttrName())); + CIRToLLVMTBAAAttrLowering lower(ctx, langAttr.isCXX()); if (auto tbaaTag = mlir::dyn_cast(tbaa)) { mlir::LLVM::TBAATypeDescriptorAttr accessType = lower.lowerCIRTBAAAttrToLLVMTBAAAttr(tbaaTag.getAccess()); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index fd846d8d4d23..2ef482325ba0 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -4739,8 +4739,6 @@ void ConvertCIRToLLVMPass::runOnOperation() { // Allow operations that will be lowered directly to LLVM IR. target.addLegalOp(); - processCIRAttrs(module); - llvm::SmallVector ops; ops.push_back(module); collect_unreachable(module, ops); @@ -4767,6 +4765,8 @@ void ConvertCIRToLLVMPass::runOnOperation() { dtorAttr.getPriority()); }); buildGlobalAnnotationsVar(stringGlobalsMap, argStringGlobalsMap, argsVarMap); + + processCIRAttrs(module); } std::unique_ptr createConvertCIRToLLVMPass() { diff --git a/clang/test/CIR/CodeGen/tbaa-struct.cpp b/clang/test/CIR/CodeGen/tbaa-struct.cpp index 7349ff4cc5e1..a071ce3f4ae6 100644 --- a/clang/test/CIR/CodeGen/tbaa-struct.cpp +++ b/clang/test/CIR/CodeGen/tbaa-struct.cpp @@ -380,7 +380,7 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) { // OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0} // OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0} // OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]], -// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"} +// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"} // OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4} // OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12} // OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]