Skip to content

Commit b528b13

Browse files
authored
[clang] Fix crash related to _BitInt constant split (#112218)
9ad72df added split of _BitInt constants when required. Before folding back, check that the constant exists.
1 parent 5a7b79c commit b528b13

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/CodeGen/CGDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
19451945
replaceUndef(CGM, isPattern, constant));
19461946
}
19471947

1948-
if (D.getType()->isBitIntType() &&
1948+
if (constant && D.getType()->isBitIntType() &&
19491949
CGM.getTypes().typeRequiresSplitIntoByteArray(D.getType())) {
19501950
// Constants for long _BitInt types are split into individual bytes.
19511951
// Try to fold these back into an integer constant so it can be stored

clang/test/CodeGenCXX/ext-int.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,18 @@ void TBAATest(_BitInt(sizeof(int) * 8) ExtInt,
614614
// NewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 4, !"_BitInt(32)"}
615615
// NewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0, i64 1}
616616
// NewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 1, !"_BitInt(6)"}
617+
618+
namespace A {
619+
template <int N> struct S {
620+
using T = _BitInt(N);
621+
T Data;
622+
};
623+
template <int N> void foo(S<N> B) {
624+
const auto Var = B.Data;
625+
}
626+
627+
void bar() {
628+
S<2080> a;
629+
foo(a);
630+
}
631+
}

0 commit comments

Comments
 (0)