[cfe-dev] Adding access to array size expressions in ConstantArrayType.

Enea Zaffanella zaffanella at cs.unipr.it
Tue Jun 30 12:35:59 PDT 2009

Eli Friedman wrote:
> On Wed, Jun 24, 2009 at 2:45 AM, Enea Zaffanella<zaffanella at cs.unipr.it> wrote:
>> We have an issue we do not know how to solve, but we believe should be
>> routine for someone knowing more about clang internals (there are a couple
>> of FIXME in the patch). The problem is in SemaDecl.cpp:
>> static QualType
>> TryToFixInvalidVariablyModifiedType(QualType T,
>>                                    ASTContext &Context,
>>                                    bool &SizeIsNegative)
>> Here we need to transform a VariableArray into a ConstantArrayWithExpr. To
>> avoid resource ownership issues, we should either steal or clone the VLA
>> size expression and put it in the ConstantArrayWithExpr.
>> Since we do not know how to do it, in the proposed patch we simply copy the
>> SizeExpr pointer as is ... leading to a shared resource. To avoid the
>> double-deletion problem, we do *not* delete it in the destructor of
>> ConstantArrayWithExpr.
> The ownership is already kind of messy here; it's okay to leave it
> like that for now.  Eventually, we want the parent Decl to destroy it,
> I think.
>> Regarding the addition of SourceLocation's for the array brackets: we
>> haven't implemented it (yet). I guess that, in order to do it, we should
>> change something in the parsing process (i.e., before the AST build process)
>> so as to gather and propagate the required info.
>> Could you please provide us with a hint regarding the portions of code we
>> should modify?
> getSourceRange on a Declarator has the right locations, I think.
> -Eli


Here is the completed patch, where the array type classes have a new method

   SourceRange getBracketsRange() const;

returning the source range going from the left to the right bracket 
tokens. Additional helper methods have been added to get just one of the 
two bracket locations:

   SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
   SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }

According to the tests we made, everything is working as expected.
We hope to see the patch applied soon.

Enea Zaffanella.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ConstantArrayWithExprAndBrackets.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090630/dc1db53d/attachment.ksh>

More information about the cfe-dev mailing list