[PATCH] D15985: AST: Support constant folding of variables of const pointer type.

Peter Collingbourne via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 17:29:30 PST 2016


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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15985.44297.patch
Type: text/x-patch
Size: 1998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160108/2c38317d/attachment.bin>


More information about the cfe-commits mailing list