[clang] 7b4b85b - [clang][bytecode] Reject void InitListExpr differently (#105802)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 23 02:56:45 PDT 2024
Author: Timm Baeder
Date: 2024-08-23T11:56:42+02:00
New Revision: 7b4b85b75d22a792b2ef80e6af4f0faf18da0a43
URL: https://github.com/llvm/llvm-project/commit/7b4b85b75d22a792b2ef80e6af4f0faf18da0a43
DIFF: https://github.com/llvm/llvm-project/commit/7b4b85b75d22a792b2ef80e6af4f0faf18da0a43.diff
LOG: [clang][bytecode] Reject void InitListExpr differently (#105802)
This reverts c79d1fa540390f6e37e1ea326153559eeadd0de6 and
125aa10b3d645bd26523a1bc321bb2e6b1cf04e1
Instead, use the previous approach but allow void-typed InitListExprs
with 0 initializers.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/c.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index d24384ca4ac7a4..f11196d2b02707 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1344,6 +1344,16 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
const Expr *ArrayFiller, const Expr *E) {
+ QualType QT = E->getType();
+ if (const auto *AT = QT->getAs<AtomicType>())
+ QT = AT->getValueType();
+
+ if (QT->isVoidType()) {
+ if (Inits.size() == 0)
+ return true;
+ return this->emitInvalid(E);
+ }
+
// Handle discarding first.
if (DiscardResult) {
for (const Expr *Init : Inits) {
@@ -1353,13 +1363,6 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return true;
}
- QualType QT = E->getType();
- if (const auto *AT = QT->getAs<AtomicType>())
- QT = AT->getValueType();
-
- if (QT->isVoidType())
- return this->emitInvalid(E);
-
// Primitive values.
if (std::optional<PrimType> T = classify(QT)) {
assert(!DiscardResult);
@@ -3272,9 +3275,12 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {
if (E->getType().isNull())
return false;
+ if (E->getType()->isVoidType())
+ return this->discard(E);
+
// Create local variable to hold the return value.
- if (!E->getType()->isVoidType() && !E->isGLValue() &&
- !E->getType()->isAnyComplexType() && !classify(E->getType())) {
+ if (!E->isGLValue() && !E->getType()->isAnyComplexType() &&
+ !classify(E->getType())) {
std::optional<unsigned> LocalIndex = allocateLocal(E);
if (!LocalIndex)
return false;
@@ -5174,7 +5180,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
// We should already have a pointer when we get here.
return this->delegate(SubExpr);
case UO_Deref: // *x
- if (DiscardResult || E->getType()->isVoidType())
+ if (DiscardResult)
return this->discard(SubExpr);
return this->visit(SubExpr);
case UO_Not: // ~x
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 60f4d6ad1b2967..7cb7f96049f2de 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -298,7 +298,6 @@ void T1(void) {
enum teste1 test1f(void), (*test1)(void) = test1f; // pedantic-warning {{ISO C forbids forward references to 'enum' types}}
enum teste1 { TEST1 };
-
void func(void) {
_Static_assert(func + 1 - func == 1, ""); // pedantic-warning {{arithmetic on a pointer to the function type}} \
// pedantic-warning {{arithmetic on pointers to the function type}} \
@@ -313,3 +312,9 @@ void func(void) {
func - 0xdead000000000000UL; // all-warning {{expression result unused}} \
// pedantic-warning {{arithmetic on a pointer to the function type}}
}
+
+void foo3 (void)
+{
+ void* x = 0;
+ void* y = &*x;
+}
More information about the cfe-commits
mailing list