[cfe-commits] r72928 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Basic/LangOptions.h include/clang/Basic/TargetInfo.h lib/AST/ASTContext.cpp lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp lib/Frontend/InitPreprocessor.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Lex/LiteralSupport.cpp lib/Lex/PPExpressions.cpp

Eli Friedman eli.friedman at gmail.com
Fri Jun 5 00:05:07 PDT 2009


Author: efriedma
Date: Fri Jun  5 02:05:05 2009
New Revision: 72928

URL: http://llvm.org/viewvc/llvm-project?rev=72928&view=rev
Log:
Move CharIsSigned from TargetInfo to LangOptions.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/include/clang/Basic/LangOptions.h
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Jun  5 02:05:05 2009
@@ -130,6 +130,9 @@
 def warn_pch_access_control : Error<
     "C++ access control was %select{disabled|enabled}0 in the PCH file but "
     "is currently %select{disabled|enabled}1">;
+def warn_pch_char_signed : Error<
+    "char was %select{unsigned|signed}0 in the PCH file but "
+    "is currently %select{unsigned|signed}1">;
 
 def err_not_a_pch_file : Error<
     "'%0' does not appear to be a precompiled header file">, DefaultFatal;

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Fri Jun  5 02:05:05 2009
@@ -79,6 +79,7 @@
 
   unsigned AccessControl     : 1; // Whether C++ access control should 
                                   // be enabled.
+  unsigned CharIsSigned      : 1; // Whether char is a signed or unsigned type
 private:
   unsigned GC : 2; // Objective-C Garbage Collection modes.  We declare
                    // this enum as unsigned because MSVC insists on making enums
@@ -137,6 +138,8 @@
     GNUInline = 0;
     NoInline = 0;
 
+    CharIsSigned = 1;
+
     MainFileName = 0;
   }
   

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jun  5 02:05:05 2009
@@ -38,7 +38,6 @@
 protected:
   // Target values set by the ctor of the actual target implementation.  Default
   // values are specified by the TargetInfo constructor.
-  bool CharIsSigned;
   bool TLSSupported;
   unsigned char PointerWidth, PointerAlign;
   unsigned char WCharWidth, WCharAlign;
@@ -88,11 +87,6 @@
   IntType getIntPtrType() const { return IntPtrType; }
   IntType getWCharType() const { return WCharType; }
 
-  /// isCharSigned - Return true if 'char' is 'signed char' or false if it is
-  /// treated as 'unsigned char'.  This is implementation defined according to
-  /// C99 6.2.5p15.  In our implementation, this is target-specific.
-  bool isCharSigned() const { return CharIsSigned; }
-  
   /// getPointerWidth - Return the width of pointers on this target, for the
   /// specified address space.
   uint64_t getPointerWidth(unsigned AddrSpace) const {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jun  5 02:05:05 2009
@@ -143,7 +143,7 @@
   // C99 6.2.5p2.
   InitBuiltinType(BoolTy,              BuiltinType::Bool);
   // C99 6.2.5p3.
-  if (Target.isCharSigned())
+  if (LangOpts.CharIsSigned)
     InitBuiltinType(CharTy,            BuiltinType::Char_S);
   else
     InitBuiltinType(CharTy,            BuiltinType::Char_U);

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Jun  5 02:05:05 2009
@@ -22,7 +22,6 @@
   // Set defaults.  Defaults are set for a 32-bit RISC platform,
   // like PPC or SPARC.
   // These should be overridden by concrete targets as needed.
-  CharIsSigned = true;
   TLSSupported = true;
   PointerWidth = PointerAlign = 32;
   WCharWidth = WCharAlign = 32;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Jun  5 02:05:05 2009
@@ -257,9 +257,8 @@
   static const TargetInfo::GCCRegAlias GCCRegAliases[];
 
 public:
-  PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {
-    CharIsSigned = false;
-  }
+  PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
+
   virtual void getTargetBuiltins(const Builtin::Info *&Records,
                                  unsigned &NumRecords) const {
     Records = BuiltinInfo;
@@ -299,6 +298,10 @@
       return true;
     }
   }
+  virtual void getDefaultLangOptions(LangOptions &Opts) {
+    TargetInfo::getDefaultLangOptions(Opts);
+    Opts.CharIsSigned = false;
+  }
   virtual const char *getClobbers() const {
     return "";
   }
@@ -449,6 +452,7 @@
   /// various language options.  These may be overridden by command line
   /// options.
   virtual void getDefaultLangOptions(LangOptions &Opts) {
+    PPC32TargetInfo::getDefaultLangOptions(Opts);
     GetDarwinLanguageOptions(Opts, getTargetTriple());
   }
 };
@@ -469,6 +473,7 @@
   /// various language options.  These may be overridden by command line
   /// options.
   virtual void getDefaultLangOptions(LangOptions &Opts) {
+    PPC64TargetInfo::getDefaultLangOptions(Opts);
     GetDarwinLanguageOptions(Opts, getTargetTriple());
   }
 };
@@ -845,6 +850,7 @@
   /// various language options.  These may be overridden by command line
   /// options.
   virtual void getDefaultLangOptions(LangOptions &Opts) {
+    X86_32TargetInfo::getDefaultLangOptions(Opts);
     GetDarwinLanguageOptions(Opts, getTargetTriple());
   }
 };

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Fri Jun  5 02:05:05 2009
@@ -367,7 +367,7 @@
   sprintf(MacroBuf, "__POINTER_WIDTH__=%d", (int)TI.getPointerWidth(0));
   DefineBuiltinMacro(Buf, MacroBuf);
   
-  if (!TI.isCharSigned())
+  if (!LangOpts.CharIsSigned)
     DefineBuiltinMacro(Buf, "__CHAR_UNSIGNED__");  
 
   // Define fixed-sized integer types for stdint.h

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Jun  5 02:05:05 2009
@@ -1521,6 +1521,7 @@
   PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline);
   PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline);
   PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control);
+  PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed);
   if ((LangOpts.getGCMode() != 0) != (Record[Idx] != 0)) {
     Diag(diag::warn_pch_gc_mode) 
       << (unsigned)Record[Idx] << LangOpts.getGCMode();

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jun  5 02:05:05 2009
@@ -556,6 +556,8 @@
   Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined.
   Record.push_back(LangOpts.AccessControl); // Whether C++ access control should
                                             // be enabled.
+  Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or
+                                           // unsigned type
   Record.push_back(LangOpts.getGCMode());
   Record.push_back(LangOpts.getVisibilityMode());
   Record.push_back(LangOpts.InstantiationDepth);

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Fri Jun  5 02:05:05 2009
@@ -691,7 +691,7 @@
   // character constants are not sign extended in the this implementation:
   // '\xFF\xFF' = 65536 and '\x0\xFF' = 255, which matches GCC.
   if (!IsWide && NumCharsSoFar == 1 && (Value & 128) &&
-      PP.getTargetInfo().isCharSigned())
+      PP.getLangOptions().CharIsSigned)
     Value = (signed char)Value;
 }
 

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=72928&r1=72927&r2=72928&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Fri Jun  5 02:05:05 2009
@@ -232,7 +232,7 @@
     // Set the value.
     Val = Literal.getValue();
     // Set the signedness.
-    Val.setIsUnsigned(!TI.isCharSigned());
+    Val.setIsUnsigned(!PP.getLangOptions().CharIsSigned);
     
     if (Result.Val.getBitWidth() > Val.getBitWidth()) {
       Result.Val = Val.extend(Result.Val.getBitWidth());





More information about the cfe-commits mailing list