aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-11-29 00:56:49 +0000
committerTed Kremenek <kremenek@apple.com>2007-11-29 00:56:49 +0000
commit720c4ec57b6110873cd533ad434853a27e7c3f4a (patch)
tree7d33954c252aa1b8764c56145eb69cd7ce99ed80
parent32e61bf91fba3c7946b9f71918202e5e55859a5c (diff)
Added "isExact" field to FloatingLiteral. This flag indicates whether or not
the APFloat representing the parsed literal can represent the literal value exactly. This is useful when performing various semantic checks on the code, and issuing appropriate warnings to users. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44423 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/StmtSerialization.cpp4
-rw-r--r--Sema/SemaExpr.cpp8
-rw-r--r--include/clang/AST/Expr.h8
3 files changed, 15 insertions, 5 deletions
diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp
index 3134f8859c..120b68e5c5 100644
--- a/AST/StmtSerialization.cpp
+++ b/AST/StmtSerialization.cpp
@@ -507,14 +507,16 @@ DoStmt* DoStmt::CreateImpl(Deserializer& D) {
void FloatingLiteral::EmitImpl(Serializer& S) const {
S.Emit(Loc);
S.Emit(getType());
+ S.EmitBool(isExact());
S.Emit(Value);
}
FloatingLiteral* FloatingLiteral::CreateImpl(Deserializer& D) {
SourceLocation Loc = SourceLocation::ReadVal(D);
QualType t = QualType::ReadVal(D);
+ bool isExact = D.ReadBool();
llvm::APFloat Val = llvm::APFloat::ReadVal(D);
- FloatingLiteral* expr = new FloatingLiteral(Val,t,Loc);
+ FloatingLiteral* expr = new FloatingLiteral(Val,&isExact,t,Loc);
return expr;
}
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 14302aab08..336dca716e 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -188,8 +188,12 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Context.Target.getDoubleInfo(Size, Align, Format, Tok.getLocation());
}
- Res = new FloatingLiteral(Literal.GetFloatValue(*Format), Ty,
- Tok.getLocation());
+ // isExact will be set by GetFloatValue().
+ bool isExact = false;
+
+ Res = new FloatingLiteral(Literal.GetFloatValue(*Format,&isExact), &isExact,
+ Ty, Tok.getLocation());
+
} else if (!Literal.isIntegerLiteral()) {
return ExprResult(true);
} else {
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 7ee3afc6b7..91cee5ef00 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -240,12 +240,16 @@ public:
class FloatingLiteral : public Expr {
llvm::APFloat Value;
+ bool IsExact : 1;
SourceLocation Loc;
public:
- FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L)
- : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {}
+ FloatingLiteral(const llvm::APFloat &V, bool* isexact,
+ QualType Type, SourceLocation L)
+ : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
const llvm::APFloat &getValue() const { return Value; }
+
+ bool isExact() const { return IsExact; }
/// getValueAsDouble - This returns the value as an inaccurate double. Note
/// that this may cause loss of precision, but is useful for debugging dumps