Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Fix crash related to _BitInt constant split #112218

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

Fznamznon
Copy link
Contributor

9ad72df added split of _BitInt constants when required. Before folding back, check that the constant exists.

9ad72df added split of _BitInt
constants when required. Before folding back, check that the constant
exists.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Oct 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Mariya Podchishchaeva (Fznamznon)

Changes

9ad72df 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 --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);
+}
+}

@Fznamznon Fznamznon merged commit b528b13 into llvm:main Oct 15, 2024
11 checks passed
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
9ad72df added split of _BitInt
constants when required. Before folding back, check that the constant
exists.
bricknerb pushed a commit to bricknerb/llvm-project that referenced this pull request Oct 17, 2024
9ad72df added split of _BitInt
constants when required. Before folding back, check that the constant
exists.
EricWF pushed a commit to efcs/llvm-project that referenced this pull request Oct 22, 2024
9ad72df added split of _BitInt
constants when required. Before folding back, check that the constant
exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants