[clang] [clang] Fix crash related to _BitInt constant split (PR #112218)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 07:45:48 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Mariya Podchishchaeva (Fznamznon)
<details>
<summary>Changes</summary>
9ad72df55cb74b29193270c28f6974d2af8e0b71 added split of _BitInt constants when required. Before folding back, check that the constant exists.
---
Full diff: https://github.com/llvm/llvm-project/pull/112218.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGDecl.cpp (+1-1)
- (modified) clang/test/CodeGenCXX/ext-int.cpp (+15)
``````````diff
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 30af9268b30e2e..1d0660292cecc1 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1945,7 +1945,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
replaceUndef(CGM, isPattern, constant));
}
- if (D.getType()->isBitIntType() &&
+ if (constant && D.getType()->isBitIntType() &&
CGM.getTypes().typeRequiresSplitIntoByteArray(D.getType())) {
// Constants for long _BitInt types are split into individual bytes.
// Try to fold these back into an integer constant so it can be stored
diff --git a/clang/test/CodeGenCXX/ext-int.cpp b/clang/test/CodeGenCXX/ext-int.cpp
index 7758e92d74a05f..a098f5a9057c0e 100644
--- a/clang/test/CodeGenCXX/ext-int.cpp
+++ b/clang/test/CodeGenCXX/ext-int.cpp
@@ -614,3 +614,18 @@ void TBAATest(_BitInt(sizeof(int) * 8) ExtInt,
// NewStructPathTBAA-DAG: ![[EXTINT_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 4, !"_BitInt(32)"}
// NewStructPathTBAA-DAG: ![[EXTINT6_TBAA]] = !{![[EXTINT6_TBAA_ROOT:.+]], ![[EXTINT6_TBAA_ROOT]], i64 0, i64 1}
// NewStructPathTBAA-DAG: ![[EXTINT6_TBAA_ROOT]] = !{![[CHAR_TBAA_ROOT]], i64 1, !"_BitInt(6)"}
+
+namespace A {
+template <int N> struct S {
+ using T = _BitInt(N);
+ T Data;
+};
+template <int N> void foo(S<N> B) {
+ const auto Var = B.Data;
+}
+
+void bar() {
+ S<2080> a;
+ foo(a);
+}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112218
More information about the cfe-commits
mailing list