2008-10-05 03:21:03 +08:00
|
|
|
//===--- ParsePragma.cpp - Language specific pragma parsing ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the language specific #pragma handlers.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-04-09 06:30:47 +08:00
|
|
|
#include "RAIIObjectsForParser.h"
|
2014-10-17 04:52:46 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2014-08-14 14:35:08 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2014-06-07 04:31:48 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "clang/Parse/ParseDiagnostic.h"
|
|
|
|
#include "clang/Parse/Parser.h"
|
|
|
|
#include "clang/Sema/LoopHint.h"
|
|
|
|
#include "clang/Sema/Scope.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
using namespace clang;
|
2008-10-05 03:21:03 +08:00
|
|
|
|
2014-02-21 06:52:09 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PragmaAlignHandler : public PragmaHandler {
|
|
|
|
explicit PragmaAlignHandler() : PragmaHandler("align") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaGCCVisibilityHandler : public PragmaHandler {
|
|
|
|
explicit PragmaGCCVisibilityHandler() : PragmaHandler("visibility") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaOptionsHandler : public PragmaHandler {
|
|
|
|
explicit PragmaOptionsHandler() : PragmaHandler("options") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaPackHandler : public PragmaHandler {
|
|
|
|
explicit PragmaPackHandler() : PragmaHandler("pack") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaMSStructHandler : public PragmaHandler {
|
|
|
|
explicit PragmaMSStructHandler() : PragmaHandler("ms_struct") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaUnusedHandler : public PragmaHandler {
|
|
|
|
PragmaUnusedHandler() : PragmaHandler("unused") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaWeakHandler : public PragmaHandler {
|
|
|
|
explicit PragmaWeakHandler() : PragmaHandler("weak") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaRedefineExtnameHandler : public PragmaHandler {
|
|
|
|
explicit PragmaRedefineExtnameHandler() : PragmaHandler("redefine_extname") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaOpenCLExtensionHandler : public PragmaHandler {
|
|
|
|
PragmaOpenCLExtensionHandler() : PragmaHandler("EXTENSION") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct PragmaFPContractHandler : public PragmaHandler {
|
|
|
|
PragmaFPContractHandler() : PragmaHandler("FP_CONTRACT") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaNoOpenMPHandler : public PragmaHandler {
|
|
|
|
PragmaNoOpenMPHandler() : PragmaHandler("omp") { }
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaOpenMPHandler : public PragmaHandler {
|
|
|
|
PragmaOpenMPHandler() : PragmaHandler("omp") { }
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// PragmaCommentHandler - "\#pragma comment ...".
|
|
|
|
struct PragmaCommentHandler : public PragmaHandler {
|
|
|
|
PragmaCommentHandler(Sema &Actions)
|
|
|
|
: PragmaHandler("comment"), Actions(Actions) {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
private:
|
|
|
|
Sema &Actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaDetectMismatchHandler : public PragmaHandler {
|
|
|
|
PragmaDetectMismatchHandler(Sema &Actions)
|
|
|
|
: PragmaHandler("detect_mismatch"), Actions(Actions) {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
private:
|
|
|
|
Sema &Actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaMSPointersToMembers : public PragmaHandler {
|
|
|
|
explicit PragmaMSPointersToMembers() : PragmaHandler("pointers_to_members") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaMSVtorDisp : public PragmaHandler {
|
|
|
|
explicit PragmaMSVtorDisp() : PragmaHandler("vtordisp") {}
|
2014-03-12 13:09:18 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
2014-02-21 06:52:09 +08:00
|
|
|
};
|
|
|
|
|
2014-04-09 06:30:47 +08:00
|
|
|
struct PragmaMSPragma : public PragmaHandler {
|
|
|
|
explicit PragmaMSPragma(const char *name) : PragmaHandler(name) {}
|
2014-04-04 03:04:24 +08:00
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
|
|
|
};
|
|
|
|
|
2014-05-23 20:13:25 +08:00
|
|
|
/// PragmaOptimizeHandler - "\#pragma clang optimize on/off".
|
|
|
|
struct PragmaOptimizeHandler : public PragmaHandler {
|
|
|
|
PragmaOptimizeHandler(Sema &S)
|
|
|
|
: PragmaHandler("optimize"), Actions(S) {}
|
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
|
|
|
private:
|
2014-06-07 04:31:48 +08:00
|
|
|
Sema &Actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PragmaLoopHintHandler : public PragmaHandler {
|
|
|
|
PragmaLoopHintHandler() : PragmaHandler("loop") {}
|
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
|
|
|
};
|
|
|
|
|
2014-07-22 02:08:34 +08:00
|
|
|
struct PragmaUnrollHintHandler : public PragmaHandler {
|
|
|
|
PragmaUnrollHintHandler(const char *name) : PragmaHandler(name) {}
|
|
|
|
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) override;
|
|
|
|
};
|
|
|
|
|
2015-10-13 04:47:58 +08:00
|
|
|
struct PragmaMSRuntimeChecksHandler : public EmptyPragmaHandler {
|
|
|
|
PragmaMSRuntimeChecksHandler() : EmptyPragmaHandler("runtime_checks") {}
|
|
|
|
};
|
|
|
|
|
2014-06-07 04:31:48 +08:00
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
void Parser::initializePragmaHandlers() {
|
2014-02-21 06:52:09 +08:00
|
|
|
AlignHandler.reset(new PragmaAlignHandler());
|
|
|
|
PP.AddPragmaHandler(AlignHandler.get());
|
|
|
|
|
|
|
|
GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler());
|
|
|
|
PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get());
|
|
|
|
|
|
|
|
OptionsHandler.reset(new PragmaOptionsHandler());
|
|
|
|
PP.AddPragmaHandler(OptionsHandler.get());
|
|
|
|
|
|
|
|
PackHandler.reset(new PragmaPackHandler());
|
|
|
|
PP.AddPragmaHandler(PackHandler.get());
|
|
|
|
|
|
|
|
MSStructHandler.reset(new PragmaMSStructHandler());
|
|
|
|
PP.AddPragmaHandler(MSStructHandler.get());
|
|
|
|
|
|
|
|
UnusedHandler.reset(new PragmaUnusedHandler());
|
|
|
|
PP.AddPragmaHandler(UnusedHandler.get());
|
|
|
|
|
|
|
|
WeakHandler.reset(new PragmaWeakHandler());
|
|
|
|
PP.AddPragmaHandler(WeakHandler.get());
|
|
|
|
|
|
|
|
RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler());
|
|
|
|
PP.AddPragmaHandler(RedefineExtnameHandler.get());
|
|
|
|
|
|
|
|
FPContractHandler.reset(new PragmaFPContractHandler());
|
|
|
|
PP.AddPragmaHandler("STDC", FPContractHandler.get());
|
|
|
|
|
|
|
|
if (getLangOpts().OpenCL) {
|
|
|
|
OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler());
|
|
|
|
PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
|
|
|
|
|
|
|
PP.AddPragmaHandler("OPENCL", FPContractHandler.get());
|
|
|
|
}
|
|
|
|
if (getLangOpts().OpenMP)
|
|
|
|
OpenMPHandler.reset(new PragmaOpenMPHandler());
|
|
|
|
else
|
|
|
|
OpenMPHandler.reset(new PragmaNoOpenMPHandler());
|
|
|
|
PP.AddPragmaHandler(OpenMPHandler.get());
|
|
|
|
|
2015-03-24 04:41:42 +08:00
|
|
|
if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) {
|
2014-02-21 06:52:09 +08:00
|
|
|
MSCommentHandler.reset(new PragmaCommentHandler(Actions));
|
|
|
|
PP.AddPragmaHandler(MSCommentHandler.get());
|
2015-03-24 04:41:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getLangOpts().MicrosoftExt) {
|
2014-02-21 06:52:09 +08:00
|
|
|
MSDetectMismatchHandler.reset(new PragmaDetectMismatchHandler(Actions));
|
|
|
|
PP.AddPragmaHandler(MSDetectMismatchHandler.get());
|
|
|
|
MSPointersToMembers.reset(new PragmaMSPointersToMembers());
|
|
|
|
PP.AddPragmaHandler(MSPointersToMembers.get());
|
|
|
|
MSVtorDisp.reset(new PragmaMSVtorDisp());
|
|
|
|
PP.AddPragmaHandler(MSVtorDisp.get());
|
2014-04-09 06:30:47 +08:00
|
|
|
MSInitSeg.reset(new PragmaMSPragma("init_seg"));
|
2014-04-04 03:04:24 +08:00
|
|
|
PP.AddPragmaHandler(MSInitSeg.get());
|
2014-04-09 06:30:47 +08:00
|
|
|
MSDataSeg.reset(new PragmaMSPragma("data_seg"));
|
|
|
|
PP.AddPragmaHandler(MSDataSeg.get());
|
|
|
|
MSBSSSeg.reset(new PragmaMSPragma("bss_seg"));
|
|
|
|
PP.AddPragmaHandler(MSBSSSeg.get());
|
|
|
|
MSConstSeg.reset(new PragmaMSPragma("const_seg"));
|
|
|
|
PP.AddPragmaHandler(MSConstSeg.get());
|
|
|
|
MSCodeSeg.reset(new PragmaMSPragma("code_seg"));
|
|
|
|
PP.AddPragmaHandler(MSCodeSeg.get());
|
|
|
|
MSSection.reset(new PragmaMSPragma("section"));
|
|
|
|
PP.AddPragmaHandler(MSSection.get());
|
2015-10-13 04:47:58 +08:00
|
|
|
MSRuntimeChecks.reset(new PragmaMSRuntimeChecksHandler());
|
|
|
|
PP.AddPragmaHandler(MSRuntimeChecks.get());
|
2014-02-21 06:52:09 +08:00
|
|
|
}
|
2014-06-07 04:31:48 +08:00
|
|
|
|
|
|
|
OptimizeHandler.reset(new PragmaOptimizeHandler(Actions));
|
|
|
|
PP.AddPragmaHandler("clang", OptimizeHandler.get());
|
|
|
|
|
|
|
|
LoopHintHandler.reset(new PragmaLoopHintHandler());
|
|
|
|
PP.AddPragmaHandler("clang", LoopHintHandler.get());
|
2014-07-22 02:08:34 +08:00
|
|
|
|
|
|
|
UnrollHintHandler.reset(new PragmaUnrollHintHandler("unroll"));
|
|
|
|
PP.AddPragmaHandler(UnrollHintHandler.get());
|
2014-07-25 02:09:38 +08:00
|
|
|
|
|
|
|
NoUnrollHintHandler.reset(new PragmaUnrollHintHandler("nounroll"));
|
|
|
|
PP.AddPragmaHandler(NoUnrollHintHandler.get());
|
2014-06-07 04:31:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::resetPragmaHandlers() {
|
2014-02-21 06:52:09 +08:00
|
|
|
// Remove the pragma handlers we installed.
|
|
|
|
PP.RemovePragmaHandler(AlignHandler.get());
|
|
|
|
AlignHandler.reset();
|
|
|
|
PP.RemovePragmaHandler("GCC", GCCVisibilityHandler.get());
|
|
|
|
GCCVisibilityHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(OptionsHandler.get());
|
|
|
|
OptionsHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(PackHandler.get());
|
|
|
|
PackHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(MSStructHandler.get());
|
|
|
|
MSStructHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(UnusedHandler.get());
|
|
|
|
UnusedHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(WeakHandler.get());
|
|
|
|
WeakHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(RedefineExtnameHandler.get());
|
|
|
|
RedefineExtnameHandler.reset();
|
|
|
|
|
|
|
|
if (getLangOpts().OpenCL) {
|
|
|
|
PP.RemovePragmaHandler("OPENCL", OpenCLExtensionHandler.get());
|
|
|
|
OpenCLExtensionHandler.reset();
|
|
|
|
PP.RemovePragmaHandler("OPENCL", FPContractHandler.get());
|
|
|
|
}
|
|
|
|
PP.RemovePragmaHandler(OpenMPHandler.get());
|
|
|
|
OpenMPHandler.reset();
|
|
|
|
|
2015-03-24 04:41:42 +08:00
|
|
|
if (getLangOpts().MicrosoftExt || getTargetInfo().getTriple().isPS4()) {
|
2014-02-21 06:52:09 +08:00
|
|
|
PP.RemovePragmaHandler(MSCommentHandler.get());
|
|
|
|
MSCommentHandler.reset();
|
2015-03-24 04:41:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getLangOpts().MicrosoftExt) {
|
2014-02-21 06:52:09 +08:00
|
|
|
PP.RemovePragmaHandler(MSDetectMismatchHandler.get());
|
|
|
|
MSDetectMismatchHandler.reset();
|
|
|
|
PP.RemovePragmaHandler(MSPointersToMembers.get());
|
|
|
|
MSPointersToMembers.reset();
|
|
|
|
PP.RemovePragmaHandler(MSVtorDisp.get());
|
|
|
|
MSVtorDisp.reset();
|
2014-04-04 03:04:24 +08:00
|
|
|
PP.RemovePragmaHandler(MSInitSeg.get());
|
|
|
|
MSInitSeg.reset();
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.RemovePragmaHandler(MSDataSeg.get());
|
|
|
|
MSDataSeg.reset();
|
|
|
|
PP.RemovePragmaHandler(MSBSSSeg.get());
|
|
|
|
MSBSSSeg.reset();
|
|
|
|
PP.RemovePragmaHandler(MSConstSeg.get());
|
|
|
|
MSConstSeg.reset();
|
|
|
|
PP.RemovePragmaHandler(MSCodeSeg.get());
|
|
|
|
MSCodeSeg.reset();
|
|
|
|
PP.RemovePragmaHandler(MSSection.get());
|
|
|
|
MSSection.reset();
|
2015-10-13 04:47:58 +08:00
|
|
|
PP.RemovePragmaHandler(MSRuntimeChecks.get());
|
|
|
|
MSRuntimeChecks.reset();
|
2014-02-21 06:52:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PP.RemovePragmaHandler("STDC", FPContractHandler.get());
|
|
|
|
FPContractHandler.reset();
|
2014-06-07 04:31:48 +08:00
|
|
|
|
|
|
|
PP.RemovePragmaHandler("clang", OptimizeHandler.get());
|
|
|
|
OptimizeHandler.reset();
|
|
|
|
|
|
|
|
PP.RemovePragmaHandler("clang", LoopHintHandler.get());
|
|
|
|
LoopHintHandler.reset();
|
2014-07-22 02:08:34 +08:00
|
|
|
|
|
|
|
PP.RemovePragmaHandler(UnrollHintHandler.get());
|
|
|
|
UnrollHintHandler.reset();
|
2014-07-25 02:09:38 +08:00
|
|
|
|
|
|
|
PP.RemovePragmaHandler(NoUnrollHintHandler.get());
|
|
|
|
NoUnrollHintHandler.reset();
|
2014-06-07 04:31:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Handle the annotation token produced for #pragma unused(...)
|
2011-01-18 02:58:44 +08:00
|
|
|
///
|
|
|
|
/// Each annot_pragma_unused is followed by the argument token so e.g.
|
|
|
|
/// "#pragma unused(x,y)" becomes:
|
|
|
|
/// annot_pragma_unused 'x' annot_pragma_unused 'y'
|
|
|
|
void Parser::HandlePragmaUnused() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_unused));
|
|
|
|
SourceLocation UnusedLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaUnused(Tok, getCurScope(), UnusedLoc);
|
|
|
|
ConsumeToken(); // The argument token.
|
|
|
|
}
|
2010-08-05 14:57:20 +08:00
|
|
|
|
2012-01-26 10:02:57 +08:00
|
|
|
void Parser::HandlePragmaVisibility() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_vis));
|
|
|
|
const IdentifierInfo *VisType =
|
|
|
|
static_cast<IdentifierInfo *>(Tok.getAnnotationValue());
|
|
|
|
SourceLocation VisLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaVisibility(VisType, VisLoc);
|
|
|
|
}
|
|
|
|
|
2015-10-28 21:54:16 +08:00
|
|
|
namespace {
|
2012-02-24 07:47:16 +08:00
|
|
|
struct PragmaPackInfo {
|
|
|
|
Sema::PragmaPackKind Kind;
|
|
|
|
IdentifierInfo *Name;
|
2012-10-04 10:36:51 +08:00
|
|
|
Token Alignment;
|
2012-02-24 07:47:16 +08:00
|
|
|
SourceLocation LParenLoc;
|
|
|
|
SourceLocation RParenLoc;
|
|
|
|
};
|
2015-10-28 21:54:16 +08:00
|
|
|
} // end anonymous namespace
|
2012-02-24 07:47:16 +08:00
|
|
|
|
|
|
|
void Parser::HandlePragmaPack() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_pack));
|
|
|
|
PragmaPackInfo *Info =
|
|
|
|
static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
2012-10-04 10:36:51 +08:00
|
|
|
ExprResult Alignment;
|
|
|
|
if (Info->Alignment.is(tok::numeric_constant)) {
|
|
|
|
Alignment = Actions.ActOnNumericConstant(Info->Alignment);
|
|
|
|
if (Alignment.isInvalid())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Actions.ActOnPragmaPack(Info->Kind, Info->Name, Alignment.get(), PragmaLoc,
|
2012-02-24 07:47:16 +08:00
|
|
|
Info->LParenLoc, Info->RParenLoc);
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
void Parser::HandlePragmaMSStruct() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_msstruct));
|
|
|
|
Sema::PragmaMSStructKind Kind =
|
|
|
|
static_cast<Sema::PragmaMSStructKind>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
Actions.ActOnPragmaMSStruct(Kind);
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaAlign() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_align));
|
|
|
|
Sema::PragmaOptionsAlignKind Kind =
|
|
|
|
static_cast<Sema::PragmaOptionsAlignKind>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaOptionsAlign(Kind, PragmaLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaWeak() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_weak));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
Actions.ActOnPragmaWeakID(Tok.getIdentifierInfo(), PragmaLoc,
|
|
|
|
Tok.getLocation());
|
|
|
|
ConsumeToken(); // The weak name.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaWeakAlias() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_weakalias));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken();
|
|
|
|
IdentifierInfo *WeakName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation WeakNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
IdentifierInfo *AliasName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation AliasNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
Actions.ActOnPragmaWeakAlias(WeakName, AliasName, PragmaLoc,
|
|
|
|
WeakNameLoc, AliasNameLoc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaRedefineExtname() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_redefine_extname));
|
|
|
|
SourceLocation RedefLoc = ConsumeToken();
|
|
|
|
IdentifierInfo *RedefName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation RedefNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
IdentifierInfo *AliasName = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation AliasNameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken();
|
|
|
|
Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc,
|
|
|
|
RedefNameLoc, AliasNameLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaFPContract() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_fp_contract));
|
|
|
|
tok::OnOffSwitch OOS =
|
|
|
|
static_cast<tok::OnOffSwitch>(
|
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
Actions.ActOnPragmaFPContract(OOS);
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
}
|
|
|
|
|
2013-04-17 02:41:26 +08:00
|
|
|
StmtResult Parser::HandlePragmaCaptured()
|
|
|
|
{
|
|
|
|
assert(Tok.is(tok::annot_pragma_captured));
|
|
|
|
ConsumeToken();
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::l_brace)) {
|
2013-12-24 17:48:30 +08:00
|
|
|
PP.Diag(Tok, diag::err_expected) << tok::l_brace;
|
2013-04-17 02:41:26 +08:00
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
|
2013-04-17 03:37:38 +08:00
|
|
|
SourceLocation Loc = Tok.getLocation();
|
|
|
|
|
|
|
|
ParseScope CapturedRegionScope(this, Scope::FnScope | Scope::DeclScope);
|
2013-05-04 03:00:33 +08:00
|
|
|
Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_Default,
|
|
|
|
/*NumParams=*/1);
|
2013-04-17 03:37:38 +08:00
|
|
|
|
|
|
|
StmtResult R = ParseCompoundStatement();
|
|
|
|
CapturedRegionScope.Exit();
|
|
|
|
|
|
|
|
if (R.isInvalid()) {
|
|
|
|
Actions.ActOnCapturedRegionError();
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Actions.ActOnCapturedRegionEnd(R.get());
|
2013-04-17 02:41:26 +08:00
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
namespace {
|
|
|
|
typedef llvm::PointerIntPair<IdentifierInfo *, 1, bool> OpenCLExtData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Parser::HandlePragmaOpenCLExtension() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_opencl_extension));
|
|
|
|
OpenCLExtData data =
|
|
|
|
OpenCLExtData::getFromOpaqueValue(Tok.getAnnotationValue());
|
|
|
|
unsigned state = data.getInt();
|
|
|
|
IdentifierInfo *ename = data.getPointer();
|
|
|
|
SourceLocation NameLoc = Tok.getLocation();
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
|
|
|
|
OpenCLOptions &f = Actions.getOpenCLOptions();
|
|
|
|
// OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions,
|
|
|
|
// overriding all previously issued extension directives, but only if the
|
|
|
|
// behavior is set to disable."
|
|
|
|
if (state == 0 && ename->isStr("all")) {
|
|
|
|
#define OPENCLEXT(nm) f.nm = 0;
|
|
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
|
|
|
}
|
|
|
|
#define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; }
|
|
|
|
#include "clang/Basic/OpenCLExtensions.def"
|
|
|
|
else {
|
|
|
|
PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-11 03:50:15 +08:00
|
|
|
void Parser::HandlePragmaMSPointersToMembers() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_ms_pointers_to_members));
|
2014-02-12 05:05:00 +08:00
|
|
|
LangOptions::PragmaMSPointersToMembersKind RepresentationMethod =
|
|
|
|
static_cast<LangOptions::PragmaMSPointersToMembersKind>(
|
2014-02-11 03:50:15 +08:00
|
|
|
reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken(); // The annotation token.
|
|
|
|
Actions.ActOnPragmaMSPointersToMembers(RepresentationMethod, PragmaLoc);
|
|
|
|
}
|
2013-04-17 02:41:26 +08:00
|
|
|
|
2014-02-13 07:50:26 +08:00
|
|
|
void Parser::HandlePragmaMSVtorDisp() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_ms_vtordisp));
|
|
|
|
uintptr_t Value = reinterpret_cast<uintptr_t>(Tok.getAnnotationValue());
|
|
|
|
Sema::PragmaVtorDispKind Kind =
|
|
|
|
static_cast<Sema::PragmaVtorDispKind>((Value >> 16) & 0xFFFF);
|
|
|
|
MSVtorDispAttr::Mode Mode = MSVtorDispAttr::Mode(Value & 0xFFFF);
|
|
|
|
SourceLocation PragmaLoc = ConsumeToken(); // The annotation token.
|
|
|
|
Actions.ActOnPragmaMSVtorDisp(Kind, PragmaLoc, Mode);
|
|
|
|
}
|
2013-04-17 02:41:26 +08:00
|
|
|
|
2014-04-09 06:30:47 +08:00
|
|
|
void Parser::HandlePragmaMSPragma() {
|
|
|
|
assert(Tok.is(tok::annot_pragma_ms_pragma));
|
|
|
|
// Grab the tokens out of the annotation and enter them into the stream.
|
|
|
|
auto TheTokens = (std::pair<Token*, size_t> *)Tok.getAnnotationValue();
|
|
|
|
PP.EnterTokenStream(TheTokens->first, TheTokens->second, true, true);
|
|
|
|
SourceLocation PragmaLocation = ConsumeToken(); // The annotation token.
|
|
|
|
assert(Tok.isAnyIdentifier());
|
2014-07-18 08:13:16 +08:00
|
|
|
StringRef PragmaName = Tok.getIdentifierInfo()->getName();
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // pragma kind
|
2014-07-18 08:13:16 +08:00
|
|
|
|
2014-04-09 06:30:47 +08:00
|
|
|
// Figure out which #pragma we're dealing with. The switch has no default
|
|
|
|
// because lex shouldn't emit the annotation token for unrecognized pragmas.
|
2014-07-18 08:13:16 +08:00
|
|
|
typedef bool (Parser::*PragmaHandler)(StringRef, SourceLocation);
|
2014-04-09 06:30:47 +08:00
|
|
|
PragmaHandler Handler = llvm::StringSwitch<PragmaHandler>(PragmaName)
|
|
|
|
.Case("data_seg", &Parser::HandlePragmaMSSegment)
|
|
|
|
.Case("bss_seg", &Parser::HandlePragmaMSSegment)
|
|
|
|
.Case("const_seg", &Parser::HandlePragmaMSSegment)
|
|
|
|
.Case("code_seg", &Parser::HandlePragmaMSSegment)
|
|
|
|
.Case("section", &Parser::HandlePragmaMSSection)
|
|
|
|
.Case("init_seg", &Parser::HandlePragmaMSInitSeg);
|
2014-07-18 08:13:16 +08:00
|
|
|
|
|
|
|
if (!(this->*Handler)(PragmaName, PragmaLocation)) {
|
|
|
|
// Pragma handling failed, and has been diagnosed. Slurp up the tokens
|
|
|
|
// until eof (really end of line) to prevent follow-on errors.
|
2014-04-09 06:30:47 +08:00
|
|
|
while (Tok.isNot(tok::eof))
|
|
|
|
PP.Lex(Tok);
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 08:13:16 +08:00
|
|
|
bool Parser::HandlePragmaMSSection(StringRef PragmaName,
|
|
|
|
SourceLocation PragmaLocation) {
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // (
|
|
|
|
// Parsing code for pragma section
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::string_literal)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ExprResult StringResult = ParseStringLiteralExpression();
|
|
|
|
if (StringResult.isInvalid())
|
|
|
|
return false; // Already diagnosed.
|
|
|
|
StringLiteral *SegmentName = cast<StringLiteral>(StringResult.get());
|
|
|
|
if (SegmentName->getCharByteWidth() != 1) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-23 05:08:43 +08:00
|
|
|
int SectionFlags = ASTContext::PSF_Read;
|
|
|
|
bool SectionFlagsAreDefault = true;
|
2014-04-09 06:30:47 +08:00
|
|
|
while (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok); // ,
|
2014-10-23 05:08:43 +08:00
|
|
|
// Ignore "long" and "short".
|
|
|
|
// They are undocumented, but widely used, section attributes which appear
|
|
|
|
// to do nothing.
|
|
|
|
if (Tok.is(tok::kw_long) || Tok.is(tok::kw_short)) {
|
|
|
|
PP.Lex(Tok); // long/short
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-18 08:13:16 +08:00
|
|
|
if (!Tok.isAnyIdentifier()) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-17 04:52:46 +08:00
|
|
|
ASTContext::PragmaSectionFlag Flag =
|
|
|
|
llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
|
2014-04-09 06:30:47 +08:00
|
|
|
Tok.getIdentifierInfo()->getName())
|
2014-10-17 04:52:46 +08:00
|
|
|
.Case("read", ASTContext::PSF_Read)
|
|
|
|
.Case("write", ASTContext::PSF_Write)
|
|
|
|
.Case("execute", ASTContext::PSF_Execute)
|
|
|
|
.Case("shared", ASTContext::PSF_Invalid)
|
|
|
|
.Case("nopage", ASTContext::PSF_Invalid)
|
|
|
|
.Case("nocache", ASTContext::PSF_Invalid)
|
|
|
|
.Case("discard", ASTContext::PSF_Invalid)
|
|
|
|
.Case("remove", ASTContext::PSF_Invalid)
|
|
|
|
.Default(ASTContext::PSF_None);
|
|
|
|
if (Flag == ASTContext::PSF_None || Flag == ASTContext::PSF_Invalid) {
|
|
|
|
PP.Diag(PragmaLocation, Flag == ASTContext::PSF_None
|
2014-07-18 08:13:16 +08:00
|
|
|
? diag::warn_pragma_invalid_specific_action
|
|
|
|
: diag::warn_pragma_unsupported_action)
|
2014-04-09 06:30:47 +08:00
|
|
|
<< PragmaName << Tok.getIdentifierInfo()->getName();
|
2014-07-18 08:13:16 +08:00
|
|
|
return false;
|
2014-04-09 06:30:47 +08:00
|
|
|
}
|
|
|
|
SectionFlags |= Flag;
|
2014-10-23 05:08:43 +08:00
|
|
|
SectionFlagsAreDefault = false;
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // Identifier
|
|
|
|
}
|
2014-10-23 05:08:43 +08:00
|
|
|
// If no section attributes are specified, the section will be marked as
|
|
|
|
// read/write.
|
|
|
|
if (SectionFlagsAreDefault)
|
|
|
|
SectionFlags |= ASTContext::PSF_Write;
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // )
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::eof)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // eof
|
|
|
|
Actions.ActOnPragmaMSSection(PragmaLocation, SectionFlags, SegmentName);
|
2014-07-18 08:13:16 +08:00
|
|
|
return true;
|
2014-04-09 06:30:47 +08:00
|
|
|
}
|
|
|
|
|
2014-07-18 08:13:16 +08:00
|
|
|
bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
|
|
|
|
SourceLocation PragmaLocation) {
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // (
|
|
|
|
Sema::PragmaMsStackAction Action = Sema::PSK_Reset;
|
2014-07-18 08:13:16 +08:00
|
|
|
StringRef SlotLabel;
|
2014-04-09 06:30:47 +08:00
|
|
|
if (Tok.isAnyIdentifier()) {
|
2014-07-18 08:13:16 +08:00
|
|
|
StringRef PushPop = Tok.getIdentifierInfo()->getName();
|
2014-04-09 06:30:47 +08:00
|
|
|
if (PushPop == "push")
|
|
|
|
Action = Sema::PSK_Push;
|
|
|
|
else if (PushPop == "pop")
|
|
|
|
Action = Sema::PSK_Pop;
|
2014-07-18 08:13:16 +08:00
|
|
|
else {
|
|
|
|
PP.Diag(PragmaLocation,
|
|
|
|
diag::warn_pragma_expected_section_push_pop_or_name)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
if (Action != Sema::PSK_Reset) {
|
|
|
|
PP.Lex(Tok); // push | pop
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok); // ,
|
|
|
|
// If we've got a comma, we either need a label or a string.
|
|
|
|
if (Tok.isAnyIdentifier()) {
|
|
|
|
SlotLabel = Tok.getIdentifierInfo()->getName();
|
|
|
|
PP.Lex(Tok); // identifier
|
|
|
|
if (Tok.is(tok::comma))
|
|
|
|
PP.Lex(Tok);
|
2014-07-18 08:13:16 +08:00
|
|
|
else if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_punc)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
}
|
2014-07-18 08:13:16 +08:00
|
|
|
} else if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Grab the string literal for our section name.
|
|
|
|
StringLiteral *SegmentName = nullptr;
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::string_literal)) {
|
|
|
|
unsigned DiagID = Action != Sema::PSK_Reset ? !SlotLabel.empty() ?
|
2014-04-09 06:30:47 +08:00
|
|
|
diag::warn_pragma_expected_section_name :
|
|
|
|
diag::warn_pragma_expected_section_label_or_name :
|
|
|
|
diag::warn_pragma_expected_section_push_pop_or_name;
|
2014-07-18 08:13:16 +08:00
|
|
|
PP.Diag(PragmaLocation, DiagID) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ExprResult StringResult = ParseStringLiteralExpression();
|
|
|
|
if (StringResult.isInvalid())
|
|
|
|
return false; // Already diagnosed.
|
|
|
|
SegmentName = cast<StringLiteral>(StringResult.get());
|
|
|
|
if (SegmentName->getCharByteWidth() != 1) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
// Setting section "" has no effect
|
|
|
|
if (SegmentName->getLength())
|
|
|
|
Action = (Sema::PragmaMsStackAction)(Action | Sema::PSK_Set);
|
|
|
|
}
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // )
|
2014-07-18 08:13:16 +08:00
|
|
|
if (Tok.isNot(tok::eof)) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
PP.Lex(Tok); // eof
|
|
|
|
Actions.ActOnPragmaMSSeg(PragmaLocation, Action, SlotLabel,
|
|
|
|
SegmentName, PragmaName);
|
2014-07-18 08:13:16 +08:00
|
|
|
return true;
|
2014-04-09 06:30:47 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 08:53:05 +08:00
|
|
|
// #pragma init_seg({ compiler | lib | user | "section-name" [, func-name]} )
|
2014-07-18 08:13:16 +08:00
|
|
|
bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
|
|
|
|
SourceLocation PragmaLocation) {
|
2014-08-14 14:35:08 +08:00
|
|
|
if (getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-22 08:53:05 +08:00
|
|
|
if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
|
|
|
|
PragmaName))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Parse either the known section names or the string section name.
|
|
|
|
StringLiteral *SegmentName = nullptr;
|
|
|
|
if (Tok.isAnyIdentifier()) {
|
|
|
|
auto *II = Tok.getIdentifierInfo();
|
|
|
|
StringRef Section = llvm::StringSwitch<StringRef>(II->getName())
|
|
|
|
.Case("compiler", "\".CRT$XCC\"")
|
|
|
|
.Case("lib", "\".CRT$XCL\"")
|
|
|
|
.Case("user", "\".CRT$XCU\"")
|
|
|
|
.Default("");
|
|
|
|
|
|
|
|
if (!Section.empty()) {
|
|
|
|
// Pretend the user wrote the appropriate string literal here.
|
|
|
|
Token Toks[1];
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::string_literal);
|
|
|
|
Toks[0].setLocation(Tok.getLocation());
|
|
|
|
Toks[0].setLiteralData(Section.data());
|
|
|
|
Toks[0].setLength(Section.size());
|
|
|
|
SegmentName =
|
|
|
|
cast<StringLiteral>(Actions.ActOnStringLiteral(Toks, nullptr).get());
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
} else if (Tok.is(tok::string_literal)) {
|
|
|
|
ExprResult StringResult = ParseStringLiteralExpression();
|
|
|
|
if (StringResult.isInvalid())
|
|
|
|
return false;
|
|
|
|
SegmentName = cast<StringLiteral>(StringResult.get());
|
|
|
|
if (SegmentName->getCharByteWidth() != 1) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
|
|
|
|
<< PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// FIXME: Add support for the '[, func-name]' part of the pragma.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SegmentName) {
|
|
|
|
PP.Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
|
|
|
|
PragmaName) ||
|
|
|
|
ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
|
|
|
|
PragmaName))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Actions.ActOnPragmaMSInitSeg(PragmaLocation, SegmentName);
|
|
|
|
return true;
|
2014-06-07 04:31:48 +08:00
|
|
|
}
|
|
|
|
|
2015-10-28 21:54:16 +08:00
|
|
|
namespace {
|
2014-06-07 04:31:48 +08:00
|
|
|
struct PragmaLoopHintInfo {
|
2014-07-22 02:08:34 +08:00
|
|
|
Token PragmaName;
|
2014-06-07 04:31:48 +08:00
|
|
|
Token Option;
|
2015-08-05 17:39:57 +08:00
|
|
|
ArrayRef<Token> Toks;
|
2014-06-07 04:31:48 +08:00
|
|
|
};
|
2015-10-28 21:54:16 +08:00
|
|
|
} // end anonymous namespace
|
2014-06-07 04:31:48 +08:00
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
|
|
|
|
std::string PragmaString;
|
|
|
|
if (PragmaName.getIdentifierInfo()->getName() == "loop") {
|
|
|
|
PragmaString = "clang loop ";
|
|
|
|
PragmaString += Option.getIdentifierInfo()->getName();
|
|
|
|
} else {
|
|
|
|
assert(PragmaName.getIdentifierInfo()->getName() == "unroll" &&
|
|
|
|
"Unexpected pragma name");
|
|
|
|
PragmaString = "unroll";
|
|
|
|
}
|
|
|
|
return PragmaString;
|
|
|
|
}
|
|
|
|
|
2014-08-01 04:15:14 +08:00
|
|
|
bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
|
2014-06-07 04:31:48 +08:00
|
|
|
assert(Tok.is(tok::annot_pragma_loop_hint));
|
|
|
|
PragmaLoopHintInfo *Info =
|
|
|
|
static_cast<PragmaLoopHintInfo *>(Tok.getAnnotationValue());
|
|
|
|
|
2014-08-01 04:15:14 +08:00
|
|
|
IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo();
|
|
|
|
Hint.PragmaNameLoc = IdentifierLoc::create(
|
|
|
|
Actions.Context, Info->PragmaName.getLocation(), PragmaNameInfo);
|
|
|
|
|
2014-08-01 05:24:32 +08:00
|
|
|
// It is possible that the loop hint has no option identifier, such as
|
|
|
|
// #pragma unroll(4).
|
|
|
|
IdentifierInfo *OptionInfo = Info->Option.is(tok::identifier)
|
|
|
|
? Info->Option.getIdentifierInfo()
|
|
|
|
: nullptr;
|
2014-08-01 04:15:14 +08:00
|
|
|
Hint.OptionLoc = IdentifierLoc::create(
|
|
|
|
Actions.Context, Info->Option.getLocation(), OptionInfo);
|
|
|
|
|
2015-08-05 17:39:57 +08:00
|
|
|
const Token *Toks = Info->Toks.data();
|
|
|
|
size_t TokSize = Info->Toks.size();
|
2014-10-13 04:46:07 +08:00
|
|
|
|
2014-08-01 04:15:14 +08:00
|
|
|
// Return a valid hint if pragma unroll or nounroll were specified
|
|
|
|
// without an argument.
|
|
|
|
bool PragmaUnroll = PragmaNameInfo->getName() == "unroll";
|
|
|
|
bool PragmaNoUnroll = PragmaNameInfo->getName() == "nounroll";
|
2014-10-13 04:46:07 +08:00
|
|
|
if (TokSize == 0 && (PragmaUnroll || PragmaNoUnroll)) {
|
|
|
|
ConsumeToken(); // The annotation token.
|
2014-08-01 04:15:14 +08:00
|
|
|
Hint.Range = Info->PragmaName.getLocation();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
// The constant expression is always followed by an eof token, which increases
|
|
|
|
// the TokSize by 1.
|
|
|
|
assert(TokSize > 0 &&
|
|
|
|
"PragmaLoopHintInfo::Toks must contain at least one token.");
|
|
|
|
|
|
|
|
// If no option is specified the argument is assumed to be a constant expr.
|
2015-06-09 07:13:43 +08:00
|
|
|
bool OptionUnroll = false;
|
2014-08-01 04:15:14 +08:00
|
|
|
bool StateOption = false;
|
2015-06-09 07:13:43 +08:00
|
|
|
if (OptionInfo) { // Pragma Unroll does not specify an option.
|
|
|
|
OptionUnroll = OptionInfo->isStr("unroll");
|
2014-08-01 04:15:14 +08:00
|
|
|
StateOption = llvm::StringSwitch<bool>(OptionInfo->getName())
|
|
|
|
.Case("vectorize", true)
|
|
|
|
.Case("interleave", true)
|
|
|
|
.Case("unroll", true)
|
|
|
|
.Default(false);
|
2014-10-13 04:46:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify loop hint has an argument.
|
|
|
|
if (Toks[0].is(tok::eof)) {
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
|
2015-06-09 07:13:43 +08:00
|
|
|
<< /*StateArgument=*/StateOption << /*FullKeyword=*/OptionUnroll;
|
2014-10-13 04:46:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-01 04:15:14 +08:00
|
|
|
|
|
|
|
// Validate the argument.
|
|
|
|
if (StateOption) {
|
2014-10-13 04:46:07 +08:00
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
SourceLocation StateLoc = Toks[0].getLocation();
|
|
|
|
IdentifierInfo *StateInfo = Toks[0].getIdentifierInfo();
|
2015-06-12 07:23:17 +08:00
|
|
|
if (!StateInfo ||
|
2015-08-11 01:29:39 +08:00
|
|
|
(!StateInfo->isStr("enable") && !StateInfo->isStr("disable") &&
|
|
|
|
((OptionUnroll && !StateInfo->isStr("full")) ||
|
|
|
|
(!OptionUnroll && !StateInfo->isStr("assume_safety"))))) {
|
2014-10-13 04:46:07 +08:00
|
|
|
Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
|
|
|
|
<< /*FullKeyword=*/OptionUnroll;
|
2014-08-01 04:15:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-13 04:46:07 +08:00
|
|
|
if (TokSize > 2)
|
|
|
|
Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< PragmaLoopHintString(Info->PragmaName, Info->Option);
|
2014-08-01 04:15:14 +08:00
|
|
|
Hint.StateLoc = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo);
|
|
|
|
} else {
|
2014-10-13 04:46:07 +08:00
|
|
|
// Enter constant expression including eof terminator into token stream.
|
|
|
|
PP.EnterTokenStream(Toks, TokSize, /*DisableMacroExpansion=*/false,
|
|
|
|
/*OwnsTokens=*/false);
|
|
|
|
ConsumeToken(); // The annotation token.
|
|
|
|
|
|
|
|
ExprResult R = ParseConstantExpression();
|
|
|
|
|
|
|
|
// Tokens following an error in an ill-formed constant expression will
|
|
|
|
// remain in the token stream and must be removed.
|
|
|
|
if (Tok.isNot(tok::eof)) {
|
|
|
|
Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< PragmaLoopHintString(Info->PragmaName, Info->Option);
|
|
|
|
while (Tok.isNot(tok::eof))
|
|
|
|
ConsumeAnyToken();
|
2014-08-01 04:15:14 +08:00
|
|
|
}
|
2014-10-13 04:46:07 +08:00
|
|
|
|
|
|
|
ConsumeToken(); // Consume the constant expression eof terminator.
|
|
|
|
|
|
|
|
if (R.isInvalid() ||
|
|
|
|
Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Argument is a constant expression with an integer type.
|
|
|
|
Hint.ValueExpr = R.get();
|
2014-07-22 02:08:34 +08:00
|
|
|
}
|
2014-06-07 04:31:48 +08:00
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
Hint.Range = SourceRange(Info->PragmaName.getLocation(),
|
|
|
|
Info->Toks[TokSize - 1].getLocation());
|
2014-08-01 04:15:14 +08:00
|
|
|
return true;
|
2014-06-07 04:31:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// #pragma GCC visibility comes in two variants:
|
|
|
|
// 'push' '(' [visibility] ')'
|
|
|
|
// 'pop'
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &VisTok) {
|
2010-08-05 14:57:20 +08:00
|
|
|
SourceLocation VisLoc = VisTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
2011-07-20 09:03:50 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 14:57:20 +08:00
|
|
|
|
|
|
|
const IdentifierInfo *PushPop = Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
const IdentifierInfo *VisType;
|
|
|
|
if (PushPop && PushPop->isStr("pop")) {
|
2014-05-21 14:02:52 +08:00
|
|
|
VisType = nullptr;
|
2010-08-05 14:57:20 +08:00
|
|
|
} else if (PushPop && PushPop->isStr("push")) {
|
2011-07-20 09:03:50 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 14:57:20 +08:00
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 09:03:50 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 14:57:20 +08:00
|
|
|
VisType = Tok.getIdentifierInfo();
|
|
|
|
if (!VisType) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2011-07-20 09:03:50 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2010-08-05 14:57:20 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 08:10:23 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
2011-07-20 09:03:50 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2011-02-28 10:37:51 +08:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2010-08-05 14:57:20 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "visibility";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-26 10:02:57 +08:00
|
|
|
Token *Toks = new Token[1];
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_vis);
|
|
|
|
Toks[0].setLocation(VisLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(EndLoc);
|
2012-01-26 10:02:57 +08:00
|
|
|
Toks[0].setAnnotationValue(
|
|
|
|
const_cast<void*>(static_cast<const void*>(VisType)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/true);
|
2010-08-05 14:57:20 +08:00
|
|
|
}
|
|
|
|
|
2008-10-05 03:21:03 +08:00
|
|
|
// #pragma pack(...) comes in the following delicious flavors:
|
|
|
|
// pack '(' [integer] ')'
|
|
|
|
// pack '(' 'show' ')'
|
|
|
|
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaPackHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &PackTok) {
|
2008-10-05 03:21:03 +08:00
|
|
|
SourceLocation PackLoc = PackTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
2009-03-24 06:28:25 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "pack";
|
2008-10-05 03:21:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
Sema::PragmaPackKind Kind = Sema::PPK_Default;
|
2014-05-21 14:02:52 +08:00
|
|
|
IdentifierInfo *Name = nullptr;
|
2012-10-04 10:36:51 +08:00
|
|
|
Token Alignment;
|
|
|
|
Alignment.startToken();
|
2008-10-05 03:21:03 +08:00
|
|
|
SourceLocation LParenLoc = Tok.getLocation();
|
2009-09-09 23:08:12 +08:00
|
|
|
PP.Lex(Tok);
|
2008-10-05 03:21:03 +08:00
|
|
|
if (Tok.is(tok::numeric_constant)) {
|
2012-10-04 10:36:51 +08:00
|
|
|
Alignment = Tok;
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
2011-11-02 09:53:16 +08:00
|
|
|
|
|
|
|
// In MSVC/gcc, #pragma pack(4) sets the alignment without affecting
|
|
|
|
// the push/pop stack.
|
|
|
|
// In Apple gcc, #pragma pack(4) is equivalent to #pragma pack(push, 4)
|
2012-03-11 15:00:24 +08:00
|
|
|
if (PP.getLangOpts().ApplePragmaPack)
|
2011-11-02 09:53:16 +08:00
|
|
|
Kind = Sema::PPK_Push;
|
2008-10-05 03:21:03 +08:00
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
2008-11-24 05:45:46 +08:00
|
|
|
if (II->isStr("show")) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::PPK_Show;
|
2008-10-05 03:21:03 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
} else {
|
2008-11-24 05:45:46 +08:00
|
|
|
if (II->isStr("push")) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::PPK_Push;
|
2008-11-24 05:45:46 +08:00
|
|
|
} else if (II->isStr("pop")) {
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::PPK_Pop;
|
2008-10-05 03:21:03 +08:00
|
|
|
} else {
|
2014-02-13 07:50:26 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action) << "pack";
|
2008-10-05 03:21:03 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2008-10-05 03:21:03 +08:00
|
|
|
PP.Lex(Tok);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-05 03:21:03 +08:00
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-05 03:21:03 +08:00
|
|
|
if (Tok.is(tok::numeric_constant)) {
|
2012-10-04 10:36:51 +08:00
|
|
|
Alignment = Tok;
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
} else if (Tok.is(tok::identifier)) {
|
|
|
|
Name = Tok.getIdentifierInfo();
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-05 03:21:03 +08:00
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-05 03:21:03 +08:00
|
|
|
if (Tok.isNot(tok::numeric_constant)) {
|
2008-11-24 05:45:46 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
|
2008-10-05 03:21:03 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Alignment = Tok;
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
} else {
|
2008-11-24 05:45:46 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
|
2008-10-05 03:21:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-11 15:00:24 +08:00
|
|
|
} else if (PP.getLangOpts().ApplePragmaPack) {
|
2011-11-02 09:53:16 +08:00
|
|
|
// In MSVC/gcc, #pragma pack() resets the alignment without affecting
|
|
|
|
// the push/pop stack.
|
|
|
|
// In Apple gcc #pragma pack() is equivalent to #pragma pack(pop).
|
|
|
|
Kind = Sema::PPK_Pop;
|
2008-12-09 21:15:23 +08:00
|
|
|
}
|
2008-10-05 03:21:03 +08:00
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2009-03-24 06:28:25 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "pack";
|
2008-10-05 03:21:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-27 07:29:06 +08:00
|
|
|
SourceLocation RParenLoc = Tok.getLocation();
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Lex(Tok);
|
2011-02-28 10:37:51 +08:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-29 09:38:22 +08:00
|
|
|
PragmaPackInfo *Info =
|
|
|
|
(PragmaPackInfo*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(PragmaPackInfo), llvm::alignOf<PragmaPackInfo>());
|
|
|
|
new (Info) PragmaPackInfo();
|
2012-02-24 07:47:16 +08:00
|
|
|
Info->Kind = Kind;
|
|
|
|
Info->Name = Name;
|
2012-10-04 10:36:51 +08:00
|
|
|
Info->Alignment = Alignment;
|
2012-02-24 07:47:16 +08:00
|
|
|
Info->LParenLoc = LParenLoc;
|
|
|
|
Info->RParenLoc = RParenLoc;
|
|
|
|
|
2012-02-29 09:38:22 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
2012-02-24 07:47:16 +08:00
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_pack);
|
|
|
|
Toks[0].setLocation(PackLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(RParenLoc);
|
2012-02-24 07:47:16 +08:00
|
|
|
Toks[0].setAnnotationValue(static_cast<void*>(Info));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
2012-02-29 09:38:22 +08:00
|
|
|
/*OwnsTokens=*/false);
|
2008-10-05 03:21:03 +08:00
|
|
|
}
|
|
|
|
|
2011-04-26 02:49:15 +08:00
|
|
|
// #pragma ms_struct on
|
|
|
|
// #pragma ms_struct off
|
|
|
|
void PragmaMSStructHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &MSStructTok) {
|
|
|
|
Sema::PragmaMSStructKind Kind = Sema::PMSST_OFF;
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 08:10:23 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
2011-04-26 02:49:15 +08:00
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
if (II->isStr("on")) {
|
|
|
|
Kind = Sema::PMSST_ON;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
else if (II->isStr("off") || II->isStr("reset"))
|
|
|
|
PP.Lex(Tok);
|
|
|
|
else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_ms_struct);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
2012-02-29 09:38:22 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "ms_struct";
|
2011-04-26 02:49:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-10-04 10:36:51 +08:00
|
|
|
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_msstruct);
|
|
|
|
Toks[0].setLocation(MSStructTok.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(EndLoc);
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(Kind)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2011-04-26 02:49:15 +08:00
|
|
|
}
|
|
|
|
|
2010-08-01 03:17:07 +08:00
|
|
|
// #pragma 'align' '=' {'native','natural','mac68k','power','reset'}
|
|
|
|
// #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'}
|
2012-10-04 10:36:51 +08:00
|
|
|
static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok,
|
2010-08-01 03:17:07 +08:00
|
|
|
bool IsOptions) {
|
2010-05-27 07:29:06 +08:00
|
|
|
Token Tok;
|
2010-08-01 03:17:07 +08:00
|
|
|
|
|
|
|
if (IsOptions) {
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier) ||
|
|
|
|
!Tok.getIdentifierInfo()->isStr("align")) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_options_expected_align);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-27 07:29:06 +08:00
|
|
|
}
|
2010-05-28 02:42:09 +08:00
|
|
|
|
2010-05-27 07:29:06 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::equal)) {
|
2010-08-01 03:17:07 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_align_expected_equal)
|
|
|
|
<< IsOptions;
|
2010-05-27 07:29:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
2010-08-01 03:17:07 +08:00
|
|
|
<< (IsOptions ? "options" : "align");
|
2010-05-27 07:29:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
Sema::PragmaOptionsAlignKind Kind = Sema::POAK_Natural;
|
2010-05-27 07:29:06 +08:00
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
2010-05-28 02:42:09 +08:00
|
|
|
if (II->isStr("native"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Native;
|
2010-05-28 02:42:09 +08:00
|
|
|
else if (II->isStr("natural"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Natural;
|
2010-05-28 02:42:17 +08:00
|
|
|
else if (II->isStr("packed"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Packed;
|
2010-05-27 07:29:06 +08:00
|
|
|
else if (II->isStr("power"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Power;
|
2010-05-27 07:29:06 +08:00
|
|
|
else if (II->isStr("mac68k"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Mac68k;
|
2010-05-27 07:29:06 +08:00
|
|
|
else if (II->isStr("reset"))
|
2010-08-27 07:41:50 +08:00
|
|
|
Kind = Sema::POAK_Reset;
|
2010-05-27 07:29:06 +08:00
|
|
|
else {
|
2010-08-01 03:17:07 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_align_invalid_option)
|
|
|
|
<< IsOptions;
|
2010-05-27 07:29:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-19 08:10:23 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
2010-05-27 07:29:06 +08:00
|
|
|
PP.Lex(Tok);
|
2011-02-28 10:37:51 +08:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2010-05-27 07:29:06 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
2010-08-01 03:17:07 +08:00
|
|
|
<< (IsOptions ? "options" : "align");
|
2010-05-27 07:29:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_align);
|
|
|
|
Toks[0].setLocation(FirstTok.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(EndLoc);
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(Kind)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2010-08-01 03:17:07 +08:00
|
|
|
}
|
|
|
|
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaAlignHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &AlignTok) {
|
2012-10-04 10:36:51 +08:00
|
|
|
ParseAlignPragma(PP, AlignTok, /*IsOptions=*/false);
|
2010-08-01 03:17:07 +08:00
|
|
|
}
|
|
|
|
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaOptionsHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &OptionsTok) {
|
2012-10-04 10:36:51 +08:00
|
|
|
ParseAlignPragma(PP, OptionsTok, /*IsOptions=*/true);
|
2010-05-27 07:29:06 +08:00
|
|
|
}
|
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
// #pragma unused(identifier)
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaUnusedHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &UnusedTok) {
|
2009-03-24 06:28:25 +08:00
|
|
|
// FIXME: Should we be expanding macros here? My guess is no.
|
|
|
|
SourceLocation UnusedLoc = UnusedTok.getLocation();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
// Lex the left '('.
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "unused";
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
// Lex the declaration reference(s).
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Token, 5> Identifiers;
|
2009-03-24 06:28:25 +08:00
|
|
|
SourceLocation RParenLoc;
|
|
|
|
bool LexID = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
while (true) {
|
|
|
|
PP.Lex(Tok);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
if (LexID) {
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Tok.is(tok::identifier)) {
|
2009-08-04 07:24:57 +08:00
|
|
|
Identifiers.push_back(Tok);
|
2009-03-24 06:28:25 +08:00
|
|
|
LexID = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-04 07:24:57 +08:00
|
|
|
// Illegal token!
|
2009-03-24 06:28:25 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
// We are execting a ')' or a ','.
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
LexID = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
if (Tok.is(tok::r_paren)) {
|
|
|
|
RParenLoc = Tok.getLocation();
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-04 07:24:57 +08:00
|
|
|
// Illegal token!
|
2014-02-11 03:06:37 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_punc) << "unused";
|
2009-03-24 06:28:25 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-06-05 08:49:58 +08:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
2011-02-28 10:37:51 +08:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"unused";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-24 06:28:25 +08:00
|
|
|
// Verify that we have a location for the right parenthesis.
|
|
|
|
assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'");
|
2009-08-04 07:24:57 +08:00
|
|
|
assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments");
|
2009-03-24 06:28:25 +08:00
|
|
|
|
2011-01-18 02:58:44 +08:00
|
|
|
// For each identifier token, insert into the token stream a
|
|
|
|
// annot_pragma_unused token followed by the identifier token.
|
|
|
|
// This allows us to cache a "#pragma unused" that occurs inside an inline
|
|
|
|
// C++ member function.
|
|
|
|
|
2012-02-29 09:38:22 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 2 * Identifiers.size(), llvm::alignOf<Token>());
|
2011-01-18 02:58:44 +08:00
|
|
|
for (unsigned i=0; i != Identifiers.size(); i++) {
|
|
|
|
Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_unused);
|
|
|
|
pragmaUnusedTok.setLocation(UnusedLoc);
|
|
|
|
idTok = Identifiers[i];
|
|
|
|
}
|
2012-02-29 09:38:22 +08:00
|
|
|
PP.EnterTokenStream(Toks, 2*Identifiers.size(),
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-03-24 06:28:25 +08:00
|
|
|
}
|
2009-06-05 08:49:58 +08:00
|
|
|
|
|
|
|
// #pragma weak identifier
|
|
|
|
// #pragma weak identifier '=' identifier
|
2010-09-10 06:45:38 +08:00
|
|
|
void PragmaWeakHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &WeakTok) {
|
2009-06-05 08:49:58 +08:00
|
|
|
SourceLocation WeakLoc = WeakTok.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Token WeakName = Tok;
|
|
|
|
bool HasAlias = false;
|
|
|
|
Token AliasName;
|
2009-06-05 08:49:58 +08:00
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.is(tok::equal)) {
|
2012-10-04 10:36:51 +08:00
|
|
|
HasAlias = true;
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
2009-06-05 08:49:58 +08:00
|
|
|
<< "weak";
|
|
|
|
return;
|
|
|
|
}
|
2012-10-04 10:36:51 +08:00
|
|
|
AliasName = Tok;
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
|
2011-02-28 10:37:51 +08:00
|
|
|
if (Tok.isNot(tok::eod)) {
|
2009-06-05 08:49:58 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
if (HasAlias) {
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 3, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaUnusedTok = Toks[0];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_weakalias);
|
|
|
|
pragmaUnusedTok.setLocation(WeakLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
pragmaUnusedTok.setAnnotationEndLoc(AliasName.getLocation());
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[1] = WeakName;
|
|
|
|
Toks[2] = AliasName;
|
|
|
|
PP.EnterTokenStream(Toks, 3,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-06-05 08:49:58 +08:00
|
|
|
} else {
|
2012-10-04 10:36:51 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 2, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaUnusedTok = Toks[0];
|
|
|
|
pragmaUnusedTok.startToken();
|
|
|
|
pragmaUnusedTok.setKind(tok::annot_pragma_weak);
|
|
|
|
pragmaUnusedTok.setLocation(WeakLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
pragmaUnusedTok.setAnnotationEndLoc(WeakLoc);
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[1] = WeakName;
|
|
|
|
PP.EnterTokenStream(Toks, 2,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2009-06-05 08:49:58 +08:00
|
|
|
}
|
|
|
|
}
|
2011-02-14 09:42:35 +08:00
|
|
|
|
2012-02-19 00:12:34 +08:00
|
|
|
// #pragma redefine_extname identifier identifier
|
|
|
|
void PragmaRedefineExtnameHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &RedefToken) {
|
|
|
|
SourceLocation RedefLoc = RedefToken.getLocation();
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) <<
|
|
|
|
"redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Token RedefName = Tok;
|
2012-02-19 00:12:34 +08:00
|
|
|
PP.Lex(Tok);
|
2012-10-04 10:36:51 +08:00
|
|
|
|
2012-02-19 00:12:34 +08:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
2012-10-04 10:36:51 +08:00
|
|
|
|
|
|
|
Token AliasName = Tok;
|
2012-02-19 00:12:34 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"redefine_extname";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 3, llvm::alignOf<Token>());
|
|
|
|
Token &pragmaRedefTok = Toks[0];
|
|
|
|
pragmaRedefTok.startToken();
|
|
|
|
pragmaRedefTok.setKind(tok::annot_pragma_redefine_extname);
|
|
|
|
pragmaRedefTok.setLocation(RedefLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
pragmaRedefTok.setAnnotationEndLoc(AliasName.getLocation());
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[1] = RedefName;
|
|
|
|
Toks[2] = AliasName;
|
|
|
|
PP.EnterTokenStream(Toks, 3,
|
|
|
|
/*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);
|
2012-02-19 00:12:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-14 09:42:35 +08:00
|
|
|
void
|
|
|
|
PragmaFPContractHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
tok::OnOffSwitch OOS;
|
|
|
|
if (PP.LexOnOffSwitch(OOS))
|
|
|
|
return;
|
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_fp_contract);
|
|
|
|
Toks[0].setLocation(Tok.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(Tok.getLocation());
|
2012-10-04 10:36:51 +08:00
|
|
|
Toks[0].setAnnotationValue(reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(OOS)));
|
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2011-02-14 09:42:35 +08:00
|
|
|
}
|
2011-02-14 09:42:53 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
PragmaOpenCLExtensionHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
2011-04-15 07:35:31 +08:00
|
|
|
PP.LexUnexpandedToken(Tok);
|
2011-02-14 09:42:53 +08:00
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) <<
|
|
|
|
"OPENCL";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IdentifierInfo *ename = Tok.getIdentifierInfo();
|
|
|
|
SourceLocation NameLoc = Tok.getLocation();
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::colon)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_colon) << ename;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IdentifierInfo *op = Tok.getIdentifierInfo();
|
|
|
|
|
|
|
|
unsigned state;
|
|
|
|
if (op->isStr("enable")) {
|
|
|
|
state = 1;
|
|
|
|
} else if (op->isStr("disable")) {
|
|
|
|
state = 0;
|
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_enable_disable);
|
|
|
|
return;
|
|
|
|
}
|
2013-10-12 17:29:48 +08:00
|
|
|
SourceLocation StateLoc = Tok.getLocation();
|
2011-02-14 09:42:53 +08:00
|
|
|
|
2012-10-04 10:36:51 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
|
|
|
|
"OPENCL EXTENSION";
|
2011-02-14 09:42:53 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-10-04 10:36:51 +08:00
|
|
|
|
|
|
|
OpenCLExtData data(ename, state);
|
|
|
|
Token *Toks =
|
|
|
|
(Token*) PP.getPreprocessorAllocator().Allocate(
|
|
|
|
sizeof(Token) * 1, llvm::alignOf<Token>());
|
|
|
|
new (Toks) Token();
|
|
|
|
Toks[0].startToken();
|
|
|
|
Toks[0].setKind(tok::annot_pragma_opencl_extension);
|
|
|
|
Toks[0].setLocation(NameLoc);
|
|
|
|
Toks[0].setAnnotationValue(data.getOpaqueValue());
|
2015-03-19 08:10:23 +08:00
|
|
|
Toks[0].setAnnotationEndLoc(StateLoc);
|
2012-10-04 10:36:51 +08:00
|
|
|
PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,
|
|
|
|
/*OwnsTokens=*/false);
|
2013-10-12 17:29:48 +08:00
|
|
|
|
|
|
|
if (PP.getPPCallbacks())
|
|
|
|
PP.getPPCallbacks()->PragmaOpenCLExtension(NameLoc, ename,
|
|
|
|
StateLoc, state);
|
2011-02-14 09:42:53 +08:00
|
|
|
}
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
/// \brief Handle '#pragma omp ...' when OpenMP is disabled.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
PragmaNoOpenMPHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstTok) {
|
2014-06-16 07:30:39 +08:00
|
|
|
if (!PP.getDiagnostics().isIgnored(diag::warn_pragma_omp_ignored,
|
|
|
|
FirstTok.getLocation())) {
|
2013-03-22 14:34:35 +08:00
|
|
|
PP.Diag(FirstTok, diag::warn_pragma_omp_ignored);
|
2014-06-12 19:13:52 +08:00
|
|
|
PP.getDiagnostics().setSeverity(diag::warn_pragma_omp_ignored,
|
|
|
|
diag::Severity::Ignored, SourceLocation());
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
PP.DiscardUntilEndOfDirective();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Handle '#pragma omp ...' when OpenMP is enabled.
|
|
|
|
///
|
|
|
|
void
|
|
|
|
PragmaOpenMPHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstTok) {
|
|
|
|
SmallVector<Token, 16> Pragma;
|
|
|
|
Token Tok;
|
|
|
|
Tok.startToken();
|
|
|
|
Tok.setKind(tok::annot_pragma_openmp);
|
|
|
|
Tok.setLocation(FirstTok.getLocation());
|
|
|
|
|
|
|
|
while (Tok.isNot(tok::eod)) {
|
|
|
|
Pragma.push_back(Tok);
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
|
|
|
SourceLocation EodLoc = Tok.getLocation();
|
|
|
|
Tok.startToken();
|
|
|
|
Tok.setKind(tok::annot_pragma_openmp_end);
|
|
|
|
Tok.setLocation(EodLoc);
|
|
|
|
Pragma.push_back(Tok);
|
|
|
|
|
|
|
|
Token *Toks = new Token[Pragma.size()];
|
|
|
|
std::copy(Pragma.begin(), Pragma.end(), Toks);
|
|
|
|
PP.EnterTokenStream(Toks, Pragma.size(),
|
2015-05-05 17:53:25 +08:00
|
|
|
/*DisableMacroExpansion=*/false, /*OwnsTokens=*/true);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-07 05:02:12 +08:00
|
|
|
|
2014-02-11 03:50:15 +08:00
|
|
|
/// \brief Handle '#pragma pointers_to_members'
|
|
|
|
// The grammar for this pragma is as follows:
|
|
|
|
//
|
|
|
|
// <inheritance model> ::= ('single' | 'multiple' | 'virtual') '_inheritance'
|
|
|
|
//
|
|
|
|
// #pragma pointers_to_members '(' 'best_case' ')'
|
|
|
|
// #pragma pointers_to_members '(' 'full_generality' [',' inheritance-model] ')'
|
|
|
|
// #pragma pointers_to_members '(' inheritance-model ')'
|
|
|
|
void PragmaMSPointersToMembers::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
SourceLocation PointersToMembersLoc = Tok.getLocation();
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
|
|
|
|
<< "pointers_to_members";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
const IdentifierInfo *Arg = Tok.getIdentifierInfo();
|
|
|
|
if (!Arg) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
|
|
|
|
<< "pointers_to_members";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
|
2014-02-12 05:05:00 +08:00
|
|
|
LangOptions::PragmaMSPointersToMembersKind RepresentationMethod;
|
2014-02-11 03:50:15 +08:00
|
|
|
if (Arg->isStr("best_case")) {
|
2014-02-12 05:05:00 +08:00
|
|
|
RepresentationMethod = LangOptions::PPTMK_BestCase;
|
2014-02-11 03:50:15 +08:00
|
|
|
} else {
|
|
|
|
if (Arg->isStr("full_generality")) {
|
|
|
|
if (Tok.is(tok::comma)) {
|
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
Arg = Tok.getIdentifierInfo();
|
|
|
|
if (!Arg) {
|
|
|
|
PP.Diag(Tok.getLocation(),
|
|
|
|
diag::err_pragma_pointers_to_members_unknown_kind)
|
|
|
|
<< Tok.getKind() << /*OnlyInheritanceModels*/ 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
} else if (Tok.is(tok::r_paren)) {
|
|
|
|
// #pragma pointers_to_members(full_generality) implicitly specifies
|
|
|
|
// virtual_inheritance.
|
2014-05-21 14:02:52 +08:00
|
|
|
Arg = nullptr;
|
2014-02-12 05:05:00 +08:00
|
|
|
RepresentationMethod = LangOptions::PPTMK_FullGeneralityVirtualInheritance;
|
2014-02-11 03:50:15 +08:00
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_expected_punc)
|
|
|
|
<< "full_generality";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg) {
|
|
|
|
if (Arg->isStr("single_inheritance")) {
|
2014-02-12 05:05:00 +08:00
|
|
|
RepresentationMethod =
|
|
|
|
LangOptions::PPTMK_FullGeneralitySingleInheritance;
|
2014-02-11 03:50:15 +08:00
|
|
|
} else if (Arg->isStr("multiple_inheritance")) {
|
2014-02-12 05:05:00 +08:00
|
|
|
RepresentationMethod =
|
|
|
|
LangOptions::PPTMK_FullGeneralityMultipleInheritance;
|
2014-02-11 03:50:15 +08:00
|
|
|
} else if (Arg->isStr("virtual_inheritance")) {
|
2014-02-12 05:05:00 +08:00
|
|
|
RepresentationMethod =
|
|
|
|
LangOptions::PPTMK_FullGeneralityVirtualInheritance;
|
2014-02-11 03:50:15 +08:00
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(),
|
|
|
|
diag::err_pragma_pointers_to_members_unknown_kind)
|
|
|
|
<< Arg << /*HasPointerDeclaration*/ 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_expected_rparen_after)
|
|
|
|
<< (Arg ? Arg->getName() : "full_generality");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-19 08:10:23 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
2014-02-11 03:50:15 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "pointers_to_members";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Token AnnotTok;
|
|
|
|
AnnotTok.startToken();
|
|
|
|
AnnotTok.setKind(tok::annot_pragma_ms_pointers_to_members);
|
|
|
|
AnnotTok.setLocation(PointersToMembersLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
AnnotTok.setAnnotationEndLoc(EndLoc);
|
2014-02-11 03:50:15 +08:00
|
|
|
AnnotTok.setAnnotationValue(
|
|
|
|
reinterpret_cast<void *>(static_cast<uintptr_t>(RepresentationMethod)));
|
|
|
|
PP.EnterToken(AnnotTok);
|
|
|
|
}
|
|
|
|
|
2014-02-13 07:50:26 +08:00
|
|
|
/// \brief Handle '#pragma vtordisp'
|
|
|
|
// The grammar for this pragma is as follows:
|
|
|
|
//
|
|
|
|
// <vtordisp-mode> ::= ('off' | 'on' | '0' | '1' | '2' )
|
|
|
|
//
|
|
|
|
// #pragma vtordisp '(' ['push' ','] vtordisp-mode ')'
|
|
|
|
// #pragma vtordisp '(' 'pop' ')'
|
|
|
|
// #pragma vtordisp '(' ')'
|
|
|
|
void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
SourceLocation VtorDispLoc = Tok.getLocation();
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) << "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
Sema::PragmaVtorDispKind Kind = Sema::PVDK_Set;
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
if (II) {
|
|
|
|
if (II->isStr("push")) {
|
|
|
|
// #pragma vtordisp(push, mode)
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::comma)) {
|
|
|
|
PP.Diag(VtorDispLoc, diag::warn_pragma_expected_punc) << "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
Kind = Sema::PVDK_Push;
|
|
|
|
// not push, could be on/off
|
|
|
|
} else if (II->isStr("pop")) {
|
|
|
|
// #pragma vtordisp(pop)
|
|
|
|
PP.Lex(Tok);
|
|
|
|
Kind = Sema::PVDK_Pop;
|
|
|
|
}
|
|
|
|
// not push or pop, could be on/off
|
|
|
|
} else {
|
|
|
|
if (Tok.is(tok::r_paren)) {
|
|
|
|
// #pragma vtordisp()
|
|
|
|
Kind = Sema::PVDK_Reset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-13 08:44:34 +08:00
|
|
|
uint64_t Value = 0;
|
2014-02-13 07:50:26 +08:00
|
|
|
if (Kind == Sema::PVDK_Push || Kind == Sema::PVDK_Set) {
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
if (II && II->isStr("off")) {
|
|
|
|
PP.Lex(Tok);
|
|
|
|
Value = 0;
|
|
|
|
} else if (II && II->isStr("on")) {
|
|
|
|
PP.Lex(Tok);
|
|
|
|
Value = 1;
|
|
|
|
} else if (Tok.is(tok::numeric_constant) &&
|
|
|
|
PP.parseSimpleIntegerLiteral(Tok, Value)) {
|
|
|
|
if (Value > 2) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_integer)
|
|
|
|
<< 0 << 2 << "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_action)
|
|
|
|
<< "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish the pragma: ')' $
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) << "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
2015-03-19 08:10:23 +08:00
|
|
|
SourceLocation EndLoc = Tok.getLocation();
|
2014-02-13 07:50:26 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "vtordisp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enter the annotation.
|
|
|
|
Token AnnotTok;
|
|
|
|
AnnotTok.startToken();
|
|
|
|
AnnotTok.setKind(tok::annot_pragma_ms_vtordisp);
|
|
|
|
AnnotTok.setLocation(VtorDispLoc);
|
2015-03-19 08:10:23 +08:00
|
|
|
AnnotTok.setAnnotationEndLoc(EndLoc);
|
2014-02-13 08:44:34 +08:00
|
|
|
AnnotTok.setAnnotationValue(reinterpret_cast<void *>(
|
|
|
|
static_cast<uintptr_t>((Kind << 16) | (Value & 0xFFFF))));
|
2014-02-13 07:50:26 +08:00
|
|
|
PP.EnterToken(AnnotTok);
|
|
|
|
}
|
|
|
|
|
2014-04-09 06:30:47 +08:00
|
|
|
/// \brief Handle all MS pragmas. Simply forwards the tokens after inserting
|
|
|
|
/// an annotation token.
|
|
|
|
void PragmaMSPragma::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
Token EoF, AnnotTok;
|
|
|
|
EoF.startToken();
|
|
|
|
EoF.setKind(tok::eof);
|
|
|
|
AnnotTok.startToken();
|
|
|
|
AnnotTok.setKind(tok::annot_pragma_ms_pragma);
|
|
|
|
AnnotTok.setLocation(Tok.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
AnnotTok.setAnnotationEndLoc(Tok.getLocation());
|
2014-04-09 06:30:47 +08:00
|
|
|
SmallVector<Token, 8> TokenVector;
|
|
|
|
// Suck up all of the tokens before the eod.
|
2015-03-19 08:10:23 +08:00
|
|
|
for (; Tok.isNot(tok::eod); PP.Lex(Tok)) {
|
2014-04-09 06:30:47 +08:00
|
|
|
TokenVector.push_back(Tok);
|
2015-03-19 08:10:23 +08:00
|
|
|
AnnotTok.setAnnotationEndLoc(Tok.getLocation());
|
|
|
|
}
|
2014-04-09 06:30:47 +08:00
|
|
|
// Add a sentinal EoF token to the end of the list.
|
|
|
|
TokenVector.push_back(EoF);
|
|
|
|
// We must allocate this array with new because EnterTokenStream is going to
|
|
|
|
// delete it later.
|
|
|
|
Token *TokenArray = new Token[TokenVector.size()];
|
|
|
|
std::copy(TokenVector.begin(), TokenVector.end(), TokenArray);
|
|
|
|
auto Value = new (PP.getPreprocessorAllocator())
|
|
|
|
std::pair<Token*, size_t>(std::make_pair(TokenArray, TokenVector.size()));
|
|
|
|
AnnotTok.setAnnotationValue(Value);
|
|
|
|
PP.EnterToken(AnnotTok);
|
2014-04-04 03:04:24 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 10:07:14 +08:00
|
|
|
/// \brief Handle the Microsoft \#pragma detect_mismatch extension.
|
|
|
|
///
|
|
|
|
/// The syntax is:
|
|
|
|
/// \code
|
|
|
|
/// #pragma detect_mismatch("name", "value")
|
|
|
|
/// \endcode
|
|
|
|
/// Where 'name' and 'value' are quoted strings. The values are embedded in
|
|
|
|
/// the object file and passed along to the linker. If the linker detects a
|
|
|
|
/// mismatch in the object file's values for the given name, a LNK2038 error
|
|
|
|
/// is emitted. See MSDN for more details.
|
|
|
|
void PragmaDetectMismatchHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
SourceLocation CommentLoc = Tok.getLocation();
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
2013-12-24 17:48:30 +08:00
|
|
|
PP.Diag(CommentLoc, diag::err_expected) << tok::l_paren;
|
2013-06-04 10:07:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the name to embed, which must be a string literal.
|
|
|
|
std::string NameString;
|
|
|
|
if (!PP.LexStringLiteral(Tok, NameString,
|
|
|
|
"pragma detect_mismatch",
|
|
|
|
/*MacroExpansion=*/true))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Read the comma followed by a second string literal.
|
|
|
|
std::string ValueString;
|
|
|
|
if (Tok.isNot(tok::comma)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_detect_mismatch_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PP.LexStringLiteral(Tok, ValueString, "pragma detect_mismatch",
|
|
|
|
/*MacroExpansion=*/true))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
2013-12-24 17:48:30 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren;
|
2013-06-04 10:07:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok); // Eat the r_paren.
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_detect_mismatch_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 07:37:45 +08:00
|
|
|
// If the pragma is lexically sound, notify any interested PPCallbacks.
|
|
|
|
if (PP.getPPCallbacks())
|
|
|
|
PP.getPPCallbacks()->PragmaDetectMismatch(CommentLoc, NameString,
|
|
|
|
ValueString);
|
|
|
|
|
2013-06-04 10:07:14 +08:00
|
|
|
Actions.ActOnPragmaDetectMismatch(NameString, ValueString);
|
|
|
|
}
|
|
|
|
|
2013-05-07 05:02:12 +08:00
|
|
|
/// \brief Handle the microsoft \#pragma comment extension.
|
|
|
|
///
|
|
|
|
/// The syntax is:
|
|
|
|
/// \code
|
|
|
|
/// #pragma comment(linker, "foo")
|
|
|
|
/// \endcode
|
|
|
|
/// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user.
|
|
|
|
/// "foo" is a string, which is fully macro expanded, and permits string
|
|
|
|
/// concatenation, embedded escape characters etc. See MSDN for more details.
|
|
|
|
void PragmaCommentHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
|
|
|
SourceLocation CommentLoc = Tok.getLocation();
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(CommentLoc, diag::err_pragma_comment_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the identifier.
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(CommentLoc, diag::err_pragma_comment_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that this is one of the 5 whitelisted options.
|
2013-05-08 21:44:39 +08:00
|
|
|
IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
Sema::PragmaMSCommentKind Kind =
|
|
|
|
llvm::StringSwitch<Sema::PragmaMSCommentKind>(II->getName())
|
|
|
|
.Case("linker", Sema::PCK_Linker)
|
|
|
|
.Case("lib", Sema::PCK_Lib)
|
|
|
|
.Case("compiler", Sema::PCK_Compiler)
|
|
|
|
.Case("exestr", Sema::PCK_ExeStr)
|
|
|
|
.Case("user", Sema::PCK_User)
|
|
|
|
.Default(Sema::PCK_Unknown);
|
|
|
|
if (Kind == Sema::PCK_Unknown) {
|
2013-05-07 05:02:12 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-24 04:41:42 +08:00
|
|
|
// On PS4, issue a warning about any pragma comments other than
|
|
|
|
// #pragma comment lib.
|
|
|
|
if (PP.getTargetInfo().getTriple().isPS4() && Kind != Sema::PCK_Lib) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_comment_ignored)
|
|
|
|
<< II->getName();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-07 05:02:12 +08:00
|
|
|
// Read the optional string if present.
|
|
|
|
PP.Lex(Tok);
|
|
|
|
std::string ArgumentString;
|
|
|
|
if (Tok.is(tok::comma) && !PP.LexStringLiteral(Tok, ArgumentString,
|
|
|
|
"pragma comment",
|
|
|
|
/*MacroExpansion=*/true))
|
|
|
|
return;
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
// FIXME: warn that 'exestr' is deprecated.
|
2013-05-07 05:02:12 +08:00
|
|
|
// FIXME: If the kind is "compiler" warn if the string is present (it is
|
|
|
|
// ignored).
|
2013-05-08 21:44:39 +08:00
|
|
|
// The MSDN docs say that "lib" and "linker" require a string and have a short
|
|
|
|
// whitelist of linker options they support, but in practice MSVC doesn't
|
|
|
|
// issue a diagnostic. Therefore neither does clang.
|
2013-05-07 05:02:12 +08:00
|
|
|
|
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok); // eat the r_paren.
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 07:37:45 +08:00
|
|
|
// If the pragma is lexically sound, notify any interested PPCallbacks.
|
|
|
|
if (PP.getPPCallbacks())
|
|
|
|
PP.getPPCallbacks()->PragmaComment(CommentLoc, II, ArgumentString);
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
Actions.ActOnPragmaMSComment(Kind, ArgumentString);
|
2013-05-07 05:02:12 +08:00
|
|
|
}
|
2014-05-23 20:13:25 +08:00
|
|
|
|
|
|
|
// #pragma clang optimize off
|
|
|
|
// #pragma clang optimize on
|
|
|
|
void PragmaOptimizeHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &FirstToken) {
|
|
|
|
Token Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.is(tok::eod)) {
|
2014-07-22 02:08:34 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_missing_argument)
|
2014-07-24 01:31:31 +08:00
|
|
|
<< "clang optimize" << /*Expected=*/true << "'on' or 'off'";
|
2014-05-23 20:13:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument)
|
|
|
|
<< PP.getSpelling(Tok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const IdentifierInfo *II = Tok.getIdentifierInfo();
|
|
|
|
// The only accepted values are 'on' or 'off'.
|
|
|
|
bool IsOn = false;
|
|
|
|
if (II->isStr("on")) {
|
|
|
|
IsOn = true;
|
|
|
|
} else if (!II->isStr("off")) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument)
|
|
|
|
<< PP.getSpelling(Tok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_extra_argument)
|
|
|
|
<< PP.getSpelling(Tok);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-07 04:31:48 +08:00
|
|
|
|
|
|
|
Actions.ActOnPragmaOptimize(IsOn, FirstToken.getLocation());
|
|
|
|
}
|
|
|
|
|
2014-07-22 02:08:34 +08:00
|
|
|
/// \brief Parses loop or unroll pragma hint value and fills in Info.
|
2014-08-01 04:15:14 +08:00
|
|
|
static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName,
|
|
|
|
Token Option, bool ValueInParens,
|
2014-07-22 02:08:34 +08:00
|
|
|
PragmaLoopHintInfo &Info) {
|
2014-10-13 04:46:07 +08:00
|
|
|
SmallVector<Token, 1> ValueList;
|
|
|
|
int OpenParens = ValueInParens ? 1 : 0;
|
|
|
|
// Read constant expression.
|
|
|
|
while (Tok.isNot(tok::eod)) {
|
|
|
|
if (Tok.is(tok::l_paren))
|
|
|
|
OpenParens++;
|
|
|
|
else if (Tok.is(tok::r_paren)) {
|
|
|
|
OpenParens--;
|
|
|
|
if (OpenParens == 0 && ValueInParens)
|
|
|
|
break;
|
2014-07-22 02:08:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
ValueList.push_back(Tok);
|
|
|
|
PP.Lex(Tok);
|
|
|
|
}
|
2014-07-22 02:08:34 +08:00
|
|
|
|
|
|
|
if (ValueInParens) {
|
2014-08-01 04:15:14 +08:00
|
|
|
// Read ')'
|
2014-07-22 02:08:34 +08:00
|
|
|
if (Tok.isNot(tok::r_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren;
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-01 04:15:14 +08:00
|
|
|
PP.Lex(Tok);
|
2014-07-22 02:08:34 +08:00
|
|
|
}
|
|
|
|
|
2014-10-13 04:46:07 +08:00
|
|
|
Token EOFTok;
|
|
|
|
EOFTok.startToken();
|
|
|
|
EOFTok.setKind(tok::eof);
|
|
|
|
EOFTok.setLocation(Tok.getLocation());
|
|
|
|
ValueList.push_back(EOFTok); // Terminates expression for parsing.
|
|
|
|
|
2015-08-05 17:39:57 +08:00
|
|
|
Info.Toks = llvm::makeArrayRef(ValueList).copy(PP.getPreprocessorAllocator());
|
2014-10-13 04:46:07 +08:00
|
|
|
|
2014-07-22 02:08:34 +08:00
|
|
|
Info.PragmaName = PragmaName;
|
|
|
|
Info.Option = Option;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-07 04:31:48 +08:00
|
|
|
/// \brief Handle the \#pragma clang loop directive.
|
|
|
|
/// #pragma clang 'loop' loop-hints
|
|
|
|
///
|
|
|
|
/// loop-hints:
|
|
|
|
/// loop-hint loop-hints[opt]
|
|
|
|
///
|
|
|
|
/// loop-hint:
|
|
|
|
/// 'vectorize' '(' loop-hint-keyword ')'
|
|
|
|
/// 'interleave' '(' loop-hint-keyword ')'
|
2014-07-24 01:31:31 +08:00
|
|
|
/// 'unroll' '(' unroll-hint-keyword ')'
|
2014-06-07 04:31:48 +08:00
|
|
|
/// 'vectorize_width' '(' loop-hint-value ')'
|
|
|
|
/// 'interleave_count' '(' loop-hint-value ')'
|
2014-06-12 01:56:26 +08:00
|
|
|
/// 'unroll_count' '(' loop-hint-value ')'
|
2014-06-07 04:31:48 +08:00
|
|
|
///
|
|
|
|
/// loop-hint-keyword:
|
|
|
|
/// 'enable'
|
|
|
|
/// 'disable'
|
2015-06-12 07:23:17 +08:00
|
|
|
/// 'assume_safety'
|
2014-06-07 04:31:48 +08:00
|
|
|
///
|
2014-07-24 01:31:31 +08:00
|
|
|
/// unroll-hint-keyword:
|
2015-08-11 01:29:39 +08:00
|
|
|
/// 'enable'
|
2014-07-24 01:31:31 +08:00
|
|
|
/// 'disable'
|
2015-08-11 01:29:39 +08:00
|
|
|
/// 'full'
|
2014-07-24 01:31:31 +08:00
|
|
|
///
|
2014-06-07 04:31:48 +08:00
|
|
|
/// loop-hint-value:
|
|
|
|
/// constant-expression
|
|
|
|
///
|
|
|
|
/// Specifying vectorize(enable) or vectorize_width(_value_) instructs llvm to
|
|
|
|
/// try vectorizing the instructions of the loop it precedes. Specifying
|
|
|
|
/// interleave(enable) or interleave_count(_value_) instructs llvm to try
|
|
|
|
/// interleaving multiple iterations of the loop it precedes. The width of the
|
|
|
|
/// vector instructions is specified by vectorize_width() and the number of
|
|
|
|
/// interleaved loop iterations is specified by interleave_count(). Specifying a
|
|
|
|
/// value of 1 effectively disables vectorization/interleaving, even if it is
|
|
|
|
/// possible and profitable, and 0 is invalid. The loop vectorizer currently
|
|
|
|
/// only works on inner loops.
|
|
|
|
///
|
2014-06-12 01:56:26 +08:00
|
|
|
/// The unroll and unroll_count directives control the concatenation
|
2015-08-11 01:29:39 +08:00
|
|
|
/// unroller. Specifying unroll(enable) instructs llvm to unroll the loop
|
|
|
|
/// completely if the trip count is known at compile time and unroll partially
|
|
|
|
/// if the trip count is not known. Specifying unroll(full) is similar to
|
|
|
|
/// unroll(enable) but will unroll the loop only if the trip count is known at
|
|
|
|
/// compile time. Specifying unroll(disable) disables unrolling for the
|
|
|
|
/// loop. Specifying unroll_count(_value_) instructs llvm to try to unroll the
|
|
|
|
/// loop the number of times indicated by the value.
|
2014-06-07 04:31:48 +08:00
|
|
|
void PragmaLoopHintHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
2014-07-22 02:08:34 +08:00
|
|
|
// Incoming token is "loop" from "#pragma clang loop".
|
|
|
|
Token PragmaName = Tok;
|
2014-06-07 04:31:48 +08:00
|
|
|
SmallVector<Token, 1> TokenList;
|
|
|
|
|
|
|
|
// Lex the optimization option and verify it is an identifier.
|
|
|
|
PP.Lex(Tok);
|
|
|
|
if (Tok.isNot(tok::identifier)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_loop_invalid_option)
|
|
|
|
<< /*MissingOption=*/true << "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (Tok.is(tok::identifier)) {
|
|
|
|
Token Option = Tok;
|
|
|
|
IdentifierInfo *OptionInfo = Tok.getIdentifierInfo();
|
|
|
|
|
2014-06-12 01:56:26 +08:00
|
|
|
bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->getName())
|
2014-07-22 02:08:34 +08:00
|
|
|
.Case("vectorize", true)
|
|
|
|
.Case("interleave", true)
|
|
|
|
.Case("unroll", true)
|
|
|
|
.Case("vectorize_width", true)
|
|
|
|
.Case("interleave_count", true)
|
|
|
|
.Case("unroll_count", true)
|
|
|
|
.Default(false);
|
2014-06-12 01:56:26 +08:00
|
|
|
if (!OptionValid) {
|
2014-06-07 04:31:48 +08:00
|
|
|
PP.Diag(Tok.getLocation(), diag::err_pragma_loop_invalid_option)
|
|
|
|
<< /*MissingOption=*/false << OptionInfo;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-31 04:54:33 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
|
2014-08-01 04:15:14 +08:00
|
|
|
// Read '('
|
|
|
|
if (Tok.isNot(tok::l_paren)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren;
|
2014-07-31 04:54:33 +08:00
|
|
|
return;
|
2014-07-31 09:52:33 +08:00
|
|
|
}
|
2014-08-01 04:15:14 +08:00
|
|
|
PP.Lex(Tok);
|
|
|
|
|
|
|
|
auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo;
|
|
|
|
if (ParseLoopHintValue(PP, Tok, PragmaName, Option, /*ValueInParens=*/true,
|
|
|
|
*Info))
|
|
|
|
return;
|
2014-06-07 04:31:48 +08:00
|
|
|
|
2014-07-22 02:08:34 +08:00
|
|
|
// Generate the loop hint token.
|
2014-06-07 04:31:48 +08:00
|
|
|
Token LoopHintTok;
|
|
|
|
LoopHintTok.startToken();
|
|
|
|
LoopHintTok.setKind(tok::annot_pragma_loop_hint);
|
2014-07-22 02:08:34 +08:00
|
|
|
LoopHintTok.setLocation(PragmaName.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
LoopHintTok.setAnnotationEndLoc(PragmaName.getLocation());
|
2014-06-07 04:31:48 +08:00
|
|
|
LoopHintTok.setAnnotationValue(static_cast<void *>(Info));
|
|
|
|
TokenList.push_back(LoopHintTok);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "clang loop";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Token *TokenArray = new Token[TokenList.size()];
|
|
|
|
std::copy(TokenList.begin(), TokenList.end(), TokenArray);
|
|
|
|
|
|
|
|
PP.EnterTokenStream(TokenArray, TokenList.size(),
|
|
|
|
/*DisableMacroExpansion=*/false,
|
|
|
|
/*OwnsTokens=*/true);
|
|
|
|
}
|
2014-07-22 02:08:34 +08:00
|
|
|
|
|
|
|
/// \brief Handle the loop unroll optimization pragmas.
|
|
|
|
/// #pragma unroll
|
|
|
|
/// #pragma unroll unroll-hint-value
|
|
|
|
/// #pragma unroll '(' unroll-hint-value ')'
|
2014-07-25 02:09:38 +08:00
|
|
|
/// #pragma nounroll
|
2014-07-22 02:08:34 +08:00
|
|
|
///
|
|
|
|
/// unroll-hint-value:
|
|
|
|
/// constant-expression
|
|
|
|
///
|
2014-07-25 02:09:38 +08:00
|
|
|
/// Loop unrolling hints can be specified with '#pragma unroll' or
|
|
|
|
/// '#pragma nounroll'. '#pragma unroll' can take a numeric argument optionally
|
|
|
|
/// contained in parentheses. With no argument the directive instructs llvm to
|
|
|
|
/// try to unroll the loop completely. A positive integer argument can be
|
|
|
|
/// specified to indicate the number of times the loop should be unrolled. To
|
|
|
|
/// maximize compatibility with other compilers the unroll count argument can be
|
|
|
|
/// specified with or without parentheses. Specifying, '#pragma nounroll'
|
|
|
|
/// disables unrolling of the loop.
|
2014-07-22 02:08:34 +08:00
|
|
|
void PragmaUnrollHintHandler::HandlePragma(Preprocessor &PP,
|
|
|
|
PragmaIntroducerKind Introducer,
|
|
|
|
Token &Tok) {
|
2014-07-25 02:09:38 +08:00
|
|
|
// Incoming token is "unroll" for "#pragma unroll", or "nounroll" for
|
|
|
|
// "#pragma nounroll".
|
2014-07-22 02:08:34 +08:00
|
|
|
Token PragmaName = Tok;
|
|
|
|
PP.Lex(Tok);
|
|
|
|
auto *Info = new (PP.getPreprocessorAllocator()) PragmaLoopHintInfo;
|
|
|
|
if (Tok.is(tok::eod)) {
|
2014-07-25 02:09:38 +08:00
|
|
|
// nounroll or unroll pragma without an argument.
|
2014-07-22 02:08:34 +08:00
|
|
|
Info->PragmaName = PragmaName;
|
2014-08-01 20:41:37 +08:00
|
|
|
Info->Option.startToken();
|
2014-07-25 02:09:38 +08:00
|
|
|
} else if (PragmaName.getIdentifierInfo()->getName() == "nounroll") {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "nounroll";
|
|
|
|
return;
|
2014-07-22 02:08:34 +08:00
|
|
|
} else {
|
|
|
|
// Unroll pragma with an argument: "#pragma unroll N" or
|
|
|
|
// "#pragma unroll(N)".
|
2014-08-01 04:15:14 +08:00
|
|
|
// Read '(' if it exists.
|
|
|
|
bool ValueInParens = Tok.is(tok::l_paren);
|
|
|
|
if (ValueInParens)
|
|
|
|
PP.Lex(Tok);
|
|
|
|
|
2014-08-01 20:20:20 +08:00
|
|
|
Token Option;
|
|
|
|
Option.startToken();
|
|
|
|
if (ParseLoopHintValue(PP, Tok, PragmaName, Option, ValueInParens, *Info))
|
2014-07-22 02:08:34 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// In CUDA, the argument to '#pragma unroll' should not be contained in
|
|
|
|
// parentheses.
|
|
|
|
if (PP.getLangOpts().CUDA && ValueInParens)
|
2014-10-13 04:46:07 +08:00
|
|
|
PP.Diag(Info->Toks[0].getLocation(),
|
2014-07-22 02:08:34 +08:00
|
|
|
diag::warn_pragma_unroll_cuda_value_in_parens);
|
|
|
|
|
|
|
|
if (Tok.isNot(tok::eod)) {
|
|
|
|
PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
|
|
|
|
<< "unroll";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the hint token.
|
|
|
|
Token *TokenArray = new Token[1];
|
|
|
|
TokenArray[0].startToken();
|
|
|
|
TokenArray[0].setKind(tok::annot_pragma_loop_hint);
|
|
|
|
TokenArray[0].setLocation(PragmaName.getLocation());
|
2015-03-19 08:10:23 +08:00
|
|
|
TokenArray[0].setAnnotationEndLoc(PragmaName.getLocation());
|
2014-07-22 02:08:34 +08:00
|
|
|
TokenArray[0].setAnnotationValue(static_cast<void *>(Info));
|
|
|
|
PP.EnterTokenStream(TokenArray, 1, /*DisableMacroExpansion=*/false,
|
|
|
|
/*OwnsTokens=*/true);
|
|
|
|
}
|