Move CharIsSigned from TargetInfo to LangOptions.

llvm-svn: 72928
This commit is contained in:
Eli Friedman 2009-06-05 07:05:05 +00:00
parent d7bcad67d4
commit 9ffd4a9b96
11 changed files with 22 additions and 14 deletions

View File

@ -130,6 +130,9 @@ def warn_pch_compiler_options_mismatch : Error<
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;

View File

@ -79,6 +79,7 @@ public:
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 @@ public:
GNUInline = 0;
NoInline = 0;
CharIsSigned = 1;
MainFileName = 0;
}

View File

@ -38,7 +38,6 @@ class TargetInfo {
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 @@ public:
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 {

View File

@ -143,7 +143,7 @@ void ASTContext::InitBuiltinTypes() {
// 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);

View File

@ -22,7 +22,6 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
// 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;

View File

@ -257,9 +257,8 @@ class PPCTargetInfo : public TargetInfo {
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 @@ public:
return true;
}
}
virtual void getDefaultLangOptions(LangOptions &Opts) {
TargetInfo::getDefaultLangOptions(Opts);
Opts.CharIsSigned = false;
}
virtual const char *getClobbers() const {
return "";
}
@ -449,6 +452,7 @@ public:
/// 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 @@ public:
/// 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 @@ public:
/// various language options. These may be overridden by command line
/// options.
virtual void getDefaultLangOptions(LangOptions &Opts) {
X86_32TargetInfo::getDefaultLangOptions(Opts);
GetDarwinLanguageOptions(Opts, getTargetTriple());
}
};

View File

@ -367,7 +367,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
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

View File

@ -1521,6 +1521,7 @@ bool PCHReader::ParseLanguageOptions(
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();

View File

@ -556,6 +556,8 @@ void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
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);

View File

@ -691,7 +691,7 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
// 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;
}

View File

@ -232,7 +232,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
// 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());