[PATCH] D129435: [Clang] Parse toolchain-specific offloading arguments directly

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl, MaskRay.
Herald added subscribers: kosarev, StephenFan, tpr.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

OpenMP supports multiple offloading toolchains and architectures. In
order to support this we originally used `getArgsForToolchain` to get
the arguments only intended for each toolchain. This allowed users to
manually specify if an `--offload-arch=` argument was intended for which
toolchain using `-Xopenmp-target=` or other methods. For example,

  clang input.c -fopenmp -fopenmp-targets=nvptx64,amdgcn 
-Xopenmp-target=nvptx64 --offload-arch=sm_70 -Xopenmp-target=amdgcn 
--offload-arch=gfx908

However, this was causing problems with the AMDGPU toolchain. This is
because the AMDGPU toolchain for OpenMP uses an `amdgpu` arch to determine the
architecture. If this tool is not availible the compiler will exit with an error
even when manually specifying the architecture. This patch pulls out the logic 
in
`getArgsForToolchain` and specializes it for extracting `--offload-arch`
arguments to avoid this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129435

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4355,7 +4355,17 @@
 return KnownArchs.lookup(TC);
 
   llvm::DenseSet Archs;
-  for (auto  : Args) {
+  for (auto *Arg : Args) {
+// Extract any '--[no-]offload-arch' arguments intended for this toolchain.
+std::unique_ptr ExtractedArg = nullptr;
+if (Arg->getOption().matches(options::OPT_Xopenmp_target_EQ) &&
+ToolChain::getOpenMPTriple(Arg->getValue(0)) == TC->getTriple()) {
+  Arg->claim();
+  unsigned Index = Args.getBaseArgs().MakeIndex(Arg->getValue(1));
+  ExtractedArg = getOpts().ParseOneArg(Args, Index);
+  Arg = ExtractedArg.get();
+}
+
 if (Arg->getOption().matches(options::OPT_offload_arch_EQ)) {
   for (StringRef Arch : llvm::split(Arg->getValue(), ","))
 Archs.insert(getCanonicalArchString(C, Args, Arch, TC->getTriple()));
@@ -4425,8 +4435,7 @@
 // Get the product of all bound architectures and toolchains.
 SmallVector> TCAndArchs;
 for (const ToolChain *TC : ToolChains)
-  for (StringRef Arch : getOffloadArchs(
-   C, C.getArgsForToolChain(TC, "generic", Kind), Kind, TC))
+  for (StringRef Arch : getOffloadArchs(C, Args, Kind, TC))
 TCAndArchs.push_back(std::make_pair(TC, Arch));
 
 for (unsigned I = 0, E = TCAndArchs.size(); I != E; ++I)


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4355,7 +4355,17 @@
 return KnownArchs.lookup(TC);
 
   llvm::DenseSet Archs;
-  for (auto  : Args) {
+  for (auto *Arg : Args) {
+// Extract any '--[no-]offload-arch' arguments intended for this toolchain.
+std::unique_ptr ExtractedArg = nullptr;
+if (Arg->getOption().matches(options::OPT_Xopenmp_target_EQ) &&
+ToolChain::getOpenMPTriple(Arg->getValue(0)) == TC->getTriple()) {
+  Arg->claim();
+  unsigned Index = Args.getBaseArgs().MakeIndex(Arg->getValue(1));
+  ExtractedArg = getOpts().ParseOneArg(Args, Index);
+  Arg = ExtractedArg.get();
+}
+
 if (Arg->getOption().matches(options::OPT_offload_arch_EQ)) {
   for (StringRef Arch : llvm::split(Arg->getValue(), ","))
 Archs.insert(getCanonicalArchString(C, Args, Arch, TC->getTriple()));
@@ -4425,8 +4435,7 @@
 // Get the product of all bound architectures and toolchains.
 SmallVector> TCAndArchs;
 for (const ToolChain *TC : ToolChains)
-  for (StringRef Arch : getOffloadArchs(
-   C, C.getArgsForToolChain(TC, "generic", Kind), Kind, TC))
+  for (StringRef Arch : getOffloadArchs(C, Args, Kind, TC))
 TCAndArchs.push_back(std::make_pair(TC, Arch));
 
 for (unsigned I = 0, E = TCAndArchs.size(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129424: [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22a01b860b90: [LinkerWrapper] Forward `-mllvm` options to 
the linker wrapper (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129424/new/

https://reviews.llvm.org/D129424

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/linker-wrapper.c
  clang/test/Driver/openmp-offload.c
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -70,6 +70,10 @@
 def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>,
   HelpText<"The separator for the wrapped linker arguments">;
 
+// Arguments for the LLVM backend.
+def mllvm : Separate<["-"], "mllvm">, Flags<[WrapperOnlyOption]>,
+  MetaVarName<"">, HelpText<"Arguments passed to the LLVM invocation">;
+
 // Standard linker flags also used by the linker wrapper.
 def sysroot_EQ : Joined<["--"], "sysroot">, HelpText<"Set the system root">;
 
Index: clang/test/Driver/openmp-offload.c
===
--- clang/test/Driver/openmp-offload.c
+++ clang/test/Driver/openmp-offload.c
@@ -664,7 +664,13 @@
 // CHK-NEW-DRIVER: 
clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget"
 
 /// Check arguments to the linker wrapper
-// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g -fopenmp-new-driver %s 2>&1 \
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s
 
-// CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}}"--device-debug
+// CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}} "--device-debug"
+
+/// Check arguments to the linker wrapper
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu \
+// RUN: -mllvm -abc %s 2>&1 | FileCheck -check-prefix=CHK-NEW-DRIVER-MLLVM 
%s
+
+// CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}} "-abc"
Index: clang/test/Driver/linker-wrapper.c
===
--- clang/test/Driver/linker-wrapper.c
+++ clang/test/Driver/linker-wrapper.c
@@ -39,10 +39,11 @@
 // CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out 
{{.*}}.o {{.*}}.o
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
-// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -abc \
 // RUN:   --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | 
FileCheck %s --check-prefix=HOST_LINK
 
 // HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out
+// HOST_LINK-NOT: ld.lld{{.*}}-abc
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%S/Inputs/dummy-bc.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8449,19 +8449,26 @@
   const auto  = C.getJobs().getJobs().back();
 
   // Forward -Xoffload-linker<-triple> arguments to the device link job.
-  for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
-StringRef Val = Arg->getValue(0);
+  for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
+StringRef Val = A->getValue(0);
 if (Val.empty())
   CmdArgs.push_back(
-  Args.MakeArgString(Twine("--device-linker=") + Arg->getValue(1)));
+  Args.MakeArgString(Twine("--device-linker=") + A->getValue(1)));
 else
   CmdArgs.push_back(Args.MakeArgString(
   "--device-linker=" +
   ToolChain::getOpenMPTriple(Val.drop_front()).getTriple() + "=" +
-  Arg->getValue(1)));
+  A->getValue(1)));
   }
   Args.ClaimAllArgs(options::OPT_Xoffload_linker);
 
+  // Forward `-mllvm` arguments to the LLVM invocations if present.
+  for (Arg *A : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
LinkCommand->getExecutable()));


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ 

[clang] 22a01b8 - [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

2022-07-09 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-09T21:18:19-04:00
New Revision: 22a01b860b909d7836658e0c58e484950766239b

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

LOG: [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

This patch adds the ability to use `-mllvm` options in the linker
wrapper when performing bitcode linking or the module compilation.
This is done by passing in the LLVM argument to the clang-linker-wrapper
tool. Inside the linker-wrapper tool we invoke the `CommandLine` parser
solely for forwarding command line options to the `clang-linker-wrapper`
to the LLVM tools that also use the `CommandLine` parser. The actual
arguments to the linker wrapper are parsed using the `Opt` library
instead.

For example, in the following command the `CommandLine` parser will attempt to
parse `abc`, while the `opt` parser takes `-mllvm ` and ignores it so it is
not passed to the linker arguments.
```
clang-linker-wrapper -mllvm -abc -- 
```

As far as I can tell this is the easiest way to forward arguments to
LLVM tool invocations. If there is a better way to pass these arguments
(such as through the LTO config) let me know.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/linker-wrapper.c
clang/test/Driver/openmp-offload.c
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc29dd8107a60..ee445775e7b72 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8449,19 +8449,26 @@ void LinkerWrapper::ConstructJob(Compilation , const 
JobAction ,
   const auto  = C.getJobs().getJobs().back();
 
   // Forward -Xoffload-linker<-triple> arguments to the device link job.
-  for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
-StringRef Val = Arg->getValue(0);
+  for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
+StringRef Val = A->getValue(0);
 if (Val.empty())
   CmdArgs.push_back(
-  Args.MakeArgString(Twine("--device-linker=") + Arg->getValue(1)));
+  Args.MakeArgString(Twine("--device-linker=") + A->getValue(1)));
 else
   CmdArgs.push_back(Args.MakeArgString(
   "--device-linker=" +
   ToolChain::getOpenMPTriple(Val.drop_front()).getTriple() + "=" +
-  Arg->getValue(1)));
+  A->getValue(1)));
   }
   Args.ClaimAllArgs(options::OPT_Xoffload_linker);
 
+  // Forward `-mllvm` arguments to the LLVM invocations if present.
+  for (Arg *A : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
LinkCommand->getExecutable()));

diff  --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 7adf627cba178..201a69c44c999 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -39,10 +39,11 @@
 // CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out 
{{.*}}.o {{.*}}.o
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
-// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -abc \
 // RUN:   --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | 
FileCheck %s --check-prefix=HOST_LINK
 
 // HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out
+// HOST_LINK-NOT: ld.lld{{.*}}-abc
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%S/Inputs/dummy-bc.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \

diff  --git a/clang/test/Driver/openmp-offload.c 
b/clang/test/Driver/openmp-offload.c
index 5a5da4c408ecf..a800c75f8c236 100644
--- a/clang/test/Driver/openmp-offload.c
+++ b/clang/test/Driver/openmp-offload.c
@@ -664,7 +664,13 @@
 // CHK-NEW-DRIVER: 
clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget"
 
 /// Check arguments to the linker wrapper
-// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g -fopenmp-new-driver %s 2>&1 \
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s
 
-// CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}}"--device-debug
+// CHK-NEW-DRIVER-DEBUG: 

[PATCH] D129424: [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 443464.
jhuber6 added a comment.

Addressing comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129424/new/

https://reviews.llvm.org/D129424

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/linker-wrapper.c
  clang/test/Driver/openmp-offload.c
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -70,6 +70,10 @@
 def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>,
   HelpText<"The separator for the wrapped linker arguments">;
 
+// Arguments for the LLVM backend.
+def mllvm : Separate<["-"], "mllvm">, Flags<[WrapperOnlyOption]>,
+  MetaVarName<"">, HelpText<"Arguments passed to the LLVM invocation">;
+
 // Standard linker flags also used by the linker wrapper.
 def sysroot_EQ : Joined<["--"], "sysroot">, HelpText<"Set the system root">;
 
Index: clang/test/Driver/openmp-offload.c
===
--- clang/test/Driver/openmp-offload.c
+++ clang/test/Driver/openmp-offload.c
@@ -664,7 +664,13 @@
 // CHK-NEW-DRIVER: 
clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget"
 
 /// Check arguments to the linker wrapper
-// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g -fopenmp-new-driver %s 2>&1 \
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s
 
-// CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}}"--device-debug
+// CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}} "--device-debug"
+
+/// Check arguments to the linker wrapper
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu \
+// RUN: -mllvm -abc %s 2>&1 | FileCheck -check-prefix=CHK-NEW-DRIVER-MLLVM 
%s
+
+// CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}} "-abc"
Index: clang/test/Driver/linker-wrapper.c
===
--- clang/test/Driver/linker-wrapper.c
+++ clang/test/Driver/linker-wrapper.c
@@ -39,10 +39,11 @@
 // CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out 
{{.*}}.o {{.*}}.o
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
-// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -abc \
 // RUN:   --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | 
FileCheck %s --check-prefix=HOST_LINK
 
 // HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out
+// HOST_LINK-NOT: ld.lld{{.*}}-abc
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%S/Inputs/dummy-bc.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8449,19 +8449,26 @@
   const auto  = C.getJobs().getJobs().back();
 
   // Forward -Xoffload-linker<-triple> arguments to the device link job.
-  for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
-StringRef Val = Arg->getValue(0);
+  for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
+StringRef Val = A->getValue(0);
 if (Val.empty())
   CmdArgs.push_back(
-  Args.MakeArgString(Twine("--device-linker=") + Arg->getValue(1)));
+  Args.MakeArgString(Twine("--device-linker=") + A->getValue(1)));
 else
   CmdArgs.push_back(Args.MakeArgString(
   "--device-linker=" +
   ToolChain::getOpenMPTriple(Val.drop_front()).getTriple() + "=" +
-  Arg->getValue(1)));
+  A->getValue(1)));
   }
   Args.ClaimAllArgs(options::OPT_Xoffload_linker);
 
+  // Forward `-mllvm` arguments to the LLVM invocations if present.
+  for (Arg *A : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
LinkCommand->getExecutable()));


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -70,6 +70,10 @@
 def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>,
   HelpText<"The separator for the 

[PATCH] D129424: [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

2022-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

> This patch adds the ability to use -mllvm options in the linker wrapper when 
> performing bitcode linking or the module compilation. This is done by passing 
> in the LLVM argument to the clang-linker-wrapper ...

The description can be simplified. "This patch adds the ability to " can be 
simplified as "Add ..." (imperative).

> The actual arguments to the linker wrapper are parsed using the Opt library 
> instead.

It is called `LLVMOption`. You can also refer to it as `llvm/lib/Option`.

> As far as I can tell this is the easiest way to forward arguments to LLVM 
> tool invocations. If there is a better way to pass these arguments (such as 
> through the LTO config) let me know.

This is how `Clang::ConstructJob` handles -mllvm, too.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:8466
+  // Forward `-mllvm` arguments to the LLVM invocations if present.
+  for (auto *Arg : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");





Comment at: clang/lib/Driver/ToolChains/Clang.cpp:8467
+  for (auto *Arg : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Arg->getValue());

Add `A->claim();`



Comment at: clang/test/Driver/openmp-offload.c:676
+
+// CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}}"-abc

Just add the ending `"`



Comment at: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td:74
+// Arguments for the LLVM backend.
+def mllvm : Separate<["--", "-"], "mllvm">, Flags<[WrapperOnlyOption]>,
+  MetaVarName<"">, HelpText<"Arguments passed to the LLVM invocation">;

Just keep `"-"` and remove `"--"`. clang doesn't support --mllvm. There is no 
need making users choose different spellings.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129424/new/

https://reviews.llvm.org/D129424

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


[PATCH] D126676: [clang] Disallow differences in defines used for creating and using PCH

2022-07-09 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 443461.
mstorsjo added a comment.

Reduce the scope and impact of the change: When telling Clang to include a 
specifically named PCH file, keep tolerating the same set of mismatches as 
before. (Clang has been tolerating such differences for over 10 years, and 
there are a number of tests specifically for such fuzzy matches.) When using a 
GCC style directory with multiple alternative PCH files, require an exact 
match, to avoid the case where multiple ones are acceptable and Clang 
erroneously picks the first seemingly acceptable one.

In this form, the patch no longer breaks other testcases than the one that is 
meant to be fixed/changed.

This still has a small risk of breaking someone's setup, but as this makes 
Clang match GCC's behaviour for the compatible option, the risk is probably 
quite small.

(A more comprehensive solution to avoid breaking that case, would be to iterate 
over the PCH directory, first requiring a strict match, and if none is found, 
iterate over the directory again, tolerating inexact matches like before. But I 
don't think that's necessary.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126676/new/

https://reviews.llvm.org/D126676

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/pch-dir.c

Index: clang/test/PCH/pch-dir.c
===
--- clang/test/PCH/pch-dir.c
+++ clang/test/PCH/pch-dir.c
@@ -6,7 +6,7 @@
 // RUN: %clang -x c++-header -std=c++98 %S/pch-dir.h -o %t.h.gch/cpp.gch 
 // RUN: %clang -include %t.h -DFOO=foo -fsyntax-only %s -Xclang -print-stats 2> %t.clog
 // RUN: FileCheck -check-prefix=CHECK-C %s < %t.clog
-// RUN: %clang -include %t.h -DFOO=bar -DBAR=bar -fsyntax-only %s -Xclang -ast-print > %t.cbarlog
+// RUN: %clang -include %t.h -DFOO=bar -fsyntax-only %s -Xclang -ast-print > %t.cbarlog
 // RUN: FileCheck -check-prefix=CHECK-CBAR %s < %t.cbarlog
 // RUN: %clang -x c++ -include %t.h -std=c++98 -fsyntax-only %s -Xclang -print-stats 2> %t.cpplog
 // RUN: FileCheck -check-prefix=CHECK-CPP %s < %t.cpplog
@@ -14,6 +14,11 @@
 // RUN: not %clang -x c++ -std=c++11 -include %t.h -fsyntax-only %s 2> %t.cpp11log
 // RUN: FileCheck -check-prefix=CHECK-NO-SUITABLE %s < %t.cpp11log
 
+// RUN: not %clang -include %t.h -fsyntax-only %s 2> %t.missinglog2
+// RUN: FileCheck -check-prefix=CHECK-NO-SUITABLE %s < %t.missinglog2
+// RUN: not %clang -include %t.h -DFOO=foo -DBAR=bar -fsyntax-only %s 2> %t.missinglog2
+// RUN: FileCheck -check-prefix=CHECK-NO-SUITABLE %s < %t.missinglog2
+
 // Don't crash if the precompiled header file is missing.
 // RUN: not %clang_cc1 -include-pch %t.h.gch -DFOO=baz -fsyntax-only %s -print-stats 2> %t.missinglog
 // RUN: FileCheck -check-prefix=CHECK-NO-SUITABLE %s < %t.missinglog
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -637,7 +637,8 @@
  FileManager ,
  std::string ,
  const LangOptions ,
- bool Validate = true) {
+ bool Validate = true,
+ bool ValidateStrict = false) {
   // Check macro definitions.
   MacroDefinitionsMap ASTFileMacros;
   collectMacroDefinitions(PPOpts, ASTFileMacros);
@@ -654,6 +655,14 @@
 llvm::StringMap>::iterator Known =
 ASTFileMacros.find(MacroName);
 if (!Validate || Known == ASTFileMacros.end()) {
+  if (ValidateStrict) {
+// If strict matches are requested, don't tolerate any extra defines on
+// the command line that are missing in the AST file.
+if (Diags) {
+  Diags->Report(diag::err_pch_macro_def_undef) << MacroName << true;
+}
+return true;
+  }
   // FIXME: Check whether this identifier was referenced anywhere in the
   // AST file. If so, we should reject the AST file. Unfortunately, this
   // information isn't in the control block. What shall we do about it?
@@ -684,8 +693,10 @@
 
 // If the macro was #undef'd in both, or if the macro bodies are identical,
 // it's fine.
-if (Existing.second || Existing.first == Known->second.first)
+if (Existing.second || Existing.first == Known->second.first) {
+  ASTFileMacros.erase(Known);
   continue;
+}
 
 // The macro bodies differ; complain.
 if (Diags) {
@@ -694,6 +705,16 @@
 }
 return true;
   }
+  if (ValidateStrict) {
+// If strict matches are requested, don't tolerate any extra defines in
+// the AST file that are missing on the command line.
+for (const auto  : 

[PATCH] D128119: [clang] Enforce instantiation of constexpr template functions during non-constexpr evaluation

2022-07-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 443459.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128119/new/

https://reviews.llvm.org/D128119

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenCXX/constexpr-late-instantiation.cpp
  clang/test/SemaCXX/constexpr-late-instantiation.cpp


Index: clang/test/SemaCXX/constexpr-late-instantiation.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-late-instantiation.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+template 
+constexpr T foo(T a);   // expected-note {{declared here}}
+
+int main() {
+  int k = foo(5);  // Ok
+  constexpr int j = // expected-error {{constexpr variable 'j' must be 
initialized by a constant expression}}
+  foo(5);  // expected-note {{undefined function 'foo' 
cannot be used in a constant expression}}
+}
+
+template 
+constexpr T foo(T a) {
+  return a;
+}
Index: clang/test/CodeGenCXX/constexpr-late-instantiation.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/constexpr-late-instantiation.cpp
@@ -0,0 +1,17 @@
+// Make sure foo is instantiated and we don't get a link error
+// RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple %s -o- | 
FileCheck %s
+
+template 
+constexpr T foo(T a);
+
+// CHECK-LABEL: define {{.*}} @main
+int main() {
+  // CHECK: call {{.*}} @_Z3fooIiET_S0_
+  int k = foo(5);
+}
+// CHECK: }
+
+template 
+constexpr T foo(T a) {
+  return a;
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4840,7 +4840,8 @@
  /*Complain*/DefinitionRequired)) {
 if (DefinitionRequired)
   Function->setInvalidDecl();
-else if (TSK == TSK_ExplicitInstantiationDefinition) {
+else if (TSK == TSK_ExplicitInstantiationDefinition ||
+ (Function->isConstexpr() && !Recursive)) {
   // Try again at the end of the translation unit (at which point a
   // definition will be required).
   assert(!Recursive);
@@ -4855,7 +4856,7 @@
 Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
 if (getLangOpts().CPlusPlus11)
   Diag(PointOfInstantiation, diag::note_inst_declaration_hint)
-<< Function;
+  << Function;
   }
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -181,6 +181,8 @@
   emitted as a dynamic initializer. Previously the variable would
   incorrectly be zero-initialized. In contexts where a dynamic
   initializer is not allowed this is now diagnosed as an error.
+- Clang now correctly emits symbols for implicitly instantiated constexpr
+  template function. Fixes `Issue 55560 
`_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/constexpr-late-instantiation.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-late-instantiation.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+template 
+constexpr T foo(T a);   // expected-note {{declared here}}
+
+int main() {
+  int k = foo(5);  // Ok
+  constexpr int j = // expected-error {{constexpr variable 'j' must be initialized by a constant expression}}
+  foo(5);  // expected-note {{undefined function 'foo' cannot be used in a constant expression}}
+}
+
+template 
+constexpr T foo(T a) {
+  return a;
+}
Index: clang/test/CodeGenCXX/constexpr-late-instantiation.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/constexpr-late-instantiation.cpp
@@ -0,0 +1,17 @@
+// Make sure foo is instantiated and we don't get a link error
+// RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple %s -o- | FileCheck %s
+
+template 
+constexpr T foo(T a);
+
+// CHECK-LABEL: define {{.*}} @main
+int main() {
+  // CHECK: call {{.*}} @_Z3fooIiET_S0_
+  int k = foo(5);
+}
+// CHECK: }
+
+template 
+constexpr T foo(T a) {
+  return a;
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4840,7 +4840,8 @@
  /*Complain*/DefinitionRequired)) {
 if (DefinitionRequired)
   Function->setInvalidDecl();
-else if (TSK == TSK_ExplicitInstantiationDefinition) {
+else if (TSK == TSK_ExplicitInstantiationDefinition ||
+ (Function->isConstexpr() && 

[PATCH] D129138: [clang] [docs] Update the changes of C++20 Modules in clang15

2022-07-09 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added inline comments.



Comment at: clang/www/cxx_status.html:1183
 https://wg21.link/p1874r1;>P1874R1
-Partial
+Clang 15
   

should this be `class="unreleased"` instead of `class="full"`? At least this is 
what other places in this document use when mentioning clang 15


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129138/new/

https://reviews.llvm.org/D129138

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


[PATCH] D127887: [CMake][Fuchsia] Use libunwind as the default unwinder

2022-07-09 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8e6056e2417: [CMake][Fuchsia] Use libunwind as the default 
unwinder (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D127887?vs=441734=443449#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127887/new/

https://reviews.llvm.org/D127887

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -26,6 +26,7 @@
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -32,6 +32,7 @@
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
@@ -119,7 +120,6 @@
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
@@ -183,10 +183,8 @@
 set(RUNTIMES_${target}_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
-
set(RUNTIMES_${target}_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -26,6 +26,7 @@
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -32,6 +32,7 @@
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
@@ -119,7 +120,6 @@
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
@@ -183,10 +183,8 @@
 set(RUNTIMES_${target}_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE 

[clang] a8e6056 - [CMake][Fuchsia] Use libunwind as the default unwinder

2022-07-09 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-07-09T18:15:04Z
New Revision: a8e6056e24173167fa8d3a588982f36ba83312bd

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

LOG: [CMake][Fuchsia] Use libunwind as the default unwinder

Fuchsia already uses libunwind, but it does so implicitly via libc++.
This change makes the unwinder choice explicit.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 9e51dcbbf4f0..566df27c1d1c 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -32,6 +32,7 @@ set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
@@ -119,7 +120,6 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
@@ -183,10 +183,8 @@ if(FUCHSIA_SDK)
 set(RUNTIMES_${target}_LIBUNWIND_HIDE_SYMBOLS ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-set(RUNTIMES_${target}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
-
set(RUNTIMES_${target}_LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OFF 
CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
 set(RUNTIMES_${target}_LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")

diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 53bb78d9ea36..73ef57150717 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -26,6 +26,7 @@ set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")



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


[PATCH] D129061: [Lex] Diagnose macro in command lines

2022-07-09 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 updated this revision to Diff 443447.
jackhong12 added a comment.
Herald added subscribers: mstorsjo, MaskRay.
Herald added a reviewer: sscalpone.
Herald added a project: clang-tools-extra.

I added two flags, `-driver-define` and `-driver-undefine`, to indicate macros 
that the driver defines. And I moved driver-defined macros from `` file to `` file, like

  # 1 "" 3
  #define __llvm__ 1
  #define __clang__ 1
  ...
  # 1 "" 1
  #define __WHY_NOT_ME__ 1
  #undef __STDC__
  # 1 "" 2
  #define __GCC_HAVE_DWARF2_CFI_ASM 1
  ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129061/new/

https://reviews.llvm.org/D129061

Files:
  clang-tools-extra/test/pp-trace/pp-trace-include.cpp
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Driver/cl-runtime-flags.c
  clang/test/Driver/mingw.cpp
  clang/test/Preprocessor/macro-command-line-diagnosis.c

Index: clang/test/Preprocessor/macro-command-line-diagnosis.c
===
--- /dev/null
+++ clang/test/Preprocessor/macro-command-line-diagnosis.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -Wreserved-identifier -D__WHY_NOT_ME__ -U__STDC__ %s -o - 2>&1 | FileCheck %s
+
+// CHECK:  warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
+// CHECK-NEXT: #define __WHY_NOT_ME__ 1
+// CHECK:  warning: macro name is a reserved identifier [-Wreserved-macro-identifier]
+// CHECK-NEXT: #undef __STDC__
Index: clang/test/Driver/mingw.cpp
===
--- clang/test/Driver/mingw.cpp
+++ clang/test/Driver/mingw.cpp
@@ -61,7 +61,7 @@
 // RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s
 // RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s
 // CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
-// CHECK_MINGW_UNICODE: "-DUNICODE"
+// CHECK_MINGW_UNICODE: "-driver-define UNICODE"
 
 // RUN: %clang -target i686-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_NO_SUBSYS %s
 // RUN: %clang -target i686-windows-gnu -### %s -mwindows -mconsole 2>&1 | FileCheck -check-prefix=CHECK_SUBSYS_CONSOLE %s
Index: clang/test/Driver/cl-runtime-flags.c
===
--- clang/test/Driver/cl-runtime-flags.c
+++ clang/test/Driver/cl-runtime-flags.c
@@ -3,85 +3,85 @@
 
 // First check that regular clang doesn't do any of this stuff.
 // RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=CHECK-CLANG %s
-// CHECK-CLANG-NOT: "-D_DEBUG"
-// CHECK-CLANG-NOT: "-D_MT"
-// CHECK-CLANG-NOT: "-D_DLL"
+// CHECK-CLANG-NOT: "-driver-define _DEBUG"
+// CHECK-CLANG-NOT: "-driver-define _MT"
+// CHECK-CLANG-NOT: "-driver-define _DLL"
 // CHECK-CLANG-NOT: --dependent-lib
 
 // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s
 // RUN: %clang_cl -### /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-MT %s
-// CHECK-MT-NOT: "-D_DEBUG"
-// CHECK-MT: "-D_MT"
-// CHECK-MT-NOT: "-D_DLL"
+// CHECK-MT-NOT: "-driver-define _DEBUG"
+// CHECK-MT: "-driver-define _MT"
+// CHECK-MT-NOT: "-driver-define _DLL"
 // CHECK-MT: "-flto-visibility-public-std"
 // CHECK-MT: "--dependent-lib=libcmt"
 // CHECK-MT: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTd %s
 // RUN: %clang_cl -### /LD /MTd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTd %s
-// CHECK-MTd: "-D_DEBUG"
-// CHECK-MTd: "-D_MT"
-// CHECK-MTd-NOT: "-D_DLL"
+// CHECK-MTd: "-driver-define _DEBUG"
+// CHECK-MTd: "-driver-define _MT"
+// CHECK-MTd-NOT: "-driver-define _DLL"
 // CHECK-MTd: "-flto-visibility-public-std"
 // CHECK-MTd: "--dependent-lib=libcmtd"
 // CHECK-MTd: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MD -- %s 2>&1 | FileCheck -check-prefix=CHECK-MD %s
-// CHECK-MD-NOT: "-D_DEBUG"
-// CHECK-MD: "-D_MT"
-// CHECK-MD: "-D_DLL"
+// CHECK-MD-NOT: "-driver-define _DEBUG"
+// CHECK-MD: "-driver-define _MT"
+// CHECK-MD: "-driver-define _DLL"
 // CHECK-MD: "--dependent-lib=msvcrt"
 // CHECK-MD: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /MDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MDd %s
-// CHECK-MDd: "-D_DEBUG"
-// CHECK-MDd: "-D_MT"
-// CHECK-MDd: "-D_DLL"
+// CHECK-MDd: "-driver-define _DEBUG"
+// CHECK-MDd: "-driver-define _MT"
+// CHECK-MDd: "-driver-define _DLL"
 // CHECK-MDd: "--dependent-lib=msvcrtd"
 // CHECK-MDd: "--dependent-lib=oldnames"
 
 // RUN: %clang_cl -### /LD -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
 // RUN: %clang_cl -### /LD /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
-// CHECK-LD-NOT: "-D_DEBUG"
-// CHECK-LD: "-D_MT"
-// CHECK-LD-NOT: "-D_DLL"
+// CHECK-LD-NOT: "-driver-define 

[clang] d3dd6e5 - [Fuchsia] Remove the test cflags to explicitly set the unwinder

2022-07-09 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-07-09T17:08:35Z
New Revision: d3dd6e57fe84e90cadcdc78fa71d632f6573f156

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

LOG: [Fuchsia] Remove the test cflags to explicitly set the unwinder

These are no longer needed and cause issue when cross-compiling.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7d055ab27..9e51dcbbf4f06 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -130,9 +130,6 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 set(RUNTIMES_${target}_SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "")
 set(RUNTIMES_${target}_SANITIZER_TEST_CXX "libc++" CACHE STRING "")
 set(RUNTIMES_${target}_SANITIZER_TEST_CXX_INTREE ON CACHE BOOL "")
-set(RUNTIMES_${target}_COMPILER_RT_TEST_COMPILER_CFLAGS 
"--unwindlib=libunwind -static-libgcc" CACHE STRING "")
-set(RUNTIMES_${target}_SANITIZER_COMMON_TEST_TARGET_CFLAGS 
"--unwindlib=libunwind -static-libgcc" CACHE STRING "")
-set(RUNTIMES_${target}_TSAN_TEST_TARGET_CFLAGS "--unwindlib=libunwind 
-static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_LLVM_TOOLS_DIR "${CMAKE_BINARY_DIR}/bin" CACHE BOOL 
"")
 set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 



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


[PATCH] D129424: [LinkerWrapper] Forward `-mllvm` options to the linker wrapper

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, ye-luo, JonChesterfield, MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the ability to use `-mllvm` options in the linker
wrapper when performing bitcode linking or the module compilation.
This is done by passing in the LLVM argument to the clang-linker-wrapper
tool. Inside the linker-wrapper tool we invoke the `CommandLine` parser
solely for forwarding command line options to the `clang-linker-wrapper`
to the LLVM tools that also use the `CommandLine` parser. The actual
arguments to the linker wrapper are parsed using the `Opt` library
instead.

For example, in the following command the `CommandLine` parser will attempt to
parse `abc`, while the `opt` parser takes `-mllvm ` and ignores it so it is
not passed to the linker arguments.

  clang-linker-wrapper -mllvm -abc -- 

As far as I can tell this is the easiest way to forward arguments to
LLVM tool invocations. If there is a better way to pass these arguments
(such as through the LTO config) let me know.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129424

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/linker-wrapper.c
  clang/test/Driver/openmp-offload.c
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -70,6 +70,10 @@
 def separator : Flag<["--"], "">, Flags<[WrapperOnlyOption]>,
   HelpText<"The separator for the wrapped linker arguments">;
 
+// Arguments for the LLVM backend.
+def mllvm : Separate<["--", "-"], "mllvm">, Flags<[WrapperOnlyOption]>,
+  MetaVarName<"">, HelpText<"Arguments passed to the LLVM invocation">;
+
 // Standard linker flags also used by the linker wrapper.
 def sysroot_EQ : Joined<["--"], "sysroot">, HelpText<"Set the system root">;
 
Index: clang/test/Driver/openmp-offload.c
===
--- clang/test/Driver/openmp-offload.c
+++ clang/test/Driver/openmp-offload.c
@@ -664,7 +664,13 @@
 // CHK-NEW-DRIVER: 
clang-linker-wrapper{{.*}}"--host-triple=powerpc64le-unknown-linux"{{.*}}--{{.*}}"-lomp"{{.*}}"-lomptarget"
 
 /// Check arguments to the linker wrapper
-// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g -fopenmp-new-driver %s 2>&1 \
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -g %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-NEW-DRIVER-DEBUG %s
 
 // CHK-NEW-DRIVER-DEBUG: clang-linker-wrapper{{.*}}"--device-debug
+
+/// Check arguments to the linker wrapper
+// RUN:   %clang -### --target=powerpc64le-linux -fopenmp=libomp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu \
+// RUN: -mllvm -abc %s 2>&1 | FileCheck -check-prefix=CHK-NEW-DRIVER-MLLVM 
%s
+
+// CHK-NEW-DRIVER-MLLVM: clang-linker-wrapper{{.*}}"-abc
Index: clang/test/Driver/linker-wrapper.c
===
--- clang/test/Driver/linker-wrapper.c
+++ clang/test/Driver/linker-wrapper.c
@@ -39,10 +39,11 @@
 // CPU_LINK: ld.lld{{.*}}-m elf_x86_64 -shared -Bsymbolic -o {{.*}}.out 
{{.*}}.o {{.*}}.o
 
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
-// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
+// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu 
-mllvm -abc \
 // RUN:   --linker-path=/usr/bin/ld.lld -- -a -b -c %t.o -o a.out 2>&1 | 
FileCheck %s --check-prefix=HOST_LINK
 
 // HOST_LINK: ld.lld{{.*}}-a -b -c {{.*}}.o -o a.out
+// HOST_LINK-NOT: ld.lld{{.*}}-abc
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%S/Inputs/dummy-bc.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8462,6 +8462,12 @@
   }
   Args.ClaimAllArgs(options::OPT_Xoffload_linker);
 
+  // Forward `-mllvm` arguments to the LLVM invocations if present.
+  for (auto *Arg : Args.filtered(options::OPT_mllvm)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Arg->getValue());
+  }
+
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
LinkCommand->getExecutable()));


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- 

[PATCH] D129423: [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbd3ade17bc1: [LinkerWrapper] Fix errors not exiting inside 
of the LTO pipeline (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129423/new/

https://reviews.llvm.org/D129423

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@
   switch (DI.getSeverity()) {
   case DS_Error:
 WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+LTOError = true;
 break;
   case DS_Warning:
 WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@
   if (Conf.OptLevel > 0)
 Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@
   if (Error Err = LTOBackend->run(AddStream))
 return Err;
 
+  if (LTOError)
+return createStringError(inconvertibleErrorCode(),
+ "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
 if (BitcodeOutput.size() != 1 || !WholeProgram)


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@
   switch (DI.getSeverity()) {
   case DS_Error:
 WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+LTOError = true;
 break;
   case DS_Warning:
 WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@
   if (Conf.OptLevel > 0)
 Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@
   if (Error Err = LTOBackend->run(AddStream))
 return Err;
 
+  if (LTOError)
+return createStringError(inconvertibleErrorCode(),
+ "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
 if (BitcodeOutput.size() != 1 || !WholeProgram)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dbd3ade - [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

2022-07-09 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-09T11:29:04-04:00
New Revision: dbd3ade17bc1ed889f306ce13955b2048b5df969

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

LOG: [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

The LTO pipeline handles its errors using the diagnostics handler
callback function. We were not checking the results of these errors and
not properly returning an error code in the linker wrapper when errors
occured inside of the LTO pipeline. This patch adds a simple boolean
flag to indicate if the LTO backend failed to any reason and quit.

Reviewed By: ye-luo

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

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index f0509b68ee0b3..21a8bfa966626 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@ static std::list> TempFiles;
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@ void diagnosticHandler(const DiagnosticInfo ) {
   switch (DI.getSeverity()) {
   case DS_Error:
 WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+LTOError = true;
 break;
   case DS_Warning:
 WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@ std::unique_ptr createLTO(
   if (Conf.OptLevel > 0)
 Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@ Error linkBitcodeFiles(SmallVectorImpl 
,
   if (Error Err = LTOBackend->run(AddStream))
 return Err;
 
+  if (LTOError)
+return createStringError(inconvertibleErrorCode(),
+ "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
 if (BitcodeOutput.size() != 1 || !WholeProgram)



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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D128059#3640564 , @cor3ntin wrote:

> Good point. The error was a bit misleading but i guess what's happening is a 
> segfault when running `clang-ast-dump`. 
> I'm reverting for now and I don't really know how to go from there as I don't 
> have the hardware to test that code path.

Sending you info via e-mail on how to request access to systems.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D128059#3640544 , 
@hubert.reinterpretcast wrote:

> In D128059#3640424 , @cor3ntin 
> wrote:
>
>> @aaron.ballman Thanks for the review. I landed the changes and got a bunch 
>> of bots screaming at me for changes that are completely unrelated
>>
>> https://lab.llvm.org/buildbot/#/builders/21/builds/45146
>> https://lab.llvm.org/buildbot/#/builders/36/builds/22838
>> https://lab.llvm.org/buildbot/#/builders/121/builds/21183
>
> What do you mean it is completely unrelated? You have `__ALTIVEC__`-specific 
> changes and it knocks out the PPC bots.

Good point. The error was a bit misleading but i guess what's happening is a 
segfault when running `clang-ast-dump`. 
I'm reverting for now and I don't really know how to go from there as I don't 
have the hardware to test that code path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

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


[clang] 50416e5 - Revert "[Clang] Add a warning on invalid UTF-8 in comments."

2022-07-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-09T17:18:35+02:00
New Revision: 50416e5454d802a3ef71bb799e5bfd38e8ec9089

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

LOG: Revert "[Clang] Add a warning on invalid UTF-8 in comments."

It is probable thart this change crashes on the powerpc bots.

This reverts commit 355532a1499aa9b13a89fb5b5caaba2344d57cd7.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da14489f6f2cd..5dae6205efa05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,11 +279,9 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
-- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
-  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -594,7 +592,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-
+  
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..ac86076140c58 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,8 +113,6 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
-def warn_invalid_utf8_in_comment : Extension<
-  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 799f3017daa82..6820057642bea 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,37 +2392,13 @@ bool Lexer::SkipLineComment(Token , const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
-
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (isASCII(C) && C != 0 &&   // Potentially EOF.
-   C != '\n' && C != '\r') { // Newline or DOS-style newline.
+while (C != 0 &&// Potentially EOF.
+   C != '\n' && C != '\r')  // Newline or DOS-style newline.
   C = *++CurPtr;
-  UnicodeDecodingAlreadyDiagnosed = false;
-}
-
-if (!isASCII(C)) {
-  unsigned Length = llvm::getUTF8SequenceSize(
-  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
-  if (Length == 0) {
-if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
-  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
-UnicodeDecodingAlreadyDiagnosed = true;
-++CurPtr;
-  } else {
-UnicodeDecodingAlreadyDiagnosed = false;
-CurPtr += Length;
-  }
-  continue;
-}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2689,12 +2665,6 @@ bool Lexer::SkipBlockComment(Token , const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   while (true) {
 // Skip over all non-interesting characters until we find end of buffer or 
a
 // (probably ending) '/' character.
@@ -2703,22 +2673,14 @@ bool 

[PATCH] D129045: [C++20][Modules] Update handling of implicit inlines [P1779R3]

2022-07-09 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef0fa9f0ef3e: [C++20][Modules] Update handling of implicit 
inlines [P1779R3] (authored by iains).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129045/new/

https://reviews.llvm.org/D129045

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-constant-expr.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/CXX/class/class.friend/p7-cxx20.cpp
  clang/test/CXX/class/class.mfct/p1-cxx20.cpp

Index: clang/test/CXX/class/class.mfct/p1-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.mfct/p1-cxx20.cpp
@@ -0,0 +1,57 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 no-modules.cpp -fsyntax-only -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-NM %s
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header header-unit.h -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-HU %s
+// RUN: %clang_cc1 -std=c++20 module.cpp -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-MOD %s
+
+//--- no-modules.cpp
+
+class X {
+  void x(){};
+};
+
+// CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 class X definition
+// CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
+// CHECK-NM-NEXT: `-CXXMethodDecl {{.*}}  col:8 x 'void ()' implicit-inline
+
+// A header unit header
+//--- header-unit.h
+
+class Y {
+  void y(){};
+};
+
+// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
+// CHECK-HU-NEXT: `-CXXMethodDecl {{.*}}  col:8 y 'void ()' implicit-inline
+
+// A textually-included header
+//--- header.h
+
+class A {
+  void a(){};
+};
+
+//--- module.cpp
+module;
+#include "header.h"
+
+export module M;
+
+class Z {
+  void z(){};
+};
+
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M. hidden class A definition
+// CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. hidden implicit class A
+// CHECK-MOD-NEXT: | `-CXXMethodDecl {{.*}}  col:8 in M. hidden a 'void ()' implicit-inline
+
+// CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M hidden class Z{{( ReachableWhenImported)?}} definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit class Z{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-CXXMethodDecl {{.*}}  col:8 in M hidden z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -0,0 +1,59 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 no-modules.cpp -fsyntax-only -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-NM %s
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header header-unit.h -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-HU %s
+// RUN: %clang_cc1 -std=c++20 module.cpp -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-MOD %s
+
+//--- no-modules.cpp
+
+class X {
+  friend void x(){};
+};
+
+// CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 class X definition
+// CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
+// CHECK-NM-NEXT: `-FriendDecl {{.*}}  col:15
+// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 x 'void ()' implicit-inline
+
+//--- header-unit.h
+
+class Y {
+  friend void y(){};
+};
+
+// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
+// CHECK-HU-NEXT: `-FriendDecl {{.*}}  col:15
+// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 y 'void ()' implicit-inline
+
+// A textually-included header
+//--- header.h
+
+class A {
+  friend void a(){};
+};
+
+//--- module.cpp
+module;
+#include "header.h"
+
+export module M;
+
+class Z {
+  friend void z(){};
+};
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M. hidden class A definition
+// CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. hidden implicit class A
+// CHECK-MOD-NEXT: | `-FriendDecl {{.*}}  col:15 in M.
+// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  col:15 in M. hidden a 'void ()' implicit-inline
+
+// CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M hidden class Z{{( ReachableWhenImported)?}} definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit class Z{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FriendDecl {{.*}}  col:15 in M{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 in M hidden z 'void 

[clang] ef0fa9f - [C++20][Modules] Update handling of implicit inlines [P1779R3]

2022-07-09 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-09T16:06:32+01:00
New Revision: ef0fa9f0ef3e530a9d600c0f6a21e68b098df7ed

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

LOG: [C++20][Modules] Update handling of implicit inlines [P1779R3]

This provides updates to
[class.mfct]:
Pre C++20 [class.mfct]p2:
  A member function may be defined (8.4) in its class definition, in
  which case it is an inline member function (7.1.2)
Post C++20 [class.mfct]p1:
  If a member function is attached to the global module and is defined
  in its class definition, it is inline.

and
[class.friend]:
Pre-C++20 [class.friend]p5
  A function can be defined in a friend declaration of a
  class . . . . Such a function is implicitly inline.
Post C++20 [class.friend]p7
  Such a function is implicitly an inline function if it is attached
  to the global module.

We add the output of implicit-inline to the TextNodeDumper, and amend
a couple of existing tests to account for this, plus add tests for the
cases covered above.

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

Added: 
clang/test/CXX/class/class.friend/p7-cxx20.cpp
clang/test/CXX/class/class.mfct/p1-cxx20.cpp

Modified: 
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-constant-expr.cpp
clang/test/AST/ast-dump-lambda.cpp

Removed: 




diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 79e9fa6ab86fc..22643d4edbecb 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1720,6 +1720,9 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl 
*D) {
 }
   }
 
+  if (!D->isInlineSpecified() && D->isInlined()) {
+OS << " implicit-inline";
+  }
   // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
   // the Params are set later, it is possible for a dump during debugging to
   // encounter a FunctionDecl that has been created but hasn't been assigned

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 927d81826425b..c5005accc6961 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9405,15 +9405,25 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 NewFD->setLocalExternDecl();
 
   if (getLangOpts().CPlusPlus) {
+// The rules for implicit inlines changed in C++20 for methods and friends
+// with an in-class definition (when such a definition is not attached to
+// the global module).  User-specified 'inline' overrides this (set when
+// the function decl is created above).
+bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlus20 ||
+   !NewFD->getOwningModule() ||
+   NewFD->getOwningModule()->isGlobalModule();
 bool isInline = D.getDeclSpec().isInlineSpecified();
 bool isVirtual = D.getDeclSpec().isVirtualSpecified();
 bool hasExplicit = D.getDeclSpec().hasExplicitSpecifier();
 isFriend = D.getDeclSpec().isFriendSpecified();
 if (isFriend && !isInline && D.isFunctionDefinition()) {
-  // C++ [class.friend]p5
+  // Pre-C++20 [class.friend]p5
   //   A function can be defined in a friend declaration of a
   //   class . . . . Such a function is implicitly inline.
-  NewFD->setImplicitlyInline();
+  // Post C++20 [class.friend]p7
+  //   Such a function is implicitly an inline function if it is attached
+  //   to the global module.
+  NewFD->setImplicitlyInline(ImplicitInlineCXX20);
 }
 
 // If this is a method defined in an __interface, and is not a constructor
@@ -9696,11 +9706,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator , 
DeclContext *DC,
 }
 
 if (isa(NewFD) && DC == CurContext &&
-D.isFunctionDefinition()) {
-  // C++ [class.mfct]p2:
+D.isFunctionDefinition() && !isInline) {
+  // Pre C++20 [class.mfct]p2:
   //   A member function may be defined (8.4) in its class definition, in
   //   which case it is an inline member function (7.1.2)
-  NewFD->setImplicitlyInline();
+  // Post C++20 [class.mfct]p1:
+  //   If a member function is attached to the global module and is defined
+  //   in its class definition, it is inline.
+  NewFD->setImplicitlyInline(ImplicitInlineCXX20);
 }
 
 if (SC == SC_Static && isa(NewFD) &&

diff  --git a/clang/test/AST/ast-dump-constant-expr.cpp 
b/clang/test/AST/ast-dump-constant-expr.cpp
index 79cdfc639af5b..302f562eadd96 100644
--- a/clang/test/AST/ast-dump-constant-expr.cpp
+++ b/clang/test/AST/ast-dump-constant-expr.cpp
@@ -58,7 +58,7 @@ struct Test {
 
 // CHECK:Dumping Test:
 // CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, 
line:57:1> 

[PATCH] D129423: [LinkerWrapper] Fix errors not exiting inside of the LTO pipeline

2022-07-09 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, ye-luo.
Herald added a subscriber: inglorion.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The LTO pipeline handles its errors using the diagnostics handler
callback function. We were not checking the results of these errors and
not properly returning an error code in the linker wrapper when errors
occured inside of the LTO pipeline. This patch adds a simple boolean
flag to indicate if the LTO backend failed to any reason and quit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129423

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@
   switch (DI.getSeverity()) {
   case DS_Error:
 WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+LTOError = true;
 break;
   case DS_Warning:
 WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@
   if (Conf.OptLevel > 0)
 Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@
   if (Error Err = LTOBackend->run(AddStream))
 return Err;
 
+  if (LTOError)
+return createStringError(inconvertibleErrorCode(),
+ "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
 if (BitcodeOutput.size() != 1 || !WholeProgram)


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -89,6 +89,9 @@
 /// Codegen flags for LTO backend.
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
+/// Global flag to indicate that the LTO pipeline threw an error.
+static std::atomic LTOError;
+
 /// Magic section string that marks the existence of offloading data. The
 /// section will contain one or more offloading binaries stored contiguously.
 #define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
@@ -694,6 +697,7 @@
   switch (DI.getSeverity()) {
   case DS_Error:
 WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
+LTOError = true;
 break;
   case DS_Warning:
 WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
@@ -763,6 +767,8 @@
   if (Conf.OptLevel > 0)
 Conf.UseDefaultPipeline = true;
   Conf.DefaultTriple = Triple.getTriple();
+
+  LTOError = false;
   Conf.DiagHandler = diagnosticHandler;
 
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
@@ -968,6 +974,10 @@
   if (Error Err = LTOBackend->run(AddStream))
 return Err;
 
+  if (LTOError)
+return createStringError(inconvertibleErrorCode(),
+ "Errors encountered inside the LTO pipeline.");
+
   // If we are embedding bitcode we only need the intermediate output.
   if (Args.hasArg(OPT_embed_bitcode)) {
 if (BitcodeOutput.size() != 1 || !WholeProgram)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D128059#3640424 , @cor3ntin wrote:

> @aaron.ballman Thanks for the review. I landed the changes and got a bunch of 
> bots screaming at me for changes that are completely unrelated
>
> https://lab.llvm.org/buildbot/#/builders/21/builds/45146
> https://lab.llvm.org/buildbot/#/builders/36/builds/22838
> https://lab.llvm.org/buildbot/#/builders/121/builds/21183

What do you mean it is completely unrelated? You have `__ALTIVEC__`-specific 
changes and it knocks out the PPC bots.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny marked an inline comment as done.
SimplyDanny added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:250-253
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to 
initialize
+  boolean variables.
+

njames93 wrote:
> Sorry I should've mentioned, we keep this list in alphabetical order(for the 
> names of the checks).
> Can you push a patch to move this into its correct place(no need for a review 
> and commit as NFC)
Ah sorry. I could have noticed that. Fixed in [[ 
https://github.com/llvm/llvm-project/commit/963192228b05e3bce86cf520e2bda5f069be9894
 | this commit ]].


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

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


[clang-tools-extra] 9631922 - [clang-tidy] Sort release notes entries alphabetically by check name

2022-07-09 Thread Danny Mösch via cfe-commits

Author: Danny Mösch
Date: 2022-07-09T15:45:19+02:00
New Revision: 963192228b05e3bce86cf520e2bda5f069be9894

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

LOG: [clang-tidy] Sort release notes entries alphabetically by check name

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 9e3bc1554f07..80bb85d1fc34 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@ Changes in existing checks
 - Made :doc:`cert-oop57-cpp ` more sensitive
   by checking for an arbitrary expression in the second argument of ``memset``.
 
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to 
initialize
+  boolean variables.
+
 - Improved :doc:`cppcoreguidelines-prefer-member-initializer
   ` check.
 
@@ -247,10 +251,6 @@ Changes in existing checks
   ` to simplify 
expressions
   using DeMorgan's Theorem.
 
-- Made the fix-it of :doc:`cppcoreguidelines-init-variables
-  ` use ``false`` to 
initialize
-  boolean variables.
-
 Removed checks
 ^^
 



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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:188
   by checking for an arbitrary expression in the second argument of ``memset``.
 
 - Improved :doc:`cppcoreguidelines-prefer-member-initializer

It should live here instead.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:250-253
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to 
initialize
+  boolean variables.
+

Sorry I should've mentioned, we keep this list in alphabetical order(for the 
names of the checks).
Can you push a patch to move this into its correct place(no need for a review 
and commit as NFC)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny added a comment.

In D129420#3640482 , @njames93 wrote:

> Can you add a line to release notes about this fix then LGTM

Sure. Thank you for the fast review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33e212954430: [clang-tidy] Initialize boolean variables with 
`false` in cppcoreguidelines… (authored by SimplyDanny).

Changed prior to commit:
  https://reviews.llvm.org/D129420?vs=443429=443434#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -64,7 +64,7 @@
 
   bool b;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized 
[cppcoreguidelines-init-variables]
-  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  // CHECK-FIXES: {{^}}  bool b = false;{{$}}
   bool bval = true;
 
   const char *ptr;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -247,6 +247,10 @@
   ` to simplify 
expressions
   using DeMorgan's Theorem.
 
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to 
initialize
+  boolean variables.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -84,6 +84,8 @@
 
   if (TypePtr->isEnumeralType())
 InitializationString = nullptr;
+  else if (TypePtr->isBooleanType())
+InitializationString = " = false";
   else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -64,7 +64,7 @@
 
   bool b;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [cppcoreguidelines-init-variables]
-  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  // CHECK-FIXES: {{^}}  bool b = false;{{$}}
   bool bval = true;
 
   const char *ptr;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -247,6 +247,10 @@
   ` to simplify expressions
   using DeMorgan's Theorem.
 
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to initialize
+  boolean variables.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -84,6 +84,8 @@
 
   if (TypePtr->isEnumeralType())
 InitializationString = nullptr;
+  else if (TypePtr->isBooleanType())
+InitializationString = " = false";
   else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 33e2129 - [clang-tidy] Initialize boolean variables with `false` in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via cfe-commits

Author: Danny Mösch
Date: 2022-07-09T14:48:50+02:00
New Revision: 33e212954430d6116d7743541a7e9be8cdfac196

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

LOG: [clang-tidy] Initialize boolean variables with `false` in 
cppcoreguidelines-init-variables' fix-it

In case of a variable with a built-in boolean type, `false` is a better fit to 
default-initialize it.

Reviewed By: njames93

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
index efe694426728e..307559a403a9a 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -84,6 +84,8 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult 
) {
 
   if (TypePtr->isEnumeralType())
 InitializationString = nullptr;
+  else if (TypePtr->isBooleanType())
+InitializationString = " = false";
   else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1d6fd05605db7..9e3bc1554f07b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -247,6 +247,10 @@ Changes in existing checks
   ` to simplify 
expressions
   using DeMorgan's Theorem.
 
+- Made the fix-it of :doc:`cppcoreguidelines-init-variables
+  ` use ``false`` to 
initialize
+  boolean variables.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
index 3ee1f0aaec49e..479e5f62eb8b5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -64,7 +64,7 @@ void init_unit_tests() {
 
   bool b;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized 
[cppcoreguidelines-init-variables]
-  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  // CHECK-FIXES: {{^}}  bool b = false;{{$}}
   bool bval = true;
 
   const char *ptr;



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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Can you add a line to release notes about this fix then LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

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


[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-07-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

gentle ping~


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128782/new/

https://reviews.llvm.org/D128782

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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny added a comment.

This is a potential fix for this issue 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129420/new/

https://reviews.llvm.org/D129420

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


[PATCH] D129420: [clang-tidy] Initialize boolean variables with 'false' in cppcoreguidelines-init-variables' fix-it

2022-07-09 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny created this revision.
SimplyDanny added a reviewer: aaron.ballman.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
SimplyDanny requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In case of a variable with a built-in boolean type, `false` is a better fit to 
default-initialize it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129420

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -64,7 +64,7 @@
 
   bool b;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized 
[cppcoreguidelines-init-variables]
-  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  // CHECK-FIXES: {{^}}  bool b = false;{{$}}
   bool bval = true;
 
   const char *ptr;
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -84,6 +84,8 @@
 
   if (TypePtr->isEnumeralType())
 InitializationString = nullptr;
+  else if (TypePtr->isBooleanType())
+InitializationString = " = false";
   else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp
@@ -64,7 +64,7 @@
 
   bool b;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [cppcoreguidelines-init-variables]
-  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  // CHECK-FIXES: {{^}}  bool b = false;{{$}}
   bool bval = true;
 
   const char *ptr;
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -84,6 +84,8 @@
 
   if (TypePtr->isEnumeralType())
 InitializationString = nullptr;
+  else if (TypePtr->isBooleanType())
+InitializationString = " = false";
   else if (TypePtr->isIntegerType())
 InitializationString = " = 0";
   else if (TypePtr->isFloatingType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4328b96 - [C++20][Modules] Fix two tests for CTORs that return pointers [NFC].

2022-07-09 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-09T11:23:20+01:00
New Revision: 4328b960176f4394416093e640ad4265bde65ad7

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

LOG: [C++20][Modules] Fix two tests for CTORs that return pointers [NFC].

The test are to check that we call the correctly mangled CTORs, so that
the return values from them are irrelevant.  I forgot that some targets
return a pointer, apologies for the breakage.

Added: 


Modified: 
clang/test/CodeGen/module-intializer-pmf.cpp
clang/test/CodeGen/module-intializer.cpp

Removed: 




diff  --git a/clang/test/CodeGen/module-intializer-pmf.cpp 
b/clang/test/CodeGen/module-intializer-pmf.cpp
index 082dda19fea09..e513b280b0a75 100644
--- a/clang/test/CodeGen/module-intializer-pmf.cpp
+++ b/clang/test/CodeGen/module-intializer-pmf.cpp
@@ -29,11 +29,11 @@ struct InPMF {
 InPMF P;
 
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call void @_ZN4GlobC1Ev
+// CHECK: call {{.*}} @_ZN4GlobC1Ev
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call void @_ZNW6HasPMF5InPMFC1Ev
+// CHECK: call {{.*}} @_ZNW6HasPMF5InPMFC1Ev
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call void @_ZNW6HasPMF5InModC1Ev
+// CHECK: call {{.*}} @_ZNW6HasPMF5InModC1Ev
 // CHECK: define void @_ZGIW6HasPMF
 // CHECK: store i8 1, ptr @_ZGIW6HasPMF__in_chrg
 // CHECK: call void @__cxx_global_var_init

diff  --git a/clang/test/CodeGen/module-intializer.cpp 
b/clang/test/CodeGen/module-intializer.cpp
index df2f0a5d17da6..0b48e87f9ea7c 100644
--- a/clang/test/CodeGen/module-intializer.cpp
+++ b/clang/test/CodeGen/module-intializer.cpp
@@ -53,9 +53,9 @@ export struct Quack {
 export Quack Duck;
 
 // CHECK-N: define internal void @__cxx_global_var_init
-// CHECK-N: call void @_ZN4OinkC1Ev
+// CHECK-N: call {{.*}} @_ZN4OinkC1Ev
 // CHECK-N: define internal void @__cxx_global_var_init
-// CHECK-N: call void @_ZNW1N5QuackC1Ev
+// CHECK-N: call {{.*}} @_ZNW1N5QuackC1Ev
 // CHECK-N: define void @_ZGIW1N
 // CHECK-N: store i8 1, ptr @_ZGIW1N__in_chrg
 // CHECK-N: call void @__cxx_global_var_init
@@ -83,9 +83,9 @@ export struct Bark {
 export Bark Dog;
 
 // CHECK-O: define internal void @__cxx_global_var_init
-// CHECK-O: call void @_ZN4MeowC2Ev
+// CHECK-O: call {{.*}} @_ZN4MeowC2Ev
 // CHECK-O: define internal void @__cxx_global_var_init
-// CHECK-O: call void @_ZNW1O4BarkC1Ev
+// CHECK-O: call {{.*}} @_ZNW1O4BarkC1Ev
 // CHECK-O: define void @_ZGIW1O
 // CHECK-O: store i8 1, ptr @_ZGIW1O__in_chrg
 // CHECK-O: call void @__cxx_global_var_init
@@ -113,9 +113,9 @@ struct Squawk {
 Squawk parrot;
 
 // CHECK-P: define internal void @__cxx_global_var_init
-// CHECK-P: call void @_ZN5CroakC1Ev
+// CHECK-P: call {{.*}} @_ZN5CroakC1Ev
 // CHECK-P: define internal void @__cxx_global_var_init
-// CHECK-P: call void @_ZNW1M6SquawkC1Ev
+// CHECK-P: call {{.*}} @_ZNW1M6SquawkC1Ev
 // CHECK-P: define void @_ZGIW1MWP4Part
 // CHECK-P: store i8 1, ptr @_ZGIW1MWP4Part__in_chrg
 // CHECK-P: call void @__cxx_global_var_init
@@ -149,9 +149,9 @@ export struct Baa {
 export Baa Sheep(10);
 
 // CHECK-M: define internal void @__cxx_global_var_init
-// CHECK-M: call void @_ZN3MooC1Ev
+// CHECK-M: call {{.*}} @_ZN3MooC1Ev
 // CHECK-M: define internal void @__cxx_global_var_init
-// CHECK-M: call void @_ZNW1M3BaaC1Ei
+// CHECK-M: call {{.*}} @_ZNW1M3BaaC1Ei
 // CHECK-M: declare void @_ZGIW1O()
 // CHECK-M: declare void @_ZGIW1N()
 // CHECK-M: declare void @_ZGIW1MWP4Part()



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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aaron.ballman Thanks for the review. I landed the changes and got a bunch of 
bots screaming at me for changes that are completely unrelated

https://lab.llvm.org/buildbot/#/builders/21/builds/45146
https://lab.llvm.org/buildbot/#/builders/36/builds/22838
https://lab.llvm.org/buildbot/#/builders/121/builds/21183


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG355532a1499a: [Clang] Add a warning on invalid UTF-8 in 
comments. (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D128059?vs=443225=443423#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/comment-invalid-utf8.c
  clang/test/Lexer/comment-utf8.c
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTF.cpp

Index: llvm/lib/Support/ConvertUTF.cpp
===
--- llvm/lib/Support/ConvertUTF.cpp
+++ llvm/lib/Support/ConvertUTF.cpp
@@ -417,6 +417,16 @@
 return isLegalUTF8(source, length);
 }
 
+/*
+ * Exported function to return the size of the first utf-8 code unit sequence,
+ * Or 0 if the sequence is not valid;
+ */
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
+  int length = trailingBytesForUTF8[*source] + 1;
+  return (length <= sourceEnd - source && isLegalUTF8(source, length)) ? length
+ : 0;
+}
+
 /* - */
 
 static unsigned
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -181,6 +181,8 @@
 
 Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd);
 
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd);
+
 unsigned getNumBytesForUTF8(UTF8 firstByte);
 
 /*/
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu -Wno-invalid-utf8
 
 int f(); // expected-note {{declared here}}
 
Index: clang/test/Lexer/comment-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-utf8.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify
+// expected-no-diagnostics
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©©©
+*/
+
+/* § § § 😀 你好 © */
+/*
+a longer comment to exerce the vectorized code path
+
+αααααααααααααααααααααα  // here is some unicode
+
+
+*/
Index: clang/test/Lexer/comment-invalid-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-invalid-utf8.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify=expected
+// RUN: %clang_cc1 -fsyntax-only %s -verify=nowarn
+// nowarn-no-diagnostics
+
+// This file is purposefully encoded as windows-1252
+// be careful when modifying.
+
+//€
+// expected-warning@-1 {{invalid UTF-8 in comment}}
+
+// € ‚ƒ„…†‡ˆ‰ Š ‹ Œ Ž
+// expected-warning@-1 6{{invalid UTF-8 in comment}}
+
+/*€*/
+// expected-warning@-1 {{invalid UTF-8 in comment}}
+
+/*€ ‚ƒ„…†‡ˆ‰ Š ‹ Œ Ž*/
+// expected-warning@-1 6{{invalid UTF-8 in comment}}
+
+/*
+€
+*/
+// expected-warning@-2 {{invalid UTF-8 in comment}}
+
+// abcd
+// €abcd
+// expected-warning@-1 {{invalid UTF-8 in comment}}
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@
   //
   // This loop terminates with CurPtr pointing at the newline (or end of buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && 

[clang] 355532a - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-09T11:26:45+02:00
New Revision: 355532a1499aa9b13a89fb5b5caaba2344d57cd7

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

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dae6205efa05..da14489f6f2cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,9 +279,11 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -592,7 +594,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..799f3017daa82 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token , const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token , const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 

[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-09 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac507102d258: [C++20][Modules] Build module static 
initializers per P1874R1. (authored by iains).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CodeGen/module-intializer-pmf.cpp
  clang/test/CodeGen/module-intializer.cpp

Index: clang/test/CodeGen/module-intializer.cpp
===
--- /dev/null
+++ clang/test/CodeGen/module-intializer.cpp
@@ -0,0 +1,186 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 N.cpp \
+// RUN:-emit-module-interface -o N.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 N.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-N
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.cpp \
+// RUN:-emit-module-interface -o O.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-O
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-part.cpp \
+// RUN:-emit-module-interface -o M-part.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-part.pcm -S \
+// RUN: -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-P
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.cpp \
+// RUN: -fmodule-file=N.pcm -fmodule-file=O.pcm -fmodule-file=M-part.pcm \
+// RUN:-emit-module-interface -o M.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.pcm -S -emit-llvm \
+// RUN:  -o - | FileCheck %s --check-prefix=CHECK-M
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 useM.cpp \
+// RUN: -fmodule-file=M.pcm -S -emit-llvm  -o - \
+// RUN: | FileCheck %s --check-prefix=CHECK-USE
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-impl.cpp \
+// RUN: -fmodule-file=M.pcm -S -emit-llvm  -o - \
+// RUN: | FileCheck %s --check-prefix=CHECK-IMPL
+
+//--- N-h.h
+
+struct Oink {
+  Oink(){};
+};
+
+Oink Hog;
+
+//--- N.cpp
+
+module;
+#include "N-h.h"
+
+export module N;
+
+export struct Quack {
+  Quack(){};
+};
+
+export Quack Duck;
+
+// CHECK-N: define internal void @__cxx_global_var_init
+// CHECK-N: call void @_ZN4OinkC1Ev
+// CHECK-N: define internal void @__cxx_global_var_init
+// CHECK-N: call void @_ZNW1N5QuackC1Ev
+// CHECK-N: define void @_ZGIW1N
+// CHECK-N: store i8 1, ptr @_ZGIW1N__in_chrg
+// CHECK-N: call void @__cxx_global_var_init
+// CHECK-N: call void @__cxx_global_var_init
+
+//--- O-h.h
+
+struct Meow {
+  Meow(){};
+};
+
+Meow Cat;
+
+//--- O.cpp
+
+module;
+#include "O-h.h"
+
+export module O;
+
+export struct Bark {
+  Bark(){};
+};
+
+export Bark Dog;
+
+// CHECK-O: define internal void @__cxx_global_var_init
+// CHECK-O: call void @_ZN4MeowC2Ev
+// CHECK-O: define internal void @__cxx_global_var_init
+// CHECK-O: call void @_ZNW1O4BarkC1Ev
+// CHECK-O: define void @_ZGIW1O
+// CHECK-O: store i8 1, ptr @_ZGIW1O__in_chrg
+// CHECK-O: call void @__cxx_global_var_init
+// CHECK-O: call void @__cxx_global_var_init
+
+//--- P-h.h
+
+struct Croak {
+  Croak(){};
+};
+
+Croak Frog;
+
+//--- M-part.cpp
+
+module;
+#include "P-h.h"
+
+module M:Part;
+
+struct Squawk {
+  Squawk(){};
+};
+
+Squawk parrot;
+
+// CHECK-P: define internal void @__cxx_global_var_init
+// CHECK-P: call void @_ZN5CroakC1Ev
+// CHECK-P: define internal void @__cxx_global_var_init
+// CHECK-P: call void @_ZNW1M6SquawkC1Ev
+// CHECK-P: define void @_ZGIW1MWP4Part
+// CHECK-P: store i8 1, ptr @_ZGIW1MWP4Part__in_chrg
+// CHECK-P: call void @__cxx_global_var_init
+// CHECK-P: call void @__cxx_global_var_init
+
+//--- M-h.h
+
+struct Moo {
+  Moo(){};
+};
+
+Moo Cow;
+
+//--- M.cpp
+
+module;
+#include "M-h.h"
+
+export module M;
+import N;
+export import O;
+import :Part;
+
+export struct Baa {
+  int x;
+  Baa(){};
+  Baa(int x) : x(x) {}
+  int getX() { return x; }
+};
+
+export Baa Sheep(10);
+
+// CHECK-M: define internal void @__cxx_global_var_init
+// CHECK-M: call void @_ZN3MooC1Ev
+// CHECK-M: define internal void @__cxx_global_var_init
+// CHECK-M: call void @_ZNW1M3BaaC1Ei
+// CHECK-M: declare void @_ZGIW1O()
+// CHECK-M: declare void @_ZGIW1N()
+// CHECK-M: declare void @_ZGIW1MWP4Part()
+// CHECK-M: define void @_ZGIW1M
+// CHECK-M: store i8 1, ptr @_ZGIW1M__in_chrg
+// CHECK-M: call void @_ZGIW1O()
+// CHECK-M: call void @_ZGIW1N()
+// CHECK-M: call void @_ZGIW1MWP4Part()
+// CHECK-M: call void @__cxx_global_var_init
+// CHECK-M: call void 

[clang] ac50710 - [C++20][Modules] Build module static initializers per P1874R1.

2022-07-09 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-09T09:09:09+01:00
New Revision: ac507102d258b6fc0cb57eb60c9dfabd57ff562f

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

LOG: [C++20][Modules] Build module static initializers per P1874R1.

Currently we only implement this for the Itanium ABI since the correct
mangling for the initializers in other ABIs is not yet known.

Intended result:

For a module interface [which includes partition interface and implementation
units] (instead of the generic CXX initializer) we emit a module init that:

 - wraps the contained initializations in a control variable to ensure that
   the inits only happen once, even if a module is imported many times by
   imports of the main unit.

 - calls module initializers for imported modules first.  Note that the
   order of module import is not significant, and therefore neither is the
   order of imported module initializers.

 - We then call initializers for the Global Module Fragment (if present)
 - We then call initializers for the current module.
 - We then call initializers for the Private Module Fragment (if present)

For a module implementation unit, or a non-module TU that imports at least one
module we emit a regular CXX init that:

 - Calls the initializers for any imported modules first.
 - Then proceeds as normal with remaining inits.

For all module unit kinds we include a global constructor entry, this allows
for the (in most cases unusual) possibility that a module object could be
included in a final binary without a specific call to its initializer.

Implementation:

 - We provide the module pointer in the AST Context so that CodeGen can act
   on it and its sub-modules.

 - We need to account for module build lines like this:
  ` clang -cc1 -std=c++20 Foo.pcm -emit-obj -o Foo.o` or
  ` clang -cc1 -std=c++20 -xc++-module Foo.cpp -emit-obj -o Foo.o`

 - in order to do this, we add to ParseAST to set the module pointer in
   the ASTContext, once we establish that this is a module build and we
   know the module pointer. To be able to do this, we make the query for
   current module public in Sema.

 - In CodeGen, we determine if the current build requires a CXX20-style module
   init and, if so, we defer any module initializers during the "Eagerly
   Emitted" phase.

 - We then walk the module initializers at the end of the TU but before
   emitting deferred inits (which adds any hidden and static ones, fixing
   https://github.com/llvm/llvm-project/issues/51873 ).

 - We then proceed to emit the deferred inits and continue to emit the CXX
   init function.

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

Added: 
clang/test/CodeGen/module-intializer-pmf.cpp
clang/test/CodeGen/module-intializer.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/Module.h
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Parse/ParseAST.cpp
clang/lib/Sema/SemaModule.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 87b5a6053f1f2..db7ae9a0b55c9 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -472,6 +472,9 @@ class ASTContext : public RefCountedBase {
   };
   llvm::DenseMap ModuleInitializers;
 
+  /// For module code-gen cases, this is the top-level module we are building.
+  Module *TopLevelModule = nullptr;
+
   static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
   static constexpr unsigned GeneralTypesLog2InitSize = 9;
   static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
@@ -1075,6 +1078,12 @@ class ASTContext : public RefCountedBase {
   /// Get the initializations to perform when importing a module, if any.
   ArrayRef getModuleInitializers(Module *M);
 
+  /// Set the (C++20) module we are building.
+  void setModuleForCodeGen(Module *M) { TopLevelModule = M; }
+
+  /// Get module under construction, nullptr if this is not a C++20 module.
+  Module *getModuleForCodeGen() const { return TopLevelModule; }
+
   TranslationUnitDecl *getTranslationUnitDecl() const {
 return TUDecl->getMostRecentDecl();
   }

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index a1778baa04530..47d736a3b4557 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -665,6 +665,18 @@ class Module {
   Module *findSubmodule(StringRef Name) const;
   Module *findOrInferSubmodule(StringRef Name);
 
+  /// Get the Global Module Fragment (sub-module) for this module, it there is
+  /// one.
+  ///
+  /// \returns The GMF sub-module if found, or NULL otherwise.
+  Module 

[PATCH] D129202: [clang] Add a fixit for warn-self-assign if LHS is a field with the same name as parameter on RHS

2022-07-09 Thread Nathan James via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54f57d3847c0: [clang] Add a fixit for warn-self-assign if 
LHS is a field with the same name… (authored by njames93).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129202/new/

https://reviews.llvm.org/D129202

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-self-assign-builtin.cpp
  clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -39,6 +39,9 @@
 other.x = std::move(x);
 other.x = std::move(other.x);  // expected-warning{{explicitly moving}}
   }
+  void withSuggest(int x) {
+x = std::move(x); // expected-warning{{explicitly moving variable of type 'int' to itself; did you mean to move to member 'x'?}}
+  }
 };
 
 struct A {};
Index: clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
===
--- clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
+++ clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
@@ -4,6 +4,8 @@
   int a;
   int b;
 
+  C(int a, int b) : a(a), b(b) {}
+
   void f() {
 a = a; // expected-warning {{assigning field to itself}}
 b = b; // expected-warning {{assigning field to itself}}
Index: clang/test/SemaCXX/warn-self-assign-builtin.cpp
===
--- clang/test/SemaCXX/warn-self-assign-builtin.cpp
+++ clang/test/SemaCXX/warn-self-assign-builtin.cpp
@@ -65,3 +65,26 @@
   g();
   g();
 }
+
+struct Foo {
+  int A;
+
+  Foo(int A) : A(A) {}
+
+  void setA(int A) {
+A = A; // expected-warning{{explicitly assigning value of variable of type 'int' to itself; did you mean to assign to member 'A'?}}
+  }
+
+  void setThroughLambda() {
+[](int A) {
+  // To fix here we would need to insert an explicit capture 'this'
+  A = A; // expected-warning{{explicitly assigning}}
+}(5);
+
+[this](int A) {
+  this->A = 0;
+  // This fix would be possible by just adding this-> as above, but currently unsupported.
+  A = A; // expected-warning{{explicitly assigning}}
+}(5);
+  }
+};
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14600,6 +14600,40 @@
   return Opc;
 }
 
+const FieldDecl *
+Sema::getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned) {
+  // Explore the case for adding 'this->' to the LHS of a self assignment, very
+  // common for setters.
+  // struct A {
+  // int X;
+  // -void setX(int X) { X = X; }
+  // +void setX(int X) { this->X = X; }
+  // };
+
+  // Only consider parameters for self assignment fixes.
+  if (!isa(SelfAssigned))
+return nullptr;
+  const auto *Method =
+  dyn_cast_or_null(getCurFunctionDecl(true));
+  if (!Method)
+return nullptr;
+
+  const CXXRecordDecl *Parent = Method->getParent();
+  // In theory this is fixable if the lambda explicitly captures this, but
+  // that's added complexity that's rarely going to be used.
+  if (Parent->isLambda())
+return nullptr;
+
+  // FIXME: Use an actual Lookup operation instead of just traversing fields
+  // in order to get base class fields.
+  auto Field =
+  llvm::find_if(Parent->fields(),
+[Name(SelfAssigned->getDeclName())](const FieldDecl *F) {
+  return F->getDeclName() == Name;
+});
+  return (Field != Parent->field_end()) ? *Field : nullptr;
+}
+
 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
 /// This warning suppressed in the event of macro expansions.
 static void DiagnoseSelfAssignment(Sema , Expr *LHSExpr, Expr *RHSExpr,
@@ -14630,10 +14664,16 @@
 if (RefTy->getPointeeType().isVolatileQualified())
   return;
 
-  S.Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
-  : diag::warn_self_assignment_overloaded)
-  << LHSDeclRef->getType() << LHSExpr->getSourceRange()
-  << RHSExpr->getSourceRange();
+  auto Diag = S.Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
+  : diag::warn_self_assignment_overloaded)
+  << LHSDeclRef->getType() << LHSExpr->getSourceRange()
+  << RHSExpr->getSourceRange();
+  if (const FieldDecl *SelfAssignField =
+  S.getSelfAssignmentClassMemberCandidate(RHSDecl))
+Diag << 1 << SelfAssignField
+ << 

[clang] 54f57d3 - [clang] Add a fixit for warn-self-assign if LHS is a field with the same name as parameter on RHS

2022-07-09 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-07-09T08:28:07+01:00
New Revision: 54f57d3847c00d0233e287ebb5283d04e6083062

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

LOG: [clang] Add a fixit for warn-self-assign if LHS is a field with the same 
name as parameter on RHS

Add a fix-it for the common case of setters/constructors using parameters with 
the same name as fields
```lang=c++
struct A{
  int X;
  A(int X) { /*this->*/X = X; }
  void setX(int X) { /*this->*/X = X;
};
```

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-self-assign-builtin.cpp
clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
clang/test/SemaCXX/warn-self-move.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c6d36568099b4..5dae6205efa05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,6 +279,9 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+  suggest a fix if the decl being assigned is a parameter that shadows a data
+  member of the contained class.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fd10bd9c70e6a..0d25c718d09e9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6610,13 +6610,16 @@ def warn_addition_in_bitshift : Warning<
   "'%1' will be evaluated first">, InGroup;
 
 def warn_self_assignment_builtin : Warning<
-  "explicitly assigning value of variable of type %0 to itself">,
+  "explicitly assigning value of variable of type %0 to itself%select{|; did "
+  "you mean to assign to member %2?}1">,
   InGroup, DefaultIgnore;
 def warn_self_assignment_overloaded : Warning<
-  "explicitly assigning value of variable of type %0 to itself">,
+  "explicitly assigning value of variable of type %0 to itself%select{|; did "
+  "you mean to assign to member %2?}1">,
   InGroup, DefaultIgnore;
 def warn_self_move : Warning<
-  "explicitly moving variable of type %0 to itself">,
+  "explicitly moving variable of type %0 to itself%select{|; did you mean to "
+  "move to member %2?}1">,
   InGroup, DefaultIgnore;
 
 def err_builtin_move_forward_unsupported : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4fc53a0697a5c..75a2e7eb31d19 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5170,6 +5170,11 @@ class Sema final {
   void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
 SourceLocation OpLoc);
 
+  /// Returns a field in a CXXRecordDecl that has the same name as the decl \p
+  /// SelfAssigned when inside a CXXMethodDecl.
+  const FieldDecl *
+  getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned);
+
   /// Warn if we're implicitly casting from a _Nullable pointer type to a
   /// _Nonnull one.
   void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ed745c5634c8..d3929361213ad 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16830,9 +16830,15 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, const 
Expr *RHSExpr,
 RHSDeclRef->getDecl()->getCanonicalDecl())
   return;
 
-Diag(OpLoc, diag::warn_self_move) << LHSExpr->getType()
-<< LHSExpr->getSourceRange()
-<< RHSExpr->getSourceRange();
+auto D = Diag(OpLoc, diag::warn_self_move)
+ << LHSExpr->getType() << LHSExpr->getSourceRange()
+ << RHSExpr->getSourceRange();
+if (const FieldDecl *F =
+getSelfAssignmentClassMemberCandidate(RHSDeclRef->getDecl()))
+  D << 1 << F
+<< FixItHint::CreateInsertion(LHSDeclRef->getBeginLoc(), "this->");
+else
+  D << 0;
 return;
   }
 
@@ -16867,16 +16873,16 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, 
const Expr *RHSExpr,
 RHSDeclRef->getDecl()->getCanonicalDecl())
   return;
 
-Diag(OpLoc, diag::warn_self_move) << 

[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-09 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129398/new/

https://reviews.llvm.org/D129398

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


[PATCH] D129202: [clang] Add a fixit for warn-self-assign if LHS is a field with the same name as parameter on RHS

2022-07-09 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 443417.
njames93 added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129202/new/

https://reviews.llvm.org/D129202

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-self-assign-builtin.cpp
  clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -39,6 +39,9 @@
 other.x = std::move(x);
 other.x = std::move(other.x);  // expected-warning{{explicitly moving}}
   }
+  void withSuggest(int x) {
+x = std::move(x); // expected-warning{{explicitly moving variable of type 'int' to itself; did you mean to move to member 'x'?}}
+  }
 };
 
 struct A {};
Index: clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
===
--- clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
+++ clang/test/SemaCXX/warn-self-assign-field-builtin.cpp
@@ -4,6 +4,8 @@
   int a;
   int b;
 
+  C(int a, int b) : a(a), b(b) {}
+
   void f() {
 a = a; // expected-warning {{assigning field to itself}}
 b = b; // expected-warning {{assigning field to itself}}
Index: clang/test/SemaCXX/warn-self-assign-builtin.cpp
===
--- clang/test/SemaCXX/warn-self-assign-builtin.cpp
+++ clang/test/SemaCXX/warn-self-assign-builtin.cpp
@@ -65,3 +65,26 @@
   g();
   g();
 }
+
+struct Foo {
+  int A;
+
+  Foo(int A) : A(A) {}
+
+  void setA(int A) {
+A = A; // expected-warning{{explicitly assigning value of variable of type 'int' to itself; did you mean to assign to member 'A'?}}
+  }
+
+  void setThroughLambda() {
+[](int A) {
+  // To fix here we would need to insert an explicit capture 'this'
+  A = A; // expected-warning{{explicitly assigning}}
+}(5);
+
+[this](int A) {
+  this->A = 0;
+  // This fix would be possible by just adding this-> as above, but currently unsupported.
+  A = A; // expected-warning{{explicitly assigning}}
+}(5);
+  }
+};
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14600,6 +14600,40 @@
   return Opc;
 }
 
+const FieldDecl *
+Sema::getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned) {
+  // Explore the case for adding 'this->' to the LHS of a self assignment, very
+  // common for setters.
+  // struct A {
+  // int X;
+  // -void setX(int X) { X = X; }
+  // +void setX(int X) { this->X = X; }
+  // };
+
+  // Only consider parameters for self assignment fixes.
+  if (!isa(SelfAssigned))
+return nullptr;
+  const auto *Method =
+  dyn_cast_or_null(getCurFunctionDecl(true));
+  if (!Method)
+return nullptr;
+
+  const CXXRecordDecl *Parent = Method->getParent();
+  // In theory this is fixable if the lambda explicitly captures this, but
+  // that's added complexity that's rarely going to be used.
+  if (Parent->isLambda())
+return nullptr;
+
+  // FIXME: Use an actual Lookup operation instead of just traversing fields
+  // in order to get base class fields.
+  auto Field =
+  llvm::find_if(Parent->fields(),
+[Name(SelfAssigned->getDeclName())](const FieldDecl *F) {
+  return F->getDeclName() == Name;
+});
+  return (Field != Parent->field_end()) ? *Field : nullptr;
+}
+
 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
 /// This warning suppressed in the event of macro expansions.
 static void DiagnoseSelfAssignment(Sema , Expr *LHSExpr, Expr *RHSExpr,
@@ -14630,10 +14664,16 @@
 if (RefTy->getPointeeType().isVolatileQualified())
   return;
 
-  S.Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
-  : diag::warn_self_assignment_overloaded)
-  << LHSDeclRef->getType() << LHSExpr->getSourceRange()
-  << RHSExpr->getSourceRange();
+  auto Diag = S.Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
+  : diag::warn_self_assignment_overloaded)
+  << LHSDeclRef->getType() << LHSExpr->getSourceRange()
+  << RHSExpr->getSourceRange();
+  if (const FieldDecl *SelfAssignField =
+  S.getSelfAssignmentClassMemberCandidate(RHSDecl))
+Diag << 1 << SelfAssignField
+ << FixItHint::CreateInsertion(LHSDeclRef->getBeginLoc(), "this->");
+  else
+Diag << 0;
 }
 
 /// Check if a bitwise-& is performed on an Objective-C pointer.  This
Index: clang/lib/Sema/SemaChecking.cpp

[PATCH] D129348: [clang-format] Fix an assertion failure on -lines=0:n

2022-07-09 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG615f838f7380: [clang-format] Fix an assertion failure on 
-lines=0:n (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129348/new/

https://reviews.llvm.org/D129348

Files:
  clang/test/Format/line-ranges.cpp
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -246,8 +246,12 @@
 errs() << "error: invalid : pair\n";
 return true;
   }
+  if (FromLine < 1) {
+errs() << "error: start line should be at least 1\n";
+return true;
+  }
   if (FromLine > ToLine) {
-errs() << "error: start line should be less than end line\n";
+errs() << "error: start line should not exceed end line\n";
 return true;
   }
   SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
Index: clang/test/Format/line-ranges.cpp
===
--- clang/test/Format/line-ranges.cpp
+++ clang/test/Format/line-ranges.cpp
@@ -9,3 +9,11 @@
 
 // CHECK: {{^int\ \*i;$}}
 int   *   i;
+
+// RUN: not clang-format -lines=0:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK0 %s
+// CHECK0: error: start line should be at least 1
+
+// RUN: not clang-format -lines=2:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
+// CHECK1: error: start line should not exceed end line


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -246,8 +246,12 @@
 errs() << "error: invalid : pair\n";
 return true;
   }
+  if (FromLine < 1) {
+errs() << "error: start line should be at least 1\n";
+return true;
+  }
   if (FromLine > ToLine) {
-errs() << "error: start line should be less than end line\n";
+errs() << "error: start line should not exceed end line\n";
 return true;
   }
   SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
Index: clang/test/Format/line-ranges.cpp
===
--- clang/test/Format/line-ranges.cpp
+++ clang/test/Format/line-ranges.cpp
@@ -9,3 +9,11 @@
 
 // CHECK: {{^int\ \*i;$}}
 int   *   i;
+
+// RUN: not clang-format -lines=0:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK0 %s
+// CHECK0: error: start line should be at least 1
+
+// RUN: not clang-format -lines=2:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
+// CHECK1: error: start line should not exceed end line
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 615f838 - [clang-format] Fix an assertion failure on -lines=0:n

2022-07-09 Thread via cfe-commits

Author: owenca
Date: 2022-07-08T23:41:16-07:00
New Revision: 615f838f7380e6a4f3df8e16f04dea3c8eed656c

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

LOG: [clang-format] Fix an assertion failure on -lines=0:n

Also fixed the error message for start line > end line and added test cases.

Fixes #56438.

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

Added: 


Modified: 
clang/test/Format/line-ranges.cpp
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/test/Format/line-ranges.cpp 
b/clang/test/Format/line-ranges.cpp
index e81e9624344d0..91b7d2cffc8f0 100644
--- a/clang/test/Format/line-ranges.cpp
+++ b/clang/test/Format/line-ranges.cpp
@@ -9,3 +9,11 @@ int  *  i;
 
 // CHECK: {{^int\ \*i;$}}
 int   *   i;
+
+// RUN: not clang-format -lines=0:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK0 %s
+// CHECK0: error: start line should be at least 1
+
+// RUN: not clang-format -lines=2:1 < %s 2>&1 \
+// RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s
+// CHECK1: error: start line should not exceed end line

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 946ba131f6dc9..269bc59506b2d 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -246,8 +246,12 @@ static bool fillRanges(MemoryBuffer *Code,
 errs() << "error: invalid : pair\n";
 return true;
   }
+  if (FromLine < 1) {
+errs() << "error: start line should be at least 1\n";
+return true;
+  }
   if (FromLine > ToLine) {
-errs() << "error: start line should be less than end line\n";
+errs() << "error: start line should not exceed end line\n";
 return true;
   }
   SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);



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