Skip to content

Commit effbf0b

Browse files
committed
PR52183: Don't emit code for a void-typed constant expression.
This is unnecessary in general, and wrong when the expression invokes a consteval function.
1 parent 1202d28 commit effbf0b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,8 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM,
17141714

17151715
llvm::Constant *ConstantEmitter::tryEmitPrivate(const Expr *E,
17161716
QualType destType) {
1717+
assert(!destType->isVoidType() && "can't emit a void constant");
1718+
17171719
Expr::EvalResult Result;
17181720

17191721
bool Success = false;

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ class ScalarExprEmitter
419419
Value *VisitExpr(Expr *S);
420420

421421
Value *VisitConstantExpr(ConstantExpr *E) {
422+
// A constant expression of type 'void' generates no code and produces no
423+
// value.
424+
if (E->getType()->isVoidType())
425+
return nullptr;
426+
422427
if (Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
423428
if (E->isGLValue())
424429
return CGF.Builder.CreateLoad(Address(

clang/test/CodeGenCXX/cxx2a-consteval.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll
33
// RUN: FileCheck -check-prefix=EVAL -input-file=%t.ll %s
44
// RUN: FileCheck -check-prefix=EVAL-STATIC -input-file=%t.ll %s
5-
// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu -o - | FileCheck -check-prefix=EVAL-FN %s
5+
// RUN: FileCheck -check-prefix=EVAL-FN -input-file=%t.ll %s
6+
//
67
// RUN: %clang_cc1 -emit-llvm %s -Dconsteval="" -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll
78
// RUN: FileCheck -check-prefix=EXPR -input-file=%t.ll %s
89

@@ -243,3 +244,10 @@ consteval int test_UserConvOverload_helper_ceval(int a) { return a; }
243244
int test_UserConvOverload_ceval() {
244245
return test_UserConvOverload_helper_ceval(UserConv());
245246
}
247+
248+
consteval void void_test() {}
249+
void void_call() { // EVAL-FN-LABEL: define {{.*}} @_Z9void_call
250+
// EVAL-FN-NOT: call
251+
void_test();
252+
// EVAL-FN: {{^}}}
253+
}

0 commit comments

Comments
 (0)