pcc created this revision.
pcc added a reviewer: rsmith.
pcc added a subscriber: cfe-commits.

http://reviews.llvm.org/D15985

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/global-init.cpp

Index: test/CodeGenCXX/global-init.cpp
===================================================================
--- test/CodeGenCXX/global-init.cpp
+++ test/CodeGenCXX/global-init.cpp
@@ -18,8 +18,7 @@
 // CHECK: @__dso_handle = external global i8
 // CHECK: @c = global %struct.C zeroinitializer, align 8
 
-// It's okay if we ever implement the IR-generation optimization to remove 
this.
-// CHECK: @_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 
x i8], [7 x i8]* 
+// CHECK: @[[STR:.*]] = private unnamed_addr constant [7 x i8] c"string\00"
 
 // PR6205: The casts should not require global initializers
 // CHECK: @_ZN6PR59741cE = external global %"struct.PR5974::C"
@@ -66,10 +65,10 @@
 }
 
 namespace test3 {
-  // Tested at the beginning of the file.
   const char * const var = "string";
   extern const char * const var;
 
+  // CHECK: ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @[[STR]], i32 
0, i32 0)
   const char *test() { return var; }
 }
 
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2678,10 +2678,11 @@
           }
           return CompleteObject();
         }
-      } else if (BaseType->isFloatingType() && BaseType.isConstQualified()) {
-        // We support folding of const floating-point types, in order to make
-        // static const data members of such types (supported as an extension)
-        // more useful.
+      } else if ((BaseType->isFloatingType() || BaseType->isPointerType()) &&
+                 BaseType.isConstQualified()) {
+        // We support folding of const floating-point and pointer types, in
+        // order to make static const data members of such types (supported as
+        // an extension) more useful.
         if (Info.getLangOpts().CPlusPlus11) {
           Info.CCEDiag(E, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
           Info.Note(VD->getLocation(), diag::note_declared_at);


Index: test/CodeGenCXX/global-init.cpp
===================================================================
--- test/CodeGenCXX/global-init.cpp
+++ test/CodeGenCXX/global-init.cpp
@@ -18,8 +18,7 @@
 // CHECK: @__dso_handle = external global i8
 // CHECK: @c = global %struct.C zeroinitializer, align 8
 
-// It's okay if we ever implement the IR-generation optimization to remove this.
-// CHECK: @_ZN5test3L3varE = internal constant i8* getelementptr inbounds ([7 x i8], [7 x i8]* 
+// CHECK: @[[STR:.*]] = private unnamed_addr constant [7 x i8] c"string\00"
 
 // PR6205: The casts should not require global initializers
 // CHECK: @_ZN6PR59741cE = external global %"struct.PR5974::C"
@@ -66,10 +65,10 @@
 }
 
 namespace test3 {
-  // Tested at the beginning of the file.
   const char * const var = "string";
   extern const char * const var;
 
+  // CHECK: ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @[[STR]], i32 0, i32 0)
   const char *test() { return var; }
 }
 
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2678,10 +2678,11 @@
           }
           return CompleteObject();
         }
-      } else if (BaseType->isFloatingType() && BaseType.isConstQualified()) {
-        // We support folding of const floating-point types, in order to make
-        // static const data members of such types (supported as an extension)
-        // more useful.
+      } else if ((BaseType->isFloatingType() || BaseType->isPointerType()) &&
+                 BaseType.isConstQualified()) {
+        // We support folding of const floating-point and pointer types, in
+        // order to make static const data members of such types (supported as
+        // an extension) more useful.
         if (Info.getLangOpts().CPlusPlus11) {
           Info.CCEDiag(E, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
           Info.Note(VD->getLocation(), diag::note_declared_at);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to