We ICE in handle_assume_aligned_attribute since r271338 which added
@@ -2935,8 +2936,8 @@ handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
/* The misalignment specified by the second argument
must be non-negative and less than the alignment. */
warning (OPT_Wattributes,
- "%qE attribute argument %E is not in the range [0, %E)",
- name, val, align);
+ "%qE attribute argument %E is not in the range [0, %wu]",
+ name, val, tree_to_uhwi (align) - 1);
*no_add_attrs = true;
return NULL_TREE;
}
because align is INT_MIN and tree_to_uhwi asserts tree_fits_uhwi_p -- which
ALIGN does not and the prior tree_fits_shwi_p check is fine with it, as
well as the integer_pow2p check.
Since neither of the arguments to assume_aligned can be negative, I've
hoisted the tree_int_cst_sgn check. And add the missing "argument"
word to an existing warning.
gcc/c-family/ChangeLog:
PR c++/99062
* c-attribs.c (handle_assume_aligned_attribute): Check that the
alignment argument is non-negative. Tweak a warning message.
gcc/testsuite/ChangeLog:
PR c++/99062
* gcc.dg/attr-assume_aligned-4.c: Adjust dg-warning.
* g++.dg/ext/attr-assume-aligned.C: New test.
if (!tree_fits_shwi_p (val))
{
warning (OPT_Wattributes,
- "%qE attribute %E is not an integer constant",
+ "%qE attribute argument %E is not an integer constant",
name, val);
*no_add_attrs = true;
return NULL_TREE;
}
+ else if (tree_int_cst_sgn (val) < 0)
+ {
+ warning (OPT_Wattributes,
+ "%qE attribute argument %E is not positive", name, val);
+ *no_add_attrs = true;
+ return NULL_TREE;
+ }
if (!align)
{
align = val;
}
- else if (tree_int_cst_sgn (val) < 0 || tree_int_cst_le (align, val))
+ else if (tree_int_cst_le (align, val))
{
/* The misalignment specified by the second argument
must be non-negative and less than the alignment. */
--- /dev/null
+// PR c++/99062
+// { dg-do compile }
+
+#define INT_MIN (-__INT_MAX__ - 1)
+void *f () __attribute__ ((assume_aligned (INT_MIN, 4))); // { dg-warning "is not positive" }
A (1) int fi_1 (void); /* { dg-warning ".assume_aligned. attribute ignored on a function returning .int." } */
-A (-1) void* fpv_m1 (void); /* { dg-warning ".assume_aligned. attribute argument -1 is not a power of 2" } */
+A (-1) void* fpv_m1 (void); /* { dg-warning ".assume_aligned. attribute argument -1 is not positive" } */
A (0) void* fpv_0 (void); /* { dg-warning ".assume_aligned. attribute argument 0 is not a power of 2" } */
A (32767) void* fpv_32km1 (void); /* { dg-warning ".assume_aligned. attribute argument 32767 is not a power of 2" } */
-A (4, -1) void* fpv_4_m1 (void); /* { dg-warning ".assume_aligned. attribute argument -1 is not in the range \\\[0, 3]" } */
+A (4, -1) void* fpv_4_m1 (void); /* { dg-warning ".assume_aligned. attribute argument -1 is not positive" } */
A (4, 0) void* fpv_4_0 (void);
A (4, 1) void* fpv_4_1 (void);