From bae5cddff8b905bb49ed4e013e9756ebea13c099 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 12 Apr 2011 08:27:23 +0200 Subject: [PATCH] re PR c/48552 (ICE with void type expressions in asm inputs/outputs) PR c/48552 * c-typeck.c (build_asm_expr): Error out on attempts to use void type outputs or inputs for constraints that allow reg or don't allow memory. * gcc.dg/pr48552-1.c: New test. * gcc.dg/pr48552-2.c: New test. From-SVN: r172298 --- gcc/ChangeLog | 7 +++++ gcc/c-typeck.c | 14 ++++++++- gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/gcc.dg/pr48552-1.c | 53 ++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr48552-2.c | 53 ++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr48552-1.c create mode 100644 gcc/testsuite/gcc.dg/pr48552-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bf897c9b80e..3fe9cdb6214 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-04-12 Jakub Jelinek + + PR c/48552 + * c-typeck.c (build_asm_expr): Error out on attempts to use + void type outputs or inputs for constraints that allow reg or + don't allow memory. + 2011-04-11 Chung-Lin Tang Richard Earnshaw diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 049a8af8330..c386f56c775 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -8502,6 +8502,13 @@ build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, mark it addressable. */ if (!allows_reg && !c_mark_addressable (output)) output = error_mark_node; + if (!(!allows_reg && allows_mem) + && output != error_mark_node + && VOID_TYPE_P (TREE_TYPE (output))) + { + error_at (loc, "invalid use of void expression"); + output = error_mark_node; + } } else output = error_mark_node; @@ -8528,7 +8535,12 @@ build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, STRIP_NOPS (input); if (!c_mark_addressable (input)) input = error_mark_node; - } + } + else if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input))) + { + error_at (loc, "invalid use of void expression"); + input = error_mark_node; + } } else input = error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5efa1b5e63..6d657590c52 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-04-12 Jakub Jelinek + + PR c/48552 + * gcc.dg/pr48552-1.c: New test. + * gcc.dg/pr48552-2.c: New test. + 2011-04-11 Jason Merrill * g++.dg/cpp0x/sfinae12.C: New. diff --git a/gcc/testsuite/gcc.dg/pr48552-1.c b/gcc/testsuite/gcc.dg/pr48552-1.c new file mode 100644 index 00000000000..5590549a7ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr48552-1.c @@ -0,0 +1,53 @@ +/* PR c/48552 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S; + +void +f1 (void *x) +{ + __asm volatile ("" : : "r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */ + +void +f2 (void *x) +{ + __asm volatile ("" : "=r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */ +void +f3 (void *x) +{ + __asm volatile ("" : : "m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f4 (void *x) +{ + __asm volatile ("" : "=m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f5 (void *x) +{ + __asm volatile ("" : : "g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */ + +void +f6 (void *x) +{ + __asm volatile ("" : "=g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */ +void +f7 (struct S *x) +{ + __asm volatile ("" : : "r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} + +void +f8 (struct S *x) +{ + __asm volatile ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */ diff --git a/gcc/testsuite/gcc.dg/pr48552-2.c b/gcc/testsuite/gcc.dg/pr48552-2.c new file mode 100644 index 00000000000..4408279f8ac --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr48552-2.c @@ -0,0 +1,53 @@ +/* PR c/48552 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S; + +void +f1 (void *x) +{ + __asm ("" : : "r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */ + +void +f2 (void *x) +{ + __asm ("" : "=r" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */ +void +f3 (void *x) +{ + __asm ("" : : "m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f4 (void *x) +{ + __asm ("" : "=m" (*x)); /* { dg-warning "dereferencing" } */ +} + +void +f5 (void *x) +{ + __asm ("" : : "g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */ + +void +f6 (void *x) +{ + __asm ("" : "=g" (*x)); /* { dg-warning "dereferencing" } */ +} /* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */ + /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */ +void +f7 (struct S *x) +{ + __asm ("" : : "r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} + +void +f8 (struct S *x) +{ + __asm ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" } */ +} /* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */ -- 2.30.2