Skip to content

Commit 582f046

Browse files
nickdesaulnierstru
authored andcommitted
[CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (#70366)
Fixes a bug introduced by commit b54294e ("[clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first") In the added test case, the QualType is a LValueReferenceType. LValueReferenceType 0x558412998d90 'const char (&)[41]' `-ParenType 0x558412998d30 'const char[41]' sugar `-ConstantArrayType 0x558412998cf0 'const char[41]' 41 `-QualType 0x55841294c271 'const char' const `-BuiltinType 0x55841294c270 'char' Fixes: #69979 (cherry picked from commit d9b15b0)
1 parent 309d551 commit 582f046

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,9 +1736,10 @@ llvm::Constant *ConstantEmitter::tryEmitPrivate(const Expr *E,
17361736
QualType destType) {
17371737
assert(!destType->isVoidType() && "can't emit a void constant");
17381738

1739-
if (llvm::Constant *C =
1740-
ConstExprEmitter(*this).Visit(const_cast<Expr *>(E), destType))
1741-
return C;
1739+
if (!destType->isReferenceType())
1740+
if (llvm::Constant *C =
1741+
ConstExprEmitter(*this).Visit(const_cast<Expr *>(E), destType))
1742+
return C;
17421743

17431744
Expr::EvalResult Result;
17441745

clang/test/CodeGenCXX/const-init-cxx11.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ namespace DR2126 {
424424
// CHECK: @_ZN33ClassTemplateWithStaticDataMember3useE ={{.*}} constant ptr @_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE_
425425
// CHECK: @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_ = linkonce_odr hidden constant i32 5, comdat
426426
// CHECK: @_ZN39ClassTemplateWithHiddenStaticDataMember3useE ={{.*}} constant ptr @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE_
427+
// CHECK: @.str.[[STR:[0-9]+]] ={{.*}} constant [9 x i8] c"12345678\00"
428+
// CHECK-NEXT: @e = global %struct.PR69979 { ptr @.str.[[STR]] }
427429
// CHECK: @_ZGRZN20InlineStaticConstRef3funEvE1i_ = linkonce_odr constant i32 10, comdat
428430
// CHECK20: @_ZZN12LocalVarInit4dtorEvE1a = internal constant {{.*}} i32 103
429431

@@ -632,6 +634,10 @@ struct X {
632634
const char *f() { return &X::p; }
633635
}
634636

637+
struct PR69979 {
638+
const char (&d)[9];
639+
} e {"12345678"};
640+
635641
// VirtualMembers::TemplateClass::templateMethod() must be defined in this TU,
636642
// not just declared.
637643
// CHECK: define linkonce_odr void @_ZN14VirtualMembers13TemplateClassIiE14templateMethodEv(ptr {{[^,]*}} %this)

0 commit comments

Comments
 (0)