[cfe-commits] r38975 - in /cfe/cfe/trunk: Driver/Targets.cpp Driver/clang.cpp Lex/Preprocessor.cpp Parse/ParseExpr.cpp include/clang/Basic/DiagnosticKinds.def include/clang/Lex/Preprocessor.h include/clang/Parse/Parser.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:26:25 PDT 2007
Author: sabre
Date: Wed Jul 11 11:26:25 2007
New Revision: 38975
URL: http://llvm.org/viewvc/llvm-project?rev=38975&view=rev
Log:
Write up TargetInfo so that use of wchar_t strings results in a warning if
used in a target set where the size is not identical.
Modified:
cfe/cfe/trunk/Driver/Targets.cpp
cfe/cfe/trunk/Driver/clang.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/cfe/trunk/Driver/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/Targets.cpp?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/Targets.cpp (original)
+++ cfe/cfe/trunk/Driver/Targets.cpp Wed Jul 11 11:26:25 2007
@@ -53,6 +53,8 @@
// Specific target implementations.
//===----------------------------------------------------------------------===//
+// FIXME: Move target-specific preprocessor definitions here.
+
namespace {
class DarwinPPCTargetInfo : public DarwinTargetInfo {
public:
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:26:25 2007
@@ -691,7 +691,7 @@
FileManager FileMgr;
// Set up the preprocessor with these options.
- Preprocessor PP(OurDiagnostics, Options, FileMgr, SourceMgr);
+ Preprocessor PP(OurDiagnostics, Options, *Target, FileMgr, SourceMgr);
// Install things like __POWERPC__, __GNUC__, etc into the macro table.
std::vector<char> PrologMacros;
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:26:25 2007
@@ -39,9 +39,10 @@
//===----------------------------------------------------------------------===//
-Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
+Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
+ TargetInfo &target,
FileManager &FM, SourceManager &SM)
- : Diags(diags), Features(opts), FileMgr(FM), SourceMgr(SM),
+ : Diags(diags), Features(opts), Target(target), FileMgr(FM), SourceMgr(SM),
SystemDirIdx(0), NoCurDirSearch(false),
CurLexer(0), CurDirLookup(0), CurMacroExpander(0) {
ScratchBuf = new ScratchBuffer(SourceMgr);
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:26:25 2007
@@ -21,6 +21,7 @@
#include "clang/Parse/Parser.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/Alloca.h"
@@ -943,8 +944,11 @@
// TODO: K&R warning: "traditional C rejects string constant concatenation"
- // FIXME: Size of wchar_t should not be hardcoded!
- unsigned wchar_tByteWidth = 4;
+ // Get the width in bytes of wchar_t. If no wchar_t strings are used, do not
+ // query the target. As such, wchar_tByteWidth is only valid if AnyWide=true.
+ unsigned wchar_tByteWidth = ~0U;
+ if (AnyWide)
+ wchar_tByteWidth=getTargetInfo().getWCharWidth(StringToks[0].getLocation());
// The output buffer size needs to be large enough to hold wide characters.
// This is a worst-case assumption which basically corresponds to L"" "long".
@@ -1087,8 +1091,12 @@
}
// Note: our internal rep of wide char tokens is always little-endian.
- for (unsigned i = 0, e = wchar_tByteWidth; i != e; ++i)
- *ResultPtr++ = ResultChar >> i*8;
+ *ResultPtr++ = ResultChar & 0xFF;
+
+ if (AnyWide) {
+ for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
+ *ResultPtr++ = ResultChar >> i*8;
+ }
}
}
Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:26:25 2007
@@ -25,7 +25,7 @@
//===----------------------------------------------------------------------===//
DIAG(port_wchar_t, NOTE,
- "sizeof(wchar_t) varies between targets")
+ "sizeof(wchar_t) varies between targets, source is not 'portable'")
//===----------------------------------------------------------------------===//
// Lexer Diagnostics
Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:26:25 2007
@@ -29,6 +29,7 @@
class PragmaNamespace;
class PragmaHandler;
class ScratchBuffer;
+class TargetInfo;
/// DirectoryLookup - This class is used to specify the search order for
/// directories in #include directives.
@@ -74,11 +75,12 @@
/// like the #include stack, token expansion, etc.
///
class Preprocessor {
- Diagnostic &Diags;
+ Diagnostic &Diags;
const LangOptions &Features;
- FileManager &FileMgr;
- SourceManager &SourceMgr;
- ScratchBuffer *ScratchBuf;
+ TargetInfo &Target;
+ FileManager &FileMgr;
+ SourceManager &SourceMgr;
+ ScratchBuffer *ScratchBuf;
// #include search path information. Requests for #include "x" search the
/// directory of the #including file first, then each directory in SearchDirs
@@ -201,12 +203,13 @@
unsigned NumFastMacroExpanded, NumTokenPaste, NumFastTokenPaste;
unsigned NumSkipped;
public:
- Preprocessor(Diagnostic &diags, const LangOptions &opts, FileManager &FM,
- SourceManager &SM);
+ Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target,
+ FileManager &FM, SourceManager &SM);
~Preprocessor();
Diagnostic &getDiagnostics() const { return Diags; }
const LangOptions &getLangOptions() const { return Features; }
+ TargetInfo &getTargetInfo() const { return Target; }
FileManager &getFileManager() const { return FileMgr; }
SourceManager &getSourceManager() const { return SourceMgr; }
Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38975&r1=38974&r2=38975&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:26:25 2007
@@ -42,6 +42,7 @@
~Parser();
const LangOptions &getLang() const { return PP.getLangOptions(); }
+ TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
Action &getActions() const { return Actions; }
// Type forwarding. All of these are statically 'void*', but they may all be
More information about the cfe-commits
mailing list