diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index dd5d0a6873c6..d29a905fd4a2 100644 --- a/clang/include/clang/CIR/MissingFeatures.h +++ b/clang/include/clang/CIR/MissingFeatures.h @@ -60,7 +60,6 @@ struct MissingFeatures { static bool tbaa() { return false; } static bool tbaaStruct() { return false; } static bool tbaaTagForStruct() { return false; } - static bool tbaaTagForBitInt() { return false; } static bool tbaaVTablePtr() { return false; } static bool tbaaIncompleteType() { return false; } static bool tbaaMergeTBAAInfo() { return false; } diff --git a/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp b/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp index d2a7ff946b7b..c1eb9326c04a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTBAA.cpp @@ -192,8 +192,13 @@ cir::TBAAAttr CIRGenTBAA::getTypeInfoHelper(clang::QualType qty) { types.convertType(qty)); } if (const auto *eit = dyn_cast(ty)) { - assert(!cir::MissingFeatures::tbaaTagForBitInt()); - return tbaa_NYI(mlirContext); + SmallString<256> outName; + llvm::raw_svector_ostream out(outName); + // Don't specify signed/unsigned since integer types can alias despite sign + // differences. + out << "_BitInt(" << eit->getNumBits() << ')'; + return cir::TBAAScalarAttr::get(mlirContext, outName, + types.convertType(qty)); } // For now, handle any other kind of type conservatively. return getChar(); diff --git a/clang/test/CIR/CodeGen/tbaa-bitinit.c b/clang/test/CIR/CodeGen/tbaa-bitinit.c index 72c62162e91e..286db47c3fba 100644 --- a/clang/test/CIR/CodeGen/tbaa-bitinit.c +++ b/clang/test/CIR/CodeGen/tbaa-bitinit.c @@ -1,13 +1,26 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -O1 // RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O1 -disable-llvm-passes +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s - -// CIR: #tbaa[[tbaa_NYI:.*]] = #cir.tbaa +// CIR: #tbaa[[BitInt33:.*]] = #cir.tbaa_scalar> +// CIR: #tbaa[[BitInt31:.*]] = #cir.tbaa_scalar> _BitInt(33) a; _BitInt(31) b; void c() { - // CIR: %{{.*}} = cir.load %{{.*}} : !cir.ptr>, !cir.int tbaa(#tbaa[[tbaa_NYI]]) - // CIR: cir.store %{{.*}}, %{{.*}} : !cir.int, !cir.ptr> tbaa(#tbaa[[tbaa_NYI]]) + // CIR-LABEL: cir.func {{.*}} @c() + // CIR: %{{.*}} = cir.load %{{.*}} : !cir.ptr>, !cir.int tbaa(#tbaa[[BitInt33]]) + // CIR: cir.store %{{.*}}, %{{.*}} : !cir.int, !cir.ptr> tbaa(#tbaa[[BitInt31]]) + + // LLVM-LABEL: define {{.*}} void @c() + // LLVM: %{{.*}} = load i33, ptr @a, align 8, !tbaa [[tbaa_tag_bitint_33:!.*]] + // LLVM: store i31 %{{.*}}, ptr @b, align 4, !tbaa [[tbaa_tag_bitint_31:!.*]] b = a; } +// LLVM: [[tbaa_tag_bitint_33]] = !{[[TYPE_bitint_33:!.*]], [[TYPE_bitint_33]], i64 0} +// LLVM: [[TYPE_bitint_33]] = !{!"_BitInt(33)", [[TYPE_char:!.*]], i64 0} +// LLVM: [[TYPE_char]] = !{!"omnipotent char", [[TAG_c_tbaa:!.*]], i64 0} +// LLVM: [[TAG_c_tbaa]] = !{!"Simple C/C++ TBAA"} +// LLVM: [[tbaa_tag_bitint_31]] = !{[[TYPE_bitint_31:!.*]], [[TYPE_bitint_31]], i64 0} +// LLVM: [[TYPE_bitint_31]] = !{!"_BitInt(31)", [[TYPE_char:!.*]], i64 0}