[clang] [clang]Avoid to check created local variable multiple time when evaluating (PR #69106)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 16 02:40:17 PDT 2023


https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/69106

>From 8e599770d1dc3a5cd3edc011e7d830bc5b428410 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Sun, 15 Oct 2023 19:48:09 +0800
Subject: [PATCH 1/2] [clang]Avoid to check created local variable multiple
 time when constant evaluating

When evaluting variable initialized from compound literal multiple times, it will be
converted to evaluting the compound literal itself multiple times, which causes clang
crash in assertions.

And the further evaluting is not rely on this assertion.

Fixes: #69065
---
 clang/docs/ReleaseNotes.rst    |  3 +++
 clang/lib/AST/ExprConstant.cpp |  1 -
 clang/test/AST/issue69065.c    | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/issue69065.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index be7c8bf247f7af5..5578663a90f104a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,6 +393,9 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 <https://github.com/llvm/llvm-project/issues/69008>`_)
+- Fix a crash when evaluating comparasion between the field from the same variable
+  which initialized from compound literals in C. Fixes
+  (`#69065 <https://github.com/llvm/llvm-project/issues/69065>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..9948b516745a30b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1912,7 +1912,6 @@ APValue &CallStackFrame::createLocal(APValue::LValueBase Base, const void *Key,
   assert(Base.getCallIndex() == Index && "lvalue for wrong frame");
   unsigned Version = Base.getVersion();
   APValue &Result = Temporaries[MapKeyTy(Key, Version)];
-  assert(Result.isAbsent() && "local created multiple times");
 
   // If we're creating a local immediately in the operand of a speculative
   // evaluation, don't register a cleanup to be run outside the speculative
diff --git a/clang/test/AST/issue69065.c b/clang/test/AST/issue69065.c
new file mode 100644
index 000000000000000..11428932019418d
--- /dev/null
+++ b/clang/test/AST/issue69065.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// expected-no-diagnostics
+
+struct A {
+  int i;
+};
+struct B {
+  struct A *a;
+};
+const struct B c = {&(struct A){1}};
+
+int main(void) {
+  if ((c.a->i != 1) || (c.a->i)) {
+    return 1;
+  }
+  return 0;
+}

>From a3085aa7a927206a464335c07ebbbf17d4c96180 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Mon, 16 Oct 2023 17:40:10 +0800
Subject: [PATCH 2/2] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva at intel.com>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5578663a90f104a..50c34de51f254ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,7 +393,7 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 <https://github.com/llvm/llvm-project/issues/69008>`_)
-- Fix a crash when evaluating comparasion between the field from the same variable
+- Fix a crash when evaluating comparison between the field from the same variable
   which initialized from compound literals in C. Fixes
   (`#69065 <https://github.com/llvm/llvm-project/issues/69065>`_)
 



More information about the cfe-commits mailing list