[cfe-commits] [PATCH] Disallow __has_include and __has_include_next outside of preprocessor directives

Dmitri Gribenko gribozavr at gmail.com
Wed Jan 16 07:33:14 PST 2013


On Wed, Jan 16, 2013 at 3:15 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> This patch moves the logic around slightly to handle macros better;
> instead of relying on the PP Lexer, we track the information in the PP
> itself so that is is always available.  I've expanded the test cases
> to cover macros more fully.

 void Preprocessor::HandleIfDirective(Token &IfToken,
                                      bool ReadAnyTokensBeforeDirective) {
+  ParsingPreprocessorDirective = true;
   ++NumIf;

   // Parse and evaluate the conditional expression.
@@ -2101,6 +2102,7 @@
     SkipExcludedConditionalBlock(IfToken.getLocation(), /*Foundnonskip*/false,
                                  /*FoundElse*/false);
   }
+  ParsingPreprocessorDirective = false;
 }

We have llvm/Support/SaveAndRestore.h to simplify this.

+  /// \brief Returns true if currently parsing a preprocessor directive
+  bool isParsingPreprocessorDirective() const {
+    return ParsingPreprocessorDirective;
+  }

+  /// \brief True if we are currently preprocessing a #if or #elif directive
+  bool ParsingPreprocessorDirective : 1;

Please synchronize these two comments, and maybe rename to
ParsingIfOrElifDirective.

LGTM with that.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-commits mailing list