[cfe-dev] Distinguish in the AST constant array declarations which size is set directly and by the initializer.
Paolo Bolzoni
bolzoni at cs.unipr.it
Wed Feb 18 08:46:03 PST 2009
On Wed, 18 Feb 2009 01:28:50 -0800
Eli Friedman <eli.friedman at gmail.com> wrote:
> On Wed, Feb 18, 2009 at 12:59 AM, Paolo Bolzoni <bolzoni at cs.unipr.it> wrote:
> > Visiting the clang AST, is there a way to distinguish between the arrays
> > a1 and a2 and the two unnamed objects whose address will be stored in p1
> > and p2?
>
> No, we don't distinguish those cases at the moment. Patches welcome,
> I guess, but I'm not sure where the best place to note it would be.
> -Eli
About arrays, I noticed there was still one free bit pattern (2 bit
allocated, 3 possible size modifiers) so I added NormalImplicit
size modifier that has the same meaning of Normal but indicates that the size
was implicitly defined by the initialiser.
When Sema::AddInitializerToDecl notices the change of type from VariableArray
to ConstantArray it creates a new array type with NormalImplicit as size
modifier.
Here is code:
if (ConstantArrayType* T = cast<ConstantArrayType>(DclT.getTypePtr())) {
if(isa<IncompleteArrayType>(SavT.getTypePtr())) {
assert(T-> getSizeModifier() == ArrayType::Normal);
DclT = Context.getConstantArrayType(T->getElementType(),
T->getSize(),
ArrayType::NormalImplicit,
T->getIndexTypeQualifier());
ConstantArrayType* T1 = cast<ConstantArrayType>(DclT.getTypePtr());
assert(T1-> getSizeModifier() == ArrayType::NormalImplicit);
}
}
Unfortunately, it happens that the second assert fails because
getConstantArrayType returns the previous QualType instead of a new one.
This is caused by the fact that two constant array types are considered
identical no matter the storage class.
I enclosed a patch to this message, it should work using patch -p0 in
the llvm directory.
A real code example where you can see the problem is this one:
void f(int b[5][static 5]);
int a[5][5];
the size storage `static' appears also in the latter array definition.
Thanks,
pb
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.tar.gz
Type: application/x-gzip
Size: 718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090218/c45ea2f9/attachment.bin>
More information about the cfe-dev
mailing list