diff options
author | Jakub Jelinek <jakub@redhat.com> | 2013-02-13 17:09:27 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2013-02-13 17:09:27 +0100 |
commit | 6760071f307c18d0aef50f9c848d15cb7c1a687d (patch) | |
tree | c87a849d123fb35e51e20d6ce9d167ff6c8400ee /gcc | |
parent | 6422242b91c9568e93010d3d323ceb57a15aa751 (diff) | |
download | gcc-6760071f307c18d0aef50f9c848d15cb7c1a687d.zip gcc-6760071f307c18d0aef50f9c848d15cb7c1a687d.tar.gz gcc-6760071f307c18d0aef50f9c848d15cb7c1a687d.tar.bz2 |
re PR c++/56302 (sys/sdt.h asms stopped working at -O0)
PR c++/56302
* semantics.c (finish_asm_stmt): If input constraints allow
neither register nor memory, try maybe_constant_value to get
a constant if possible.
* g++.dg/torture/pr56302.C: New test.
* g++.dg/cpp0x/constexpr-56302.C: New test.
* c-c++-common/pr56302.c: New test.
From-SVN: r196018
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr56302.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C | 12 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr56302.C | 41 |
6 files changed, 84 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bc4e41c..442b369 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2013-02-13 Jakub Jelinek <jakub@redhat.com> + + PR c++/56302 + * semantics.c (finish_asm_stmt): If input constraints allow + neither register nor memory, try maybe_constant_value to get + a constant if possible. + 2013-02-12 Jason Merrill <jason@redhat.com> PR c++/56285 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e31ae30..3415828 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1402,6 +1402,14 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands, if (!cxx_mark_addressable (operand)) operand = error_mark_node; } + else if (!allows_reg && !allows_mem) + { + /* If constraint allows neither register nor memory, + try harder to get a constant. */ + tree constop = maybe_constant_value (operand); + if (TREE_CONSTANT (constop)) + operand = constop; + } } else operand = error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9e70c94..2bc5381 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2013-02-13 Jakub Jelinek <jakub@redhat.com> + + PR c++/56302 + * g++.dg/torture/pr56302.C: New test. + * g++.dg/cpp0x/constexpr-56302.C: New test. + * c-c++-common/pr56302.c: New test. + 2013-02-13 Tobias Burnus <burnus@net-b.de> Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> diff --git a/gcc/testsuite/c-c++-common/pr56302.c b/gcc/testsuite/c-c++-common/pr56302.c new file mode 100644 index 0000000..fb67d12 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr56302.c @@ -0,0 +1,9 @@ +/* PR c++/56302 */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +void +foo (int x) +{ + __asm__ __volatile__ ("" : : "n" (-1 * (int) sizeof (&x))); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C new file mode 100644 index 0000000..c0adae4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C @@ -0,0 +1,12 @@ +// PR c++/56302 +// { dg-do compile } +// { dg-options "-std=c++11 -O0" } + +constexpr int foo () { return 42; } +constexpr int x = foo () + 2; + +void +bar () +{ + __asm ("" : : "n" (x), "n" (foo () * 7 + x)); +} diff --git a/gcc/testsuite/g++.dg/torture/pr56302.C b/gcc/testsuite/g++.dg/torture/pr56302.C new file mode 100644 index 0000000..08d4798 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr56302.C @@ -0,0 +1,41 @@ +// PR c++/56302 +// { dg-do compile } + +typedef __SIZE_TYPE__ size_t; +# define STAP_SDT_ARG_CONSTRAINT nor +# define _SDT_STRINGIFY(x) #x +# define _SDT_ARG_CONSTRAINT_STRING(x) _SDT_STRINGIFY(x) +# define _SDT_ARG(n, x) \ + [_SDT_S##n] "n" ((_SDT_ARGSIGNED (x) ? 1 : -1) * (int) _SDT_ARGSIZE (x)), \ + [_SDT_A##n] _SDT_ARG_CONSTRAINT_STRING (STAP_SDT_ARG_CONSTRAINT) (_SDT_ARGVAL (x)) +#define _SDT_ARGARRAY(x) (__builtin_classify_type (x) == 14 \ + || __builtin_classify_type (x) == 5) +# define _SDT_ARGSIGNED(x) (!_SDT_ARGARRAY (x) \ + && __sdt_type<__typeof (x)>::__sdt_signed) +# define _SDT_ARGSIZE(x) (_SDT_ARGARRAY (x) \ + ? sizeof (void *) : sizeof (x)) +# define _SDT_ARGVAL(x) (x) +template<typename __sdt_T> +struct __sdt_type +{ + static const bool __sdt_signed = false; +}; +#define __SDT_ALWAYS_SIGNED(T) \ +template<> struct __sdt_type<T> { static const bool __sdt_signed = true; }; +__SDT_ALWAYS_SIGNED(signed char) +__SDT_ALWAYS_SIGNED(short) +__SDT_ALWAYS_SIGNED(int) +__SDT_ALWAYS_SIGNED(long) +__SDT_ALWAYS_SIGNED(long long) +template<typename __sdt_E> +struct __sdt_type<__sdt_E[]> : public __sdt_type<__sdt_E *> {}; +template<typename __sdt_E, size_t __sdt_N> +struct __sdt_type<__sdt_E[__sdt_N]> : public __sdt_type<__sdt_E *> {}; + +struct S { char p[8]; }; + +void +foo (const S &str) +{ + __asm__ __volatile__ ("" : : _SDT_ARG (0, &str)); +} |