[clang] 54eea61 - add -fpch-codegen/debuginfo mapping to -fmodules-codegen/debuginfo

2020-07-22 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-07-22T10:21:53+02:00
New Revision: 54eea6127c4d77db03787b7c55765632fb9a6f1c

URL: 
https://github.com/llvm/llvm-project/commit/54eea6127c4d77db03787b7c55765632fb9a6f1c
DIFF: 
https://github.com/llvm/llvm-project/commit/54eea6127c4d77db03787b7c55765632fb9a6f1c.diff

LOG: add -fpch-codegen/debuginfo mapping to -fmodules-codegen/debuginfo

Using -fmodules-* options for PCHs is a bit confusing, so add -fpch-*
variants. Having extra options also makes it simple to do a configure
check for the feature.
Also document the options in the release notes.

Differential Revision: https://reviews.llvm.org/D83623

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/pch-codegen.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 21689c5c5d85..9274081c4d62 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -63,6 +63,32 @@ New Compiler Flags
 
 - ...
 
+- -fpch-codegen and -fpch-debuginfo generate shared code and/or debuginfo
+  for contents of a precompiled header in a separate object file. This object
+  file needs to be linked in, but its contents do not need to be generated
+  for other objects using the precompiled header. This should usually save
+  compile time. If not using clang-cl, the separate object file needs to
+  be created explicitly from the precompiled header.
+  Example of use:
+
+  .. code-block:: console
+
+$ clang++ -x c++-header header.h -o header.pch -fpch-codegen 
-fpch-debuginfo
+$ clang++ -c header.pch -o shared.o
+$ clang++ -c source.cpp -o source.o -include-pch header.pch
+$ clang++ -o binary source.o shared.o
+
+  - Using -fpch-instantiate-templates when generating the precompiled header
+usually increases the amount of code/debuginfo that can be shared.
+  - In some cases, especially when building with optimizations enabled, using
+-fpch-codegen may generate so much code in the shared object that compiling
+it may be a net loss in build time.
+  - Since headers may bring in private symbols of other libraries, it may be
+sometimes necessary to discard unused symbols (such as by adding
+-Wl,--gc-sections on ELF platforms to the linking command, and possibly
+adding -fdata-sections -ffunction-sections to the command generating
+the shared object).
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c2d349866814..700a5c4578f6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1440,6 +1440,10 @@ def fpch_instantiate_templates:
 def fno_pch_instantiate_templates:
   Flag <["-"], "fno-pch-instantiate-templates">,
   Group, Flags<[CC1Option]>;
+defm pch_codegen: OptInFFlag<"pch-codegen", "Generate ", "Do not generate ",
+  "code for uses of this PCH that assumes an explicit object file will be 
built for the PCH">;
+defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate ", "Do not generate 
",
+  "debug info for types in an object file built from this PCH and do not 
generate them elsewhere">;
 
 def fmodules : Flag <["-"], "fmodules">, Group,
   Flags<[DriverOption, CC1Option]>,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8ce7e20408ab..7a73eea013bd 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5642,6 +5642,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
options::OPT_fno_pch_instantiate_templates, false))
 CmdArgs.push_back("-fpch-instantiate-templates");
+  if (Args.hasFlag(options::OPT_fpch_codegen, options::OPT_fno_pch_codegen,
+   false))
+CmdArgs.push_back("-fmodules-codegen");
+  if (Args.hasFlag(options::OPT_fpch_debuginfo, options::OPT_fno_pch_debuginfo,
+   false))
+CmdArgs.push_back("-fmodules-debuginfo");
 
   Args.AddLastArg(CmdArgs, options::OPT_fexperimental_new_pass_manager,
   options::OPT_fno_experimental_new_pass_manager);

diff  --git a/clang/test/Driver/pch-codegen.cpp 
b/clang/test/Driver/pch-codegen.cpp
index 1b125107fb28..c6b6d9217e42 100644
--- a/clang/test/Driver/pch-codegen.cpp
+++ b/clang/test/Driver/pch-codegen.cpp
@@ -7,21 +7,21 @@
 // CHECK-PCH-CREATE-NOT: -fmodules-codegen
 // CHECK-PCH-CREATE-NOT: -fmodules-debuginfo
 
-// Create PCH with -fmodules-codegen.
-// RUN: %clang -x c++-header -Xclang -fmodules-codegen 
%S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-cg.pch -### 2>&1 | FileCheck 
%s -check-prefix=CHECK-PCH-CODEGEN-CREATE
+// Create PCH with -fpch-codegen.
+// RUN: %clang -x c++-header -fpch-codegen 
%

[clang] 3895466 - accept 'clang++ -c a.pch -o a.o' to create PCH's object file

2020-07-22 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-07-22T10:21:23+02:00
New Revision: 3895466e2c336c0797710ae35150ba1ce6bc0b96

URL: 
https://github.com/llvm/llvm-project/commit/3895466e2c336c0797710ae35150ba1ce6bc0b96
DIFF: 
https://github.com/llvm/llvm-project/commit/3895466e2c336c0797710ae35150ba1ce6bc0b96.diff

LOG: accept 'clang++ -c a.pch -o a.o' to create PCH's object file

This way should be the same like with a.pcm for modules.
An alternative way is 'clang++ -c empty.cpp -include-pch a.pch -o a.o
-Xclang -building-pch-with-obj', which is what clang-cl's /Yc does
internally.

Differential Revision: https://reviews.llvm.org/D83716

Added: 
clang/test/Driver/pch-codegen.cpp

Modified: 
clang/lib/Driver/Types.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/PCH/codegen.cpp

Removed: 




diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 399e26d8d64a..2050dffa6fa0 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -141,7 +141,7 @@ bool types::isAcceptedByClang(ID Id) {
   case TY_CXXHeader: case TY_PP_CXXHeader:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
   case TY_CXXModule: case TY_PP_CXXModule:
-  case TY_AST: case TY_ModuleFile:
+  case TY_AST: case TY_ModuleFile: case TY_PCH:
   case TY_LLVM_IR: case TY_LLVM_BC:
 return true;
   }

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index c34c2a18b048..0b5f33541060 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2022,8 +2022,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 // FIXME: Supporting '-header-cpp-output' would be useful.
 bool Preprocessed = XValue.consume_back("-cpp-output");
 bool ModuleMap = XValue.consume_back("-module-map");
-IsHeaderFile =
-!Preprocessed && !ModuleMap && XValue.consume_back("-header");
+IsHeaderFile = !Preprocessed && !ModuleMap &&
+   XValue != "precompiled-header" &&
+   XValue.consume_back("-header");
 
 // Principal languages.
 DashX = llvm::StringSwitch(XValue)
@@ -2050,7 +2051,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   DashX = llvm::StringSwitch(XValue)
   .Case("cpp-output", InputKind(Language::C).getPreprocessed())
   .Case("assembler-with-cpp", Language::Asm)
-  .Cases("ast", "pcm",
+  .Cases("ast", "pcm", "precompiled-header",
  InputKind(Language::Unknown, InputKind::Precompiled))
   .Case("ir", Language::LLVM_IR)
   .Default(Language::Unknown);

diff  --git a/clang/test/Driver/pch-codegen.cpp 
b/clang/test/Driver/pch-codegen.cpp
new file mode 100644
index ..1b125107fb28
--- /dev/null
+++ b/clang/test/Driver/pch-codegen.cpp
@@ -0,0 +1,38 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// Create PCH without codegen.
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -o 
%t/foo-cg.pch -### 2>&1 | FileCheck %s -check-prefix=CHECK-PCH-CREATE
+// CHECK-PCH-CREATE: -emit-pch
+// CHECK-PCH-CREATE-NOT: -fmodules-codegen
+// CHECK-PCH-CREATE-NOT: -fmodules-debuginfo
+
+// Create PCH with -fmodules-codegen.
+// RUN: %clang -x c++-header -Xclang -fmodules-codegen 
%S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-cg.pch -### 2>&1 | FileCheck 
%s -check-prefix=CHECK-PCH-CODEGEN-CREATE
+// CHECK-PCH-CODEGEN-CREATE: -emit-pch
+// CHECK-PCH-CODEGEN-CREATE: -fmodules-codegen
+// CHECK-PCH-CODEGEN-CREATE: "-x" "c++-header"
+// CHECK-PCH-CODEGEN-CREATE-NOT: -fmodules-debuginfo
+
+// Create PCH with -fmodules-debuginfo.
+// RUN: %clang -x c++-header -Xclang -fmodules-debuginfo 
%S/../Modules/Inputs/codegen-flags/foo.h -g -o %t/foo-di.pch -### 2>&1 | 
FileCheck %s -check-prefix=CHECK-PCH-DEBUGINFO-CREATE
+// CHECK-PCH-DEBUGINFO-CREATE: -emit-pch
+// CHECK-PCH-DEBUGINFO-CREATE: -fmodules-debuginfo
+// CHECK-PCH-DEBUGINFO-CREATE: "-x" "c++-header"
+// CHECK-PCH-DEBUGINFO-CREATE-NOT: -fmodules-codegen
+
+// Create PCH's object file for -fmodules-codegen.
+// RUN: touch %t/foo-cg.pch
+// RUN: %clang -c %t/foo-cg.pch -o %t/foo-cg.o -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-PCH-CODEGEN-OBJ
+// CHECK-PCH-CODEGEN-OBJ: -emit-obj
+// CHECK-PCH-CODEGEN-OBJ: "-main-file-name" "foo-cg.pch"
+// CHECK-PCH-CODEGEN-OBJ: "-o" "{{.*}}foo-cg.o"
+// CHECK-PCH-CODEGEN-OBJ: "-x" "precompiled-header"
+
+// Create PCH's object file for -fmodules-debuginfo.
+// RUN: touch %t/foo-di.pch
+// RUN: %clang -c %t/foo-di.pch -g -o %t/foo-di.o -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-PCH-DEBUGINFO-OBJ
+// CHECK-PCH-DEBUGINFO-OBJ: -emit-obj
+// CHECK-PCH-DEBUGINFO-OBJ: "-main-file-name" "foo-di.pch"
+// CHECK-PCH-DEBUGINFO-OBJ: "-o" "{{.*}}foo-di.o"
+// CHECK-PCH-DEBUGINFO-OBJ: "-x" "precompiled-header"

dif

[clang] d1ca996 - document -fpch-instantiate-templates in release notes

2020-07-14 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-07-14T23:18:27+02:00
New Revision: d1ca9960bc1930bed49dd19b4ff442a9de13a0de

URL: 
https://github.com/llvm/llvm-project/commit/d1ca9960bc1930bed49dd19b4ff442a9de13a0de
DIFF: 
https://github.com/llvm/llvm-project/commit/d1ca9960bc1930bed49dd19b4ff442a9de13a0de.diff

LOG: document -fpch-instantiate-templates in release notes

This should have been included in D69585.

Differential Revision: https://reviews.llvm.org/D83622

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8a9a58aa01f8..8b27e663d9f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,6 +108,13 @@ New Compiler Flags
   By default, this is ~/.cache but on some platforms or installations, this
   might be elsewhere. The -fmodules-cache-path=... flag continues to work.
 
+- -fpch-instantiate-templates tries to instantiate templates already while
+  generating a precompiled header. Such templates do not need to be
+  instantiated every time the precompiled header is used, which saves compile
+  time. This may result in an error during the precompiled header generation
+  if the source header file is not self-contained. This option is enabled
+  by default for clang-cl.
+
 Deprecated Compiler Flags
 -
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 31b0569 - make -fmodules-codegen and -fmodules-debuginfo work also with PCHs

2020-07-09 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-07-09T15:22:26+02:00
New Revision: 31b05692cd33b6dcc39402169b36d895e1aa87f4

URL: 
https://github.com/llvm/llvm-project/commit/31b05692cd33b6dcc39402169b36d895e1aa87f4
DIFF: 
https://github.com/llvm/llvm-project/commit/31b05692cd33b6dcc39402169b36d895e1aa87f4.diff

LOG: make -fmodules-codegen and -fmodules-debuginfo work also with PCHs

Allow to build PCH's (with -building-pch-with-obj and the extra .o file)
with -fmodules-codegen -fmodules-debuginfo to allow emitting shared code
into the extra .o file, similarly to how it works with modules. A bit of
a misnomer, but the underlying functionality is the same. This saves up
to 20% of build time here. The patch is fairly simple, it basically just
duplicates -fmodules checks to also alternatively check
-building-pch-with-obj.

This already got committed as cbc9d22e49b434b6ceb2eb94b67079d02e0a7b74,
but then got reverted in 7ea9a6e0220da36ff2fd1fbc29c2755be23e5166
because of PR44953, as discussed in D74846. This is a corrected version
which does not include two places for the PCH case that aren't included
in the modules -fmodules-codegen path either.

Differential Revision: https://reviews.llvm.org/D69778

Added: 
clang/test/PCH/codegen.cpp

Modified: 
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/Inputs/codegen-flags/foo.h

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 74aaf0f9c56e..4a1a995204e5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -3234,7 +3234,8 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned 
ClientLoadCapabilities) {
 case MODULAR_CODEGEN_DECLS:
   // FIXME: Skip reading this record if our ASTConsumer doesn't care about
   // them (ie: if we're not codegenerating this module).
-  if (F.Kind == MK_MainFile)
+  if (F.Kind == MK_MainFile ||
+  getContext().getLangOpts().BuildingPCHWithObjectFile)
 for (unsigned I = 0, N = Record.size(); I != N; ++I)
   EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I]));
   break;

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 359d5e567e67..eef4ab16ec15 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -503,8 +503,12 @@ uint64_t ASTDeclReader::GetCurrentCursorOffset() {
 }
 
 void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) {
-  if (Record.readInt())
+  if (Record.readInt()) {
 Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile;
+if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
+Reader.DeclIsFromPCHWithObjectFile(FD))
+  Reader.DefinitionSource[FD] = true;
+  }
   if (auto *CD = dyn_cast(FD)) {
 CD->setNumCtorInitializers(Record.readInt());
 if (CD->getNumCtorInitializers())
@@ -1431,8 +1435,12 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
   Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt());
   }
 
-  if (VD->getStorageDuration() == SD_Static && Record.readInt())
+  if (VD->getStorageDuration() == SD_Static && Record.readInt()) {
 Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile;
+if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
+Reader.DeclIsFromPCHWithObjectFile(VD))
+  Reader.DefinitionSource[VD] = true;
+  }
 
   enum VarKind {
 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
@@ -1691,8 +1699,12 @@ void ASTDeclReader::ReadCXXDefinitionData(
   Data.ODRHash = Record.readInt();
   Data.HasODRHash = true;
 
-  if (Record.readInt())
+  if (Record.readInt()) {
 Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile;
+if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
+Reader.DeclIsFromPCHWithObjectFile(D))
+  Reader.DefinitionSource[D] = true;
+  }
 
   Data.NumBases = Record.readInt();
   if (Data.NumBases)

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 6f364df80f32..2345a12caeb2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5688,8 +5688,8 @@ void ASTRecordWriter::AddCXXDefinitionData(const 
CXXRecordDecl *D) {
 
   // getODRHash will compute the ODRHash if it has not been previously 
computed.
   Record->push_back(D->getODRHash());
-  bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo &&
-  Writer->WritingModule && !D->isDependentType();
+  bool ModulesDebugInfo =
+  Writer->Context->getLangOpts().ModulesDebugInfo && !D->isDependentType()

[clang] 448bbc5 - fix clang/PCH/delayed-pch-instantiate test

2020-06-21 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-06-21T19:00:42+02:00
New Revision: 448bbc512f456df6fc817b0d7041897eea2375b7

URL: 
https://github.com/llvm/llvm-project/commit/448bbc512f456df6fc817b0d7041897eea2375b7
DIFF: 
https://github.com/llvm/llvm-project/commit/448bbc512f456df6fc817b0d7041897eea2375b7.diff

LOG: fix clang/PCH/delayed-pch-instantiate test

-target must match between PCH creation and use.

Added: 


Modified: 
clang/test/PCH/delayed-pch-instantiate.cpp

Removed: 




diff  --git a/clang/test/PCH/delayed-pch-instantiate.cpp 
b/clang/test/PCH/delayed-pch-instantiate.cpp
index cf7a9f2d4a86..d340b3b8b25d 100644
--- a/clang/test/PCH/delayed-pch-instantiate.cpp
+++ b/clang/test/PCH/delayed-pch-instantiate.cpp
@@ -2,10 +2,10 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -DBODY %s -o - | 
FileCheck %s
 
 // Test with pch.
-// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-pch -o %t %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -include-pch %t -DBODY 
%s -o - | FileCheck %s
 
-// RUN: %clang_cc1 -emit-pch -fpch-instantiate-templates -o %t %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-pch 
-fpch-instantiate-templates -o %t %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -include-pch %t -DBODY 
%s -o - | FileCheck %s
 
 // expected-no-diagnostics



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a45f713 - add option to instantiate templates already in the PCH

2020-06-21 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-06-21T17:05:52+02:00
New Revision: a45f713c673001abb4fe0612b909c698073eb356

URL: 
https://github.com/llvm/llvm-project/commit/a45f713c673001abb4fe0612b909c698073eb356
DIFF: 
https://github.com/llvm/llvm-project/commit/a45f713c673001abb4fe0612b909c698073eb356.diff

LOG: add option to instantiate templates already in the PCH

Add -fpch-instantiate-templates which makes template instantiations be
performed already in the PCH instead of it being done in every single
file that uses the PCH (but every single file will still do it as well
in order to handle its own instantiations). I can see 20-30% build
time saved with the few tests I've tried.

The change may reorder compiler output and also generated code, but
should be generally safe and produce functionally identical code.
There are some rare cases that do not compile with it,
such as test/PCH/pch-instantiate-templates-forward-decl.cpp. If
template instantiation bailed out instead of reporting the error,
these instantiations could even be postponed, which would make them
work.

Enable this by default for clang-cl. MSVC creates PCHs by compiling
them using an empty .cpp file, which means templates are instantiated
while building the PCH and so the .h needs to be self-contained,
making test/PCH/pch-instantiate-templates-forward-decl.cpp to fail
with MSVC anyway. So the option being enabled for clang-cl matches this.

Differential Revision: https://reviews.llvm.org/D69585

Added: 
clang/test/PCH/delayed-pch-instantiate.cpp
clang/test/PCH/pch-instantiate-templates-forward-decl.cpp
clang/test/PCH/pch-instantiate-templates.cpp
clang/test/PCH/specialization-after-instantiation.cpp

Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Sema/Sema.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/PCH/crash-12631281.cpp
clang/test/PCH/cxx-alias-decl.cpp
clang/test/PCH/cxx-dependent-sized-ext-vector.cpp
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/PCH/cxx-exprs.cpp
clang/test/PCH/cxx-friends.cpp
clang/test/PCH/cxx-member-init.cpp
clang/test/PCH/cxx-ms-function-specialization-class-scope.cpp
clang/test/PCH/cxx-static_assert.cpp
clang/test/PCH/cxx-templates.cpp
clang/test/PCH/cxx-variadic-templates-with-default-params.cpp
clang/test/PCH/cxx-variadic-templates.cpp
clang/test/PCH/cxx0x-default-delete.cpp
clang/test/PCH/cxx11-constexpr.cpp
clang/test/PCH/cxx11-enum-template.cpp
clang/test/PCH/cxx11-exception-spec.cpp
clang/test/PCH/cxx11-inheriting-ctors.cpp
clang/test/PCH/cxx11-user-defined-literals.cpp
clang/test/PCH/cxx1y-decltype-auto.cpp
clang/test/PCH/cxx1y-deduced-return-type.cpp
clang/test/PCH/cxx1y-default-initializer.cpp
clang/test/PCH/cxx1y-init-captures.cpp
clang/test/PCH/cxx1y-variable-templates.cpp
clang/test/PCH/cxx1z-aligned-alloc.cpp
clang/test/PCH/cxx1z-decomposition.cpp
clang/test/PCH/cxx1z-using-declaration.cpp
clang/test/PCH/cxx2a-bitfield-init.cpp
clang/test/PCH/cxx2a-concept-specialization-expr.cpp
clang/test/PCH/cxx2a-constraints.cpp
clang/test/PCH/cxx2a-defaulted-comparison.cpp
clang/test/PCH/cxx2a-requires-expr.cpp
clang/test/PCH/cxx2a-template-lambdas.cpp
clang/test/PCH/friend-template.cpp
clang/test/PCH/implicitly-deleted.cpp
clang/test/PCH/late-parsed-instantiations.cpp
clang/test/PCH/local_static.cpp
clang/test/PCH/macro-undef.cpp
clang/test/PCH/make-integer-seq.cpp
clang/test/PCH/ms-if-exists.cpp
clang/test/PCH/pr18806.cpp
clang/test/PCH/pragma-diag-section.cpp
clang/test/PCH/rdar10830559.cpp
clang/test/PCH/type_pack_element.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 9236327f688f..bc0c17a14789 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -165,6 +165,7 @@ BENIGN_ENUM_LANGOPT(CompilingModule, CompilingModuleKind, 
2, CMK_None,
 BENIGN_LANGOPT(CompilingPCH, 1, 0, "building a pch")
 BENIGN_LANGOPT(BuildingPCHWithObjectFile, 1, 0, "building a pch which has a 
corresponding object file")
 BENIGN_LANGOPT(CacheGeneratedPCH, 1, 0, "cache generated PCH files in memory")
+BENIGN_LANGOPT(PCHInstantiateTemplates, 1, 0, "instantiate templates while 
building a PCH")
 COMPATIBLE_LANGOPT(ModulesDeclUse, 1, 0, "require declaration of module 
uses")
 BENIGN_LANGOPT(ModulesSearchAll  , 1, 1, "searching even non-imported modules 
to find unresolved references")
 COMPATIBLE_LANGOPT(ModulesStrictDeclUse, 1, 0, "requiring declaration of 
module uses and all headers to be in modules")

diff  --git a/clang/include/clang/D

[clang] 5c8c990 - make sure to not warn about unused macros from -D

2020-04-27 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-04-27T21:26:13+02:00
New Revision: 5c8c9905c2496a38a17f1b2a180601e790e45db9

URL: 
https://github.com/llvm/llvm-project/commit/5c8c9905c2496a38a17f1b2a180601e790e45db9
DIFF: 
https://github.com/llvm/llvm-project/commit/5c8c9905c2496a38a17f1b2a180601e790e45db9.diff

LOG: make sure to not warn about unused macros from -D

If a PCH is used for compilation, SourceManager::isInMainFile()
returns true even for the "" predefines area. Using -D
only for the TU compilation may trigger -Wunused-macros for it.
It is admitedly a bit fishy to set a macro only for a TU and not
for the PCH, but this works fine if the PCH does not use the macro
(I couldn't find a statement on this for Clang, but GCC explicitly
allows this in the docs).

Differential Revision: https://reviews.llvm.org/D73846

Added: 
clang/test/PCH/cli-macro.c

Modified: 
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index d6b6f5695b6c..d8041aef08ac 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2802,7 +2802,9 @@ void Preprocessor::HandleDefineDirective(
   // warn-because-unused-macro set. If it gets used it will be removed from 
set.
   if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
   !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
-  !MacroExpansionInDirectivesOverride) {
+  !MacroExpansionInDirectivesOverride &&
+  getSourceManager().getFileID(MI->getDefinitionLoc()) !=
+  getPredefinesFileID()) {
 MI->setIsWarnIfUnused(true);
 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
   }

diff  --git a/clang/test/PCH/cli-macro.c b/clang/test/PCH/cli-macro.c
new file mode 100644
index ..bae8cc3ff0e7
--- /dev/null
+++ b/clang/test/PCH/cli-macro.c
@@ -0,0 +1,12 @@
+// Test this without pch.
+// RUN: %clang_cc1 -Wunused-macros -Dunused=1 -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -Wunused-macros -emit-pch -o %t %s
+// RUN: %clang_cc1 -Wunused-macros -Dunused=1 -include-pch %t -fsyntax-only 
-verify %s
+
+// expected-no-diagnostics
+
+// -Dunused=1 is intentionally not set for the pch.
+// There still should be no unused warning for a macro from the command line.
+



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c61401b - Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

2020-03-02 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-03-02T22:33:25+01:00
New Revision: c61401b89742f230b7e6a2cc0548fbf7442e906d

URL: 
https://github.com/llvm/llvm-project/commit/c61401b89742f230b7e6a2cc0548fbf7442e906d
DIFF: 
https://github.com/llvm/llvm-project/commit/c61401b89742f230b7e6a2cc0548fbf7442e906d.diff

LOG: Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

This reverts commit 398b4ed87d488b42032c8d0304324dce76ba9b66.
As requested in https://bugs.llvm.org/show_bug.cgi?id=43465#c37 .

Added: 


Modified: 
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 
clang/test/Sema/fallthrough-comment.c



diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index a162ff091efd..04611dadde66 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1148,11 +1148,6 @@ namespace {
   continue;
 }
 
-if (isFollowedByFallThroughComment(LastStmt)) {
-  ++AnnotatedCnt;
-  continue; // Fallthrough comment, good.
-}
-
 ++UnannotatedCnt;
   }
   return !!UnannotatedCnt;
@@ -1213,41 +1208,10 @@ namespace {
   return nullptr;
 }
 
-bool isFollowedByFallThroughComment(const Stmt *Statement) {
-  // Try to detect whether the fallthough is marked by a comment like
-  // /*FALLTHOUGH*/.
-  bool Invalid;
-  const char *SourceData = S.getSourceManager().getCharacterData(
-  Statement->getEndLoc(), &Invalid);
-  if (Invalid)
-return false;
-  const char *LineStart = SourceData;
-  for (;;) {
-LineStart = strchr(LineStart, '\n');
-if (LineStart == nullptr)
-  return false;
-++LineStart; // Start of next line.
-const char *LineEnd = strchr(LineStart, '\n');
-StringRef Line(LineStart,
-   LineEnd ? LineEnd - LineStart : strlen(LineStart));
-if (LineStart == LineEnd ||
-Line.find_first_not_of(" \t\r") == StringRef::npos)
-  continue; // Whitespace-only line.
-if (!FallthroughRegex.isValid())
-  FallthroughRegex =
-  llvm::Regex("(/\\*[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ 
\\t]*\\*/)"
-  "|(//[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ \\t]*)",
-  llvm::Regex::IgnoreCase);
-assert(FallthroughRegex.isValid());
-return FallthroughRegex.match(Line);
-  }
-}
-
 bool FoundSwitchStatements;
 AttrStmts FallthroughStmts;
 Sema &S;
 llvm::SmallPtrSet ReachableBlocks;
-llvm::Regex FallthroughRegex;
   };
 } // anonymous namespace
 

diff  --git a/clang/test/Sema/fallthrough-comment.c 
b/clang/test/Sema/fallthrough-comment.c
deleted file mode 100644
index 85d1257932f6..
--- a/clang/test/Sema/fallthrough-comment.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
-
-int fallthrough_comment(int n) {
-  switch (n) {
-  case 0:
-n++;
-// FALLTHROUGH
-  case 1:
-n++;
-
-/*fall-through.*/
-
-  case 2:
-n++;
-  case 3: // expected-warning{{unannotated fall-through between switch 
labels}} expected-note{{insert '__attribute__((fallthrough));' to silence this 
warning}} expected-note{{insert 'break;' to avoid fall-through}}
-n++;
-break;
-  }
-  return n;
-}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits