[cfe-commits] [PATCH] CallExprs returning references can be lvalues

Zhongxing Xu xuzhongxing at gmail.com
Wed Jun 2 21:48:50 PDT 2010


On Thu, Jun 3, 2010 at 12:21 PM, Zhongxing Xu <xuzhongxing at gmail.com> wrote:

> Hi Jordy,
>
> One small suggestion: It's easier to review if each patch only solves one
> specific problem. We'd like small patches that fix one well defined and
> isolated problem.
>
> Comments below:
>
> Index: lib/Analysis/CFG.cpp
> ===================================================================
> --- lib/Analysis/CFG.cpp    (revision 105255)
> +++ lib/Analysis/CFG.cpp    (working copy)
> @@ -538,6 +538,15 @@
>      addStmt(B->getRHS());
>      return addStmt(B->getLHS());
>    }
> +  else if (B->isAssignmentOp()) {
> +    if (asc.alwaysAdd()) {
> +      autoCreateBlock();
> +      AppendStmt(Block, B, asc);
> +    }
> +
> +    addStmt(B->getRHS());
>
> Is it necessary to add all RHS of assignment expr as block-level expr?
>
> +    return addStmt(B->getLHS(), AddStmtChoice::AsLValueNotAlwaysAdd);
> +  }
>

Here better to use visitStmt, because addStmt() means we want to 'add' the
statement. Maybe we should modify some of the existing code to emphasize
this.


>
>
> On Thu, Jun 3, 2010 at 6:19 AM, Jordy Rose <jediknil at belkadan.com> wrote:
>
>> Fixes a crasher, by allowing CallExprs to be lvalues, and making sure
>> assignment LHSes are treated as lvalues.
>>
>> char& ref();
>> void t5 () {
>>  ref() = 'c';
>> }
>>
>> And an incorrect "undefined dereference" warning, by noting that assigning
>> to a reference variable does not kill its value.
>>
>> char t1 () {
>>  char& r = ref();
>>  r = 'c'; // no-warning
>>  if (r) return r;
>>  return *(char*)0; // no-warning
>> }
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100603/9ae63f5b/attachment.html>


More information about the cfe-commits mailing list