[PATCH] D149965: [clang][Interp] Fix tests for ignored expressions
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 8 06:40:04 PDT 2023
tbaeder updated this revision to Diff 520352.
tbaeder added a comment.
@aaron.ballman This is where the sizeof/alignof tests were actually broken.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149965/new/
https://reviews.llvm.org/D149965
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -196,6 +196,21 @@
// ref-error {{must be initialized by a constant expression}}
}
+#if __cplusplus >= 201402L
+ constexpr int IgnoredRejected() { // ref-error {{never produces a constant expression}}
+ int n = 0;
+ sizeof(int[n++]); // expected-warning {{expression result unused}} \
+ // ref-warning {{expression result unused}} \
+ // ref-note 2{{subexpression not valid in a constant expression}}
+ return n;
+ }
+ /// FIXME: This is rejected because the parameter so sizeof() is not constant.
+ /// produce a proper diagnostic.
+ static_assert(IgnoredRejected() == 0, ""); // expected-error {{not an integral constant expression}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'IgnoredRejected()'}}
+#endif
+
#if __cplusplus >= 202002L
/// FIXME: The following code should be accepted.
@@ -886,7 +901,7 @@
struct A{ int a; };
constexpr int ignoredExprs() {
(void)(1 / 2);
- A a;
+ A a{12};
a;
(void)a;
(a);
@@ -902,9 +917,12 @@
arr[0];
"a";
'b';
+ sizeof(int);
+ alignof(int);
return 0;
}
+ static_assert(ignoredExprs() == 0, "");
constexpr int oh_my(int x) {
(int){ x++ };
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,6 +200,8 @@
case CK_NoOp:
case CK_UserDefinedConversion:
case CK_BitCast:
+ if (DiscardResult)
+ return this->discard(SubExpr);
return this->visit(SubExpr);
case CK_IntegralToBoolean:
@@ -588,6 +590,9 @@
Size = ASTCtx.getTypeSizeInChars(ArgType);
}
+ if (DiscardResult)
+ return true;
+
return this->emitConst(Size.getQuantity(), E);
}
@@ -618,6 +623,9 @@
Size = AlignOfType(Arg->getType(), ASTCtx, Kind);
}
+ if (DiscardResult)
+ return true;
+
return this->emitConst(Size.getQuantity(), E);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149965.520352.patch
Type: text/x-patch
Size: 2387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230508/091a3ce5/attachment.bin>
More information about the cfe-commits
mailing list