]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix up expr location for __builtin_stdc_rotate_* [PR118376]
authorJakub Jelinek <jakub@redhat.com>
Fri, 10 Jan 2025 14:07:41 +0000 (15:07 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 10 Jan 2025 14:07:41 +0000 (15:07 +0100)
Seems I forgot to set_c_expr_source_range for the __builtin_stdc_rotate_*
case (the other __builtin_stdc_* cases already have it), which means
the locations in expr are uninitialized, sometimes causing ICEs in linemap
code, at other times just valgrind errors about uninitialized var uses.

2025-01-10  Jakub Jelinek  <jakub@redhat.com>

PR c/118376
* c-parser.cc (c_parser_postfix_expression): Call
set_c_expr_source_range before break in the __builtin_stdc_rotate_*
case.

* gcc.dg/pr118376.c: New test.

gcc/c/c-parser.cc
gcc/testsuite/gcc.dg/pr118376.c [new file with mode: 0644]

index c46aac5f0a2b2a288b994eb1757eb96a93d3ae49..d2f45912cc43f2ba67b207dea21318cda2ef61d8 100644 (file)
@@ -12906,6 +12906,7 @@ c_parser_postfix_expression (c_parser *parser)
                  expr.value = build2_loc (loc, COMPOUND_EXPR,
                                           TREE_TYPE (expr.value),
                                           instrument_expr, expr.value);
+               set_c_expr_source_range (&expr, loc, close_paren_loc);
                break;
              }
            tree barg1 = arg;
diff --git a/gcc/testsuite/gcc.dg/pr118376.c b/gcc/testsuite/gcc.dg/pr118376.c
new file mode 100644 (file)
index 0000000..16b2f54
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/118376 */
+/* { dg-do compile } */
+/* { dg-options "-Wsign-conversion" } */
+
+unsigned x;
+
+void
+foo ()
+{
+  __builtin_memset (&x, (long long) __builtin_stdc_rotate_right (x, 0), 1);
+} /* { dg-warning "conversion to 'int' from 'long long int' may change the sign of the result" "" { target *-*-* } .-1 } */