Skip to content

Commit 06519b5

Browse files
committed
[CIR][CIRGen][TBAA] Add support for BitInt
1 parent 7f66a20 commit 06519b5

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

clang/include/clang/CIR/MissingFeatures.h

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct MissingFeatures {
6060
static bool tbaa() { return false; }
6161
static bool tbaaStruct() { return false; }
6262
static bool tbaaTagForStruct() { return false; }
63-
static bool tbaaTagForBitInt() { return false; }
6463
static bool tbaaVTablePtr() { return false; }
6564
static bool tbaaIncompleteType() { return false; }
6665
static bool tbaaMergeTBAAInfo() { return false; }

clang/lib/CIR/CodeGen/CIRGenTBAA.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,13 @@ cir::TBAAAttr CIRGenTBAA::getTypeInfoHelper(clang::QualType qty) {
192192
types.convertType(qty));
193193
}
194194
if (const auto *eit = dyn_cast<BitIntType>(ty)) {
195-
assert(!cir::MissingFeatures::tbaaTagForBitInt());
196-
return tbaa_NYI(mlirContext);
195+
SmallString<256> outName;
196+
llvm::raw_svector_ostream out(outName);
197+
// Don't specify signed/unsigned since integer types can alias despite sign
198+
// differences.
199+
out << "_BitInt(" << eit->getNumBits() << ')';
200+
return cir::TBAAScalarAttr::get(mlirContext, outName,
201+
types.convertType(qty));
197202
}
198203
// For now, handle any other kind of type conservatively.
199204
return getChar();

clang/test/CIR/CodeGen/tbaa-bitinit.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -O1
22
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll -O1 -disable-llvm-passes
4+
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
35

4-
5-
// CIR: #tbaa[[tbaa_NYI:.*]] = #cir.tbaa
6+
// CIR: #tbaa[[BitInt33:.*]] = #cir.tbaa_scalar<id = "_BitInt(33)", type = !cir.int<s, 33>>
7+
// CIR: #tbaa[[BitInt31:.*]] = #cir.tbaa_scalar<id = "_BitInt(31)", type = !cir.int<s, 31>>
68

79
_BitInt(33) a;
810
_BitInt(31) b;
911
void c() {
10-
// CIR: %{{.*}} = cir.load %{{.*}} : !cir.ptr<!cir.int<s, 33>>, !cir.int<s, 33> tbaa(#tbaa[[tbaa_NYI]])
11-
// CIR: cir.store %{{.*}}, %{{.*}} : !cir.int<s, 31>, !cir.ptr<!cir.int<s, 31>> tbaa(#tbaa[[tbaa_NYI]])
12+
// CIR-LABEL: cir.func {{.*}} @c()
13+
// CIR: %{{.*}} = cir.load %{{.*}} : !cir.ptr<!cir.int<s, 33>>, !cir.int<s, 33> tbaa(#tbaa[[BitInt33]])
14+
// CIR: cir.store %{{.*}}, %{{.*}} : !cir.int<s, 31>, !cir.ptr<!cir.int<s, 31>> tbaa(#tbaa[[BitInt31]])
15+
16+
// LLVM-LABEL: define {{.*}} void @c()
17+
// LLVM: %{{.*}} = load i33, ptr @a, align 8, !tbaa [[tbaa_tag_bitint_33:!.*]]
18+
// LLVM: store i31 %{{.*}}, ptr @b, align 4, !tbaa [[tbaa_tag_bitint_31:!.*]]
1219
b = a;
1320
}
21+
// LLVM: [[tbaa_tag_bitint_33]] = !{[[TYPE_bitint_33:!.*]], [[TYPE_bitint_33]], i64 0}
22+
// LLVM: [[TYPE_bitint_33]] = !{!"_BitInt(33)", [[TYPE_char:!.*]], i64 0}
23+
// LLVM: [[TYPE_char]] = !{!"omnipotent char", [[TAG_c_tbaa:!.*]], i64 0}
24+
// LLVM: [[TAG_c_tbaa]] = !{!"Simple C/C++ TBAA"}
25+
// LLVM: [[tbaa_tag_bitint_31]] = !{[[TYPE_bitint_31:!.*]], [[TYPE_bitint_31]], i64 0}
26+
// LLVM: [[TYPE_bitint_31]] = !{!"_BitInt(31)", [[TYPE_char:!.*]], i64 0}

0 commit comments

Comments
 (0)