forked from OSchip/llvm-project
Revert change that made isNullPointerConstant start emitting warnings. We don't want that :)
llvm-svn: 60333
This commit is contained in:
parent
2aebea5735
commit
eade3ad1f1
|
@ -181,7 +181,6 @@ public:
|
||||||
/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
|
/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
|
||||||
/// integer constant expression with the value zero, or if this is one that is
|
/// integer constant expression with the value zero, or if this is one that is
|
||||||
/// cast to void*.
|
/// cast to void*.
|
||||||
bool isNullPointerConstant(EvalResult &Result, ASTContext &Ctx) const;
|
|
||||||
bool isNullPointerConstant(ASTContext &Ctx) const;
|
bool isNullPointerConstant(ASTContext &Ctx) const;
|
||||||
|
|
||||||
/// hasGlobalStorage - Return true if this expression has static storage
|
/// hasGlobalStorage - Return true if this expression has static storage
|
||||||
|
|
|
@ -1009,12 +1009,6 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
|
||||||
/// cast to void*.
|
/// cast to void*.
|
||||||
bool Expr::isNullPointerConstant(ASTContext &Ctx) const
|
bool Expr::isNullPointerConstant(ASTContext &Ctx) const
|
||||||
{
|
{
|
||||||
EvalResult EvalResult;
|
|
||||||
|
|
||||||
return isNullPointerConstant(EvalResult, Ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Expr::isNullPointerConstant(EvalResult &Result, ASTContext &Ctx) const {
|
|
||||||
// Strip off a cast to void*, if it exists. Except in C++.
|
// Strip off a cast to void*, if it exists. Except in C++.
|
||||||
if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
|
if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
|
||||||
if (!Ctx.getLangOptions().CPlusPlus) {
|
if (!Ctx.getLangOptions().CPlusPlus) {
|
||||||
|
@ -1024,20 +1018,20 @@ bool Expr::isNullPointerConstant(EvalResult &Result, ASTContext &Ctx) const {
|
||||||
if (Pointee.getCVRQualifiers() == 0 &&
|
if (Pointee.getCVRQualifiers() == 0 &&
|
||||||
Pointee->isVoidType() && // to void*
|
Pointee->isVoidType() && // to void*
|
||||||
CE->getSubExpr()->getType()->isIntegerType()) // from int.
|
CE->getSubExpr()->getType()->isIntegerType()) // from int.
|
||||||
return CE->getSubExpr()->isNullPointerConstant(Result, Ctx);
|
return CE->getSubExpr()->isNullPointerConstant(Ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
|
} else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
|
||||||
// Ignore the ImplicitCastExpr type entirely.
|
// Ignore the ImplicitCastExpr type entirely.
|
||||||
return ICE->getSubExpr()->isNullPointerConstant(Result, Ctx);
|
return ICE->getSubExpr()->isNullPointerConstant(Ctx);
|
||||||
} else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
|
} else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
|
||||||
// Accept ((void*)0) as a null pointer constant, as many other
|
// Accept ((void*)0) as a null pointer constant, as many other
|
||||||
// implementations do.
|
// implementations do.
|
||||||
return PE->getSubExpr()->isNullPointerConstant(Result, Ctx);
|
return PE->getSubExpr()->isNullPointerConstant(Ctx);
|
||||||
} else if (const CXXDefaultArgExpr *DefaultArg
|
} else if (const CXXDefaultArgExpr *DefaultArg
|
||||||
= dyn_cast<CXXDefaultArgExpr>(this)) {
|
= dyn_cast<CXXDefaultArgExpr>(this)) {
|
||||||
// See through default argument expressions
|
// See through default argument expressions
|
||||||
return DefaultArg->getExpr()->isNullPointerConstant(Result, Ctx);
|
return DefaultArg->getExpr()->isNullPointerConstant(Ctx);
|
||||||
} else if (isa<GNUNullExpr>(this)) {
|
} else if (isa<GNUNullExpr>(this)) {
|
||||||
// The GNU __null extension is always a null pointer constant.
|
// The GNU __null extension is always a null pointer constant.
|
||||||
return true;
|
return true;
|
||||||
|
@ -1049,8 +1043,12 @@ bool Expr::isNullPointerConstant(EvalResult &Result, ASTContext &Ctx) const {
|
||||||
|
|
||||||
// If we have an integer constant expression, we need to *evaluate* it and
|
// If we have an integer constant expression, we need to *evaluate* it and
|
||||||
// test for the value 0.
|
// test for the value 0.
|
||||||
|
// FIXME: We should probably return false if we're compiling in strict mode
|
||||||
|
// and Diag is not null (this indicates that the value was foldable but not
|
||||||
|
// an ICE.
|
||||||
|
EvalResult Result;
|
||||||
return Evaluate(Result, Ctx) && !Result.HasSideEffects &&
|
return Evaluate(Result, Ctx) && !Result.HasSideEffects &&
|
||||||
Result.Val.isInt() && Result.Val.getInt() == 0;
|
Result.Val.isInt() && Result.Val.getInt() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isBitField - Return true if this expression is a bit-field.
|
/// isBitField - Return true if this expression is a bit-field.
|
||||||
|
|
|
@ -1352,8 +1352,6 @@ public:
|
||||||
/// Can optionally return the value of the expression.
|
/// 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
|
// Extra semantic analysis beyond the C type system
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1582,13 +1582,13 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
|
||||||
// the type of the other operand."
|
// the type of the other operand."
|
||||||
if ((lexT->isPointerType() || lexT->isBlockPointerType() ||
|
if ((lexT->isPointerType() || lexT->isBlockPointerType() ||
|
||||||
Context.isObjCObjectPointerType(lexT)) &&
|
Context.isObjCObjectPointerType(lexT)) &&
|
||||||
isNullPointerConstant(rex)) {
|
rex->isNullPointerConstant(Context)) {
|
||||||
ImpCastExprToType(rex, lexT); // promote the null to a pointer.
|
ImpCastExprToType(rex, lexT); // promote the null to a pointer.
|
||||||
return lexT;
|
return lexT;
|
||||||
}
|
}
|
||||||
if ((rexT->isPointerType() || rexT->isBlockPointerType() ||
|
if ((rexT->isPointerType() || rexT->isBlockPointerType() ||
|
||||||
Context.isObjCObjectPointerType(rexT)) &&
|
Context.isObjCObjectPointerType(rexT)) &&
|
||||||
isNullPointerConstant(lex)) {
|
lex->isNullPointerConstant(Context)) {
|
||||||
ImpCastExprToType(lex, rexT); // promote the null to a pointer.
|
ImpCastExprToType(lex, rexT); // promote the null to a pointer.
|
||||||
return rexT;
|
return rexT;
|
||||||
}
|
}
|
||||||
|
@ -3706,23 +3706,3 @@ bool Sema::VerifyIntegerConstantExpression(const Expr* E, llvm::APSInt *Result)
|
||||||
*Result = EvalResult.Val.getInt();
|
*Result = EvalResult.Val.getInt();
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue