]> granicus.if.org Git - clang/commitdiff
Conditionally parse documentation comments in system headers by
authorTed Kremenek <kremenek@apple.com>
Thu, 13 Sep 2012 06:41:18 +0000 (06:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 13 Sep 2012 06:41:18 +0000 (06:41 +0000)
passing -fretain-comments-from-system-headers.  By default, the
compiler no longer parses such documentation comments, as they
can result in a noticeable compile time/PCH slowdown.

Fixes <rdar://problem/11860820>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163778 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
include/clang/Basic/LangOptions.def
include/clang/Driver/Options.td
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Sema/Sema.cpp

index 08975822055f16c25581ad0c39bffdde6e1d5916..5555e97a8c9a2b6a85a4b7b2c1825c0b0f5f17a3 100644 (file)
@@ -514,6 +514,8 @@ public:
   }
 
   void addComment(const RawComment &RC) {
+    assert(LangOpts.RetainCommentsFromSystemHeaders ||
+           !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin()));
     Comments.addComment(RC, BumpAlloc);
   }
 
index 8f94ade80fca06393ce16066dbc36e8c2b2df5a5..0ef4ad2c19067e1d59a1254593a9d2df88898f9d 100644 (file)
@@ -166,6 +166,8 @@ LANGOPT(ApplePragmaPack, 1, 0, "Apple gcc-compatible #pragma pack handling")
 BENIGN_LANGOPT(EmitMicrosoftInlineAsm , 1, 0, 
                "Enable emission of MS-style inline assembly.")
 
+BENIGN_LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, "retain documentation comments from system headers in the AST")
+
 #undef LANGOPT
 #undef VALUE_LANGOPT
 #undef BENIGN_LANGOPT
index c7698a28f910d95aaa4ae04908702f7863ab6c7f..6a5c42b3e1b6b56921193ea21c58b621925c525d 100644 (file)
@@ -468,6 +468,7 @@ def fmodule_cache_path : Separate<"-fmodule-cache-path">, Group<i_Group>,
   HelpText<"Specify the module cache path">;
 def fmodules : Flag <"-fmodules">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
   HelpText<"Enable the 'modules' language feature">;
+def fretain_comments_from_system_headers : Flag<"-fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>;
   
 def fmudflapth : Flag<"-fmudflapth">, Group<f_Group>;
 def fmudflap : Flag<"-fmudflap">, Group<f_Group>;
index c10df6fc6344d161341bc85387b84dabaeffa2e2..f26ed159d1e15d6d6596110ff6845649830e0cae 100644 (file)
@@ -2785,6 +2785,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(A->getValue(Args)));
   }
 
+  if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
+    CmdArgs.push_back("-fretain-comments-from-system-headers");
+
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
   Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
index 6d6dbfcc2865bf6cd2a59466e2bdd1096e48be64..6d34425e130f679142600561ecab83cbc0a20b02 100644 (file)
@@ -2151,6 +2151,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
 
   Opts.EmitMicrosoftInlineAsm = Args.hasArg(OPT_fenable_experimental_ms_inline_asm);
 
+  Opts.RetainCommentsFromSystemHeaders =
+      Args.hasArg(OPT_fretain_comments_from_system_headers);
+
   unsigned SSP = Args.getLastArgIntValue(OPT_stack_protector, 0, Diags);
   switch (SSP) {
   default:
index fd57bbc237db94e56e53a1a83908f1c0ad857fea..bd7c8515f64d413abbea057d376ddce7664eca65 100644 (file)
@@ -1026,6 +1026,9 @@ LambdaScopeInfo *Sema::getCurLambda() {
 }
 
 void Sema::ActOnComment(SourceRange Comment) {
+  if (!LangOpts.RetainCommentsFromSystemHeaders &&
+      SourceMgr.isInSystemHeader(Comment.getBegin()))
+    return;
   RawComment RC(SourceMgr, Comment);
   if (RC.isAlmostTrailingComment()) {
     SourceRange MagicMarkerRange(Comment.getBegin(),