From f8362f9e5d8b3e2fdfc2d54cdc5cb45c84dff06b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 31 Oct 2008 08:56:51 +0000 Subject: [PATCH] "One" line fix for -parse-noop failure, "id" and several other things were being treated as type names for non-Objective-C files. - Other lines are just because MinimalAction didn't have access to the LangOptions. llvm-svn: 58498 --- clang/Driver/PrintParserCallbacks.cpp | 6 +++--- clang/Driver/clang.cpp | 4 ++-- clang/Driver/clang.h | 2 +- clang/include/clang/Parse/Action.h | 4 +++- clang/lib/Parse/MinimalAction.cpp | 10 +++++++--- clang/test/Parser/2008-10-31-parse-noop-failure.c | 4 ++++ 6 files changed, 20 insertions(+), 10 deletions(-) create mode 100755 clang/test/Parser/2008-10-31-parse-noop-failure.c diff --git a/clang/Driver/PrintParserCallbacks.cpp b/clang/Driver/PrintParserCallbacks.cpp index 94cc0e223743..43dbf341e969 100644 --- a/clang/Driver/PrintParserCallbacks.cpp +++ b/clang/Driver/PrintParserCallbacks.cpp @@ -22,7 +22,7 @@ namespace { class ParserPrintActions : public MinimalAction { public: - ParserPrintActions(IdentifierTable &IT) : MinimalAction(IT) {} + ParserPrintActions(Preprocessor &PP) : MinimalAction(PP) {} // Printing Functions which also must call MinimalAction @@ -568,6 +568,6 @@ namespace { }; } -MinimalAction *clang::CreatePrintParserActionsAction(IdentifierTable &IT) { - return new ParserPrintActions(IT); +MinimalAction *clang::CreatePrintParserActionsAction(Preprocessor &PP) { + return new ParserPrintActions(PP); } diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 84eb341b61e0..cf19c66d7753 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -1304,12 +1304,12 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, break; case ParseNoop: // -parse-noop - ParseFile(PP, new MinimalAction(PP.getIdentifierTable())); + ParseFile(PP, new MinimalAction(PP)); ClearSourceMgr = true; break; case ParsePrintCallbacks: - ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable())); + ParseFile(PP, CreatePrintParserActionsAction(PP)); ClearSourceMgr = true; break; diff --git a/clang/Driver/clang.h b/clang/Driver/clang.h index 46c0085f1fe1..e0ddd08b2d39 100644 --- a/clang/Driver/clang.h +++ b/clang/Driver/clang.h @@ -39,7 +39,7 @@ void DoRewriteTest(Preprocessor &PP, const std::string &InFileName, /// CreatePrintParserActionsAction - Return the actions implementation that /// implements the -parse-print-callbacks option. -MinimalAction *CreatePrintParserActionsAction(IdentifierTable &); +MinimalAction *CreatePrintParserActionsAction(Preprocessor &PP); /// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C. void EmitLLVMFromASTs(Preprocessor &PP, bool PrintStats); diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h index 7564aefdc87c..8972328b936b 100644 --- a/clang/include/clang/Parse/Action.h +++ b/clang/include/clang/Parse/Action.h @@ -31,6 +31,7 @@ namespace clang { class Selector; class InitListDesignations; // Lex. + class Preprocessor; class Token; /// Action - As the parser reads the input file and recognizes the productions @@ -923,8 +924,9 @@ class MinimalAction : public Action { /// For example, user-defined classes, built-in "id" type, etc. Scope *TUScope; IdentifierTable &Idents; + Preprocessor &PP; public: - MinimalAction(IdentifierTable &IT) : Idents(IT) {} + MinimalAction(Preprocessor &pp); /// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to /// determine whether the name is a typedef or not in this scope. diff --git a/clang/lib/Parse/MinimalAction.cpp b/clang/lib/Parse/MinimalAction.cpp index cb130c3d268a..c98830ca79c7 100644 --- a/clang/lib/Parse/MinimalAction.cpp +++ b/clang/lib/Parse/MinimalAction.cpp @@ -28,12 +28,16 @@ struct TypeNameInfo { } }; -void MinimalAction:: ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { +MinimalAction::MinimalAction(Preprocessor &pp) + : Idents(pp.getIdentifierTable()), PP(pp) {} + +void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { TUScope = S; + if (!PP.getLangOptions().ObjC1) return; + + // recognize the ObjC built-in type identifiers. IdentifierInfo *II; TypeNameInfo *TI; - - // recognize the ObjC built-in type identifiers. II = &Idents.get("id"); TI = new TypeNameInfo(1, II->getFETokenInfo()); II->setFETokenInfo(TI); diff --git a/clang/test/Parser/2008-10-31-parse-noop-failure.c b/clang/test/Parser/2008-10-31-parse-noop-failure.c new file mode 100755 index 000000000000..c93947591b9b --- /dev/null +++ b/clang/test/Parser/2008-10-31-parse-noop-failure.c @@ -0,0 +1,4 @@ +// RUN: clang -verify -parse-noop %t + +void add_attribute(id) int id; {} +