LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 16986 - attribute vector_size doesn't allow value dependent expressions in templates
Summary: attribute vector_size doesn't allow value dependent expressions in templates
Status: RESOLVED DUPLICATE of bug 15730
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-24 05:25 PDT by Artur Bać
Modified: 2020-08-05 03:39 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Artur Bać 2013-08-24 05:25:05 PDT
template<typename T>
union point 
{ 
  T vec __attribute__((__vector_size__((sizeof(T)<<1))));
 struct { T x,y; }; 
 };

error: '__vector_size__' attribute requires an integer constant
  T vec __attribute__((__vector_size__((sizeof(T)<<1))));
                       ^               ~~~~~~~~~~~~~~
Comment 1 Richard Smith 2013-08-25 17:33:41 PDT
We should generalize the handling of dependent expressions from the alignment attributes to deal with this case too.
Comment 2 David Abdurachmanov 2014-11-16 06:07:56 PST
I hit the same issue.

typedef double __attribute__( ( vector_size( 64 ) ) ) float64x8_v0_t;
typedef double __attribute__( ( vector_size( 32 * 2 ) ) ) float64x8_v1_t;
typedef double __attribute__( ( vector_size( sizeof(double) * 8 ) ) ) float64x8_v2_t;

template<typename T, int N>
struct Traits {
  typedef T __attribute__( ( vector_size( N*sizeof(T) ) ) ) type; // the following fails
};

test.cc:13:30: error: 'vector_size' attribute requires an integer constant
  typedef T __attribute__( ( vector_size( N*sizeof(T) ) ) ) type;

Any updates?
Comment 3 Alexey Frolov 2015-06-15 05:50:19 PDT
(In reply to comment #1)
> We should generalize the handling of dependent expressions from the
> alignment attributes to deal with this case too.

Richard, as far as I know, alignment attributes only appertain to variables or typedefs (which both have AST nodes). I don't think we can generalize this approach for vector_size attribute as it appertains to types (which do not have AST nodes).
What about creating a new property for VectorType that would state that this vector type is dependent (dependent vector types are vector types with dependent base types and/or dependent size expressions)? It seems to be somewhat more appropriate to me.
What do you think?
Comment 4 Yichao Yu 2019-03-19 18:19:12 PDT
This seems to be fixed on 7.0 ?

I can still reproduce the issue with both versions above on a clang 6.0.0 from a Ubuntu 18.04.2 but I don't have this issue anymore on a clang 7.0.1 from an up to date ArchLinux.
Comment 5 Yichao Yu 2019-03-19 18:23:51 PDT
And as a workaround on older version. The solution from https://stackoverflow.com/a/48377726/904262 seems to work if you can use a typedef. The resulting vector type seems to have the correct layout and C++ name mangling so I assume it's the correct type...
Comment 6 Lars Frydendal Bonnichsen 2020-08-05 03:39:36 PDT

*** This bug has been marked as a duplicate of bug 15730 ***