re PR c++/70353 (ICE on __PRETTY_FUNCTION__ in a constexpr function)
authorJason Merrill <jason@gcc.gnu.org>
Tue, 29 Mar 2016 18:40:02 +0000 (14:40 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 29 Mar 2016 18:40:02 +0000 (14:40 -0400)
PR c++/70353

gcc/
* tree-inline.c (remap_decls): Don't add_local_decl if
cfun is null.
gcc/cp/
* decl.c (make_rtl_for_nonlocal_decl): Don't defer local statics
in constexpr functions.

From-SVN: r234530

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C [new file with mode: 0644]
gcc/tree-inline.c

index 895587a597163e094026547ac74ee59c728fb863..cb6297710d54072dc002f83d167231828ef94af1 100644 (file)
@@ -1,5 +1,9 @@
 2016-03-29  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/70353
+       * tree-inline.c (remap_decls): Don't add_local_decl if
+       cfun is null.
+
        PR tree-optimization/70405
        * ssa-iterators.h (num_imm_uses): Add missing braces.
 
index 2028f7e6d631e0ab208d03fbbba1f6edea909431..91ad5ac341f3c4d8b745f4f5c672852f9b6f1aa9 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/70353
+       * decl.c (make_rtl_for_nonlocal_decl): Don't defer local statics
+       in constexpr functions.
+
 2016-03-28  Jason Merrill  <jason@redhat.com>
 
        PR c++/70422
index cd5db3f06dc306758bec05471abbe41f4c240c5f..cfae210da552c081e9e1ab86c755db949fa169e2 100644 (file)
@@ -6251,8 +6251,11 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
     return;
 
   /* We defer emission of local statics until the corresponding
-     DECL_EXPR is expanded.  */
-  defer_p = DECL_FUNCTION_SCOPE_P (decl) || DECL_VIRTUAL_P (decl);
+     DECL_EXPR is expanded.  But with constexpr its function might never
+     be expanded, so go ahead and tell cgraph about the variable now.  */
+  defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
+             && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (decl)))
+            || DECL_VIRTUAL_P (decl));
 
   /* Defer template instantiations.  */
   if (DECL_LANG_SPECIFIC (decl)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__2.C
new file mode 100644 (file)
index 0000000..e678290
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/70353
+// { dg-do link { target c++11 } }
+
+constexpr const char* ce ()
+{
+  return __func__;
+}
+
+const char *c = ce();
+
+int main()
+{
+}
index 9d4f8f7815d56b8e4c066598be232cd22b3e7d75..5206d202babd3be4f61fceeaf83cf23d0ed96a86 100644 (file)
@@ -616,7 +616,8 @@ remap_decls (tree decls, vec<tree, va_gc> **nonlocalized_list,
          /* We need to add this variable to the local decls as otherwise
             nothing else will do so.  */
          if (TREE_CODE (old_var) == VAR_DECL
-             && ! DECL_EXTERNAL (old_var))
+             && ! DECL_EXTERNAL (old_var)
+             && cfun)
            add_local_decl (cfun, old_var);
          if ((!optimize || debug_info_level > DINFO_LEVEL_TERSE)
              && !DECL_IGNORED_P (old_var)