FastEvaluateAsRValue returns `true` without setting a result value for when a
given constant expression is an array or record type.
Clang attributes must be able to support constant expressions that are array or
record types, so proceed with the slower path for evaluation in the case where
`FastEvaluateAsRValue` does not yield an evaluation result.
Differential Revision: https://reviews.llvm.org/D141745
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");
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);