-fms-extensions: Error out on #pragma init_seg

By ignoring this pragma with a warning, we're essentially miscompiling
the user's program.  WebKit / Blink use this pragma to disable dynamic
initialization and finalization of some static data, and running the
dtors crashes the program.

Error out for now, so that /fallback compiles the TU correctly with
MSVC.  This pragma should be implemented some time this month, and we
can remove this hack.

llvm-svn: 205554
This commit is contained in:
Reid Kleckner 2014-04-03 19:04:24 +00:00
parent d7c5e51627
commit d3923aaa6e
3 changed files with 35 additions and 0 deletions

View File

@ -154,6 +154,7 @@ class Parser : public CodeCompletionHandler {
std::unique_ptr<PragmaHandler> MSDetectMismatchHandler;
std::unique_ptr<PragmaHandler> MSPointersToMembers;
std::unique_ptr<PragmaHandler> MSVtorDisp;
std::unique_ptr<PragmaHandler> MSInitSeg;
std::unique_ptr<CommentHandler> CommentSemaHandler;

View File

@ -124,6 +124,12 @@ struct PragmaMSVtorDisp : public PragmaHandler {
Token &FirstToken) override;
};
struct PragmaMSInitSeg : public PragmaHandler {
explicit PragmaMSInitSeg() : PragmaHandler("init_seg") {}
void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
Token &FirstToken) override;
};
} // end namespace
void Parser::initializePragmaHandlers() {
@ -175,6 +181,8 @@ void Parser::initializePragmaHandlers() {
PP.AddPragmaHandler(MSPointersToMembers.get());
MSVtorDisp.reset(new PragmaMSVtorDisp());
PP.AddPragmaHandler(MSVtorDisp.get());
MSInitSeg.reset(new PragmaMSInitSeg());
PP.AddPragmaHandler(MSInitSeg.get());
}
}
@ -214,6 +222,8 @@ void Parser::resetPragmaHandlers() {
MSPointersToMembers.reset();
PP.RemovePragmaHandler(MSVtorDisp.get());
MSVtorDisp.reset();
PP.RemovePragmaHandler(MSInitSeg.get());
MSInitSeg.reset();
}
PP.RemovePragmaHandler("STDC", FPContractHandler.get());
@ -1204,6 +1214,14 @@ void PragmaMSVtorDisp::HandlePragma(Preprocessor &PP,
PP.EnterToken(AnnotTok);
}
void PragmaMSInitSeg::HandlePragma(Preprocessor &PP,
PragmaIntroducerKind Introducer,
Token &Tok) {
unsigned ID = PP.getDiagnostics().getCustomDiagID(
DiagnosticsEngine::Error, "'#pragma init_seg' not implemented");
PP.Diag(Tok.getLocation(), ID);
}
/// \brief Handle the Microsoft \#pragma detect_mismatch extension.
///
/// The syntax is:

View File

@ -0,0 +1,16 @@
// RUN: not %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm-only 2>&1 | FileCheck %s
// Reduced from WebKit.
// FIXME: Implement this pragma and test the codegen. We probably want to
// completely skip @llvm.global_ctors and just create global function pointers
// to the initializer with the right section.
// CHECK: '#pragma init_seg' not implemented
#pragma init_seg(".unwantedstaticinits")
struct A {
A();
~A();
int a;
};
A a;