diff options
| author | Anders Carlsson <andersca@mac.com> | 2008-12-01 02:17:22 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2008-12-01 02:17:22 +0000 |
| commit | 1dbffc6e3661938392895c33a28feab5b01ea99e (patch) | |
| tree | fe8ddeda26db7c2cdb8267812cf2f182a749fedc /clang/lib | |
| parent | 4bb9113da462c857fc962b483a41e3df5dfe74e1 (diff) | |
| download | bcm5719-llvm-1dbffc6e3661938392895c33a28feab5b01ea99e.tar.gz bcm5719-llvm-1dbffc6e3661938392895c33a28feab5b01ea99e.zip | |
Add Sema::isNullPointerConstant which extwarns if necessary. Use it in Sema::CheckConditionalOperands.
llvm-svn: 60319
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 24 |
2 files changed, 25 insertions, 3 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 7b69de5cc24..17af72ad9d8 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -1350,7 +1350,9 @@ public: /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, /// and reports the appropriate diagnostics. Returns false on success. /// Can optionally return the value of the expression. - bool VerifyIntegerConstantExpression(const Expr* E, llvm::APSInt *Result = 0); + bool VerifyIntegerConstantExpression(const Expr*E, llvm::APSInt *Result = 0); + + bool isNullPointerConstant(const Expr *E); //===--------------------------------------------------------------------===// // Extra semantic analysis beyond the C type system diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0c17c75fceb..fa4b71b5bd7 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1582,13 +1582,13 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15 // the type of the other operand." if ((lexT->isPointerType() || lexT->isBlockPointerType() || Context.isObjCObjectPointerType(lexT)) && - rex->isNullPointerConstant(Context)) { + isNullPointerConstant(rex)) { ImpCastExprToType(rex, lexT); // promote the null to a pointer. return lexT; } if ((rexT->isPointerType() || rexT->isBlockPointerType() || Context.isObjCObjectPointerType(rexT)) && - lex->isNullPointerConstant(Context)) { + isNullPointerConstant(lex)) { ImpCastExprToType(lex, rexT); // promote the null to a pointer. return rexT; } @@ -3706,3 +3706,23 @@ bool Sema::VerifyIntegerConstantExpression(const Expr* E, llvm::APSInt *Result) *Result = EvalResult.Val.getInt(); return false; } + +bool Sema::isNullPointerConstant(const Expr *E) +{ + Expr::EvalResult EvalResult; + + if (!E->isNullPointerConstant(EvalResult, Context)) + return false; + + if (EvalResult.Diag) { + Diag(E->getExprLoc(), diag::ext_null_pointer_expr_not_ice) << + E->getSourceRange(); + + // Print the reason it's not a constant. + if (Diags.getDiagnosticLevel(diag::ext_null_pointer_expr_not_ice) != + Diagnostic::Ignored) + Diag(EvalResult.DiagLoc, EvalResult.Diag); + } + + return true; +} |

