From 3f12f6e9145ea69e9da7e9e180100e5ce7ca3ee9 Mon Sep 17 00:00:00 2001 From: Senthil Kumar Selvaraj Date: Mon, 29 Apr 2013 13:28:44 +0000 Subject: [PATCH] c-common.c (check_user_alignment): Emit error for negative values. c-family: 2013-04-03 Senthil Kumar Selvaraj * c-common.c (check_user_alignment): Emit error for negative values. testsuite: 2013-04-03 Senthil Kumar Selvaraj * gcc.dg/c1x-align-3.c: Add test for negative power of 2. From-SVN: r198417 --- gcc/c-family/ChangeLog | 4 ++++ gcc/c-family/c-common.c | 5 +++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/c1x-align-3.c | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 39390db..c28efd4 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2013-04-29 Senthil Kumar Selvaraj + + * c-common.c (check_user_alignment): Emit error for negative values. + 2013-04-24 Paolo Carlini * c-opts.c (set_std_cxx11): Use CLK_CXX1Y and CLK_GNUCXX1Y. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index b29f5fa..8d88b26 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7302,9 +7302,10 @@ check_user_alignment (const_tree align, bool allow_zero) } else if (allow_zero && integer_zerop (align)) return -1; - else if ((i = tree_log2 (align)) == -1) + else if (tree_int_cst_sgn (align) == -1 + || (i = tree_log2 (align)) == -1) { - error ("requested alignment is not a power of 2"); + error ("requested alignment is not a positive power of 2"); return -1; } else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c1db93b..ea304a0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-04-29 Senthil Kumar Selvaraj + + * gcc.dg/c1x-align-3.c: Add test for negative power of 2. + 2013-04-29 Tom de Vries * gcc.dg/pr50763.c: Update test. diff --git a/gcc/testsuite/gcc.dg/c1x-align-3.c b/gcc/testsuite/gcc.dg/c1x-align-3.c index 0b2a77f..b97351c 100644 --- a/gcc/testsuite/gcc.dg/c1x-align-3.c +++ b/gcc/testsuite/gcc.dg/c1x-align-3.c @@ -23,6 +23,7 @@ _Alignas (-(__LONG_LONG_MAX__-1)/4) char i3; /* { dg-error "too large|power of 2 _Alignas (-(__LONG_LONG_MAX__-1)/8) char i4; /* { dg-error "too large|power of 2" } */ _Alignas (-(__LONG_LONG_MAX__-1)/16) char i5; /* { dg-error "too large|power of 2" } */ _Alignas (-1) char j; /* { dg-error "power of 2" } */ +_Alignas (-2) char j; /* { dg-error "positive power of 2" } */ _Alignas (3) char k; /* { dg-error "power of 2" } */ _Alignas ((void *) 1) char k; /* { dg-error "integer constant" } */ -- 2.7.4