[cfe-commits] r64308 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaStmt.cpp test/Parser/objc-try-catch-1.m test/SemaObjC/try-catch.m

Fariborz Jahanian fjahanian at apple.com
Wed Feb 11 10:39:05 PST 2009


On Feb 11, 2009, at 10:30 AM, steve naroff wrote:

>
> On Feb 11, 2009, at 1:15 PM, Chris Lattner wrote:
>
>> On Feb 11, 2009, at 9:45 AM, Steve Naroff wrote:
>>> Log:
>>> Fix <rdar://problem/6206858> [sema] type check @throw statements.
>>>
>>
>> Thanks!
>>
>>> +Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr) {
>>> +  Expr *ThrowExpr = static_cast<Expr*>(expr.release());
>>> +  if (!ThrowExpr) {
>>> +    // FIXME: verify the 'rethrow' is within a @catch block
>>> +  } else {
>>> +    QualType ThrowType = ThrowExpr->getType();
>>> +    // Make sure the expression type is an ObjC pointer or "void  
>>> *".
>>> +    if (!Context.isObjCObjectPointerType(ThrowType)) {
>>> +      const PointerType *PT = ThrowType->getAsPointerType();
>>> +      if (!PT || !PT->getPointeeType()->isVoidType())
>>> +        // This should be an error, however GCC only yields a
>>> warning.
>>> +        Diag(AtLoc, diag::warn_objc_throw_expects_object)
>>> +                    << ThrowExpr->getType() << ThrowExpr-
>>>> getSourceRange();
>>
>>
>> Shouldn't this reject aggregates with an error?
>>
>
> I'd prefer we make this an error for all cases (rather than a mix of
> errors/warnings).
>
> GCC's "implicit" diagnostics (based on the underlying function call/
> ABI) seem like a poor model for clang to follow (in retrospect).

Yes, gcc should not point to underlying API for diagnostics. You may  
want
to file a radar against gcc.

- Fariborz

>
>
> What do you think?
>
> snaroff
>
> Here is a small test case below (with clang/gcc output).
>
> [steve-naroffs-macbook-pro:~/llvm/tools/clang] snaroffBook% ../../
> Debug/bin/clang throw.m
> throw.m:5:3: warning: invalid 'int' argument (expected an ObjC object
> type)
>   @throw 42;
>   ^      ~~
> throw.m:6:3: warning: invalid 'struct s' argument (expected an ObjC
> object type)
>   @throw agg;
>   ^      ~~~
> throw.m:7:3: warning: invalid 'struct s *' argument (expected an ObjC
> object type)
>   @throw pagg;
>   ^      ~~~~
> 3 diagnostics generated.
> [steve-naroffs-macbook-pro:~/llvm/tools/clang] snaroffBook% cc -c
> throw.m
> throw.m: In function ‘foo’:
> throw.m:5: warning: passing argument 1 of ‘objc_exception_throw’ makes
> pointer from integer without a cast
> throw.m:6: error: incompatible type for argument 1 of
> ‘objc_exception_throw’
> throw.m:7: warning: passing argument 1 of ‘objc_exception_throw’ from
> incompatible pointer type
> [steve-naroffs-macbook-pro:~/llvm/tools/clang] snaroffBook% cat  
> throw.m
>
> int foo() {
>   struct s { int a, b; } agg, *pagg;
>
>   @throw 42;
>   @throw agg;
>   @throw pagg;
> }
>
>> -Chris
>
>
> _______________________________________________
> 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