[PATCH] D149965: [clang][Interp] Fix tests for ignored expressions
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 05:59:35 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65dca4cbcbfc: [clang][Interp] Fix tests for ignored expressions (authored by tbaeder).
Repository:
rG LLVM Github Monorepo
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
@@ -193,6 +193,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.
@@ -883,7 +898,7 @@
struct A{ int a; };
constexpr int ignoredExprs() {
(void)(1 / 2);
- A a;
+ A a{12};
a;
(void)a;
(a);
@@ -903,9 +918,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
@@ -144,6 +144,8 @@
case CK_NoOp:
case CK_UserDefinedConversion:
case CK_BitCast:
+ if (DiscardResult)
+ return this->discard(SubExpr);
return this->visit(SubExpr);
case CK_IntegralToBoolean:
@@ -528,6 +530,9 @@
Size = ASTCtx.getTypeSizeInChars(ArgType);
}
+ if (DiscardResult)
+ return true;
+
return this->emitConst(Size.getQuantity(), E);
}
@@ -558,6 +563,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.546014.patch
Type: text/x-patch
Size: 2387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230801/3416e8f3/attachment-0001.bin>
More information about the cfe-commits
mailing list