[cfe-commits] r125474 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Parse/Parser.h include/clang/Sema/Sema.h lib/Lex/Pragma.cpp lib/Parse/ParsePragma.cpp lib/Parse/ParsePragma.h lib/Parse/Parser.cpp lib/Sema/Sema.cpp lib/Sema/SemaAttr.cpp
Peter Collingbourne
peter at pcc.me.uk
Sun Feb 13 17:42:35 PST 2011
Author: pcc
Date: Sun Feb 13 19:42:35 2011
New Revision: 125474
URL: http://llvm.org/viewvc/llvm-project?rev=125474&view=rev
Log:
Move support for "#pragma STDC FP_CONTRACT" to Parser; add Sema actions
Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Parse/ParsePragma.h
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Sun Feb 13 19:42:35 2011
@@ -118,6 +118,7 @@
// single precision constants.
unsigned FastRelaxedMath : 1; // OpenCL fast relaxed math (on its own,
// defines __FAST_RELAXED_MATH__).
+ unsigned DefaultFPContract : 1; // Default setting for FP_CONTRACT
// FIXME: This is just a temporary option, for testing purposes.
unsigned NoBitFieldTypeAlign : 1;
@@ -210,6 +211,7 @@
SpellChecking = 1;
SinglePrecisionConstants = 0;
FastRelaxedMath = 0;
+ DefaultFPContract = 0;
NoBitFieldTypeAlign = 0;
}
@@ -236,6 +238,17 @@
}
};
+/// Floating point control options
+class FPOptions {
+public:
+ unsigned fp_contract : 1;
+
+ FPOptions() : fp_contract(0) {}
+
+ FPOptions(const LangOptions &LangOpts) :
+ fp_contract(LangOpts.DefaultFPContract) {}
+};
+
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Feb 13 19:42:35 2011
@@ -122,6 +122,7 @@
llvm::OwningPtr<PragmaHandler> PackHandler;
llvm::OwningPtr<PragmaHandler> UnusedHandler;
llvm::OwningPtr<PragmaHandler> WeakHandler;
+ llvm::OwningPtr<PragmaHandler> FPContractHandler;
/// Whether the '>' token acts as an operator or not. This will be
/// true except when we are parsing an expression within a C++
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Feb 13 19:42:35 2011
@@ -210,6 +210,8 @@
typedef TemplateParameterList TemplateParamsTy;
typedef NestedNameSpecifier CXXScopeTy;
+ FPOptions FPFeatures;
+
const LangOptions &LangOpts;
Preprocessor &PP;
ASTContext &Context;
@@ -544,6 +546,8 @@
void Initialize();
const LangOptions &getLangOptions() const { return LangOpts; }
+ FPOptions &getFPOptions() { return FPFeatures; }
+
Diagnostic &getDiagnostics() const { return Diags; }
SourceManager &getSourceManager() const { return SourceMgr; }
const TargetAttributesSema &getTargetAttributesSema() const;
@@ -4407,6 +4411,10 @@
SourceLocation WeakNameLoc,
SourceLocation AliasNameLoc);
+ /// ActOnPragmaFPContract - Called on well formed
+ /// #pragma STDC FP_CONTRACT
+ void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
+
/// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
/// a the record decl, to handle '#pragma pack' and '#pragma options align'.
void AddAlignmentAttributesForRecord(RecordDecl *RD);
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Sun Feb 13 19:42:35 2011
@@ -962,20 +962,6 @@
// Pragma STDC implementations.
-/// PragmaSTDC_FP_CONTRACTHandler - "#pragma STDC FP_CONTRACT ...".
-struct PragmaSTDC_FP_CONTRACTHandler : public PragmaHandler {
- PragmaSTDC_FP_CONTRACTHandler() : PragmaHandler("FP_CONTRACT") {}
- virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
- Token &Tok) {
- // We just ignore the setting of FP_CONTRACT. Since we don't do contractions
- // at all, our default is OFF and setting it to ON is an optimization hint
- // we can safely ignore. When we support -ffma or something, we would need
- // to diagnose that we are ignoring FMA.
- tok::OnOffSwitch OOS;
- PP.LexOnOffSwitch(OOS);
- }
-};
-
/// PragmaSTDC_FENV_ACCESSHandler - "#pragma STDC FENV_ACCESS ...".
struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
@@ -1034,7 +1020,6 @@
AddPragmaHandler("clang", new PragmaDependencyHandler());
AddPragmaHandler("clang", new PragmaDiagnosticHandler());
- AddPragmaHandler("STDC", new PragmaSTDC_FP_CONTRACTHandler());
AddPragmaHandler("STDC", new PragmaSTDC_FENV_ACCESSHandler());
AddPragmaHandler("STDC", new PragmaSTDC_CX_LIMITED_RANGEHandler());
AddPragmaHandler("STDC", new PragmaSTDC_UnknownHandler());
Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Sun Feb 13 19:42:35 2011
@@ -371,3 +371,14 @@
Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc);
}
}
+
+void
+PragmaFPContractHandler::HandlePragma(Preprocessor &PP,
+ PragmaIntroducerKind Introducer,
+ Token &Tok) {
+ tok::OnOffSwitch OOS;
+ if (PP.LexOnOffSwitch(OOS))
+ return;
+
+ Actions.ActOnPragmaFPContract(OOS);
+}
Modified: cfe/trunk/lib/Parse/ParsePragma.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.h?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.h (original)
+++ cfe/trunk/lib/Parse/ParsePragma.h Sun Feb 13 19:42:35 2011
@@ -80,6 +80,17 @@
Token &FirstToken);
};
+class PragmaFPContractHandler : public PragmaHandler {
+ Sema &Actions;
+ Parser &parser;
+public:
+ PragmaFPContractHandler(Sema &S, Parser& p) :
+ PragmaHandler("FP_CONTRACT"), Actions(S), parser(p) {}
+ virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+ Token &FirstToken);
+};
+
+
} // end namespace clang
#endif
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sun Feb 13 19:42:35 2011
@@ -50,6 +50,9 @@
WeakHandler.reset(new PragmaWeakHandler(actions));
PP.AddPragmaHandler(WeakHandler.get());
+
+ FPContractHandler.reset(new PragmaFPContractHandler(actions, *this));
+ PP.AddPragmaHandler("STDC", FPContractHandler.get());
PP.setCodeCompletionHandler(*this);
}
@@ -360,6 +363,8 @@
UnusedHandler.reset();
PP.RemovePragmaHandler(WeakHandler.get());
WeakHandler.reset();
+ PP.RemovePragmaHandler("STDC", FPContractHandler.get());
+ FPContractHandler.reset();
PP.clearCodeCompletionHandler();
}
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Feb 13 19:42:35 2011
@@ -131,7 +131,7 @@
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
bool CompleteTranslationUnit,
CodeCompleteConsumer *CodeCompleter)
- : TheTargetAttributesSema(0),
+ : TheTargetAttributesSema(0), FPFeatures(pp.getLangOptions()),
LangOpts(pp.getLangOptions()), PP(pp), Context(ctxt), Consumer(consumer),
Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()),
ExternalSource(0), CodeCompleter(CodeCompleter), CurContext(0),
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=125474&r1=125473&r2=125474&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Sun Feb 13 19:42:35 2011
@@ -350,6 +350,20 @@
}
}
+void Sema::ActOnPragmaFPContract(tok::OnOffSwitch OOS) {
+ switch (OOS) {
+ case tok::OOS_ON:
+ FPFeatures.fp_contract = 1;
+ break;
+ case tok::OOS_OFF:
+ FPFeatures.fp_contract = 0;
+ break;
+ case tok::OOS_DEFAULT:
+ FPFeatures.fp_contract = getLangOptions().DefaultFPContract;
+ break;
+ }
+}
+
void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr) {
// Visibility calculations will consider the namespace's visibility.
// Here we just want to note that we're in a visibility context
More information about the cfe-commits
mailing list