ebevhan created this revision.
ebevhan added reviewers: leonardchan, rjmccall.
Herald added a subscriber: cfe-commits.
ebevhan marked an inline comment as done.
ebevhan added inline comments.


================
Comment at: include/clang/Serialization/ASTBitCodes.h:1637
+      /// A FixedPointLiteral record.
+      EXPR_FIXEDPOINT_LITERAL,
+
----------------
I'm unsure if this is the right location for a new code. This will bump down 
all the other codes below this and cause any older file to not be read 
correctly.

Should the file format version number be bumped up?


This patch adds the EXPR_FIXEDPOINT_LITERAL AST
code to serialize FixedPointLiterals. They were previously
being serialized with the code for integer literals, which
doesn't work properly.


Repository:
  rC Clang

https://reviews.llvm.org/D57226

Files:
  include/clang/AST/Expr.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/PCH/fixed-point-literal.c
  test/PCH/fixed-point-literal.h

Index: test/PCH/fixed-point-literal.h
===================================================================
--- /dev/null
+++ test/PCH/fixed-point-literal.h
@@ -0,0 +1,5 @@
+// Header for PCH test fixed-point-literal.c
+
+const short _Fract sf = -0.25r;
+const _Fract f = 0.75r;
+const long _Accum la = 25.25lk;
Index: test/PCH/fixed-point-literal.c
===================================================================
--- /dev/null
+++ test/PCH/fixed-point-literal.c
@@ -0,0 +1,14 @@
+// Test this without pch.
+// RUN: %clang_cc1 -ffixed-point -include %S/fixed-point-literal.h -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -ffixed-point -emit-pch -o %t %S/fixed-point-literal.h
+// RUN: %clang_cc1 -ffixed-point -include-pch %t -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// CHECK: const short _Fract sf = -0.25r;
+// CHECK: const _Fract f = 0.75r;
+// CHECK: const long _Accum la = 25.25lk;
+
+short _Fract sf2 = sf;
+_Fract f2 = f;
+long _Accum la2 = la;
Index: lib/Serialization/ASTWriterStmt.cpp
===================================================================
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -496,8 +496,9 @@
 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
+  Record.push_back(E->getScale());
   Record.AddAPInt(E->getValue());
-  Code = serialization::EXPR_INTEGER_LITERAL;
+  Code = serialization::EXPR_FIXEDPOINT_LITERAL;
 }
 
 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -958,6 +958,7 @@
   RECORD(EXPR_PREDEFINED);
   RECORD(EXPR_DECL_REF);
   RECORD(EXPR_INTEGER_LITERAL);
+  RECORD(EXPR_FIXEDPOINT_LITERAL);
   RECORD(EXPR_FLOATING_LITERAL);
   RECORD(EXPR_IMAGINARY_LITERAL);
   RECORD(EXPR_STRING_LITERAL);
Index: lib/Serialization/ASTReaderStmt.cpp
===================================================================
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -576,6 +576,7 @@
 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   E->setLocation(ReadSourceLocation());
+  E->setScale(Record.readInt());
   E->setValue(Record.getContext(), Record.readAPInt());
 }
 
@@ -2471,6 +2472,10 @@
       S = IntegerLiteral::Create(Context, Empty);
       break;
 
+    case EXPR_FIXEDPOINT_LITERAL:
+      S = FixedPointLiteral::Create(Context, Empty);
+      break;
+
     case EXPR_FLOATING_LITERAL:
       S = FloatingLiteral::Create(Context, Empty);
       break;
Index: lib/AST/Expr.cpp
===================================================================
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -818,6 +818,11 @@
   return new (C) FixedPointLiteral(C, V, type, l, Scale);
 }
 
+FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
+                                             EmptyShell Empty) {
+  return new (C) FixedPointLiteral(Empty);
+}
+
 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
   // Currently the longest decimal number that can be printed is the max for an
   // unsigned long _Accum: 4294967295.99999999976716935634613037109375
Index: include/clang/Serialization/ASTBitCodes.h
===================================================================
--- include/clang/Serialization/ASTBitCodes.h
+++ include/clang/Serialization/ASTBitCodes.h
@@ -1633,6 +1633,9 @@
       /// An IntegerLiteral record.
       EXPR_INTEGER_LITERAL,
 
+      /// A FixedPointLiteral record.
+      EXPR_FIXEDPOINT_LITERAL,
+
       /// A FloatingLiteral record.
       EXPR_FLOATING_LITERAL,
 
Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -1358,7 +1358,7 @@
   SourceLocation Loc;
   unsigned Scale;
 
-  /// \brief Construct an empty integer literal.
+  /// \brief Construct an empty fixed-point literal.
   explicit FixedPointLiteral(EmptyShell Empty)
       : Expr(FixedPointLiteralClass, Empty) {}
 
@@ -1372,6 +1372,9 @@
                                              QualType type, SourceLocation l,
                                              unsigned Scale);
 
+  /// Returns an empty fixed-point literal.
+  static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty);
+
   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
   SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
 
@@ -1380,6 +1383,9 @@
 
   void setLocation(SourceLocation Location) { Loc = Location; }
 
+  unsigned getScale() const { return Scale; }
+  void setScale(unsigned S) { Scale = S; }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == FixedPointLiteralClass;
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to