[PATCH] D141745: [clang] Don't short-circuit constant evaluation for array or record types

Charles Magahern via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 19 18:04:45 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ac4299d3798: [clang] Don't short-circuit constant evaluation for array or record types (authored by cmagahern).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141745/new/

https://reviews.llvm.org/D141745

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/2007-06-15-AnnotateAttribute.c


Index: clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
===================================================================
--- clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
+++ clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
@@ -14,6 +14,20 @@
   return y + x;
 }
 
+/* Attribute with struct argument. */
+struct TestStruct {
+  int a;
+  int b;
+};
+int Y __attribute__((annotate(
+  "GlobalValAnnotationWithArgs", 
+  42,
+  (struct TestStruct) { .a = 1, .b = 2 }
+)));
+
+// CHECK: @.str.3 = private unnamed_addr constant [28 x i8] c"GlobalValAnnotationWithArgs\00", section "llvm.metadata"
+// CHECK-NEXT: @.args = private unnamed_addr constant { i32, %struct.TestStruct } { i32 42, %struct.TestStruct { i32 1, i32 2 } }, section "llvm.metadata"
+
 int main(void) {
   static int a __attribute__((annotate("GlobalValAnnotation")));
   a = foo(2);
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15313,7 +15313,7 @@
   assert(!isValueDependent() &&
          "Expression evaluator can't be called on a dependent expression.");
   bool IsConst;
-  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue())
     return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141745.490695.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230120/27c00e58/attachment.bin>


More information about the cfe-commits mailing list