[cfe-commits] r138975 - /cfe/trunk/lib/Sema/SemaExpr.cpp

Richard Trieu rtrieu at google.com
Mon Sep 12 11:46:10 PDT 2011


On Fri, Sep 2, 2011 at 4:16 AM, Sebastian Redl
<sebastian.redl at getdesigned.at> wrote:
> On 02.09.2011 00:53, Richard Trieu wrote:
>> Author: rtrieu
>> Date: Thu Sep  1 17:53:23 2011
>> New Revision: 138975
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=138975&view=rev
>> Log:
>> Refactor CheckAdditionOperands(), CheckSubtractionOperands(), and CheckIncrementDecrementOperand() in SemaExpr.cpp to move reused code to separate functions.
> Beautiful. Some comments inline.
>>
>> Modified:
>>      cfe/trunk/lib/Sema/SemaExpr.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=138975&r1=138974&r2=138975&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep  1 17:53:23 2011
>> @@ -5822,6 +5822,30 @@
>>     return true;
>>   }
>>
>> +/// \brief Check bad cases where we step over interface counts.
>> +static bool checkArithmethicPointerOnNonFragileABI(Sema&S,
>> +                                                   SourceLocation OpLoc,
>> +                                                   Expr *Op) {
>> +  assert(Op->getType()->isAnyPointerType());
>> +  QualType PointeeTy = Op->getType()->getPointeeType();
>> +  if (!PointeeTy->isObjCObjectType() || !S.LangOpts.ObjCNonFragileABI)
>> +    return true;
>> +
>> +  S.Diag(OpLoc, diag::err_arithmetic_nonfragile_interface)
>> +<<  PointeeTy<<  Op->getSourceRange();
>> +  return false;
>> +}
>
> Clang's convention is to return true on error.
This function is next to several others which has the opposite return
value.  A future clean up should deal with all the functions together
to keep things consistent locally.
>
>> +
>> +/// \brief Warn when two pointers are incompatible.
>> +static void diagnosePointerIncompatibility(Sema&S, SourceLocation Loc,
>> +                                           Expr *LHS, Expr *RHS) {
>> +  assert(LHS->getType()->isAnyPointerType());
>> +  assert(RHS->getType()->isAnyPointerType());
>> +  S.Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
>> +<<  LHS->getType()<<  RHS->getType()<<  LHS->getSourceRange()
>> +<<  RHS->getSourceRange();
>> +}
>> +
>
> The comment says "warn", the diagnostic says "err". Which is right?
Fixed the comment in r139510.  Error is correct.
>
>>   QualType Sema::CheckAdditionOperands( // C99 6.5.6
>>     ExprResult&lex, ExprResult&rex, SourceLocation Loc, QualType* CompLHSTy) {
>>     if (lex.get()->getType()->isVectorType() ||
>> @@ -5855,11 +5879,8 @@
>>         QualType PointeeTy = PExp->getType()->getPointeeType();
>>
>>         // Diagnose bad cases where we step over interface counts.
>> -      if (PointeeTy->isObjCObjectType()&&  LangOpts.ObjCNonFragileABI) {
>> -        Diag(Loc, diag::err_arithmetic_nonfragile_interface)
>> -<<  PointeeTy<<  PExp->getSourceRange();
>> +      if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, PExp))
>>           return QualType();
>> -      }
>>
>>         // Check array bounds for pointer arithemtic
>>         CheckArrayAccess(PExp, IExp);
>> @@ -5909,11 +5930,8 @@
>>       QualType lpointee = lex.get()->getType()->getPointeeType();
>>
>>       // Diagnose bad cases where we step over interface counts.
>> -    if (lpointee->isObjCObjectType()&&  LangOpts.ObjCNonFragileABI) {
>> -      Diag(Loc, diag::err_arithmetic_nonfragile_interface)
>> -<<  lpointee<<  lex.get()->getSourceRange();
>> +    if (!checkArithmethicPointerOnNonFragileABI(*this, Loc, lex.get()))
>>         return QualType();
>> -    }
>>
>>       // The result type of a pointer-int computation is the pointer type.
>>       if (rex.get()->getType()->isIntegerType()) {
>> @@ -5938,19 +5956,14 @@
>>         if (getLangOptions().CPlusPlus) {
>>           // Pointee types must be the same: C++ [expr.add]
>>           if (!Context.hasSameUnqualifiedType(lpointee, rpointee)) {
>> -          Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
>> -<<  lex.get()->getType()<<  rex.get()->getType()
>> -<<  lex.get()->getSourceRange()<<  rex.get()->getSourceRange();
>> -          return QualType();
>> +          diagnosePointerIncompatibility(*this, Loc, lex.get(), rex.get());
>
> What happened to the early return?
r139520 changes this the pointer addition check to use early exit.
>
> Sebastian
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list