[clang] 0f6facc - Don't build a StringLiteral expression with reference type when
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 21 15:25:31 PDT 2020
Author: Richard Smith
Date: 2020-09-21T15:25:19-07:00
New Revision: 0f6facca9701f6df87d13e55d70bd7111a0472aa
URL: https://github.com/llvm/llvm-project/commit/0f6facca9701f6df87d13e55d70bd7111a0472aa
DIFF: https://github.com/llvm/llvm-project/commit/0f6facca9701f6df87d13e55d70bd7111a0472aa.diff
LOG: Don't build a StringLiteral expression with reference type when
performing list-initialization of a char array reference from a braced
string literal of a smaller size.
Added:
Modified:
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ab82f85a086e..a9f707b8cf20 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -8420,7 +8420,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
case SK_StringInit: {
QualType Ty = Step->Type;
- CheckStringInit(CurInit.get(), ResultType ? *ResultType : Ty,
+ bool UpdateType = ResultType && Entity.getType()->isIncompleteArrayType();
+ CheckStringInit(CurInit.get(), UpdateType ? *ResultType : Ty,
S.Context.getAsArrayType(Ty), S);
break;
}
diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-references.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
index 595d27ca2e83..00273ed00c70 100644
--- a/clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-references.cpp
@@ -1,5 +1,14 @@
// RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -fmerge-all-constants -emit-llvm -o - %s | FileCheck %s
+// This creates and lifetime-extends a 'const char[5]' temporary.
+// CHECK: @_ZGR19extended_string_ref_ = internal constant [5 x i8] c"hi\00\00\00",
+// CHECK: @extended_string_ref = constant [5 x i8]* @_ZGR19extended_string_ref_,
+const char (&extended_string_ref)[5] = {"hi"};
+
+// This binds directly to a string literal object.
+// CHECK: @nonextended_string_ref = constant [3 x i8]* @.str
+const char (&nonextended_string_ref)[3] = {"hi"};
+
namespace reference {
struct A {
int i1, i2;
More information about the cfe-commits
mailing list