Bug 69022 - attribute vector_size ignored with dependent bytes
Summary: attribute vector_size ignored with dependent bytes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Martin Sebor
URL:
Keywords: rejects-valid
Depends on:
Blocks: 68703
  Show dependency treegraph
 
Reported: 2015-12-22 22:41 UTC by Martin Sebor
Modified: 2016-08-07 23:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-12-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2015-12-22 22:41:28 UTC
While working on a fix for bug 58109 (and bug 69020) I came across another instance of attribute vector_size not being handled correctly (in addition to bug 35758 and bug 38260).  In the following test case, the attribute is accepted on all declarations except that of c.  As in bug 58109, the problem in this case also seems to be in the is_late_template_attribute() function which fails to treat the argument as dependent.

$ cat x.cpp && /build/gcc-trunk-svn/gcc/xg++ -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic -o/dev/null x.cpp 
template <int N>
struct A { static const int X = N; };

#define ASSERT(e) static_assert (e, #e)

template <class T, int N>
struct B: A<N>
{
    using A<N>::X;

    static void foo ()
    {
        char a __attribute__ ((vector_size (N)));
        ASSERT (sizeof a == N);

        T b __attribute__ ((vector_size (N)));
        ASSERT (sizeof b == N);
    }

    static void bar ()
    {
        char c __attribute__ ((vector_size (X)));
        ASSERT (sizeof c == X);

        T d __attribute__ ((vector_size (X)));
        ASSERT (sizeof d == X);
    }
};

void bar ()
{
    B<int, 16>::foo ();
    B<int, 16>::bar ();
}

x.cpp: In static member function ‘static void B<T, N>::bar()’:
x.cpp:22:48: warning: ‘vector_size’ attribute ignored [-Wattributes]
         char c __attribute__ ((vector_size (X)));
                                                ^

x.cpp: In instantiation of ‘static void B<T, N>::bar() [with T = int; int N = 16]’:
x.cpp:33:17:   required from here
x.cpp:4:19: error: static assertion failed: sizeof c == X
 #define ASSERT(e) static_assert (e, #e)
                   ^

x.cpp:23:9: note: in expansion of macro ‘ASSERT’
         ASSERT (sizeof c == X);
         ^~~~~~
Comment 1 Martin Sebor 2015-12-22 22:42:20 UTC
I'll try to fix this in the same patch as bug 58109.
Comment 2 Martin Sebor 2015-12-23 04:48:50 UTC
Patch posted for review:
https://gcc.gnu.org/ml/gcc-patches/2015-12/msg02074.html
Comment 3 Martin Sebor 2016-01-23 16:02:19 UTC
Author: msebor
Date: Sat Jan 23 16:01:47 2016
New Revision: 232766

URL: https://gcc.gnu.org/viewcvs?rev=232766&root=gcc&view=rev
Log:
PR c++/58109 - alignas() fails to compile with constant expression
PR c++/69022 - attribute vector_size ignored with dependent bytes
    
gcc/testsuite/ChangeLog:
2016-01-23  Martin Sebor  <msebor@redhat.com>
    
	PR c++/58109
	PR c++/69022
	* g++.dg/cpp0x/alignas5.C: New test.
	* g++.dg/ext/vector29.C: Same.
    
gcc/cp/ChangeLog:
2016-01-23  Martin Sebor  <msebor@redhat.com>
    
	PR c++/58109
	PR c++/69022
	* decl2.c (is_late_template_attribute): Handle dependent argument
 	to attribute align and attribute vector_size.

Added:
    trunk/gcc/testsuite/g++.dg/ext/vector29.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/cpp0x/alignas5.C
Comment 4 Martin Sebor 2016-01-23 16:04:15 UTC
Fixed by r232766.
Comment 5 Andrew Pinski 2016-08-07 23:37:17 UTC
This does not fully handle vector_size, see bug #68703.