public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ubsan ICE on invalid (PR sanitizer/61272)
@ 2014-05-21 18:46 Marek Polacek
  2014-05-21 18:59 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2014-05-21 18:46 UTC (permalink / raw)
  To: GCC Patches

When compiling invalid C++ code, CALL_EXPR that contains identifier_node
instead of a FUNCTION_DECL got into dump_expr - and is_ubsan_builtin_p
was expecting that it only gets FUNCTION_DECLs.  Fixed by changing the
assert into a condition so is_ubsan_builtin_p returns false for
non-functions.

Regtested/bootstrapped on x86_64-linux, ok for trunk?

2014-05-21  Marek Polacek  <polacek@redhat.com>

	PR sanitizer/61272
	* ubsan.c (is_ubsan_builtin_p): Turn assert into a condition.

	* g++.dg/ubsan/pr61272.C: New test.

diff --git gcc/testsuite/g++.dg/ubsan/pr61272.C gcc/testsuite/g++.dg/ubsan/pr61272.C
index e69de29..064678d 100644
--- gcc/testsuite/g++.dg/ubsan/pr61272.C
+++ gcc/testsuite/g++.dg/ubsan/pr61272.C
@@ -0,0 +1,24 @@
+// PR sanitizer/61272
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined -std=c++11" }
+
+namespace std
+{
+  template < typename _Tp > class allocator;
+  template < typename _Alloc > struct allocator_traits {
+  private:
+      template < typename _Tp > auto construct ( _Alloc & __a, _Tp * __p)-> // { dg-error "is private" }
+      decltype (_S_construct (__a, __p)) { }
+  };
+  namespace __gnu_cxx
+  {
+    template < typename _Alloc > struct __alloc_traits:std::allocator_traits < _Alloc > // { dg-error "within this context" }
+    {
+      typedef std::allocator_traits < _Alloc > _Base_type;
+      using _Base_type::construct;
+    };
+    template < typename _Tp, typename _Alloc > struct _Vector_base { typedef typename __gnu_cxx::__alloc_traits < _Alloc >::template rebind < _Tp >::other _Tp_alloc_type; }; // { dg-error "no class template" }
+    template < typename _Tp, typename _Alloc = std::allocator < _Tp > >class vector : protected _Vector_base < _Tp, _Alloc > { };
+    template < typename NumberT > struct Point2d { };
+    typedef Point2d < int >GdsPoint;
+    class GdsPointList : public vector < GdsPoint > {};}}
diff --git gcc/ubsan.c gcc/ubsan.c
index 11461d0..585569c 100644
--- gcc/ubsan.c
+++ gcc/ubsan.c
@@ -531,9 +531,9 @@ ubsan_instrument_unreachable (location_t loc)
 bool
 is_ubsan_builtin_p (tree t)
 {
-  gcc_checking_assert (TREE_CODE (t) == FUNCTION_DECL);
-  return strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
-		  "__builtin___ubsan_", 18) == 0;
+  return TREE_CODE (t) == FUNCTION_DECL
+	 && strncmp (IDENTIFIER_POINTER (DECL_NAME (t)),
+		     "__builtin___ubsan_", 18) == 0;
 }
 
 /* Expand UBSAN_NULL internal call.  */

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix ubsan ICE on invalid (PR sanitizer/61272)
  2014-05-21 18:46 [PATCH] Fix ubsan ICE on invalid (PR sanitizer/61272) Marek Polacek
@ 2014-05-21 18:59 ` Jakub Jelinek
  2014-09-22 11:29   ` Marek Polacek
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2014-05-21 18:59 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Wed, May 21, 2014 at 08:46:22PM +0200, Marek Polacek wrote:
> 2014-05-21  Marek Polacek  <polacek@redhat.com>
> 
> 	PR sanitizer/61272
> 	* ubsan.c (is_ubsan_builtin_p): Turn assert into a condition.
> 
> 	* g++.dg/ubsan/pr61272.C: New test.

Ok, thanks.

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix ubsan ICE on invalid (PR sanitizer/61272)
  2014-05-21 18:59 ` Jakub Jelinek
@ 2014-09-22 11:29   ` Marek Polacek
  0 siblings, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2014-09-22 11:29 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

On Wed, May 21, 2014 at 08:58:57PM +0200, Jakub Jelinek wrote:
> On Wed, May 21, 2014 at 08:46:22PM +0200, Marek Polacek wrote:
> > 2014-05-21  Marek Polacek  <polacek@redhat.com>
> > 
> > 	PR sanitizer/61272
> > 	* ubsan.c (is_ubsan_builtin_p): Turn assert into a condition.
> > 
> > 	* g++.dg/ubsan/pr61272.C: New test.
> 
> Ok, thanks.

Now committed to 4.9 branch as well to fix PR63323.

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-22 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-21 18:46 [PATCH] Fix ubsan ICE on invalid (PR sanitizer/61272) Marek Polacek
2014-05-21 18:59 ` Jakub Jelinek
2014-09-22 11:29   ` Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).