Add fnspecs for C++ new and delete operators
authorJan Hubicka <jh@suse.cz>
Thu, 5 Nov 2020 17:19:07 +0000 (18:19 +0100)
committerJan Hubicka <jh@suse.cz>
Thu, 5 Nov 2020 17:19:07 +0000 (18:19 +0100)
gcc/ChangeLog:

* gimple.c (gimple_call_fnspec): Handle C++ new and delete.
* gimple.h (gimple_call_from_new_or_delete): Constify parameter.

gcc/testsuite/ChangeLog:

* g++.dg/ipa/devirt-24.C: Update template.

gcc/gimple.c
gcc/gimple.h
gcc/testsuite/g++.dg/ipa/devirt-24.C

index 469e6f369f3c32ae4b335b7402e08c3645c34978..1afed88e1f1311456894c341f562798c62378af3 100644 (file)
@@ -1510,6 +1510,19 @@ gimple_call_fnspec (const gcall *stmt)
     }
   if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
     return builtin_fnspec (gimple_call_fndecl (stmt));
+  tree fndecl = gimple_call_fndecl (stmt);
+  /* If the call is to a replaceable operator delete and results
+     from a delete expression as opposed to a direct call to
+     such operator, then we can treat it as free.  */
+  if (fndecl
+      && DECL_IS_OPERATOR_DELETE_P (fndecl)
+      && gimple_call_from_new_or_delete (stmt))
+    return ".co ";
+  /* Similarly operator new can be treated as malloc.  */
+  if (fndecl
+      && DECL_IS_OPERATOR_NEW_P (fndecl)
+      && gimple_call_from_new_or_delete (stmt))
+    return "mC";
   return "";
 }
 
index 87c90be9a6a835bd99026806c7afcd7d985c7350..62b5a8a6124f5d2e288547f33514e03c1386dd3b 100644 (file)
@@ -3405,7 +3405,7 @@ gimple_call_set_from_new_or_delete (gcall *s, bool from_new_or_delete_p)
    from a new or delete expression.  */
 
 static inline bool
-gimple_call_from_new_or_delete (gcall *s)
+gimple_call_from_new_or_delete (const gcall *s)
 {
   return (s->subcode & GF_CALL_FROM_NEW_OR_DELETE) != 0;
 }
index eaef1f5b3f8180e88906a00f1ad3220b9fdafebf..7b5b806dd05fdf113532197e1654fd14a6c9468b 100644 (file)
@@ -37,4 +37,4 @@ C *b = new (C);
   }
 }
 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 1 "inline" { xfail *-*-* } } } */
-/* { dg-final { scan-ipa-dump-times "Aggregate passed by reference" 1 "cp"  } } */
+/* { dg-final { scan-ipa-dump-times "Aggregate passed by reference" 2 "cp"  } } */