diff mbox

Add testcase for PR59250

Message ID 20131125094457.GL30062@redhat.com
State New
Headers show

Commit Message

Marek Polacek Nov. 25, 2013, 9:44 a.m. UTC
The PR was fixed by Jakub in r205283, this patch merely adds a
testcase for it.  Passed ubsan testsuite for -m32/-m64.

Ok for trunk?

2013-11-25  Marek Polacek  <polacek@redhat.com>

testsuite/
	* g++.dg/ubsan/pr59250.C: New test.


	Marek

Comments

Jakub Jelinek Nov. 25, 2013, 9:49 a.m. UTC | #1
On Mon, Nov 25, 2013 at 10:44:57AM +0100, Marek Polacek wrote:
> The PR was fixed by Jakub in r205283, this patch merely adds a
> testcase for it.  Passed ubsan testsuite for -m32/-m64.
> 
> Ok for trunk?

Can't you reduce it at least a little bit more?
Like I doubt __attribute__ ((__visibility__ ("default")))
is needed to reproduce, I'd also think you could get rid of the namespaces,
perhaps also const _Alloc& __a = _Alloc() argument?

> 2013-11-25  Marek Polacek  <polacek@redhat.com>
> 
> testsuite/
> 	* g++.dg/ubsan/pr59250.C: New test.
> 
> --- gcc/testsuite/g++.dg/ubsan/pr59250.C.mp3	2013-11-25 10:43:24.797315678 +0100
> +++ gcc/testsuite/g++.dg/ubsan/pr59250.C	2013-11-25 10:41:24.859817636 +0100
> @@ -0,0 +1,34 @@
> +// PR sanitizer/59250
> +// { dg-do compile }
> +// { dg-options "-fsanitize=undefined" }
> +// { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
> +
> +namespace std __attribute__ ((__visibility__ ("default"))) {
> +   template<typename>     class allocator;
> +   template<class _CharT>     struct char_traits;
> +   template<typename _CharT, typename _Traits = char_traits<_CharT>,
> +            typename _Alloc = allocator<_CharT> > class basic_string;
> +   typedef basic_string<char> string;
> +}
> +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
> +  template<typename _Tp>     class new_allocator     { };
> +}
> +namespace std __attribute__ ((__visibility__ ("default"))) {
> +  template<typename _Tp>     class allocator: public __gnu_cxx::new_allocator<_Tp>     { };
> +  template<typename _CharT, typename _Traits, typename _Alloc>     class basic_string     {
> +   public:
> +    basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
> +  };
> +}
> +class FileImpl { };
> +class FileHandle {
> +  std::string fname;
> +  class FileImpl* impl;
> +  FileHandle (const char* fname);
> +};
> +class NormalFile : public FileImpl {
> +     int fd;
> +};
> +FileHandle::FileHandle (const char* fname) : fname(fname) {
> +  impl = new NormalFile();
> +}
> 
> 	Marek

	Jakub
diff mbox

Patch

--- gcc/testsuite/g++.dg/ubsan/pr59250.C.mp3	2013-11-25 10:43:24.797315678 +0100
+++ gcc/testsuite/g++.dg/ubsan/pr59250.C	2013-11-25 10:41:24.859817636 +0100
@@ -0,0 +1,34 @@ 
+// PR sanitizer/59250
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+// { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
+
+namespace std __attribute__ ((__visibility__ ("default"))) {
+   template<typename>     class allocator;
+   template<class _CharT>     struct char_traits;
+   template<typename _CharT, typename _Traits = char_traits<_CharT>,
+            typename _Alloc = allocator<_CharT> > class basic_string;
+   typedef basic_string<char> string;
+}
+namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
+  template<typename _Tp>     class new_allocator     { };
+}
+namespace std __attribute__ ((__visibility__ ("default"))) {
+  template<typename _Tp>     class allocator: public __gnu_cxx::new_allocator<_Tp>     { };
+  template<typename _CharT, typename _Traits, typename _Alloc>     class basic_string     {
+   public:
+    basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
+  };
+}
+class FileImpl { };
+class FileHandle {
+  std::string fname;
+  class FileImpl* impl;
+  FileHandle (const char* fname);
+};
+class NormalFile : public FileImpl {
+     int fd;
+};
+FileHandle::FileHandle (const char* fname) : fname(fname) {
+  impl = new NormalFile();
+}