[cfe-commits] r154595 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Rewriter/objc-bool-literal-modern-1.mm test/SemaObjCXX/literals.mm

John McCall rjmccall at apple.com
Thu Apr 12 12:10:39 PDT 2012


On Apr 12, 2012, at 10:49 AM, Fariborz Jahanian wrote:
> Author: fjahanian
> Date: Thu Apr 12 12:49:18 2012
> New Revision: 154595
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=154595&view=rev
> Log:
> objective-c numeric literal: type of boolean is
> that of typedef BOOL if found.
> // rdar://11231426
> 
> Added:
>    cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm
> Modified:
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/test/SemaObjCXX/literals.mm
> 
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154595&r1=154594&r2=154595&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Apr 12 12:49:18 2012
> @@ -11259,6 +11259,18 @@
> Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
>   assert((Kind == tok::kw___objc_yes || Kind == tok::kw___objc_no) &&
>          "Unknown Objective-C Boolean value!");
> +  QualType ObjCBoolLiteralQT = Context.ObjCBuiltinBoolTy;
> +  // signed char is the default type for boolean literals. Use 'BOOL'
> +  // instead, if BOOL typedef is visible in its scope instead.
> +  Decl *TD = 
> +    LookupSingleName(TUScope, &Context.Idents.get("BOOL"), 
> +                     SourceLocation(), LookupOrdinaryName);
> +  if (TypeDecl *BoolTD = dyn_cast_or_null<TypeDecl>(TD)) {
> +    QualType QT = QualType(BoolTD->getTypeForDecl(), 0);
> +    if (!QT.isNull())
> +      ObjCBoolLiteralQT = QT;
> +  }

If you use Context.getTypeForDecl, this can never be null.

Also, you should only do this when the BOOL type is canonically
equivalent to Context.ObjCBuiltinBoolTy, or else this will really blow
up later on.

John.



More information about the cfe-commits mailing list