[PATCH] D138183: [Driver] move FreeBSD header search path management to the driver

2022-11-17 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson added inline comments.



Comment at: clang/test/Driver/freebsd.c:217
+
+// Check that the driver passes include paths to cc1 on FreeBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-freebsd13.1 -r 2>&1 \

MaskRay wrote:
> Is this  sufficient? For Linux `linux-cross.cpp` checks a lot of directories 
> to facilitate code refactoring.
On FreeBSD, the only directories included by default are

  - /usr/include/c++/v1 (in C++ mode)
  - /include
  - /usr/include

I suppose I can add checks for the first two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138183

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


[PATCH] D137826: [clang] Allow comparing pointers to string literals

2022-11-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:12951-12954
+  // ObjC's @encode()
+  if (isa(E->getLHS()->IgnoreParenImpCasts()) ||
+  isa(E->getRHS()->IgnoreParenImpCasts()))
 return Error(E);

tahonermann wrote:
> A comment to explain this change would be helpful. It isn't intuitive (for me 
> anyway) why Objective-C's `@encode` would require special handling here. Was 
> this needed to avoid a test failure?
In `../clang/test/CodeGenObjC/encode-test-4.m`:

```
int a(void) {
  return @encode(int) == @encode(int) &&
@encode(Color) == @encode(long) &&
@encode(PrintColor) == @encode(int);
}
```

The comparisons need to be rejected here and are folded to a `1` later on, it 
seems. Letting the comparison happen will lead to a `0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137826

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


[PATCH] D88994: Fix the default alignment of i1 vectors.

2022-11-17 Thread Xiaoqiang Xu via Phabricator via cfe-commits
csstormq added inline comments.



Comment at: llvm/lib/IR/DataLayout.cpp:807
 // count should be enough here.
-Alignment *= cast(Ty)->getElementCount().getKnownMinValue();
-Alignment = PowerOf2Ceil(Alignment);
-return Align(Alignment);
+return Align(PowerOf2Ceil(getTypeStoreSize(Ty).getKnownMinSize()));
   }

Is there any way to set the alignment of fixed vector type to 1 byte rather 
than a power of 2 by default?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88994

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


[PATCH] D138183: [Driver] move FreeBSD header search path management to the driver

2022-11-17 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson updated this revision to Diff 476031.
mhjacobson added a comment.

Test for more paths; test C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138183

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/test/Driver/freebsd.c
  clang/test/Driver/freebsd.cpp

Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -40,3 +40,11 @@
 // CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
 // CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
 // CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+
+// Check that the driver passes include paths to cc1 on FreeBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-freebsd13.1 -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "/usr/include/c++/v1"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]/include"
+// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "/usr/include"
Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -213,3 +213,10 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./]+}}.o
+
+// Check that the driver passes include paths to cc1 on FreeBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-freebsd13.1 -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]/include"
+// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "/usr/include"
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -100,6 +100,11 @@
const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
+  /// ShouldAddDefaultIncludePaths - Returns true iff AddDefaultIncludePaths
+  ///  should actually do anything.  If this returns false, include management
+  ///  should instead be handled in the driver.
+  bool ShouldAddDefaultIncludePaths(const llvm::Triple &triple);
+
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
   ///  that e.g. stdio.h is found.
   void AddDefaultIncludePaths(const LangOptions &Lang,
@@ -225,18 +230,16 @@
 
 void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
 const HeaderSearchOptions &HSOpts) {
-  llvm::Triple::OSType os = triple.getOS();
-
-  if (triple.isOSDarwin()) {
+  if (!ShouldAddDefaultIncludePaths(triple)) {
 llvm_unreachable("Include management is handled in the driver.");
   }
 
+  llvm::Triple::OSType os = triple.getOS();
+
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
 case llvm::Triple::CloudABI:
-case llvm::Triple::FreeBSD:
 case llvm::Triple::NetBSD:
-case llvm::Triple::OpenBSD:
 case llvm::Triple::NaCl:
 case llvm::Triple::PS4:
 case llvm::Triple::PS5:
@@ -280,12 +283,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::Linux:
-  case llvm::Triple::Hurd:
-  case llvm::Triple::Solaris:
-  case llvm::Triple::OpenBSD:
-llvm_unreachable("Include management is handled in the driver.");
-
   case llvm::Triple::CloudABI: {
 // //include
 SmallString<128> P = StringRef(HSOpts.ResourceDir);
@@ -386,20 +383,14 @@
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
 const LangOptions &LangOpts, const llvm::Triple &triple,
 const HeaderSearchOptions &HSOpts) {
-  llvm::Triple::OSType os = triple.getOS();
-  // FIXME: temporary hack: hard-coded paths.
-
-  if (triple.isOSDarwin()) {
+  if (!ShouldAddDefaultIncludePaths(triple)) {
 llvm_unreachable("Include management is handled in the driver.");
   }
 
+  llvm::Triple::OSType os = triple.getOS();
+
+  // FIXME: temporary hack: hard-coded paths.
   switch (os) {
-  case llvm::Triple::Linux:
-  case llvm::Triple::Hurd:
-  case llvm::Triple::Solaris:
-  case llvm::Triple::AIX:
-llvm_unreachable("Include management is handled in the driver.");
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -425,46 +416,55 @@
   }
 }
 
-void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
-  const llvm::Triple &triple,
-const He

[PATCH] D138179: MIPS: fix build from IR files, nan2008 and FpAbi

2022-11-17 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 476033.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138179

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -400,6 +400,16 @@
 void MipsAsmPrinter::emitFunctionEntryLabel() {
   MipsTargetStreamer &TS = getTargetStreamer();
 
+  TS.updateABIInfo(*Subtarget);
+  if (Subtarget->isNaN2008())
+TS.emitDirectiveNaN2008();
+  const MipsTargetMachine &MTM = static_cast(TM);
+  const MipsABIInfo &ABI = MTM.getABI();
+
+  if ((ABI.IsO32() && (Subtarget->isABI_FPXX() || Subtarget->isFP64bit())) ||
+  Subtarget->useSoftFloat())
+TS.emitDirectiveModuleFP();
+
   // NaCl sandboxing requires that indirect call instructions are masked.
   // This means that function entry points should be bundle-aligned.
   if (Subtarget->isTargetNaCl())
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdsp"
+// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mdsp"
 //
 // RUN: %clang -target mips-linux-gnu -mdsp -mno-dsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -229,7 +229,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dspr2 -mdspr2 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSPR2 %s
-// MIPS-DSPR2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdspr2"
+// MIPS-DSPR2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mdspr2"
 //
 // RUN: %clang -target mips-linux-gnu -mdspr2 -mno-dspr2 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -266,7 +266,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-msa -mmsa -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MSA %s
-// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmsa"
+// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_non

[PATCH] D138179: MIPS: fix build from IR files, nan2008 and FpAbi

2022-11-17 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa updated this revision to Diff 476039.
wzssyqa added a comment.

Add llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138179

Files:
  clang/lib/Driver/ToolChains/Arch/Mips.cpp
  clang/test/Driver/mips-as.c
  clang/test/Driver/mips-integrated-as.s
  llvm/lib/Target/Mips/MipsAsmPrinter.cpp
  llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Index: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll
@@ -0,0 +1,15 @@
+; RUN: llc -filetype=asm %s -o - | FileCheck %s
+
+target datalayout = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"
+target triple = "mipsel-unknown-linux-gnu"
+
+; Function Attrs: noinline nounwind optnone
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008,-noabicalls" }
+
+
+; CHECK: .nan2008
+; CHECK: .module fp=64
Index: llvm/lib/Target/Mips/MipsAsmPrinter.cpp
===
--- llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -400,6 +400,16 @@
 void MipsAsmPrinter::emitFunctionEntryLabel() {
   MipsTargetStreamer &TS = getTargetStreamer();
 
+  TS.updateABIInfo(*Subtarget);
+  if (Subtarget->isNaN2008())
+TS.emitDirectiveNaN2008();
+  const MipsTargetMachine &MTM = static_cast(TM);
+  const MipsABIInfo &ABI = MTM.getABI();
+
+  if ((ABI.IsO32() && (Subtarget->isABI_FPXX() || Subtarget->isFP64bit())) ||
+  Subtarget->useSoftFloat())
+TS.emitDirectiveModuleFP();
+
   // NaCl sandboxing requires that indirect call instructions are masked.
   // This means that function entry points should be bundle-aligned.
   if (Subtarget->isTargetNaCl())
Index: clang/test/Driver/mips-integrated-as.s
===
--- clang/test/Driver/mips-integrated-as.s
+++ clang/test/Driver/mips-integrated-as.s
@@ -160,8 +160,8 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=FPXX-DEFAULT %s
 // FPXX-DEFAULT: -cc1as
-// FPXX-DEFAULT-NOT: "-target-feature" "+fpxx"
-// FPXX-DEFAULT-NOT: "-target-feature" "+nooddspreg"
+// FPXX-DEFAULT: "-target-feature" "+fpxx"
+// FPXX-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mfp32 2>&1 | \
 // RUN:   FileCheck -check-prefix=FP32 %s
@@ -182,7 +182,7 @@
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-DEFAULT %s
 // ODDSPREG-DEFAULT: -cc1as
-// ODDSPREG-DEFAULT-NOT: "-target-feature" "{{[+-]}}nooddspreg"
+// ODDSPREG-DEFAULT: "-target-feature" "+nooddspreg"
 
 // RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -modd-spreg 2>&1 | \
 // RUN:   FileCheck -check-prefix=ODDSPREG-ON %s
Index: clang/test/Driver/mips-as.c
===
--- clang/test/Driver/mips-as.c
+++ clang/test/Driver/mips-as.c
@@ -196,7 +196,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-16 %s
-// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
+// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mips16"
 //
 // RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -207,7 +207,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-MICRO %s
-// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
+// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mmicromips"
 //
 // RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -218,7 +218,7 @@
 // RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-DSP %s
-// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdsp"
+// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx" "-mdsp"
 //
 // RUN: %clang -target mips-linux-gnu -mdsp -mno-dsp -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
@@ -229,7 +229,7 @@
 // RUN:

[PATCH] D138183: [Driver] move FreeBSD header search path management to the driver

2022-11-17 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson updated this revision to Diff 476042.
mhjacobson added a comment.

Fix a couple warnings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138183

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/test/Driver/freebsd.c
  clang/test/Driver/freebsd.cpp

Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -40,3 +40,11 @@
 // CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
 // CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
 // CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+
+// Check that the driver passes include paths to cc1 on FreeBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-freebsd13.1 -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "/usr/include/c++/v1"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]/include"
+// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "/usr/include"
Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -213,3 +213,10 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./]+}}.o
+
+// Check that the driver passes include paths to cc1 on FreeBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-freebsd13.1 -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]/include"
+// DRIVER-PASS-INCLUDES: "-internal-externc-isystem" "/usr/include"
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -100,6 +100,11 @@
const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
+  /// ShouldAddDefaultIncludePaths - Returns true iff AddDefaultIncludePaths
+  ///  should actually do anything.  If this returns false, include management
+  ///  should instead be handled in the driver.
+  bool ShouldAddDefaultIncludePaths(const llvm::Triple &triple);
+
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
   ///  that e.g. stdio.h is found.
   void AddDefaultIncludePaths(const LangOptions &Lang,
@@ -225,18 +230,16 @@
 
 void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
 const HeaderSearchOptions &HSOpts) {
-  llvm::Triple::OSType os = triple.getOS();
-
-  if (triple.isOSDarwin()) {
+  if (!ShouldAddDefaultIncludePaths(triple)) {
 llvm_unreachable("Include management is handled in the driver.");
   }
 
+  llvm::Triple::OSType os = triple.getOS();
+
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
 case llvm::Triple::CloudABI:
-case llvm::Triple::FreeBSD:
 case llvm::Triple::NetBSD:
-case llvm::Triple::OpenBSD:
 case llvm::Triple::NaCl:
 case llvm::Triple::PS4:
 case llvm::Triple::PS5:
@@ -280,12 +283,6 @@
   }
 
   switch (os) {
-  case llvm::Triple::Linux:
-  case llvm::Triple::Hurd:
-  case llvm::Triple::Solaris:
-  case llvm::Triple::OpenBSD:
-llvm_unreachable("Include management is handled in the driver.");
-
   case llvm::Triple::CloudABI: {
 // //include
 SmallString<128> P = StringRef(HSOpts.ResourceDir);
@@ -386,20 +383,14 @@
 void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
 const LangOptions &LangOpts, const llvm::Triple &triple,
 const HeaderSearchOptions &HSOpts) {
-  llvm::Triple::OSType os = triple.getOS();
-  // FIXME: temporary hack: hard-coded paths.
-
-  if (triple.isOSDarwin()) {
+  if (!ShouldAddDefaultIncludePaths(triple)) {
 llvm_unreachable("Include management is handled in the driver.");
   }
 
+  llvm::Triple::OSType os = triple.getOS();
+
+  // FIXME: temporary hack: hard-coded paths.
   switch (os) {
-  case llvm::Triple::Linux:
-  case llvm::Triple::Hurd:
-  case llvm::Triple::Solaris:
-  case llvm::Triple::AIX:
-llvm_unreachable("Include management is handled in the driver.");
-break;
   case llvm::Triple::Win32:
 switch (triple.getEnvironment()) {
 default: llvm_unreachable("Include management is handled in the driver.");
@@ -425,46 +416,56 @@
   }
 }
 
-void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
-  const llvm::Triple &triple,
-const HeaderSear

[PATCH] D108230: [analyzer] Ignore single element arrays in getStaticSize() conditionally

2022-11-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.
Herald added a project: All.

I did some extensive measurements of this option.
According to my results, we could confidently enable this option by default; 
but still, keep the flag for backward compatibility and enable the users to 
opt-out.

The benefit of enabling this is project specific; if that exploits this single 
element FAM construct or not.
It got rid of about ~4500 reports, mostly by either of the OOB checkers and 
returned pointer checker.
Also introduced about ~170 new reports of different kinds, as expected.
I focused my evaluation on the disappearing issues, and they are all FPs 
related to buffer accesses of FAM buffers.
I found only a single questionable case, about which I'm not sure if we 
suppress a TP - difficult to tell.

Possible TP suppressed:

  Linux/CXGB4VF driver:
  struct adapter {
  // ...
  struct adapter_params params; // params.nports.
  // ...
  
  /* Linux network device resources */
  struct net_device *port[MAX_NPORTS]; // aka [1] <--- this cannot be a 
FAM, yet derefs of this gonna be suppressed
  const char *name;
  // ...
  };

Finally, here are the FAMs that actually produced FPs reports by accessing the 
FAM buffer.

  PHP zend_string
  struct _zend_string {
  zend_refcounted_h gc;
  zend_ulongh;
  size_tlen;
  char  val[1]; // <---
  };
  
  GCC
  struct decl {
  // ...
  union {
  struct excl_rel_decl {
  int all_names_num;
  int first_list_length;
  char *names [1]; // <---
  } excl;
  // ...
  } decl;
  };
  
  struct regexp {
  // ...
  union {
  struct sequence_regexp {
  int regexps_num;
  regexp_t regexps [1]; // <---
  } sequence;
  // ...
  } regexp;
  };
  
  struct GTY((tag("GSS_WITH_MEM_OPS")))
  gimple_statement_with_memory_ops : public 
gimple_statement_with_memory_ops_base {
  /* [ WORD 1-9 ] : base class */
  
  /* [ WORD 10 ]
  Operand vector.  NOTE!  This must always be the last field
  of this structure.  In particular, this means that this
  structure cannot be embedded inside another one.  */
  tree GTY((length ("%h.num_ops"))) op[1]; // <---
  };
  
  CPython
  typedef struct _longobject PyLongObject;
  struct _longobject {
  struct PyVarObject {
  PyObject ob_base;
  Py_ssize_t ob_size; /* Number of items in variable part */
  } ob_base;
  digit ob_digit[1]; // <---
  };
  typedef struct {
  struct PyVarObject {
  PyObject ob_base;
  Py_ssize_t ob_size; /* Number of items in variable part */
  } ob_base;
  uint32_t b_bitmap;
  PyObject *b_array[1]; // <---
  } PyHamtNode_Bitmap;
  struct Bigint {
  struct Bigint *next;
  int k, maxwds, sign, wds;
  ULong x[1]; // <---
  };
  
  International Components for Unicode (ICU); GCC/libdecnumber
  #define DECNUMDIGITS 1
  #define DECDPUN 1
  #define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
  typedef struct {
  int32_t digits;
  int32_t exponent;
  uint8_t bits;
  decNumberUnit lsu[DECNUMUNITS]; // aka [1] <---
  } decNumber;
  
  firebird
  typedef struct nod {
  // ...
  SSHORT  nod_count;
  struct nod *nod_arg[1]; // <---
  } *QLI_NOD;
  
  liblmdb
  struct MDB_page {
// ...
indx_t  mp_ptrs[1]; /**< dynamic size */  // <---
  };
  
  libreoffice
  typedef struct _rtl_String {
  // ...
  sal_Int32 length;
  char buffer[1]; // <---
  } rtl_String;
  
  
  sqlite3
  struct KeyInfo {
  // ...
  u16 nField; /* Number of entries in aColl[] */
  CollSeq *aColl[1]; // <---
  };
  
  
  Binutils
  struct elf_segment_map {
  // ...
  /* Number of sections (may be 0).  */
  unsigned int count;
  /* Sections.  Actual number of elements is in count field.  */
  asection *sections[1]; // <---
  };
  
  struct frag {
  // ...
  /* For variable-length tail.  */
  offsetT fr_offset;
  /* For variable-length tail.  */
  symbolS *fr_symbol;
  // ...
  /* Data begins here.  */
  char fr_literal[1]; // <---
  };
  
  Z3
  class fixed_bit_vector {
  friend class fixed_bit_vector_manager;
  friend class tbv_manager;
  unsigned m_data[1]; // <---
  };
  
  httpd
  typedef struct apreq_value_t {
  char *name;/**< value name */
  apr_size_tnlen;/**< length of name */

[clang] df6f4b8 - [clang-format] Defer formatting of operator< to honor paren spacing

2022-11-17 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2022-11-17T11:38:21+02:00
New Revision: df6f4b85138f86be73d58ff3f511df5306cc4b4d

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

LOG: [clang-format] Defer formatting of operator< to honor paren spacing

I'm not exactly sure what the intent of that section of
`spaceRequiredBetween` is doing, it seems to handle templates and <<,
but the part which adds spaces before parens is way later, as part
of `spaceRequiredBeforeParens`.

Fixes https://github.com/llvm/llvm-project/issues/58821

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 75570552146ce..6c4d908f96c8d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3441,7 +3441,9 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 return false;
   return !Style.Cpp11BracedListStyle;
 }
-return false;
+// Don't attempt to format operator<(), as it is handled later.
+if (Right.isNot(TT_OverloadedOperatorLParen))
+  return false;
   }
   if (Right.is(tok::ellipsis)) {
 return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous 
&&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 628cb82c863b7..9505fa03d3e85 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15544,6 +15544,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;
 
   verifyFormat("int f ();", Space);
+  verifyFormat("bool operator< ();", Space);
+  verifyFormat("bool operator> ();", Space);
   verifyFormat("void f (int a, T b) {\n"
"  while (true)\n"
"continue;\n"



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


[clang] 48a932e - [clang-format] Remove special case for kw_operator when aligning decls

2022-11-17 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2022-11-17T11:38:28+02:00
New Revision: 48a932e13e04a21f4422d962bf1bb4667a670e41

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

LOG: [clang-format] Remove special case for kw_operator when aligning decls

This change breaks no existing tests but does fix the linked issue.
Declarations of operator overloads are annotated with
`TT_FunctionDeclarationName` on the `operator` keyword, which is already
being checked for when aligning, so the extra `kw_operator` doesn't seem
to be necessary. (just for reference, it was added in
rG92b397fb9d55ccdf4632c2b1b15b4a0ee417cf74 / 
92b397fb9d55ccdf4632c2b1b15b4a0ee417cf74)

Fixes https://github.com/llvm/llvm-project/issues/55733

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 1f29f7ab917c..cd9773921dae 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -870,9 +870,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const &C) {
-// tok::kw_operator is necessary for aligning operator overload
-// definitions.
-if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator))
+if (C.Tok->is(TT_FunctionDeclarationName))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index adacb9761ca3..2e3bbd7e60b5 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -423,50 +423,80 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionRefQualifiers) {
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // FIXME
+  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPE

[PATCH] D137223: [clang-format] Remove special case for kw_operator when aligning decls

2022-11-17 Thread Emilia Dreamer 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 rG48a932e13e04: [clang-format] Remove special case for 
kw_operator when aligning decls (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137223

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -423,50 +423,80 @@
 TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
   auto Tokens = annotate("x.operator+()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator+=()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator,()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator()()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator[]()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
   // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"_a()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" _a()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // FIXME
+  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"if()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\"s()");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
   Tokens = annotate("x.operator\"\" s()");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // FIXME
+  // EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
+
+  Tokens = annotate("int operator+(int);");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::plus, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("auto operator=(T&) {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[2], tok::equal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("auto operator()() {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::kw_operator, TT_FunctionDeclarationNam

[PATCH] D137474: [clang-format] Defer formatting of operator< to honor paren spacing

2022-11-17 Thread Emilia Dreamer 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 rGdf6f4b85138f: [clang-format] Defer formatting of 
operator< to honor paren spacing (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137474

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15544,6 +15544,8 @@
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;
 
   verifyFormat("int f ();", Space);
+  verifyFormat("bool operator< ();", Space);
+  verifyFormat("bool operator> ();", Space);
   verifyFormat("void f (int a, T b) {\n"
"  while (true)\n"
"continue;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3441,7 +3441,9 @@
 return false;
   return !Style.Cpp11BracedListStyle;
 }
-return false;
+// Don't attempt to format operator<(), as it is handled later.
+if (Right.isNot(TT_OverloadedOperatorLParen))
+  return false;
   }
   if (Right.is(tok::ellipsis)) {
 return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous 
&&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15544,6 +15544,8 @@
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;
 
   verifyFormat("int f ();", Space);
+  verifyFormat("bool operator< ();", Space);
+  verifyFormat("bool operator> ();", Space);
   verifyFormat("void f (int a, T b) {\n"
"  while (true)\n"
"continue;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3441,7 +3441,9 @@
 return false;
   return !Style.Cpp11BracedListStyle;
 }
-return false;
+// Don't attempt to format operator<(), as it is handled later.
+if (Right.isNot(TT_OverloadedOperatorLParen))
+  return false;
   }
   if (Right.is(tok::ellipsis)) {
 return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ec78295 - [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr

2022-11-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-11-17T12:01:37+01:00
New Revision: ec782951d7bd34f9c32d08bb6ec6b43d2a805832

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

LOG: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr

Use FastEvaluateAsRValue() in EvaluateAsConstantExpr() as well, to
short-circuit evaluation of simple integrals.

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ecf072e070835..b5281a660bcf3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15051,6 +15051,12 @@ static bool FastEvaluateAsRValue(const Expr *Exp, 
Expr::EvalResult &Result,
 return true;
   }
 
+  if (const auto *L = dyn_cast(Exp)) {
+Result.Val = APValue(APSInt(APInt(1, L->getValue(;
+IsConst = true;
+return true;
+  }
+
   // This case should be rare, but we need to check it before we check on
   // the type below.
   if (Exp->getType().isNull()) {
@@ -15235,6 +15241,9 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   ConstantExprKind Kind) const {
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
+  bool IsConst;
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
   EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;



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


[PATCH] D138115: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr

2022-11-17 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec782951d7bd: [clang] Short-circuit evaluation in 
::EvaluateAsConstantExpr (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138115

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15051,6 +15051,12 @@
 return true;
   }
 
+  if (const auto *L = dyn_cast(Exp)) {
+Result.Val = APValue(APSInt(APInt(1, L->getValue(;
+IsConst = true;
+return true;
+  }
+
   // This case should be rare, but we need to check it before we check on
   // the type below.
   if (Exp->getType().isNull()) {
@@ -15235,6 +15241,9 @@
   ConstantExprKind Kind) const {
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
+  bool IsConst;
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
   EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15051,6 +15051,12 @@
 return true;
   }
 
+  if (const auto *L = dyn_cast(Exp)) {
+Result.Val = APValue(APSInt(APInt(1, L->getValue(;
+IsConst = true;
+return true;
+  }
+
   // This case should be rare, but we need to check it before we check on
   // the type below.
   if (Exp->getType().isNull()) {
@@ -15235,6 +15241,9 @@
   ConstantExprKind Kind) const {
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
+  bool IsConst;
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
   EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131295: [clangd] Implement textDocument/codeLens

2022-11-17 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

One remaining issue is multiple lenses for template code like

  template 
  int i = 0;
  
  template int i<0>;
  template int i<1>;
  template int i<2>;
  
  template 
  struct Foo {
  int foo(); // I see 3 codelenses here
  };
  
  template struct Foo<0>;
  template struct Foo<1>;
  
  int main()
  {
  // return Foo<0>().foo() + Foo<1>().foo();
  // return i<0> + i<1> + i<2>;
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131295

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


[PATCH] D138193: [Serialization] Fix crash writing non-module PCH in non-module mode including modular headers

2022-11-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

Ran into this when trying to turn off modules mode in clangd.

Took me a long time to (mostly) work out the logic behind this function
so documented my understanding, hopefully it's correct!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138193

Files:
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/PCH/preamble-modules.cpp


Index: clang/test/PCH/preamble-modules.cpp
===
--- clang/test/PCH/preamble-modules.cpp
+++ clang/test/PCH/preamble-modules.cpp
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 -emit-pch -o %t.pch %s -fmodules 
-fmodule-map-file=%S/Inputs/modules/module.modulemap 
-fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
 // RUN: %clang_cc1 -include-pch %t.pch %s -fmodules 
-fmodule-map-file=%S/Inputs/modules/module.modulemap 
-fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
 
+// Check we can build a PCH with modular includes but no -fmodules. 
(https://github.com/llvm/llvm-project/issues/59027)
+// RUN: %clang_cc1 -emit-pch -o %t.pch %s 
-fmodule-map-file=%S/Inputs/modules/module.modulemap
+
 #ifndef MAIN_FILE
 #define MAIN_FILE
 // Premable section.
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2641,16 +2641,33 @@
   if (!Mod)
 return 0;
 
+  // Is there already an ID assigned to this module?
   auto Known = SubmoduleIDs.find(Mod);
   if (Known != SubmoduleIDs.end())
 return Known->second;
 
-  auto *Top = Mod->getTopLevelModule();
-  if (Top != WritingModule &&
-  (getLangOpts().CompilingPCH ||
-   !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule
-return 0;
+  // If Mod is part of a loaded module, its ID is assigned in the ModuleRead
+  // callback. Otherwise we must assign an ID.
+  bool IDAssignedOnImport = [&]{
+// If we're simulating modules (e.g. -fmodule-map-file without -fmodules)
+// then no reading happens.
+if (!getLangOpts().Modules)
+  return false;
+// If this is a submodule of the module we're building, it's not loaded.
+auto *Top = Mod->getTopLevelModule();
+if (Top == WritingModule)
+  return false;
+// FIXME: This name-based check is similar to above, why is it needed?
+// When building a module PCH, #includes of same-module headers are 
textual.
+if (!getLangOpts().CompilingPCH &&
+Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule)))
+  return false;
+// Unrelated module that must be loaded.
+return true;
+  }();
 
+  if (IDAssignedOnImport)
+return 0;
   return SubmoduleIDs[Mod] = NextSubmoduleID++;
 }
 


Index: clang/test/PCH/preamble-modules.cpp
===
--- clang/test/PCH/preamble-modules.cpp
+++ clang/test/PCH/preamble-modules.cpp
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 -emit-pch -o %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
 // RUN: %clang_cc1 -include-pch %t.pch %s -fmodules -fmodule-map-file=%S/Inputs/modules/module.modulemap -fmodules-local-submodule-visibility -fmodules-cache-path=%t.mcp
 
+// Check we can build a PCH with modular includes but no -fmodules. (https://github.com/llvm/llvm-project/issues/59027)
+// RUN: %clang_cc1 -emit-pch -o %t.pch %s -fmodule-map-file=%S/Inputs/modules/module.modulemap
+
 #ifndef MAIN_FILE
 #define MAIN_FILE
 // Premable section.
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2641,16 +2641,33 @@
   if (!Mod)
 return 0;
 
+  // Is there already an ID assigned to this module?
   auto Known = SubmoduleIDs.find(Mod);
   if (Known != SubmoduleIDs.end())
 return Known->second;
 
-  auto *Top = Mod->getTopLevelModule();
-  if (Top != WritingModule &&
-  (getLangOpts().CompilingPCH ||
-   !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule
-return 0;
+  // If Mod is part of a loaded module, its ID is assigned in the ModuleRead
+  // callback. Otherwise we must assign an ID.
+  bool IDAssignedOnImport = [&]{
+// If we're simulating modules (e.g. -fmodule-map-file without -fmodules)
+// then no reading happens.
+if (!getLangOpts().Modules)
+  return false;
+// If this is a submodule of the module we're building, it's not loaded.
+auto *Top = Mod->getTopLevelModule();
+if (Top == WritingModule)
+  return false;
+// FIXME: This name-based check is similar to above, why is it nee

[PATCH] D138194: [clang][Parser][NFC] Simplify ParseParenExprOrCondition

2022-11-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: clang.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138194

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp

Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1270,20 +1270,22 @@
 /// should try to recover harder.  It returns false if the condition is
 /// successfully parsed.  Note that a successful parse can still have semantic
 /// errors in the condition.
-/// Additionally, if LParenLoc and RParenLoc are non-null, it will assign
-/// the location of the outer-most '(' and ')', respectively, to them.
+/// Additionally, it will assign the location of the outer-most '(' and ')',
+/// to LParenLoc and RParenLoc, respectively.
 bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
Sema::ConditionResult &Cond,
SourceLocation Loc,
-   Sema::ConditionKind CK, bool MissingOK,
+   Sema::ConditionKind CK,
SourceLocation *LParenLoc,
SourceLocation *RParenLoc) {
+  assert(LParenLoc);
+  assert(RParenLoc);
   BalancedDelimiterTracker T(*this, tok::l_paren);
   T.consumeOpen();
   SourceLocation Start = Tok.getLocation();
 
   if (getLangOpts().CPlusPlus) {
-Cond = ParseCXXCondition(InitStmt, Loc, CK, MissingOK);
+Cond = ParseCXXCondition(InitStmt, Loc, CK, false);
   } else {
 ExprResult CondExpr = ParseExpression();
 
@@ -1292,7 +1294,7 @@
   Cond = Sema::ConditionError();
 else
   Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK,
-MissingOK);
+/*MissingOK=*/false);
   }
 
   // If the parser was confused by the condition and we don't have a ')', try to
@@ -1312,18 +1314,13 @@
 Actions.PreferredConditionType(CK));
 if (!CondExpr.isInvalid())
   Cond = Actions.ActOnCondition(getCurScope(), Loc, CondExpr.get(), CK,
-MissingOK);
+/*MissingOK=*/false);
   }
 
   // Either the condition is valid or the rparen is present.
   T.consumeClose();
-
-  if (LParenLoc != nullptr) {
-*LParenLoc = T.getOpenLocation();
-  }
-  if (RParenLoc != nullptr) {
-*RParenLoc = T.getCloseLocation();
-  }
+  *LParenLoc = T.getOpenLocation();
+  *RParenLoc = T.getCloseLocation();
 
   // Check for extraneous ')'s to catch things like "if (foo())) {".  We know
   // that all callers are looking for a statement after the condition, so ")"
@@ -1499,7 +1496,7 @@
 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
   IsConstexpr ? Sema::ConditionKind::ConstexprIf
   : Sema::ConditionKind::Boolean,
-  /*MissingOK=*/false, &LParen, &RParen))
+  &LParen, &RParen))
   return StmtError();
 
 if (IsConstexpr)
@@ -1694,8 +1691,7 @@
   SourceLocation LParen;
   SourceLocation RParen;
   if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
-Sema::ConditionKind::Switch,
-/*MissingOK=*/false, &LParen, &RParen))
+Sema::ConditionKind::Switch, &LParen, &RParen))
 return StmtError();
 
   StmtResult Switch = Actions.ActOnStartOfSwitchStmt(
@@ -1785,8 +1781,7 @@
   SourceLocation LParen;
   SourceLocation RParen;
   if (ParseParenExprOrCondition(nullptr, Cond, WhileLoc,
-Sema::ConditionKind::Boolean,
-/*MissingOK=*/false, &LParen, &RParen))
+Sema::ConditionKind::Boolean, &LParen, &RParen))
 return StmtError();
 
   // C99 6.8.5p5 - In C99, the body of the while statement is a scope, even if
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2109,7 +2109,7 @@
   bool ParseParenExprOrCondition(StmtResult *InitStmt,
  Sema::ConditionResult &CondResult,
  SourceLocation Loc, Sema::ConditionKind CK,
- bool MissingOK, SourceLocation *LParenLoc,
+ SourceLocation *LParenLoc,
  SourceLocation *RParenLoc);
   StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
   StmtResult ParseSwitchStatement(SourceLoc

[PATCH] D137698: [include-cleaner] Add self-contained file support for PragmaIncludes.

2022-11-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/FindHeaders.cpp:39
 FileID FID = SM.getFileID(Loc.physical());
-const auto *FE = SM.getFileEntryForID(FID);
+const auto *FE = getResponsibleHeader(FID, SM, PI);
 if (!FE)

kadircet wrote:
> i am not sure if sequencing of this and rest of the IWYU pragma handling is 
> the right actually.
> 
> e.g. consider a scenario in which:
> private.h:
> ```
> // IWYU private, include "public.h"
> void foo();
> ```
> private-impl.h:
> ```
> #pragma once
> #include "private.h"
> ```
> 
> we'll actually now use `private-impl.h` as provider for `foo` rather than 
> `public.h`, a similar argument goes for export pragma. i think intent of the 
> developer is a lot more explicit when we have these pragmas around, so we 
> should prioritize them and then pick the self contained one, if it's still 
> needed. WDYT?
It looks reasonable to me. Thanks for raising this case, this is a good point. 
I mostly considered the case where the self-contained file has the IWYU private 
mapping.

My current thought is:

Overall algorithm: we check the original `FE` to see whether we can get any 
IWYU mapping (private, export) headers, if there is any, we use these mapping 
headers as final results; if not, we use the `selfContainedHeader(FE)` and its 
IWYU mapping headers;

Below are the cases I considered -- 1), 2), 4) works fine, but the 3) is not 
perfect (as we prioritize the IWYU mapping headers), but probably ok.

```
  // Case1: Private
  // findHeaders("private1.inc") => "path/public1.h"
  Inputs.ExtraFiles["private1.h"] = R"cpp(
#pragma once
#include "private1.inc"
  )cpp");
  Inputs.ExtraFiles["private1.inc"] = R"cpp(
// IWYU pragma: private, include "path/public1.h"
  )cpp";

  // Case2: Private
  // findHeaders("private2.inc") => "path/public2.h"
  Inputs.ExtraFiles["private2.h"] = R"cpp(
#pragma once
// IWYU pragma: private, include "path/public2.h"
#include "private2.inc"
  )cpp";
  Inputs.ExtraFiles["private2.inc"] = "";

  // Case3: Export
  // findHeaders("details1.inc") => "details1.inc", "export1.h"
  Inputs.ExtraFiles["export1.h"] = R"cpp(
#include "details1.inc" // IWYU pragma: export
  )cpp";
  Inputs.ExtraFiles["details1.inc"] = "";

  // Case4: Export
  // findHeaders("details2.inc") => "export2.h", "export2_internal.h"
  Inputs.ExtraFiles["export2.h"] =R"cpp(
#pragma once
#include "export2_internal.h" // IWYU pragma: export
  )cpp";
  Inputs.ExtraFiles["export2_internal.h"] = R"cpp(
#pragma once
#include "details2.inc"
  )cpp";
  Inputs.ExtraFiles["details2.inc"] = "";
```

Let me know what you think about it.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137698

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-11-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Depens on D135953 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -25,11 +25,49 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, /*MacroRefs=*/{}, PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -39,7 +77,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -49,40 +87,13 @@
 class Private {};
   )cpp";
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
   auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
@@ -92,6 +103,35 @@
   Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL;
 }
 
+TEST_F(WalkUsedTest, MultipleProviders) {
+  llvm::Annotations Code(R"cpp(
+  #include "header1.h"
+  #include "header2.h"
+  void foo();
+
+  void bar() {
+$foo^foo();
+  }
+  )cpp");
+  Inputs.Code = Code.code();
+  Inputs.ExtraFiles["header1.h"] = R"cpp(
+  void foo();
+  )cpp";
+  Inputs.ExtraFiles["header2.h"] = R"cpp(
+  void foo();
+  )cpp";
+
+  TestAST AST(Inputs);
+  auto &SM = AST.sourceManager();
+  auto HeaderFile1 = Header(AST.fileManager().getFile("header1.h").get());
+  auto HeaderFile2 = Header(AST.fileManager().getFile("header2.h").get());
+  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+  EXPECT_THAT(
+  offsetToProviders(AST, SM),
+  Contains(Pair(Code.point("foo"),
+UnorderedElementsAre(HeaderFile1, HeaderFile2, MainFile;
+}
+
 TEST(WalkUsed, MacroRefs) {
   llvm::Annotations Hdr(R"cpp(
 #define ^ANSWER 42
@@ 

[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-11-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 476091.
kadircet added a comment.

- Rebase
- Move to new file
- Handle macros
- Change from boolean output to enum for signalling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135953

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -7,12 +7,14 @@
 //===--===//
 #include "AnalysisInternal.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
@@ -20,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang::include_cleaner {
Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -0,0 +1,96 @@
+//===--- LocateSymbolTest.cpp -- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "AnalysisInternal.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang::include_cleaner {
+namespace {
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
+// Looks for decl with name \p SymbolName and performs locateSymbol on it.
+// Expects all the locations marked in `Code` with the right annotation to be
+// generated.
+void testLocate(llvm::StringRef Code, llvm::StringRef SymbolName = "foo") {
+  llvm::Annotations Target(Code);
+
+  TestInputs Inputs(Target.code());
+  Inputs.ExtraArgs.push_back("-std=c++17");
+  TestAST AST(Inputs);
+  const auto &SM = AST.sourceManager();
+
+  const NamedDecl *DeclToLocate;
+  struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
+MatchCB(const NamedDecl *&Out) : Out(Out) {}
+void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+  Out = Result.Nodes.getNodeAs("id");
+  assert(Out);
+  Out = llvm::cast(Out->getCanonicalDecl());
+}
+const NamedDecl *&Out;
+  } CB(DeclToLocate);
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(
+  ast_matchers::namedDecl(ast_matchers::unless(ast_matchers::isImplicit()),
+  ast_matchers::hasName(SymbolName))
+  .bind("id"),
+  &CB);
+  Finder.matchAST(AST.context());
+  ASSERT_TRUE(DeclToLocate);
+  std::vector> ReferencedOffsets;
+  for (auto Loc : locateSymbol(*DeclToLocate)) {
+switch (Loc.first.kind()) {
+case SymbolLocation::Physical: {
+  auto [FID, Offset] =
+  SM.getDecomposedLoc(SM.getFileLoc(Loc.first.physical()));
+  ASSERT_EQ(FID, SM.getMainFileID());
+  ReferencedOffsets.push_back(
+  {Offset,
+   llvm::StringRef(bool(Loc.second & Hint::Complete) ? "$def" : "")});
+  break;
+}
+case SymbolLocation::Standard:
+  EXPECT_TRUE(bool(Loc.second & Hint::Complete));
+  EXPECT_EQ(Loc.first.standard().name(), SymbolName);
+  break;
+}
+  }
+  llvm::sort(ReferencedOffsets);
+  auto AnnotatedCode = Target.code().str();
+  for (auto [Offset, Annotation] : llvm::reverse(ReferencedOffsets))
+AnnotatedCode.insert(Offset, (Annotation + "^").str());
+  EXPECT_EQ(Code, AnnotatedCode);
+}
+

[PATCH] D138137: [CodeGen][ARM] Fix ARMABIInfo::EmitVAAarg crash with empty record type variadic arg

2022-11-17 Thread Lin Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 476093.
yronglin added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138137

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/arm-vaarg.c


Index: clang/test/CodeGen/arm-vaarg.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-vaarg.c
@@ -0,0 +1,23 @@
+// RUN: %clang -Xclang -no-opaque-pointers -mfloat-abi=soft -target 
arm-linux-gnu -emit-llvm -S -o - %s | FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK: [[ALLOCA_VA_LIST:%[a-zA-Z0-9._]+]] = alloca %struct.__va_list, align 
4
+// CHECK: call void @llvm.va_start
+// CHECK-NEXT: [[AP_ADDR:%[a-zA-Z0-9._]+]] = bitcast %struct.__va_list* 
[[ALLOCA_VA_LIST]] to i8**
+// CHECK-NEXT: [[LOAD_AP:%[a-zA-Z0-9._]+]] = load i8*, i8** [[AP_ADDR]], align 
4
+// CHECK-NEXT: [[EMPTY_PTR:%[a-zA-Z0-9._]+]] = bitcast i8* [[LOAD_AP]] to 
%struct.Empty*
+
+  // It's conceivable that EMPTY_PTR may not actually be a valid pointer
+  // (e.g. it's at the very bottom of the stack and the next page is
+  // invalid). This doesn't matter provided it's never loaded (there's no
+  // well-defined way to tell), but it becomes a problem if we do try to use 
it.
+// CHECK-NOT: load %struct.Empty, %struct.Empty* [[EMPTY_PTR]]
+  __builtin_va_list l;
+  __builtin_va_start(l, a);
+  emptyvar = __builtin_va_arg(l, struct Empty);
+  __builtin_va_end(l);
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7050,10 +7050,10 @@
 
   // Empty records are ignored for parameter passing purposes.
   if (isEmptyRecord(getContext(), Ty, true)) {
-Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
-   getVAListElementType(CGF), SlotSize);
-Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
-return Addr;
+VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy);
+auto *Load = CGF.Builder.CreateLoad(VAListAddr);
+Address Addr = Address(Load, CGF.Int8Ty, SlotSize);
+return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
   }
 
   CharUnits TySize = getContext().getTypeSizeInChars(Ty);


Index: clang/test/CodeGen/arm-vaarg.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-vaarg.c
@@ -0,0 +1,23 @@
+// RUN: %clang -Xclang -no-opaque-pointers -mfloat-abi=soft -target arm-linux-gnu -emit-llvm -S -o - %s | FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK: [[ALLOCA_VA_LIST:%[a-zA-Z0-9._]+]] = alloca %struct.__va_list, align 4
+// CHECK: call void @llvm.va_start
+// CHECK-NEXT: [[AP_ADDR:%[a-zA-Z0-9._]+]] = bitcast %struct.__va_list* [[ALLOCA_VA_LIST]] to i8**
+// CHECK-NEXT: [[LOAD_AP:%[a-zA-Z0-9._]+]] = load i8*, i8** [[AP_ADDR]], align 4
+// CHECK-NEXT: [[EMPTY_PTR:%[a-zA-Z0-9._]+]] = bitcast i8* [[LOAD_AP]] to %struct.Empty*
+
+  // It's conceivable that EMPTY_PTR may not actually be a valid pointer
+  // (e.g. it's at the very bottom of the stack and the next page is
+  // invalid). This doesn't matter provided it's never loaded (there's no
+  // well-defined way to tell), but it becomes a problem if we do try to use it.
+// CHECK-NOT: load %struct.Empty, %struct.Empty* [[EMPTY_PTR]]
+  __builtin_va_list l;
+  __builtin_va_start(l, a);
+  emptyvar = __builtin_va_arg(l, struct Empty);
+  __builtin_va_end(l);
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7050,10 +7050,10 @@
 
   // Empty records are ignored for parameter passing purposes.
   if (isEmptyRecord(getContext(), Ty, true)) {
-Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
-   getVAListElementType(CGF), SlotSize);
-Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
-return Addr;
+VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy);
+auto *Load = CGF.Builder.CreateLoad(VAListAddr);
+Address Addr = Address(Load, CGF.Int8Ty, SlotSize);
+return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
   }
 
   CharUnits TySize = getContext().getTypeSizeInChars(Ty);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131295: [clangd] Implement textDocument/codeLens

2022-11-17 Thread WangWei via Phabricator via cfe-commits
lightmelodies added a comment.

In D131295#3933381 , @Trass3r wrote:

> One remaining issue is multiple lenses for template code like
>
>   template 
>   int i = 0;
>   
>   template int i<0>;
>   template int i<1>;
>   template int i<2>;
>   
>   template 
>   struct Foo {
>   int foo(); // I see 3 codelenses here
>   };
>   
>   template struct Foo<0>;
>   template struct Foo<1>;
>   
>   int main()
>   {
>   // return Foo<0>().foo() + Foo<1>().foo();
>   // return i<0> + i<1> + i<2>;
>   }

Well, multiple lenses occured due to 
https://github.com/lightmelodies/llvm-project/blob/codelens/clang-tools-extra/clangd/FindSymbols.cpp#L500
And can be fixed by 
https://github.com/lightmelodies/llvm-project/blob/codelens/clang-tools-extra/clangd/CodeLens.cpp#L69


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131295

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


[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-11-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D138117#3932688 , @kawashima-fj 
wrote:

> In D138117#3931109 , @zahiraam 
> wrote:
>
>> It would probably be better to make these changes with the appropriate code 
>> changes you are making for each semantic mode. And may be keep this patch 
>> only for the other changes you are proposing.
>
> Sorry, I don't understand what you mean.
> I didn't/won't change code (except a bug fix of D138109 
> ) or propose changing code.
> I just want the document to be consistent with the existing code by this 
> patch.
> Are you saying about D138109 ? Or other 
> things?
>
> (Sorry, I'm not a native English speaker. My understanding may be bad.)

@@kawashima-fj no need to apologize!
What I meant was that the changes about the semantic mode approx-func that you 
made here https://reviews.llvm.org/D138109 , should have included the changes 
that you are making in this patch about approx-func. 
In general, the changes to the users' manual should be in the same patch than 
the code changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138117

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


[PATCH] D138109: [clang] Fix -fp-model={strict|precise} to disable -fapprox-func

2022-11-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D138109#3932691 , @kawashima-fj 
wrote:

> Update a test to include the `ffast-math -ffp-model=fast` pattern.

Thanks. Looks good to me.


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

https://reviews.llvm.org/D138109

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-17 Thread Michael Matz via cfe-commits
Hello,

On Wed, 16 Nov 2022, Paul Eggert wrote:

> On 2022-11-16 06:26, Michael Matz wrote:
> > char foobar(void);
> > int main(void) {
> >return &foobar != 0;
> > }
> 
> That still has undefined behavior according to draft C23,

This is correct (and also holds for the actually working variant later, 
with a volatile variable).  If your argument is then that as both 
solutions for the link-test problem are relying on undefined behaviour 
they are equivalent and hence no change is needed, you have a point, but I 
disagree.  In practice one (with the call) will cause more problems than 
the other (with address taking).

> If Clang's threatened pickiness were of some real use elsewhere, it 
> might be justifiable for default Clang to break Autoconf. But so far we 
> haven't seen real-world uses that would justify this pickiness for 
> Autoconf's use of 'char memset_explicit(void);'.

Note that both, GCC and clang, already warn (not error out!) about the 
mismatching decl, even without any headers.  So we are in the pickiness 
era already.

I.e. a C file containing just a single line "char printf(void);" will be 
warned about, by default.  There is about nothing that autoconf could do 
to rectify this, except containing a long list of prototypes for 
well-known functions, with the associated maintenance hassle.  But 
autoconf _can_ do something about how the decls are used in the 
link-tests.


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


[PATCH] D138204: [clang-tidy] Fix misc-unused-using-decls for user-defined literals

2022-11-17 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added reviewers: njames93, ymandel.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Current version complains unused using-declaration even if the target
user-defined literal is used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138204

Files:
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -48,6 +48,7 @@
 void OverloadFunc(int);
 void OverloadFunc(double);
 int FuncUsedByUsingDeclInMacro() { return 1; }
+long double operator""_w(long double);
 
 class ostream {
 public:
@@ -106,6 +107,7 @@
 using n::UnusedFunc; // UnusedFunc
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'UnusedFunc' is unused
 // CHECK-FIXES: {{^}}// UnusedFunc
+using n::operator""_w;
 using n::cout;
 using n::endl;
 
@@ -183,6 +185,7 @@
   UsedInstance.i;
   UsedFunc();
   UsedTemplateFunc();
+  1.5_w;
   cout << endl;
   Color2 color2;
   int t1 = Color3::Yellow;
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -54,6 +54,7 @@
   Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument(
  templateArgument().bind("used",
  this);
+  Finder->addMatcher(userDefinedLiteral().bind("used"), this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -150,7 +151,11 @@
   if (const auto *USD = dyn_cast(ND))
 removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
 }
+return;
   }
+  // Check user-defined literals
+  if (const auto *UDL = Result.Nodes.getNodeAs("used"))
+removeFromFoundDecls(UDL->getCalleeDecl());
 }
 
 void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {


Index: clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -48,6 +48,7 @@
 void OverloadFunc(int);
 void OverloadFunc(double);
 int FuncUsedByUsingDeclInMacro() { return 1; }
+long double operator""_w(long double);
 
 class ostream {
 public:
@@ -106,6 +107,7 @@
 using n::UnusedFunc; // UnusedFunc
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'UnusedFunc' is unused
 // CHECK-FIXES: {{^}}// UnusedFunc
+using n::operator""_w;
 using n::cout;
 using n::endl;
 
@@ -183,6 +185,7 @@
   UsedInstance.i;
   UsedFunc();
   UsedTemplateFunc();
+  1.5_w;
   cout << endl;
   Color2 color2;
   int t1 = Color3::Yellow;
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -54,6 +54,7 @@
   Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument(
  templateArgument().bind("used",
  this);
+  Finder->addMatcher(userDefinedLiteral().bind("used"), this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -150,7 +151,11 @@
   if (const auto *USD = dyn_cast(ND))
 removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
 }
+return;
   }
+  // Check user-defined literals
+  if (const auto *UDL = Result.Nodes.getNodeAs("used"))
+removeFromFoundDecls(UDL->getCalleeDecl());
 }
 
 void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138194: [clang][Parser][NFC] Simplify ParseParenExprOrCondition

2022-11-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with a minor improvement.




Comment at: clang/lib/Parse/ParseStmt.cpp:1275-1282
 bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
Sema::ConditionResult &Cond,
SourceLocation Loc,
-   Sema::ConditionKind CK, bool MissingOK,
+   Sema::ConditionKind CK,
SourceLocation *LParenLoc,
SourceLocation *RParenLoc) {
+  assert(LParenLoc);

We can do better than an assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138194

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


[PATCH] D137340: [clang-tidy] Add misc-use-anonymous-namespace check

2022-11-17 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@njames93 Ping again. Alternatively, could someone else review? @aaron.ballman 
maybe?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137340

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


[PATCH] D135987: [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`

2022-11-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM from my understanding of SARIF, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135987

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-17 Thread Jason Merrill via cfe-commits
On Sat, Nov 12, 2022 at 7:44 PM Paul Eggert  wrote:

> On 2022-11-11 07:11, Aaron Ballman wrote:
> > Clang doesn't require such a linker (we work with various system
> linkers).
>
> As long as the system linkers continue to work as they have
> traditionally worked, we're fine.
>
> > the frontend perspective, we can't tell the difference between
> > "trust me this is safe because it never gets executed" and "this is a
> > CVE"
>
> If some system linker ever attempts to reject links with mismatched
> signatures, Autoconf-generated code will need to have a way to shut that
> off. I hope Clang maintainers can be cajoled into supporting that, if
> the time comes. Perhaps there can be a #pragma, or a compile-time
> option, to do that.
>

There has been discussion of the problems with compile-time options
elsewhere in the thread, but the #pragma idea sounds promising, as older
compilers can just ignore it.

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


[PATCH] D137909: [Support] Allow complex names for annotation points and ranges via ${}

2022-11-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks! sorry about continuing to drift this patch, but this looks like a great 
improvement.

Critical comments below are:

- dropping `Optional` and just use StringRef
- using one consistent way to to include payloads across the API. I think 
`pair` is actually best overall

Others are less important/optional if you want to get this wrapped up sooner :-)




Comment at: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h:119
 for (const auto &P : A.points())   
\
-  EXPECT_EQ(Available, isAvailable(AST, {P, P})) << decorate(A.code(), P); 
\
+  EXPECT_EQ(Available, isAvailable(AST, {P, P, llvm::None}))   
\
+  << decorate(A.code(), P);
\

not being able to ignore payloads (e.g. not assert the presence/absence) seems 
like a regression to me, this points further towards separating ranges() and 
rangesWithPayload



Comment at: llvm/include/llvm/Testing/Support/Annotations.h:58
   /// represents a half-open range.
   struct Range {
 size_t Begin = 0;

this patch takes too many different approaches to attaching the payloads to the 
points:
 - adding it to an existing struct that is already returned
 - defining a new wrapping struct for the andPayload version
 - defining a new inheriting struct for the andPayload version

I think we should keep it simple, and use `pair` for all the 
`andPayload` versions. This isn't optimal in isolation, but it keeps things 
coherent, avoiding:
 - confusion around clever type-system features (inheritance, implicit 
conversions, smart-pointer like types, templates)
 - introducing new structs whose names we have to remember
 - inconsistency between how payloads are accessed between 
ranges/points/clangd/llvm versions

In many cases structured bindings make using the `pair` versions less 
cumbersome than they would have been in the past.



Comment at: llvm/include/llvm/Testing/Support/Annotations.h:108
+  const llvm::StringMap> &
+  all_points_and_payloads() const;
 

I hadn't seen these context on these `all_` functions, I reached out to the 
authors to find out about them (they're used out-of-tree).

Basically the use case is to use llvm::Annotations to do the parsing, but dump 
out the data into some external test helper which lookups/assertions will run 
on.
So instead of adding extra variants, we just need to expose the parse results 
in some convenient way.



Comment at: llvm/include/llvm/Testing/Support/Annotations.h:123
   std::string Code;
-  llvm::StringMap> Points;
+  llvm::StringMap> Points;
   llvm::StringMap> Ranges;

Internally I'd consider switching to a uniform representation of points and 
ranges. For two reasons:
 - we're adding a new feature that's common between them
 - all_points/all_ranges want to expose such a representation

Something like:
```
struct Annotation {
  size_t Start;
  size_t End; // or size_t(-1) for a point
  StringRef Name;
  StringRef Payload;
}
vector All;
StringMap> Points; // values are indices into All
StringMap> Ranges; // values are indices into All

ArrayRef all() { return All; } // replaces all_points and all_ranges
```

up to you though



Comment at: llvm/include/llvm/Testing/Support/Annotations.h:61
 size_t End = 0;
+llvm::Optional Payload;
 

tom-anders wrote:
> One could argue that this should just be `llvm::StringRef`. Right now, 
> `$name^` results in `llvm::None` for the payload, while `$name()^` will yield 
> an empty string.
> 
> Do you think they should just both be empty strings instead?
Yes, I don't think that distinguishing between "no payload" and "empty payload" 
is useful, so would prefer the simpler API.



Comment at: llvm/lib/Testing/Support/Annotations.cpp:30
   };
   llvm::Optional Name;
+  llvm::Optional Payload;

(If using the `Annotation` struct I mentioned before, an instance of it could 
cover Name+Payload and it could also be the elements of OpenRanges)



Comment at: llvm/unittests/Support/AnnotationsTest.cpp:120
+TEST(AnnotationsTest, Payload) {
+  // A single unnamed point or range with empty payload
+  EXPECT_EQ(llvm::Annotations("a$^b").pointWithPayload(),

this is no payload specified, we should also have one test where it's specified 
but empty e.g. `$()^` (even if we make this equivalent to unspecified)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137909

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


[PATCH] D136082: [clangd] Extend --check to time clang-tidy checks, so we can block slow ones

2022-11-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.
Herald added a reviewer: njames93.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/tool/Check.cpp:66
+llvm::cl::desc("Print the overhead of checks matching this glob"),
+llvm::cl::init(""));
+

i guess we also need a `llvm::cl::cat(Check)` here?



Comment at: clang-tools-extra/clangd/tool/Check.cpp:303
+
+for (std::string Check : listTidyChecks(CheckTidyTime)) {
+  // vlog the check name in case we crash!

nit: `StringRef` or `std::string&` or `auto`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136082

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-11-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:749-751
+  const Descriptor::MetadataSize MDSize{sizeof(InlineDescriptor)};
+  Descriptor *D =
+  P.createDescriptor(Src, Ty, MDSize, IsConst, Src.is());

Double checking that `Src.is()` is correct here. That's being 
passed as the `IsTemporary` argument. I presume the logic is that if the decl 
type is an expression then it has to be a temporary, but that's not entirely 
true. Consider C where a compound literal is *not* a temporary but actually 
creates an lvalue: `(int){12}`. Will that be an issue?



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:782
+  P.createDescriptor(Src, Ty.getTypePtr(), MDSize, Ty.isConstQualified(),
+ IsTemporary, false, Init);
   if (!D)





Comment at: clang/lib/AST/Interp/Interp.h:950
 return false;
   if (auto *FD = Ptr.getField()) {
 Ptr.deref() = Value.truncate(FD->getBitWidthValue(S.getCtx()));

Do we need to `initialize()` here as well?



Comment at: clang/lib/AST/Interp/Interp.h:962
   const Pointer &Ptr = S.Stk.pop();
   if (!CheckStore(S, OpPC, Ptr))
 return false;

Same here?



Comment at: clang/lib/AST/Interp/InterpBlock.h:77-86
+  char *data() {
+// Data might contain metadata as well.
+size_t DataOffset = Desc->getMetadataSize();
+return reinterpret_cast(reinterpret_cast(this) +
+sizeof(Block) + DataOffset);
+  }
+

Should we have `const`-correct overloads to provide read-only access?



Comment at: clang/lib/AST/Interp/InterpBlock.h:80-88
+return reinterpret_cast(reinterpret_cast(this) +
+sizeof(Block) + DataOffset);
+  }
+
+  /// Returns a pointer to the raw data, including metadata.
+  /// You are allowed to read Desc->getAllocSize() bytes from this address.
+  char *rawData() {

Why two levels of `reinterpret_cast` to the same type?



Comment at: clang/lib/AST/Interp/InterpBlock.h:97
   void invokeCtor() {
-std::memset(data(), 0, getSize());
+std::memset(rawData(), 0, Desc->getAllocSize());
 if (Desc->CtorFn)

Why do we want to overwrite the metadata here?



Comment at: clang/lib/AST/Interp/InterpFrame.cpp:34
   B->invokeCtor();
+  auto *ID = localInlineDesc(Local.Offset);
+  ID->Desc = Local.Desc;





Comment at: clang/lib/AST/Interp/Pointer.h:41
+/// The Base field is used to access metadata about the data. For primitive
+/// arrays, the Base is followed by an InitMap. In a variety of case, the
+/// Base is preceded by an InlineDescriptor, which is used to track the





Comment at: clang/lib/AST/Interp/Pointer.h:43
+/// Base is preceded by an InlineDescriptor, which is used to track the
+/// initialization state, among others.
+///





Comment at: clang/lib/AST/Interp/Program.cpp:334
 Descriptor *ElemDesc =
-createDescriptor(D, ElemTy.getTypePtr(), IsConst, IsTemporary);
+createDescriptor(D, ElemTy.getTypePtr(), Descriptor::NoMetadata,
+ IsConst, IsTemporary);

Why does this one get no metadata while the rest of the descriptors created do?


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

https://reviews.llvm.org/D135750

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


[PATCH] D137960: [Lexer] Speedup LexTokenInternal

2022-11-17 Thread Jay Foad via Phabricator via cfe-commits
foad added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3520-3521
+LexStart:
+  assert(!Result.needsCleaning() && "Result doesn't need cleaning");
+  assert(!Result.hasPtrData() && "Result has been reset");
 

Messages are backwards. They should be like "Result needs cleaning!" and 
"Result has not been reset!".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137960

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-11-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I don't have enough knowledge about how this works to do a better review, but I 
have a couple of suggestions.




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:749
   bool IsExtended) {
-  Descriptor *D = P.createDescriptor(Src, Ty, IsConst, Src.is());
+  const Descriptor::MetadataSize MDSize{sizeof(InlineDescriptor)};
+  Descriptor *D =

aaron.ballman wrote:
> Double checking that `Src.is()` is correct here. That's being 
> passed as the `IsTemporary` argument. I presume the logic is that if the decl 
> type is an expression then it has to be a temporary, but that's not entirely 
> true. Consider C where a compound literal is *not* a temporary but actually 
> creates an lvalue: `(int){12}`. Will that be an issue?
See suggested comment below in InterpBlock.



Comment at: clang/lib/AST/Interp/Descriptor.cpp:207
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize * NumElems),
-  AllocSize(align(Size) + sizeof(InitMap *)), IsConst(IsConst),
-  IsMutable(IsMutable), IsTemporary(IsTemporary), IsArray(true),
-  CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
-  MoveFn(getMoveArrayPrim(Type)) {
+  MDSize(MD.NumBytes), AllocSize(align(Size) + sizeof(InitMap *) + MDSize),
+  IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),

Theres enough math on stuff like AllocSize/etc that we should probably:

1- do SOMETHING to make sure we're not overflowing
2- Have assertions to make sure we got the sizes looking reasonable.

Additionally, is there any ability to refactor out the common subset of 
initializers into a constructor and delegate to them instead of all these 
really fragile looking changes?



Comment at: clang/lib/AST/Interp/Descriptor.h:74
+  };
+  static constexpr MetadataSize NoMetadata = MetadataSize{0};
+

add a line: 
`static constexpr MetadataSize InlineDescriptor = 
MetadataSize{sizeof(InlineDescriptor)};` 
and you can use this instead of depending on 'sizeof' all over the place.


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

https://reviews.llvm.org/D135750

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


[PATCH] D137618: [Clang] Fix behavior of -ffp-model option when overriden

2022-11-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Looks good to me after the additional RUN line mentioned in my comment for 
Driver/fp-model.c  is added. Thanks.




Comment at: clang/test/Driver/fp-model.c:77
+// WARN12-NOT: warning: overriding '-ffp-model=strict' option with 
'-ffp-model=strict' [-Woverriding-t-option]
+
 // RUN: %clang -### -c %s 2>&1 \

Please add this:
+// RUN: %clang -### -Ofast -ffp-model=strict -c %s 2>&1 | FileCheck \
+// RUN:   --check-prefix=WARN12 %s
+// WARN12-NOT: warning: overriding '-ffp-model=strict' option with 
'-ffp-model=strict' [-Woverriding-t-option]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137618

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


[PATCH] D138204: [clang-tidy] Fix misc-unused-using-decls for user-defined literals

2022-11-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138204

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


[PATCH] D138207: [clang][Parse][NFC] Remove unused CommaLocs parameters

2022-11-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: clang.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The vectors holding the comma locs are unused (except for an assertion in two 
places).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138207

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseOpenMP.cpp

Index: clang/lib/Parse/ParseOpenMP.cpp
===
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -475,7 +475,6 @@
 T.consumeOpen();
 
 ExprVector Exprs;
-CommaLocsTy CommaLocs;
 
 SourceLocation LParLoc = T.getOpenLocation();
 auto RunSignatureHelp = [this, OmpPrivParm, LParLoc, &Exprs]() {
@@ -485,7 +484,7 @@
   CalledSignatureHelp = true;
   return PreferredType;
 };
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
+if (ParseExpressionList(Exprs, [&] {
   PreferredType.enterFunctionArgument(Tok.getLocation(),
   RunSignatureHelp);
 })) {
@@ -499,9 +498,6 @@
   if (!T.consumeClose())
 RLoc = T.getCloseLocation();
 
-  assert(!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() &&
- "Unexpected number of commas!");
-
   ExprResult Initializer =
   Actions.ActOnParenListExpr(T.getOpenLocation(), RLoc, Exprs);
   Actions.AddInitializerToDecl(OmpPrivParm, Initializer.get(),
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -981,11 +981,10 @@
 InitKind = LambdaCaptureInitKind::DirectInit;
 
 ExprVector Exprs;
-CommaLocsTy Commas;
 if (Tentative) {
   Parens.skipToEnd();
   *Tentative = LambdaIntroducerTentativeParse::Incomplete;
-} else if (ParseExpressionList(Exprs, Commas)) {
+} else if (ParseExpressionList(Exprs)) {
   Parens.skipToEnd();
   Init = ExprError();
 } else {
@@ -1929,7 +1928,6 @@
 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get());
 
 ExprVector Exprs;
-CommaLocsTy CommaLocs;
 
 auto RunSignatureHelp = [&]() {
   QualType PreferredType;
@@ -1942,7 +1940,7 @@
 };
 
 if (Tok.isNot(tok::r_paren)) {
-  if (ParseExpressionList(Exprs, CommaLocs, [&] {
+  if (ParseExpressionList(Exprs, [&] {
 PreferredType.enterFunctionArgument(Tok.getLocation(),
 RunSignatureHelp);
   })) {
@@ -1960,8 +1958,6 @@
 if (!TypeRep)
   return ExprError();
 
-assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
-   "Unexpected number of commas!");
 return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
  Exprs, T.getCloseLocation(),
  /*ListInitialization=*/false);
@@ -3239,7 +3235,6 @@
 T.consumeOpen();
 ConstructorLParen = T.getOpenLocation();
 if (Tok.isNot(tok::r_paren)) {
-  CommaLocsTy CommaLocs;
   auto RunSignatureHelp = [&]() {
 ParsedType TypeRep =
 Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
@@ -3255,7 +3250,7 @@
 CalledSignatureHelp = true;
 return PreferredType;
   };
-  if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] {
+  if (ParseExpressionList(ConstructorArgs, [&] {
 PreferredType.enterFunctionArgument(Tok.getLocation(),
 RunSignatureHelp);
   })) {
@@ -3354,9 +3349,7 @@
   }
 
   // It's not a type, it has to be an expression list.
-  // Discard the comma locations - ActOnCXXNew has enough parameters.
-  CommaLocsTy CommaLocs;
-  return ParseExpressionList(PlacementArgs, CommaLocs);
+  return ParseExpressionList(PlacementArgs);
 }
 
 /// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -1961,14 +1961,10 @@
 ArgExprs.push_back(Idx.get());
   }
 } else if (Tok.isNot(tok::r_square)) {
-  CommaLocsTy CommaLocs;
-  if (ParseExpressionList(ArgExprs, CommaLocs)) {
+  if (ParseExpressionList(ArgExprs)) {
 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
 HasError = true;
   }
-  assert(
-  (ArgExprs.empty() || ArgExprs.size() == CommaLocs.size() + 1) &&
-  "Unexpected number of com

[PATCH] D138204: [clang-tidy] Fix misc-unused-using-decls for user-defined literals

2022-11-17 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

@ymandel Thank you for reviewing!

If this patch is okay to land, could you please help me commit it? Thanks again!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138204

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


[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-11-17 Thread KAWASHIMA Takahiro via Phabricator via cfe-commits
kawashima-fj added a comment.

In D138117#3933644 , @zahiraam wrote:

> What I meant was that the changes about the semantic mode approx-func that 
> you made here https://reviews.llvm.org/D138109 , should have included the 
> changes that you are making in this patch about approx-func. 
> In general, the changes to the users' manual should be in the same patch than 
> the code changes.

Thanks. I understand.
Regarding D138109 , the current manual 
already has the following sentences.

> - `precise` Disables optimizations that are not value-safe on floating-point 
> data, although FP contraction (FMA) is enabled (`-ffp-contract=on`).  This is 
> the default behavior.
> - `strict` Enables `-frounding-math` and `-ffp-exception-behavior=strict`, 
> and disables contractions (FMA).  All of the `-ffast-math` enablements are 
> disabled. Enables `STDC FENV_ACCESS`: by default `FENV_ACCESS` is disabled. 
> This option setting behaves as though `#pragma STDC FENV_ACESS ON` appeared 
> at the top of the source file.

These indicates that `precise` and `strict` should disable `-fapprox-func`. 
D138109  changes the code to be consistent 
with the manual.
So D138109  does not need to update the 
manual and this patch does not update the corresponding sentences.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138117

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2022-11-17 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added a comment.

Is there any update to this? Or maybe someone I should add as a reviewer? 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D137980: [ARM] Pretend atomics are always lock-free for small widths.

2022-11-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

Looking at GCC it looks like there (for cortex-m0 at least) the behaviour is 
that loads and stores are generated inline, but more complex operations go to 
the atomic library calls (not the sync library calls). e.g. for

  int x, y;
  int fn() {
return __atomic_load_n(&x, __ATOMIC_SEQ_CST);
  }
  int fn2() {
return __atomic_compare_exchange_n(&x, &y, 0, 0, 0, __ATOMIC_SEQ_CST);
  }

I get with `arm-none-eabi-gcc tmp.c -O1 -mcpu=cortex-m0`

  fn:
  ldr r3, .L2
  dmb ish
  ldr r0, [r3]
  dmb ish
  bx  lr
  
  fn2:
  push{lr}
  sub sp, sp, #12
  ldr r0, .L5
  addsr1, r0, #4
  movsr3, #5
  str r3, [sp]
  movsr3, #0
  movsr2, #0
  bl  __atomic_compare_exchange_4
  add sp, sp, #12
  pop {pc}

so if we're doing this for compatibility with GCC we should do the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137980

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


[PATCH] D138210: [clang] Require parameter pack to be last argument in concepts.

2022-11-17 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google created this revision.
Herald added a project: All.
luken-google requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes GH48182.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138210

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -766,3 +766,24 @@
   __iterator_traits_member_pointer_or_arrow_or_void> f;
 }
 }// namespace InheritedFromPartialSpec
+
+namespace GH48182 {
+template // expected-error{{template 
parameter pack must be the last template parameter}}
+concept invalid = true;
+
+template requires invalid // expected-error{{use of undeclared 
identifier 'invalid'}}
+no errors are printed
+;
+
+static_assert(invalid also here ; // expected-error{{use of undeclared 
identifier 'invalid'}}
+
+int foo() {
+bool b;
+b = invalid not just in declarations; // expected-error{{expected ';' 
after expression}}
+   // expected-error@-1{{use of 
undeclared identifier 'invalid'}}
+   // expected-error@-2{{expected 
';' after expression}}
+   // expected-error@-3{{use of 
undeclared identifier 'just'}}
+   // expected-error@-4{{unknown 
type name 'in'}}
+return b;
+}
+} // namespace GH48182
\ No newline at end of file
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -8923,17 +8923,31 @@
 return nullptr;
   }
 
-  if (TemplateParameterLists.front()->size() == 0) {
+  TemplateParameterList *Params = TemplateParameterLists.front();
+
+  if (Params->size() == 0) {
 Diag(NameLoc, diag::err_concept_no_parameters);
 return nullptr;
   }
 
+  for (TemplateParameterList::const_iterator ParamIt = Params->begin(),
+ ParamEnd = Params->end();
+   ParamIt != ParamEnd; ++ParamIt) {
+Decl const *Param = *ParamIt;
+if (Param->isParameterPack()) {
+  if (++ParamIt == ParamEnd)
+break;
+  Diag(Param->getLocation(),
+   diag::err_template_param_pack_must_be_last_template_parameter);
+  return nullptr;
+}
+  }
+
   if (DiagnoseUnexpandedParameterPack(ConstraintExpr))
 return nullptr;
 
-  ConceptDecl *NewDecl = ConceptDecl::Create(Context, DC, NameLoc, Name,
- TemplateParameterLists.front(),
- ConstraintExpr);
+  ConceptDecl *NewDecl =
+  ConceptDecl::Create(Context, DC, NameLoc, Name, Params, ConstraintExpr);
 
   if (NewDecl->hasAssociatedConstraints()) {
 // C++2a [temp.concept]p4:


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -766,3 +766,24 @@
   __iterator_traits_member_pointer_or_arrow_or_void> f;
 }
 }// namespace InheritedFromPartialSpec
+
+namespace GH48182 {
+template // expected-error{{template parameter pack must be the last template parameter}}
+concept invalid = true;
+
+template requires invalid // expected-error{{use of undeclared identifier 'invalid'}}
+no errors are printed
+;
+
+static_assert(invalid also here ; // expected-error{{use of undeclared identifier 'invalid'}}
+
+int foo() {
+bool b;
+b = invalid not just in declarations; // expected-error{{expected ';' after expression}}
+   // expected-error@-1{{use of undeclared identifier 'invalid'}}
+   // expected-error@-2{{expected ';' after expression}}
+   // expected-error@-3{{use of undeclared identifier 'just'}}
+   // expected-error@-4{{unknown type name 'in'}}
+return b;
+}
+} // namespace GH48182
\ No newline at end of file
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -8923,17 +8923,31 @@
 return nullptr;
   }
 
-  if (TemplateParameterLists.front()->size() == 0) {
+  TemplateParameterList *Params = TemplateParameterLists.front();
+
+  if (Params->size() == 0) {
 Diag(NameLoc, diag::err_concept_no_parameters);
 return nullptr;
   }
 
+  for (TemplateParameterList::const_iterator ParamIt = Params->begin(),
+ ParamEnd = Params->end();
+   ParamIt != ParamEnd; ++ParamIt) {
+Decl const *Param = *Param

[PATCH] D137343: [clang] add -Wvla-stack-allocation

2022-11-17 Thread Tao Liang via Phabricator via cfe-commits
Origami404 added a comment.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137343

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


[PATCH] D137043: [clang] add implicit include for Linux/gnu compatibility

2022-11-17 Thread Tao Liang via Phabricator via cfe-commits
Origami404 added a comment.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137043

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


[PATCH] D128457: [clangd] Add new IncludeType to IncludeHeaderWithReferences

2022-11-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:1241
+  !HeaderInfo.hasFileBeenImported(FE) &&
+  (FID != SM.getMainFileID() || !fileContainsImports(FID, SM)))
 return false;

can you put a comment here saying `any header that contains #imports are 
supposed to be #import'd so no need to check for anything but the main-file.`



Comment at: clang-tools-extra/clangd/SourceCode.cpp:1249
+bool fileContainsImports(FileID ID, const SourceManager &SM) {
+  llvm::StringRef Content = SM.getBufferData(ID);
+  llvm::StringRef Line;

nit: perform `.take_front` directly here.



Comment at: clang-tools-extra/clangd/index/Merge.cpp:251
 SI.References += OI.References;
+SI.SupportedDirectives =
+SI.SupportedDirectives | OI.SupportedDirectives;

nit: `SI.SupportedDirectives |= OI.SupportedDirectives;`



Comment at: clang-tools-extra/clangd/index/Symbol.h:90
 
+  enum IncludeDirectives : uint8_t {
+Invalid = 0,

nit: I'd still keep the enum name singular



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:103
+  using SK = index::SymbolKind;
+  switch (Kind) {
+  case SK::Macro:

can we rather modify the previous function to look like:
```
IncludeDirective shouldCollectIncludePath(index::SymbolKind Kind) {
  using SK = index::SymbolKind;
  switch (Kind) {
  case SK::Macro:
  case SK::Enum:
  case SK::Struct:
  case SK::Class:
  case SK::Union:
  case SK::TypeAlias:
  case SK::Using:
  case SK::Function:
  case SK::Variable:
  case SK::EnumConstant:
  case SK::Concept:
return Include | Import;
  case SK::Protocol:
return Import;
  default:
return Invalid;
  }
}
```



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:838
+  IncludeFiles[S.ID] = FID;
+  if (S.SymInfo.Lang == index::SymbolLanguage::ObjC)
+FilesWithObjCConstructs.insert(FID);

can we do this in `addDeclaration` instead? we already have nameLocation and 
FileID there, but that's also where we have the decl itself, which might be 
needed in future if we need more detailed checks.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:886
   }
+  bool ContainsImports;
+  auto It = FileToContainsImports.find(Entry.second);

can we instead do
```
auto It = map.find(key);
if (It == map.end()) {
  It = map.insert(key, calculateValue()).first;
}
bool ContainsImports = It->second;
```



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:905
+if (shouldCollectImportPath(S->SymInfo.Kind) &&
+(ContainsImports || 
FilesWithObjCConstructs.contains(Entry.second)))
+  Directives |= Symbol::Import;

can we perform `ContainsImports` calculations/caching here instead? that way we 
can trim a bunch of redundant searches.



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:431
   }
-  return clangd::Symbol::IncludeHeaderWithReferences{Strings.save(Header),
- Message.references()};
+  auto IncludeTypes = fromProtobuf(Message.include_types());
+  if (!IncludeTypes)

i guess `IncludeTypes` pieces are leftover?



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:2679
+  assert(!Results.empty());
+  // TODO: Once #import integration support is done this shouldn't include
+  // anything.

i think this case should still be empty, otherwise we're actually regressing 
the behaviour by inserting includes for symbols that we previously wouldn't 
insert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128457

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


[PATCH] D138159: [Clang][OpenMP] Add enter clause to declare target for OpenMP 5.2

2022-11-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 476130.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138159

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/AST/AttrImpl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_ast_print.cpp

Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -4,10 +4,13 @@
 
 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
@@ -77,6 +80,48 @@
 }
 #endif // _OPENMP
 
+#if _OPENMP == 202111
+extern "C" {
+void boo_c() {}
+#pragma omp declare target enter(boo_c) indirect
+// OMP52: #pragma omp declare target indirect
+// OMP52: void boo_c() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+#pragma omp declare target indirect
+void yoo(){}
+#pragma omp end declare target
+// OMP52: #pragma omp declare target indirect
+// OMP52: void yoo() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+}
+extern "C++" {
+void boo_cpp() {}
+#pragma omp declare target enter(boo_cpp) indirect
+// OMP52: #pragma omp declare target indirect
+// OMP52: void boo_cpp() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+
+constexpr bool f() {return false;}
+#pragma omp begin declare target indirect(f())
+void zoo() {}
+void xoo();
+#pragma omp end declare target
+#pragma omp declare target enter(zoo) indirect(false)
+// OMP52: #pragma omp declare target indirect(f())
+// OMP52: #pragma omp declare target indirect(false)
+// OMP52: void zoo() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+// OMP52: #pragma omp declare target indirect(f())
+// OMP52: void xoo();
+// OMP52: #pragma omp end declare target
+
+}
+#endif // _OPENMP
+
 int out_decl_target = 0;
 #pragma omp declare target (out_decl_target)
 
@@ -185,7 +230,11 @@
 int b1, b2, b3;
 void f2() {
 }
+#if _OPENMP == 202111
+#pragma omp declare target enter(b1) enter(b2), enter(b3, f2)
+#else
 #pragma omp declare target to(b1) to(b2), to(b3, f2)
+#endif // _OPENMP == 202111
 // CHECK: #pragma omp declare target{{$}}
 // CHECK: int b1;
 // CHECK: #pragma omp end declare target{{$}}
@@ -288,7 +337,11 @@
 
 #pragma omp declare target
 int abc1() { return 1; }
+#if _OPENMP == 202111
+#pragma omp declare target enter(abc1) device_type(nohost)
+#else
 #pragma omp declare target to(abc1) device_type(nohost)
+#endif // _OPENMP == 202111
 #pragma omp end declare target
 
 // CHECK-NEXT: #pragma omp declare target
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -22670,7 +22670,8 @@
   (SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true) ||
SemaRef.getCurBlock() || SemaRef.getCurCapturedRegion()) &&
   VD->hasGlobalStorage()) {
-if (!MapTy || *MapTy != OMPDeclareTargetDeclAttr::MT_To) {
+if (!MapTy || (*MapTy != OMPDeclareTargetDeclAttr::MT_To &&
+   *MapTy != OMPDeclareTargetDeclAttr::MT_Enter)) {
   // OpenMP 5.0, 2.12.7 declare target Directive, Restrictions
   // If a lambda declaration and definition appears between a
   // declare target directive and the matching end declare target
@@ -22751,8 +22752,11 @@
 IsIndirect = true;
 }
 auto *A = OMPDe

[PATCH] D138159: [Clang][OpenMP] Add enter clause to declare target for OpenMP 5.2

2022-11-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 marked 2 inline comments as done.
doru1004 added inline comments.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:1811
+  // clause.
+  if (getLangOpts().OpenMP >= 52 && ClauseName.str() == "to") {
+Diag(Tok, diag::err_omp_declare_target_unexpected_to_clause);

ABataev wrote:
> ABataev wrote:
> > Do you really need `.str() `?
> Check for enter clause before 5.2?
Good catch, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138159

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


[PATCH] D138159: [Clang][OpenMP] Add enter clause to declare target for OpenMP 5.2

2022-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138159

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


[PATCH] D138207: [clang][Parse][NFC] Remove unused CommaLocs parameters

2022-11-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM -- it's a bit sad that we're losing some assertion coverage, but it seems 
like reasonable coverage to lose.




Comment at: clang/include/clang/Parse/Parser.h:1837-1840
 
   typedef SmallVector CommaLocsTy;
 
   /// ParseExpressionList - Used for C/C++ (argument-)expression-list.

As best I can tell, this removes all uses of that type, so we might as well 
ditch it as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138207

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


[clang] 0dff945 - Fix debug-info test

2022-11-17 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-11-17T16:02:54Z
New Revision: 0dff945bbca9e1c00ac76eafd1af61235272b7dd

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

LOG: Fix debug-info test

Added: 


Modified: 
clang/test/CodeGen/debug-info-sysroot-sdk.c

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-sysroot-sdk.c 
b/clang/test/CodeGen/debug-info-sysroot-sdk.c
index c3e00ca4a6f0e..b52d2e1de9c1d 100644
--- a/clang/test/CodeGen/debug-info-sysroot-sdk.c
+++ b/clang/test/CodeGen/debug-info-sysroot-sdk.c
@@ -9,7 +9,7 @@ void foo(void) {}
 
 // The sysroot and sdk are LLDB-tuning-specific attributes.
 
-// LLDB: distinct !DICompileUnit({{.*}}sysroot: "/CLANG_SYSROOT/MacOSX.sdk",
+// LLDB: distinct !DICompileUnit({{.*}}sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
 // LLDB-SAME:  sdk: "MacOSX.sdk"
 // GDB: distinct !DICompileUnit(
 // GDB-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"



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


[PATCH] D138217: [OpenMP] Initial parsing and semantic analysis support for 'strict' modifier with 'grainsize' clause of 'taskloop' construct

2022-11-17 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay created this revision.
mdfazlay added reviewers: ABataev, mikerice, jdoerfert.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
mdfazlay requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch gives basic parsing and semantic analysis support for for 'strict' 
modifier with 'grainsize' clause of 'taskloop' construct introduced in OpenMP 
5.1 ( section 2.12.2)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138217

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/masked_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/masked_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/master_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/master_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/parallel_masked_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_strict_modifier_ast_print.cpp
  clang/test/OpenMP/taskloop_strict_modifier_messages.cpp

Index: clang/test/OpenMP/taskloop_strict_modifier_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/taskloop_strict_modifier_messages.cpp
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -fopenmp-version=50 -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -fopenmp-version=50 -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+template 
+int tmain(T argc, S **argv) {
+  T z;
+  #pragma omp taskloop grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp taskloop grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp taskloop grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+ foo();
+
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  int z;
+  #pragma omp masked taskloop grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+ foo();
+  
+  #pragma omp masked taskloop simd grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop simd grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop simd grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of und

[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

in the description, link to the change that makes this necessary and describe 
why (need to use an analysis in the pass)




Comment at: llvm/include/llvm/IRPrinter/IRPrintingPasses.h:33
+///
+/// Note: This pass is for use with the new pass manager. Use the create...Pass
+/// functions above to create passes for use with the legacy pass manager.

obsolete (and ditto below)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D138159: [Clang][OpenMP] Add enter clause to declare target for OpenMP 5.2

2022-11-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 476143.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138159

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/AST/AttrImpl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_ast_print.cpp

Index: clang/test/OpenMP/declare_target_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_ast_print.cpp
+++ clang/test/OpenMP/declare_target_ast_print.cpp
@@ -4,10 +4,13 @@
 
 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
@@ -77,6 +80,48 @@
 }
 #endif // _OPENMP
 
+#if _OPENMP == 202111
+extern "C" {
+void boo_c() {}
+#pragma omp declare target enter(boo_c) indirect
+// OMP52: #pragma omp declare target indirect
+// OMP52: void boo_c() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+#pragma omp declare target indirect
+void yoo(){}
+#pragma omp end declare target
+// OMP52: #pragma omp declare target indirect
+// OMP52: void yoo() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+}
+extern "C++" {
+void boo_cpp() {}
+#pragma omp declare target enter(boo_cpp) indirect
+// OMP52: #pragma omp declare target indirect
+// OMP52: void boo_cpp() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+
+constexpr bool f() {return false;}
+#pragma omp begin declare target indirect(f())
+void zoo() {}
+void xoo();
+#pragma omp end declare target
+#pragma omp declare target enter(zoo) indirect(false)
+// OMP52: #pragma omp declare target indirect(f())
+// OMP52: #pragma omp declare target indirect(false)
+// OMP52: void zoo() {
+// OMP52: }
+// OMP52: #pragma omp end declare target
+// OMP52: #pragma omp declare target indirect(f())
+// OMP52: void xoo();
+// OMP52: #pragma omp end declare target
+
+}
+#endif // _OPENMP
+
 int out_decl_target = 0;
 #pragma omp declare target (out_decl_target)
 
@@ -185,7 +230,11 @@
 int b1, b2, b3;
 void f2() {
 }
+#if _OPENMP == 202111
+#pragma omp declare target enter(b1) enter(b2), enter(b3, f2)
+#else
 #pragma omp declare target to(b1) to(b2), to(b3, f2)
+#endif // _OPENMP == 202111
 // CHECK: #pragma omp declare target{{$}}
 // CHECK: int b1;
 // CHECK: #pragma omp end declare target{{$}}
@@ -288,7 +337,11 @@
 
 #pragma omp declare target
 int abc1() { return 1; }
+#if _OPENMP == 202111
+#pragma omp declare target enter(abc1) device_type(nohost)
+#else
 #pragma omp declare target to(abc1) device_type(nohost)
+#endif // _OPENMP == 202111
 #pragma omp end declare target
 
 // CHECK-NEXT: #pragma omp declare target
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -22670,7 +22670,8 @@
   (SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true) ||
SemaRef.getCurBlock() || SemaRef.getCurCapturedRegion()) &&
   VD->hasGlobalStorage()) {
-if (!MapTy || *MapTy != OMPDeclareTargetDeclAttr::MT_To) {
+if (!MapTy || (*MapTy != OMPDeclareTargetDeclAttr::MT_To &&
+   *MapTy != OMPDeclareTargetDeclAttr::MT_Enter)) {
   // OpenMP 5.0, 2.12.7 declare target Directive, Restrictions
   // If a lambda declaration and definition appears between a
   // declare target directive and the matching end declare target
@@ -22751,8 +22752,11 @@
 IsIndirect = true;
 }
 auto *A = OMPDe

[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-11-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:87
+/// FIXME: Expose in public API for decision making (ranking, ignoring, etc.).
+enum class Hint : uint8_t {
+  /// Declaration for the symbol, which is provided by all locations.

can you explain the design of hints a bit?

In particular:
 - are hints emitted by every mapping layer (node -> symbol -> location -> 
header -> include)? if so, are they the same kind (i.e. same enum?)
 - are the hints from one stage provided to subsequent stages?
 - node -> symbol mapping already produces hints in the form of RefKind, do we 
reconcile these concepts somehow?
 - do hints for the same entity found on different paths get merged, or will we 
ultimately report a list of vector where the same header may 
repeat with different hints?



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:89
+  /// Declaration for the symbol, which is provided by all locations.
+  Declaration = 0,
+  /// Complete definition for the symbol.

Is this intended to be:
 - a bit? needs to be nonzero
 - a set of bits? should be `None` or so as it does not set any bits
 - something else? I don't understand




Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:91
+  /// Complete definition for the symbol.
+  Complete = 1,
+  // FIXME: Add header based hints, e.g. IWYU mappings, header-symbol name.

You're only setting this in cases where incompleteness is possible and 
significant. e.g. for AliasDecls it is not set even though they are (shallowly) 
complete.

I think the most self-documenting solution is to invert it to `Incomplete`.
Otherwise the docs here should explain when it is set vs not set.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:108
 
+using HintedLocation = std::pair;
+/// A set of locations that provides the declaration.

Having been down this path, I think using a pair for this is too clumsy for 
such an important data type (and this may be repeated for each mapping layer).

I'd suggest a template that can attach hints to another type, and acts as a 
smart pointer to that type: `Loc->kind(), Loc.hint()` rather than 
`Loc.first.kind(), Loc.second`, can define a decent print function, etc.



Comment at: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp:24
+// Looks for a visible definition of \p D. Returns nullptr if none is 
available,
+// or there are possibly multiple definitions (e.g. namespaces).
+const Decl *getDefinition(const Decl *D) {

Hmm, this isn't list (e.g. ObjCCategoryDecl), is hard to complete, and we don't 
actually have to complete it to get the correct behavior. This suggests it's 
not the right primitive, e.g. it's hard to look at the code and see whether 
there's a bug.

One option would be to make this function `isIncomplete`, call it on each 
redecl, and use isThisDeclarationADefinition.
But we can also avoid the chain of `dyn_cast`s for each redecl by making this 
function something like `Optional getCompletingDefinition()` where 
`None` means any redecl is complete (usable without definition) and `nullptr` 
means no redecl is complete (definition needed but not found), and a pointer 
means that redecl is complete and no other is.



Comment at: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp:28
+return TD->getDefinition();
+  if (const auto *VD = dyn_cast(D))
+return VD->getDefinition();

the net result of include VarDecl and FunctionDecl here is that we prefer 
headers defining these things over headers declaring them. How sure are we that 
this is a good heuristic?

I thought the idea here was "prefer declarations that are complete enough to 
use", which is basically for classes & templates, but not functions and 
variables.

If it's rather "definitions are more likely to be the thing we want" then the 
hint should probably be named `Definition` rather than `Complete`.



Comment at: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp:43
+  std::vector Result;
+  // FIXME: Should we also provide physical locations?
+  if (auto SS = tooling::stdlib::Recognizer()(&D))

I think the same logic that says we include a header that is `// IWYU pragma 
private` says we should, probably with some `Private` hint.



Comment at: clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp:45
+  if (auto SS = tooling::stdlib::Recognizer()(&D))
+return {{*SS, Hint::Complete}};
+  SourceLocation DefLoc;

nit: I think {{...}} is less confusing for both compilers and humans if you 
spell the inner type



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:20
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"

[clang-tools-extra] 2675773 - [include-cleaner] add macro symbols and implicit refs to HTML report

2022-11-17 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-11-17T17:29:41+01:00
New Revision: 267577325876d7e3e2b96c0a577b1b8ce076dfbb

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

LOG: [include-cleaner] add macro symbols and implicit refs to HTML report

Demo: 
http://htmlpreview.github.io/?https://gist.githubusercontent.com/sam-mccall/fec9b77c726cfb3cc7c424b197e3f68c/raw/8c5c5ad927b0485db76c34c25250b0ae8f7637f8/ASTTests.html

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/lib/Types.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 7b8606f4a6ce4..31ae7592ceec0 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -45,7 +45,7 @@ using UsedSymbolCB = llvm::function_ref ASTRoots,
   llvm::ArrayRef MacroRefs,
-  const PragmaIncludes &PI, const SourceManager &, UsedSymbolCB 
CB);
+  const PragmaIncludes *PI, const SourceManager &, UsedSymbolCB 
CB);
 
 } // namespace include_cleaner
 } // namespace clang

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 890e5e13fa57f..e2455e115de24 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -19,8 +19,9 @@ namespace clang::include_cleaner {
 
 void walkUsed(llvm::ArrayRef ASTRoots,
   llvm::ArrayRef MacroRefs,
-  const PragmaIncludes &PI, const SourceManager &SM,
+  const PragmaIncludes *PI, const SourceManager &SM,
   UsedSymbolCB CB) {
+  // This is duplicated in writeHTMLReport, changes should be mirrored there.
   tooling::stdlib::Recognizer Recognizer;
   for (auto *Root : ASTRoots) {
 auto &SM = Root->getASTContext().getSourceManager();

diff  --git a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h 
b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
index 17c11c1218dde..ec378dca6ec70 100644
--- a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
+++ b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
@@ -75,18 +75,18 @@ struct SymbolLocation {
   // Order must match Kind enum!
   std::variant Storage;
 };
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Header &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
 
 /// Finds the headers that provide the symbol location.
 // FIXME: expose signals
 llvm::SmallVector findHeaders(const SymbolLocation &Loc,
   const SourceManager &SM,
-  const PragmaIncludes &PI);
+  const PragmaIncludes *PI);
 
 /// Write an HTML summary of the analysis to the given stream.
-/// FIXME: Once analysis has a public API, this should be public too.
-void writeHTMLReport(FileID File, llvm::ArrayRef Roots, ASTContext 
&Ctx,
- llvm::raw_ostream &OS);
+void writeHTMLReport(FileID File, llvm::ArrayRef Roots,
+ llvm::ArrayRef MacroRefs, ASTContext 
&Ctx,
+ PragmaIncludes *PI, llvm::raw_ostream &OS);
 
 } // namespace include_cleaner
 } // namespace clang

diff  --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index 093cba8b769a9..c782ff89755cb 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -14,7 +14,7 @@ namespace clang::include_cleaner {
 
 llvm::SmallVector findHeaders(const SymbolLocation &Loc,
   const SourceManager &SM,
-  const PragmaIncludes &PI) {
+  const PragmaIncludes *PI) {
   llvm::SmallVector Results;
   switch (Loc.kind()) {
   case SymbolLocation::Physical: {
@@ -25,18 +25,21 @@ llvm::SmallVector findHeaders(const SymbolLocation 
&Loc,
 if (!FE)
   return {};
 
-// We treat the s

[PATCH] D137677: [include-cleaner] add macro symbols and implicit refs to HTML report

2022-11-17 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG267577325876: [include-cleaner] add macro symbols and 
implicit refs to HTML report (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D137677?vs=475068&id=476144#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137677

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -61,19 +61,19 @@
/*Line=*/1, /*Col=*/1);
   };
 
-  EXPECT_THAT(findHeaders(SourceLocFromFile("header1.h"), SM, PI),
+  EXPECT_THAT(findHeaders(SourceLocFromFile("header1.h"), SM, &PI),
   UnorderedElementsAre(Header("\"path/public.h\"")));
 
-  EXPECT_THAT(findHeaders(SourceLocFromFile("detail1.h"), SM, PI),
+  EXPECT_THAT(findHeaders(SourceLocFromFile("detail1.h"), SM, &PI),
   UnorderedElementsAre(Header(FM.getFile("header2.h").get()),
Header(FM.getFile("detail1.h").get(;
-  EXPECT_THAT(findHeaders(SourceLocFromFile("detail2.h"), SM, PI),
+  EXPECT_THAT(findHeaders(SourceLocFromFile("detail2.h"), SM, &PI),
   UnorderedElementsAre(Header(FM.getFile("header2.h").get()),
Header(FM.getFile("detail2.h").get(;
 
-  EXPECT_THAT(findHeaders(SourceLocFromFile("normal.h"), SM, PI),
+  EXPECT_THAT(findHeaders(SourceLocFromFile("normal.h"), SM, &PI),
   UnorderedElementsAre(Header(FM.getFile("normal.h").get(;
 }
 
 } // namespace
 } // namespace clang::include_cleaner
\ No newline at end of file
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -72,7 +72,7 @@
 
   auto &SM = AST.sourceManager();
   llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, PI, SM,
+  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
[&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
  auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
  EXPECT_EQ(FID, SM.getMainFileID());
@@ -113,11 +113,10 @@
   Symbol Answer =
   Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())};
   llvm::DenseMap> OffsetToProviders;
-  PragmaIncludes PI;
   walkUsed(/*ASTRoots=*/{}, /*MacroRefs=*/
{SymbolReference{SM.getComposedLoc(SM.getMainFileID(), Main.point()),
 Answer, RefType::Explicit}},
-   PI, SM,
+   /*PI=*/nullptr, SM,
[&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
  auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
  EXPECT_EQ(FID, SM.getMainFileID());
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -47,6 +47,15 @@
 
 class HTMLReportAction : public clang::ASTFrontendAction {
   RecordedAST AST;
+  RecordedPP PP;
+  PragmaIncludes PI;
+
+  void ExecuteAction() override {
+auto &P = getCompilerInstance().getPreprocessor();
+P.addPPCallbacks(PP.record(P));
+PI.record(getCompilerInstance());
+ASTFrontendAction::ExecuteAction();
+  }
 
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef File) override {
@@ -62,7 +71,7 @@
   exit(1);
 }
 writeHTMLReport(AST.Ctx->getSourceManager().getMainFileID(), AST.Roots,
-*AST.Ctx, OS);
+PP.MacroReferences, *AST.Ctx, &PI, OS);
   }
 };
 
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -18,10 +18,10 @@
   switch (S.kind()) {
   case Symbol::

[clang] 858f347 - [Clang, SystemZ] Add support for option -mno-pic-data-is-text-relative.

2022-11-17 Thread Jonas Paulsson via cfe-commits

Author: Jonas Paulsson
Date: 2022-11-17T11:32:32-05:00
New Revision: 858f347c1758e2f1da5a94e3de0baae7cae2a590

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

LOG: [Clang, SystemZ] Add support for option -mno-pic-data-is-text-relative.

Add support for this GCC option which has the purpose of disallowing text
relative accesses of module local symbols with PIC. In effect, this changes
the code model to "medium".

Reviewed By: uweigand, efriedma, MaskRay

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/pic.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a501306632afb..f90aea1e21948 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2697,6 +2697,8 @@ def fpic : Flag<["-"], "fpic">, Group;
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+defm pic_data_is_text_relative : SimpleMFlag<"pic-data-is-text-relative",
+ "Assume", "Don't assume", " data segments are relative to text segment">;
 def fdirect_access_external_data : Flag<["-"], 
"fdirect-access-external-data">, Group, Flags<[CC1Option]>,
   HelpText<"Don't use GOT indirection to reference external data symbols">;
 def fno_direct_access_external_data : Flag<["-"], 
"fno-direct-access-external-data">, Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 90c4bb51c6ecf..46f642508 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5104,6 +5104,25 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   unsigned PICLevel;
   bool IsPIE;
   std::tie(RelocationModel, PICLevel, IsPIE) = ParsePICArgs(TC, Args);
+  Arg *LastPICDataRelArg =
+  Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
+  options::OPT_mpic_data_is_text_relative);
+  bool NoPICDataIsTextRelative = false;
+  if (LastPICDataRelArg) {
+if (LastPICDataRelArg->getOption().matches(
+options::OPT_mno_pic_data_is_text_relative)) {
+  NoPICDataIsTextRelative = true;
+  if (!PICLevel)
+D.Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mno-pic-data-is-text-relative"
+<< "-fpic/-fpie";
+}
+if (!Triple.isSystemZ())
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << (NoPICDataIsTextRelative ? "-mno-pic-data-is-text-relative"
+  : "-mpic-data-is-text-relative")
+  << RawTriple.str();
+  }
 
   bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
 RelocationModel == llvm::Reloc::ROPI_RWPI;
@@ -5132,6 +5151,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
 if (IsPIE)
   CmdArgs.push_back("-pic-is-pie");
+if (NoPICDataIsTextRelative)
+  CmdArgs.push_back("-mcmodel=medium");
   }
 
   if (RelocationModel == llvm::Reloc::ROPI ||

diff  --git a/clang/test/Driver/pic.c b/clang/test/Driver/pic.c
index 0ff07b0f0f453..153437daf9a32 100644
--- a/clang/test/Driver/pic.c
+++ b/clang/test/Driver/pic.c
@@ -1,5 +1,5 @@
-// Test the driver's control over the PIC behavior. These consist of tests of
-// the relocation model flags and the pic level flags passed to CC1.
+// Test the driver's control over the PIC behavior. These mainly consist of
+// tests of the relocation model flags and the pic level flags passed to CC1.
 //
 // CHECK-NO-PIC: "-mrelocation-model" "static"
 // CHECK-NO-PIC-NOT: "-pic-level"
@@ -45,6 +45,11 @@
 //
 // CHECK-NO-UNUSED-ARG-NOT: argument unused during compilation
 //
+// CHECK-NO-PIC-DATA-TEXT-REL: "-mcmodel=medium"
+// CHECK-PIC-DATA-TEXT-REL-NOT: "-mcmodel=medium"
+// CHECK-NO-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option 
'-mno-pic-data-is-text-relative' for target 'arm-arm-none-eabi'
+// CHECK-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option 
'-mpic-data-is-text-relative' for target 'arm-arm-none-eabi'
+//
 // RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
@@ -313,3 +318,12 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 // RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+
+// RUN: %clang -c --target=s390x-linux-gnu -mno-pic-data-is-text-relative %s \
+// RUN:   -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO

[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

2022-11-17 Thread Jonas Paulsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG858f347c1758: [Clang, SystemZ] Add support for option 
-mno-pic-data-is-text-relative. (authored by jonpa).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137044

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/pic.c


Index: clang/test/Driver/pic.c
===
--- clang/test/Driver/pic.c
+++ clang/test/Driver/pic.c
@@ -1,5 +1,5 @@
-// Test the driver's control over the PIC behavior. These consist of tests of
-// the relocation model flags and the pic level flags passed to CC1.
+// Test the driver's control over the PIC behavior. These mainly consist of
+// tests of the relocation model flags and the pic level flags passed to CC1.
 //
 // CHECK-NO-PIC: "-mrelocation-model" "static"
 // CHECK-NO-PIC-NOT: "-pic-level"
@@ -45,6 +45,11 @@
 //
 // CHECK-NO-UNUSED-ARG-NOT: argument unused during compilation
 //
+// CHECK-NO-PIC-DATA-TEXT-REL: "-mcmodel=medium"
+// CHECK-PIC-DATA-TEXT-REL-NOT: "-mcmodel=medium"
+// CHECK-NO-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option 
'-mno-pic-data-is-text-relative' for target 'arm-arm-none-eabi'
+// CHECK-PIC-DATA-TEXT-REL-NON-SYSTEMZ: error: unsupported option 
'-mpic-data-is-text-relative' for target 'arm-arm-none-eabi'
+//
 // RUN: %clang -c %s -target i386-unknown-unknown -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
 // RUN: %clang -c %s -target i386-unknown-unknown -fpic -### 2>&1 \
@@ -313,3 +318,12 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
 // RUN: %clang -fPIC -c %s -target armv7-pc-windows-gnu -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
+
+// RUN: %clang -c --target=s390x-linux-gnu -mno-pic-data-is-text-relative %s \
+// RUN:   -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-PIC-DATA-TEXT-REL
+// RUN: %clang -c --target=s390x-linux-gnu -mpic-data-is-text-relative %s -### 
\
+// RUN:   2>&1 | FileCheck %s --check-prefix=CHECK-PIC-DATA-TEXT-REL
+// RUN: %clang -c --target=arm-arm-none-eabi -mno-pic-data-is-text-relative %s 
\
+// RUN:   -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-NO-PIC-DATA-TEXT-REL-NON-SYSTEMZ
+// RUN: %clang -c --target=arm-arm-none-eabi -mpic-data-is-text-relative %s \
+// RUN:   -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PIC-DATA-TEXT-REL-NON-SYSTEMZ
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5104,6 +5104,25 @@
   unsigned PICLevel;
   bool IsPIE;
   std::tie(RelocationModel, PICLevel, IsPIE) = ParsePICArgs(TC, Args);
+  Arg *LastPICDataRelArg =
+  Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
+  options::OPT_mpic_data_is_text_relative);
+  bool NoPICDataIsTextRelative = false;
+  if (LastPICDataRelArg) {
+if (LastPICDataRelArg->getOption().matches(
+options::OPT_mno_pic_data_is_text_relative)) {
+  NoPICDataIsTextRelative = true;
+  if (!PICLevel)
+D.Diag(diag::err_drv_argument_only_allowed_with)
+<< "-mno-pic-data-is-text-relative"
+<< "-fpic/-fpie";
+}
+if (!Triple.isSystemZ())
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << (NoPICDataIsTextRelative ? "-mno-pic-data-is-text-relative"
+  : "-mpic-data-is-text-relative")
+  << RawTriple.str();
+  }
 
   bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
 RelocationModel == llvm::Reloc::ROPI_RWPI;
@@ -5132,6 +5151,8 @@
 CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
 if (IsPIE)
   CmdArgs.push_back("-pic-is-pie");
+if (NoPICDataIsTextRelative)
+  CmdArgs.push_back("-mcmodel=medium");
   }
 
   if (RelocationModel == llvm::Reloc::ROPI ||
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2697,6 +2697,8 @@
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+defm pic_data_is_text_relative : SimpleMFlag<"pic-data-is-text-relative",
+ "Assume", "Don't assume", " data segments are relative to text segment">;
 def fdirect_access_external_data : Flag<["-"], 
"fdirect-access-external-data">, Group, Flags<[CC1Option]>,
   HelpText<"Don't use GOT indirection to reference external data symbols">;
 def fno_direct_access_external_data : Flag<["-"], 
"fno-direct-access-external-data">, Group, Flags<[CC1Option]>,


Index: clang/test/Driver/pic.c
=

[PATCH] D137939: [CGObjC] Open cleanup scope before SaveAndRestore CurrentFuncletPad and push CatchRetScope early

2022-11-17 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz updated this revision to Diff 476150.
sgraenitz marked an inline comment as done.
sgraenitz added a comment.

Run test with -fobjc-arc-exceptions and check cleanup pads as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137939

Files:
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/test/CodeGenObjCXX/arc-exceptions-seh.mm

Index: clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
===
--- clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
+++ clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
@@ -1,29 +1,64 @@
-// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fobjc-arc-exceptions -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s
 
 // WinEH requires funclet tokens on nounwind intrinsics if they can lower to
 // regular function calls in the course of IR transformations.
 //
 // This is the case for ObjC ARC runtime intrinsics. Test that clang emits the
-// funclet tokens for llvm.objc.retain and llvm.objc.storeStrong and that they
-// refer to their catchpad's SSA value.
+// funclet tokens for llvm.objc.* calls inside catch- and cleanup-pads and that
+// they refer to their pad's SSA value.
 
-@class Ety;
-void opaque(void);
-void test_catch_with_objc_intrinsic(void) {
+void do_something();
+void may_throw(id);
+
+void try_catch_with_objc_intrinsic() {
+  id ex;
   @try {
-opaque();
-  } @catch (Ety *ex) {
-// Destroy ex when leaving catchpad. This emits calls to intrinsic functions
-// llvm.objc.retain and llvm.objc.storeStrong
+may_throw(ex);
+  } @catch (id ex_caught) {
+do_something();
+may_throw(ex_caught);
   }
 }
 
-// CHECK-LABEL: define{{.*}} void {{.*}}test_catch_with_objc_intrinsic
-//...
-// CHECK:   catch.dispatch:
-// CHECK-NEXT:[[CATCHSWITCH:%[0-9]+]] = catchswitch within none
-//...
-// CHECK:   catch:
-// CHECK-NEXT:[[CATCHPAD:%[0-9]+]] = catchpad within [[CATCHSWITCH]]
-// CHECK: {{%[0-9]+}} = call {{.*}} @llvm.objc.retain{{.*}} [ "funclet"(token [[CATCHPAD]]) ]
-// CHECK: call {{.*}} @llvm.objc.storeStrong{{.*}} [ "funclet"(token [[CATCHPAD]]) ]
+// CHECK-LABEL:   try_catch_with_objc_intrinsic
+//
+// CHECK: catch.dispatch:
+// CHECK-NEXT:  [[CATCHSWITCH:%[0-9]+]] = catchswitch within none [label %catch] unwind label %[[CLEANUP1:.*]]
+//
+// All calls within a catchpad must have funclet tokens that refer to it:
+// CHECK: catch:
+// CHECK-NEXT:  [[CATCHPAD:%[0-9]+]] = catchpad within [[CATCHSWITCH]]
+// CHECK:   call
+// CHECK: @llvm.objc.retain
+// CHECK: [ "funclet"(token [[CATCHPAD]]) ]
+// CHECK:   invoke
+// CHECK: do_something
+// CHECK: [ "funclet"(token [[CATCHPAD]]) ]
+// CHECK: unwind label %[[CLEANUP2:.*]]
+// CHECK:   invoke
+// CHECK: may_throw
+// CHECK: [ "funclet"(token [[CATCHPAD]]) ]
+// CHECK: unwind label %[[CLEANUP2]]
+// CHECK:   call
+// CHECK: @llvm.objc.storeStrong
+// CHECK: [ "funclet"(token [[CATCHPAD]]) ]
+// CHECK:   catchret from [[CATCHPAD]] to label %catchret.dest
+//
+// This block exists and it's empty:
+// CHECK: catchret.dest:
+// CHECK-NEXT:  br label %eh.cont
+//
+// CHECK: [[CLEANUP2]]:
+// CHECK-NEXT:  [[CLEANUPPAD2:%[0-9]+]] = cleanuppad within [[CATCHPAD]]
+// CHECK:   call
+// CHECK: @llvm.objc.storeStrong
+// CHECK: [ "funclet"(token [[CLEANUPPAD2]]) ]
+// CHECK:   cleanupret from [[CLEANUPPAD2]]
+// CHECK: unwind label %[[CLEANUP1]]
+//
+// CHECK: [[CLEANUP1]]:
+// CHECK-NEXT:  [[CLEANUPPAD1:%[0-9]+]] = cleanuppad within none
+// CHECK:   call
+// CHECK: @llvm.objc.storeStrong
+// CHECK: [ "funclet"(token [[CLEANUPPAD1]]) ]
+// CHECK:   cleanupret from [[CLEANUPPAD1]] unwind to caller
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
+#include "llvm/IR/Instruction.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -227,13 +228,18 @@
 CatchHandler &Handler = Handlers[I];
 
 CGF.EmitBlock(Handler.Block);
-llvm::CatchPadInst *CPI = nullptr;
-SaveAndRestore RestoreCurrentFuncletPad(CGF.CurrentFuncletPad);
-if (useFunclets)
-  if ((CPI = dyn_cast_or_null(Handler.Block->getFirstNonPHI

[PATCH] D137939: [CGObjC] Open cleanup scope before SaveAndRestore CurrentFuncletPad and push CatchRetScope early

2022-11-17 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added inline comments.



Comment at: clang/test/CodeGenObjCXX/arc-exceptions-seh.mm:36
+// CHECK:   call
+// CHECK:   do_something
+// CHECK:   [ "funclet"(token [[CATCHPAD]]) ]

rnk wrote:
> Don't we need an exceptional cleanup here to release the exception if 
> `do_something` or `may_throw` throw?
Thanks, that's a very good point! `-fobjc-arc-exceptions` tells clang to 
generate invokes here instead of calls and then we can check funclet tokens in 
cleanup pads too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137939

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


[PATCH] D138183: [Driver] move FreeBSD header search path management to the driver

2022-11-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:234
+  if (!ShouldAddDefaultIncludePaths(triple)) {
 llvm_unreachable("Include management is handled in the driver.");
   }

drop braces around simple single statements



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:391
+  llvm::Triple::OSType os = triple.getOS();
+
+  // FIXME: temporary hack: hard-coded paths.

move the variable immediately before switch `os` and move the comment before 
the variable? Avoid unneeded blank lines



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:104
+  /// ShouldAddDefaultIncludePaths - Returns true iff AddDefaultIncludePaths
+  ///  should actually do anything.  If this returns false, include management
+  ///  should instead be handled in the driver.

MaskRay wrote:
> multiple spaces => one space
not done. `///  ` => `/// `


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138183

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


[PATCH] D138183: [Driver] move FreeBSD header search path management to the driver

2022-11-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/freebsd.cpp:48
+// DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "/usr/include/c++/v1"
+// DRIVER-PASS-INCLUDES: "-internal-isystem" "[[RESOURCE]]/include"

Place `"-internal-isystem` on the same line to ensure there are no extra 
includes in between.

Alternatively, use the `-NEXT: {{^}} xxx` pattern I use in linux-cross.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138183

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


[PATCH] D138219: [include-cleaner] Show includes matched by refs in HTML report. Demo: https://htmlpreview.github.io/?https://gist.githubusercontent.com/sam-mccall/ecee6869e37af3db28089b64d8dce806/ra

2022-11-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a subscriber: mgrang.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138219

Files:
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -70,8 +70,8 @@
<< ": " << EC.message() << "\n";
   exit(1);
 }
-writeHTMLReport(AST.Ctx->getSourceManager().getMainFileID(), AST.Roots,
-PP.MacroReferences, *AST.Ctx, &PI, OS);
+writeHTMLReport(AST.Ctx->getSourceManager().getMainFileID(), PP.Includes,
+AST.Roots, PP.MacroReferences, *AST.Ctx, &PI, OS);
   }
 };
 
Index: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
===
--- clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -51,6 +51,7 @@
   #hover p, #hover pre { margin: 0; }
   #hover .target.implicit { background-color: #bbb; }
   #hover .target.ambiguous { background-color: #caf; }
+  .missing, .unused { background-color: #faa !important; }
   #hover th { color: #008; text-align: right; padding-right: 0.5em; }
   #hover .target:not(:first-child) {
 margin-top: 1em;
@@ -109,8 +110,10 @@
   llvm::raw_ostream &OS;
   const ASTContext &Ctx;
   const SourceManager &SM;
+  const RecordedPP::RecordedIncludes &Includes;
   const PragmaIncludes *PI;
   FileID File;
+  const FileEntry *FE;
 
   // References to symbols from the main file.
   // FIXME: should we deduplicate these?
@@ -119,6 +122,8 @@
 RefType Type;
 SmallVector Locations;
 SmallVector Headers;
+SmallVector Includes;
+bool Satisfied = false;
   };
   std::vector Targets;
   // Points within the main file that reference a Target.
@@ -135,7 +140,7 @@
   std::vector Refs;
 
   Target makeTarget(const SymbolReference &SR) {
-Target T{SR.Target, SR.RT, {}, {}};
+Target T{SR.Target, SR.RT, {}, {}, {}};
 
 // Duplicates logic from walkUsed(), which doesn't expose SymbolLocations.
 // FIXME: use locateDecl and friends once implemented.
@@ -150,15 +155,29 @@
 }
 
 for (const auto &Loc : T.Locations)
-  T.Headers = findHeaders(Loc, SM, PI);
+  T.Headers.append(findHeaders(Loc, SM, PI));
+
+for (const auto &H : T.Headers) {
+  T.Includes.append(Includes.match(H));
+  if (H.kind() == Header::Physical && H.physical() == FE)
+T.Satisfied = true;
+}
+if (!T.Includes.empty())
+  T.Satisfied = true;
+// Include pointers are meaningfully ordered as they are backed by a vector.
+llvm::sort(T.Includes);
+T.Includes.erase(std::unique(T.Includes.begin(), T.Includes.end()),
+ T.Includes.end());
 
 return T;
   }
 
 public:
-  Reporter(llvm::raw_ostream &OS, ASTContext &Ctx, const PragmaIncludes *PI,
-   FileID File)
-  : OS(OS), Ctx(Ctx), SM(Ctx.getSourceManager()), PI(PI), File(File) {}
+  Reporter(llvm::raw_ostream &OS, ASTContext &Ctx,
+   const RecordedPP::RecordedIncludes &Includes,
+   const PragmaIncludes *PI, FileID File)
+  : OS(OS), Ctx(Ctx), SM(Ctx.getSourceManager()), Includes(Includes),
+PI(PI), File(File), FE(SM.getFileEntryForID(File)) {}
 
   void addRef(const SymbolReference &SR) {
 auto [File, Offset] = SM.getDecomposedLoc(SM.getFileLoc(SR.RefLocation));
@@ -288,6 +307,13 @@
   OS << "\n";
 }
 
+for (const auto *I : T.Includes) {
+  OS << "Included";
+  escapeString(I->Spelled);
+  OS << ", line " << I->Line << "";
+  OS << "";
+}
+
 OS << "";
   }
 
@@ -296,7 +322,8 @@
 llvm::StringRef Code = SM.getBufferData(File);
 
 OS << "";
-OS << "";
+OS << "";
+unsigned LineNum = 1;
 auto Rest = llvm::makeArrayRef(Refs);
 unsigned End = 0;
 for (unsigned I = 0; I < Code.size(); ++I) {
@@ -309,12 +336,14 @@
   while (!Rest.empty() && Rest.front().Offset == I &&
  Rest.front().Implicit) {
 const Ref &R = Rest.front();
-OS << "◊";
+OS << "◊";
 Rest = Rest.drop_front();
   };
   // Accumulate all explicit refs that appear on the same token.
   std::string TargetList;
+  bool Unsatisfied = false;
   Rest = Rest.drop_while([&](const Ref &R) {
 if (R.Offset != I)
   return false;
@@ -322,16 +351,18 @@
   TargetList.push_back(',');
 TargetList.push_back('t');
 Targe

[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/include/llvm/IRPrinter/IRPrintingPasses.h:33
+///
+/// Note: This pass is for use with the new pass manager. Use the create...Pass
+/// functions above to create passes for use with the legacy pass manager.

aeubanks wrote:
> obsolete (and ditto below)
@aeubanks is the legacy pass manager support needed at all anymore? I'm not 
sure of the status there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: llvm/include/llvm/IRPrinter/IRPrintingPasses.h:33
+///
+/// Note: This pass is for use with the new pass manager. Use the create...Pass
+/// functions above to create passes for use with the legacy pass manager.

tejohnson wrote:
> aeubanks wrote:
> > obsolete (and ditto below)
> @aeubanks is the legacy pass manager support needed at all anymore? I'm not 
> sure of the status there.
we still need legacy PM passes in the codegen pipeline, which for sure includes 
the IR printer passes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D137043: [clang] add implicit include for Linux/gnu compatibility

2022-11-17 Thread Michał Górny via Phabricator via cfe-commits
mgorny resigned from this revision.
mgorny added a reviewer: MaskRay.
mgorny added a comment.
Herald added a subscriber: StephenFan.

I'm afraid this is above my skills. Maybe @MaskRay?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137043

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


[PATCH] D138221: [HIP] Fix lld failure when devie object is empty

2022-11-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, MaskRay.
Herald added subscribers: kosarev, StephenFan, arichardson, tpr, emaste.
Herald added a project: All.
yaxunl requested review of this revision.

When -fgpu-rdc is used for linking relocatable objects, device relocatable 
objects
are extracted from host relocatable objects. Some host relocatable objects
may not contain device relocatable objects, where an empty file is passed
to lld, which causes lld to fail.

This patch adds "elf64_amdgpu" to lld so that lld always know the target
no matter input file is empty or not.


https://reviews.llvm.org/D138221

Files:
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/test/Driver/hip-toolchain-device-only.hip
  clang/test/Driver/hip-toolchain-no-rdc.hip
  lld/ELF/Driver.cpp


Index: lld/ELF/Driver.cpp
===
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -176,6 +176,7 @@
   .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU})
   .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9})
   .Case("msp430elf", {ELF32LEKind, EM_MSP430})
+  .Case("elf64_amdgpu", {ELF32LEKind, EM_AMDGPU})
   .Default({ELFNoneKind, EM_NONE});
 
   if (ret.first == ELFNoneKind)
Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -59,7 +59,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-m" "elf64_amdgpu" 
"--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 //
@@ -82,7 +82,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 //
@@ -122,7 +122,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_803:.*out]]" [[OBJ_DEV_B_803]]
 
 //
@@ -145,7 +145,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_900:.*out]]" [[OBJ_DEV_B_900]]
 
 //
Index: clang/test/Driver/hip-toolchain-device-only.hip
===
--- clang/test/Driver/hip-toolchain-device-only.hip
+++ clang/test/Driver/hip-toolchain-device-only.hip
@@ -12,7 +12,7 @@
 // CHECK-SAME: "-target-cpu" "gfx803"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_803:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-m" "elf64_amdgpu" 
"--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
@@ -21,7 +21,7 @@
 // CHECK-SAME: "-target-cpu" "gfx900"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_900:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 // CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -111,7 +111,12 @@
  const llvm::opt::ArgList &Args) const 
{
   // Construct lld command.
   // The output from ld.lld is an HSA code object file.
-  ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", "-shared",
+  ArgStringList LldArgs{"-flavor",
+"gnu",
+"-m",
+"elf64_amdgpu",
+"--no-undefined",
+"-shared",
 "-plugin-opt=-amdgpu-internalize-symbols"};
 
   auto &TC = getToolChain();


Index: lld/ELF/Driver.cpp
===
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -176,6 +176,7 @@
   .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU})
   .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9})
   .Case("msp430elf", {ELF32LEKind, EM_MSP430})
+  .Case("elf64_amdgpu", {ELF32LEKind, EM_AMDGPU})
   .Default({ELFNoneKind, EM_NONE});
 
   if (ret.first == ELFNoneKind)
Index: clang/test/Driver/hip-toolchain-

[PATCH] D138221: [HIP] Fix lld failure when devie object is empty

2022-11-17 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 476157.
yaxunl added a comment.

fix typo


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

https://reviews.llvm.org/D138221

Files:
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/test/Driver/hip-toolchain-device-only.hip
  clang/test/Driver/hip-toolchain-no-rdc.hip
  lld/ELF/Driver.cpp


Index: lld/ELF/Driver.cpp
===
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -176,6 +176,7 @@
   .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU})
   .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9})
   .Case("msp430elf", {ELF32LEKind, EM_MSP430})
+  .Case("elf64_amdgpu", {ELF64LEKind, EM_AMDGPU})
   .Default({ELFNoneKind, EM_NONE});
 
   if (ret.first == ELFNoneKind)
Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -59,7 +59,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-m" "elf64_amdgpu" 
"--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 //
@@ -82,7 +82,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 //
@@ -122,7 +122,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_803:.*out]]" [[OBJ_DEV_B_803]]
 
 //
@@ -145,7 +145,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_900:.*out]]" [[OBJ_DEV_B_900]]
 
 //
Index: clang/test/Driver/hip-toolchain-device-only.hip
===
--- clang/test/Driver/hip-toolchain-device-only.hip
+++ clang/test/Driver/hip-toolchain-device-only.hip
@@ -12,7 +12,7 @@
 // CHECK-SAME: "-target-cpu" "gfx803"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_803:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-m" "elf64_amdgpu" 
"--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
@@ -21,7 +21,7 @@
 // CHECK-SAME: "-target-cpu" "gfx900"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_900:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" 
"-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 // CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -111,7 +111,12 @@
  const llvm::opt::ArgList &Args) const 
{
   // Construct lld command.
   // The output from ld.lld is an HSA code object file.
-  ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", "-shared",
+  ArgStringList LldArgs{"-flavor",
+"gnu",
+"-m",
+"elf64_amdgpu",
+"--no-undefined",
+"-shared",
 "-plugin-opt=-amdgpu-internalize-symbols"};
 
   auto &TC = getToolChain();


Index: lld/ELF/Driver.cpp
===
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -176,6 +176,7 @@
   .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU})
   .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9})
   .Case("msp430elf", {ELF32LEKind, EM_MSP430})
+  .Case("elf64_amdgpu", {ELF64LEKind, EM_AMDGPU})
   .Default({ELFNoneKind, EM_NONE});
 
   if (ret.first == ELFNoneKind)
Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -59,7 +59,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A

[clang-tools-extra] 6faf5d7 - Fix MSVC "not all control paths return a value" warning. NFC.

2022-11-17 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-11-17T17:19:41Z
New Revision: 6faf5d72459aee4f388dbd13eb2ddd097d2be067

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

LOG: Fix MSVC "not all control paths return a value" warning. NFC.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index b1c9f6d54866..2b5d67c29955 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -103,6 +103,7 @@ llvm::StringRef refType(RefType T) {
   case RefType::Ambiguous:
 return "ambiguous";
   }
+  llvm_unreachable("unhandled RefType enum");
 }
 
 class Reporter {



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


[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-11-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:300
+FPP_Fast,
+FPP_None
+  };

zahiraam wrote:
> andrew.w.kaylor wrote:
> > Is FPP_None somehow the same as fexcess-precision=16? If not, what does it 
> > mean?
> Yes, maybe this is confusing.  How about if we make "none" means disable 
> excess precision and not use "16"? If you agree with this, then I will edit 
> the description of the issue above.
> Is FPP_None somehow the same as fexcess-precision=16? If not, what does it 
> mean?

I remember that @rjmccall wanted to have 16 a legal value so that we are 
compatible with GCC. Done that here.


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

https://reviews.llvm.org/D136176

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


[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-11-17 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 476161.

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

https://reviews.llvm.org/D136176

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/X86/fexcess-precision.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fexcess-precision.c

Index: clang/test/Driver/fexcess-precision.c
===
--- /dev/null
+++ clang/test/Driver/fexcess-precision.c
@@ -0,0 +1,21 @@
+// RUN: %clang -### -target i386 -fexcess-precision=fast -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST %s
+// RUN: %clang -### -target i386 -fexcess-precision=standard -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-STD %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=standard -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STD %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST %s
+// RUN: %clang -### -target i386 -fexcess-precision=none -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=none -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang -### -target i386 -fexcess-precision=16 -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=16 -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+
+// CHECK-FAST: "-fexcess-precision=fast"
+// CHECK-STD: "-fexcess-precision=standard"
+// CHECK-NONE: "-fexcess-precision=none"
+// CHECK-ERR: error: unsupported option '-fexcess-precision=none' for target 'i386'
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -398,7 +398,7 @@
 // CHECK-WARNING-DAG: optimization flag '-falign-loops' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fexcess-precision=100' is not supported
+// CHECK-WARNING-DAG: unsupported argument '100' to option '-fexcess-precision='
 // CHECK-WARNING-DAG: optimization flag '-fbranch-count-reg' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fno-default-inline' is not supported
Index: clang/test/CodeGen/X86/fexcess-precision.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/fexcess-precision.c
@@ -0,0 +1,286 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=fast \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=standard \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=none \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=fast \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=standard \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=none \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=fast \
+// RUN: -emit-llvm -ffp-eval-method=double -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT-DBL %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=standard \
+// RUN: -emit-llvm -ffp-eval-method=double -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT-DBL %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=none \
+// RUN: -emit-llvm -ffp-eval-method=double -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT-DBL %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=fast \
+// RUN: -emit-llvm -ffp-eval-method=extended -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT-FP80 %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexcess-precision=standard \
+// RUN: -emit-llvm -ffp-eval-method=extended -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT-FP80 %s
+
+// RUN: %clang_cc1 -triple x

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-11-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/Context.cpp:128
   InterpState State(Parent, *P, Stk, *this);
-  State.Current = new InterpFrame(State, Func, nullptr, {}, {});
+  State.Current = new InterpFrame(State, Func, nullptr, {});
   if (Interpret(State, Result))





Comment at: clang/lib/AST/Interp/Descriptor.h:74
+  };
+  static constexpr MetadataSize NoMetadata = MetadataSize{0};
+

erichkeane wrote:
> add a line: 
> `static constexpr MetadataSize InlineDescriptor = 
> MetadataSize{sizeof(InlineDescriptor)};` 
> and you can use this instead of depending on 'sizeof' all over the place.
It feels weird to call this `NoMetadata` but we will pass this as an argument 
to a function with a parameter of `MetaDataSize`. So I am expecting a size but 
I am getting no meta data instead and it looks like a mistake. 

Maybe a better name would be `ZeroMetaDataSize`?



Comment at: clang/lib/AST/Interp/EvalEmitter.cpp:26
   // Create a dummy frame for the interpreter which does not have locals.
-  S.Current = new InterpFrame(S, nullptr, nullptr, CodePtr(), Pointer());
+  S.Current = new InterpFrame(S, nullptr, nullptr, CodePtr());
 }





Comment at: clang/lib/AST/Interp/Pointer.h:50
+///
+/// Pointee  Offset
+/// │  │

I feel like the comment block in `InterpBlock.h` is more informative.



Comment at: clang/lib/AST/Interp/Pointer.h:347
 assert(Offset != 0 && "Not a nested pointer");
-return reinterpret_cast(Pointee->data() + Offset) - 1;
+return reinterpret_cast(Pointee->rawData() + Offset) -
+   1;

Why the `-1` 



Comment at: clang/lib/AST/Interp/Program.h:116
+  const DeclTy &D, PrimType Type,
+  Descriptor::MetadataSize MDSize = Descriptor::MetadataSize{0},
+  bool IsConst = false, bool IsTemporary = false, bool IsMutable = false) {





Comment at: clang/lib/AST/Interp/Program.h:124
+  const DeclTy &D, const Type *Ty,
+  Descriptor::MetadataSize MDSize = Descriptor::MetadataSize{0},
+  // size_t MetadataSize = 0,





Comment at: clang/lib/AST/Interp/Program.h:125
+  Descriptor::MetadataSize MDSize = Descriptor::MetadataSize{0},
+  // size_t MetadataSize = 0,
+  bool IsConst = false, bool IsTemporary = false, bool IsMutable = false,

Delete commented out code.


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

https://reviews.llvm.org/D135750

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


[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D138081#3931419 , 
@alexander-shaposhnikov wrote:

> @tejohnson - the legacy pass manager depends on the interface defined in 
> IRPrintingPasses.h 
> (https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/LegacyPassManager.cpp#L266)
> so without splitting this would face the same issue - circular dependency 
> between LLVMCore (LegacyPassManager.cpp is in LLVMCore) and IRPrinter.

Ah, that's unfortunate. I guess we will have to live with the file duplication 
for a little while then.




Comment at: llvm/include/llvm/IRPrinter/IRPrintingPasses.h:33
+///
+/// Note: This pass is for use with the new pass manager. Use the create...Pass
+/// functions above to create passes for use with the legacy pass manager.

aeubanks wrote:
> tejohnson wrote:
> > aeubanks wrote:
> > > obsolete (and ditto below)
> > @aeubanks is the legacy pass manager support needed at all anymore? I'm not 
> > sure of the status there.
> we still need legacy PM passes in the codegen pipeline, which for sure 
> includes the IR printer passes
Ok that's what I though. So I guess what is obsolete is needing a comment about 
it being for the new PM.



Comment at: llvm/lib/IR/IRPrintingPasses.cpp:9
 //
 // PrintModulePass and PrintFunctionPass implementations.
 //

Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D137979: parse: process GNU and standard attributes on top-level decls

2022-11-17 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 476163.

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

https://reviews.llvm.org/D137979

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseHLSL.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/attr-order.cpp
  clang/test/Parser/cxx-attributes.cpp
  clang/test/SemaCXX/attr-unavailable.cpp
  clang/unittests/Tooling/SourceCodeTest.cpp

Index: clang/unittests/Tooling/SourceCodeTest.cpp
===
--- clang/unittests/Tooling/SourceCodeTest.cpp
+++ clang/unittests/Tooling/SourceCodeTest.cpp
@@ -247,14 +247,25 @@
 
   // Includes attributes.
   Visitor.runOverAnnotated(R"cpp(
-  #define ATTR __attribute__((deprecated("message")))
-  $r[[ATTR
+  $r[[__attribute__((deprecated("message")))
   int x;]])cpp");
 
   // Includes attributes and comments together.
   Visitor.runOverAnnotated(R"cpp(
-  #define ATTR __attribute__((deprecated("message")))
-  $r[[ATTR
+  $r[[__attribute__((deprecated("message")))
+  // Comment.
+  int x;]])cpp");
+
+  // Includes attributes through macro expansion.
+  Visitor.runOverAnnotated(R"cpp(
+  #define MACRO_EXPANSION __attribute__((deprecated("message")))
+  $r[[MACRO_EXPANSION
+  int x;]])cpp");
+
+  // Includes attributes through macro expansion with comments.
+  Visitor.runOverAnnotated(R"cpp(
+  #define MACRO_EXPANSION __attribute__((deprecated("message")))
+  $r[[MACRO_EXPANSION
   // Comment.
   int x;]])cpp");
 }
@@ -402,14 +413,25 @@
 
   // Includes attributes.
   Visit(R"cpp(
-  #define ATTR __attribute__((deprecated("message")))
-  $r[[ATTR
+  $r[[__attribute__((deprecated("message")))
   int x;]])cpp");
 
   // Includes attributes and comments together.
   Visit(R"cpp(
-  #define ATTR __attribute__((deprecated("message")))
-  $r[[ATTR
+  $r[[__attribute__((deprecated("message")))
+  // Comment.
+  int x;]])cpp");
+
+  // Includes attributes through macro expansion.
+  Visitor.runOverAnnotated(R"cpp(
+  #define MACRO_EXPANSION __attribute__((deprecated("message")))
+  $r[[MACRO_EXPANSION
+  int x;]])cpp");
+
+  // Includes attributes through macro expansion with comments.
+  Visitor.runOverAnnotated(R"cpp(
+  #define MACRO_EXPANSION __attribute__((deprecated("message")))
+  $r[[MACRO_EXPANSION
   // Comment.
   int x;]])cpp");
 }
Index: clang/test/SemaCXX/attr-unavailable.cpp
===
--- clang/test/SemaCXX/attr-unavailable.cpp
+++ clang/test/SemaCXX/attr-unavailable.cpp
@@ -42,18 +42,18 @@
 // delayed process for 'deprecated'.
 //  and 
 enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}}
-__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
 typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}}
 
+__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
 __attribute__((deprecated))
 DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; }
 
 
 enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}}
-__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
 typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}}
+ //
 
-
+__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
 __attribute__((unavailable))
 UnavailableEnum testUnavailable(UnavailableEnum X) { return X; }
 
Index: clang/test/Parser/cxx-attributes.cpp
===
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+// GH#58229 - rejects-valid
+__attribute__((__visibility__("default"))) [[nodiscard]] int f();
+[[nodiscard]] __attribute__((__visibility__("default"))) int f();
+
 class c {
   virtual void f1(const char* a, ...)
 __attribute__ (( __format__(__printf__,2,3) )) = 0;
Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -17,8 +17,8 @@
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list 

[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> This diff splits out (from LLVMCore) IR printing passes into IRPrinter.

I haven't spent too much time reading this patch. Is this to fix layering check 
for `-module-summary/-flto=thin with -S/-emit-llvm`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D135987: [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`

2022-11-17 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added a comment.

Great! Please use the following for patch attribution:

- Name: Vaibhav Yenamandra
- email address: vyenaman...@bloomberg.net


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135987

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


[PATCH] D138081: [IR] Split out IR printing passes into IRPrinter

2022-11-17 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D138081#3934386 , @MaskRay wrote:

>> This diff splits out (from LLVMCore) IR printing passes into IRPrinter.
>
> I haven't spent too much time reading this patch. Is this to fix layering 
> check for `-module-summary/-flto=thin with -S/-emit-llvm`?

Yes. That should be mentioned in the summary (as arthur requested).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138081

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


[PATCH] D136806: [Pipelines] Introduce SROA after (final, full) loop unrolling

2022-11-17 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea added a comment.

Green light perf-wise.
I cannot comment on whether the position is "the right" one though. I'm 
deferring to the other reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136806

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


[PATCH] D137059: [Driver] [Modules] Introduce -fsave-std-c++-module-file= to specify the path of the module file (2/2)

2022-11-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

@ben.boeckel

>> Plus the other compilers offer controls over it; why does Clang have to be 
>> different?
>
> Which compilers/flags are you referring to? Arguments from compatibility with 
> GCC are relatively easy to make (though I still have more hesitance for these 
> flags since there's not wide-scale adoption, and I think there's still room 
> to shape the world we want to see and limit the width of the 
> interface/variations we end up having to support long term) & might side-step 
> some of the discussions here.

I'm still curious what about the details of other compilers - I think from the 
sounds of it, @iains suggested GCC doesn't support this yet so we'll need to 
pick/name the flag ourselves & he's happy to implement whatever we pick? I 
guess Microsoft's flag naming is sufficiently differently styled as to offer no 
useful inspiration? Though wouldn't hurt to know what they name it.

Any other examples you had in mind, Ben?


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

https://reviews.llvm.org/D137059

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


[PATCH] D138224: WIP: AST{Reader,Writer} alternative

2022-11-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138224

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Lex/Token.h
  clang/include/clang/Serialization/Simple/ASTReader.h
  clang/include/clang/Serialization/Simple/ASTWriter.h
  clang/include/clang/Serialization/Simple/ModuleCache.h
  clang/include/clang/Serialization/Simple/ModuleFile.h
  clang/include/clang/Serialization/Simple/ModuleManager.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/CMakeLists.txt
  clang/lib/Serialization/GeneratePCH.cpp
  clang/lib/Serialization/Simple/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-basic.c

Index: clang/test/ClangScanDeps/modules-basic.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-basic.c
@@ -0,0 +1,181 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- include/module.modulemap
+module top { header "top.h" }
+module left { header "left.h" }
+module right { header "right.h" }
+module right_extra { header "right-extra.h" }
+module bottom { header "bottom.h" }
+//--- include/top.h
+//
+#define D1
+//--- include/left.h
+///
+#include "top.h"
+#define D2
+//--- include/right.h
+
+#include "right-extra.h"
+#include "top.h"
+#define D3
+//--- include/right-extra.h
+/
+#define D4
+//--- include/bottom.h
+//
+#include "left.h"
+#include "right.h"
+#define D5
+//--- include/t.h
+
+//--- tu.c
+#include "bottom.h"
+#ifdef D1
+#endif
+#ifdef D2
+#endif
+#ifdef D3
+#endif
+#ifdef D4
+#endif
+#ifdef D5
+#endif
+
+#define D1
+#define D2
+#define D3
+#define D4
+#define D5
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fimplicit-module-maps -I DIR/include"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "left"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "right"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/include/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/include/module.modulemap",
+// CHECK:  "-fmodule-file=left=[[PREFIX]]/cache/{{.*}}/left-{{.*}}.pcm",
+// CHECK:  "-fmodule-file=right=[[PREFIX]]/cache/{{.*}}/right-{{.*}}.pcm",
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/include/bottom.h",
+// CHECK-NEXT: "[[PREFIX]]/include/module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "bottom"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "top"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/include/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/include/module.modulemap",
+// CHECK:  "-fmodule-file=top=[[PREFIX]]/cache/{{.*}}/top-{{.*}}.pcm",
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/include/left.h",
+// CHECK-NEXT: "[[PREFIX]]/include/module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "left"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   

[PATCH] D136806: [Pipelines] Introduce SROA after (final, full) loop unrolling

2022-11-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D136806#3934445 , @asbirlea wrote:

> Green light perf-wise.
> I cannot comment on whether the position is "the right" one though. I'm 
> deferring to the other reviewers.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136806

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


[PATCH] D137979: parse: process GNU and standard attributes on top-level decls

2022-11-17 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks, this LGTM. You might want to get another reviewers approval as well.


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

https://reviews.llvm.org/D137979

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


[PATCH] D137609: [C++20] [Modules] Remove unmaintained header modules

2022-11-17 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Also not using this at Meta, LGTM.


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

https://reviews.llvm.org/D137609

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


[PATCH] D138227: [OPENMP]Initial support for severity clause

2022-11-17 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, jdoerfert, mikerice.
jyu2 added a project: OpenMP.
Herald added subscribers: arphaman, guansong, yaxunl.
Herald added projects: Flang, All.
jyu2 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

Initial support for severity clause


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138227

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/error_ast_print.cpp
  clang/test/OpenMP/error_message.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -304,6 +304,9 @@
 def OMPC_At : Clause<"at"> {
   let clangClass = "OMPAtClause";
 }
+def OMPC_Severity : Clause<"severity"> {
+  let clangClass = "OMPSeverityClause";
+}
 def OMPC_Allocate : Clause<"allocate"> {
   let clangClass = "OMPAllocateClause";
   let flangClass = "OmpAllocateClause";
@@ -532,7 +535,8 @@
 def OMP_Barrier : Directive<"barrier"> {}
 def OMP_Error : Directive<"error"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_TaskWait : Directive<"taskwait"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1869,6 +1869,7 @@
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
 CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
 CHECK_SIMPLE_CLAUSE(At, OMPC_at)
+CHECK_SIMPLE_CLAUSE(Severity, OMPC_severity)
 CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 CHECK_SIMPLE_CLAUSE(When, OMPC_when)
 CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2445,6 +2445,8 @@
 
 void OMPClauseEnqueue::VisitOMPAtClause(const OMPAtClause *) {}
 
+void OMPClauseEnqueue::VisitOMPSeverityClause(const OMPSeverityClause *) {}
+
 void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
   Visitor->AddStmt(C->getDevice());
 }
Index: clang/test/OpenMP/error_message.cpp
===
--- clang/test/OpenMP/error_message.cpp
+++ clang/test/OpenMP/error_message.cpp
@@ -67,6 +67,20 @@
 #pragma omp error at(execution) // no error
 
 #pragma omp error at(compilation) // expected-error {{ERROR}}
+
+// expected-error@+1 {{ERROR}}
+#pragma omp error severity() // expected-error {{expected 'fatal' or 'warning' in OpenMP clause 'severity'}}
+// expected-error@+1 {{ERROR}}
+#pragma omp error severity(xyz) // expected-error {{expected 'fatal' or 'warning' in OpenMP clause 'severity'}}
+// expected-warning@+1 {{WARNING}}
+#pragma omp error severity(warning) // expected-warning {{WARNING}}
+#pragma omp error severity(fatal) // expected-error {{ERROR}}
+
+// expected-warning@+1 {{WARNING}}
+#pragma omp error at(compilation) severity(warning) // expected-warning {{WARNING}}
+#pragma omp error at(execution) severity(warning) // no error, diagnosic at runtime
+#pragma omp error at(compilation) severity(fatal) // expected-error {{ERROR}}
+#pragma omp error at(execution) severity(fatal) // no error, error at runtime
   return T();
 }
 
@@ -146,5 +160,5 @@
   label2:
 #pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
 
-  return tmain(argc);
+  return tmain(argc);// expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
Index: clang/test/OpenMP/error_ast_print.cpp
===
--- clang/test/OpenMP/error_ast_print.cpp
+++ clang/test/OpenMP/error_ast_print.cpp
@@ -13,16 +13,16 @@
 void foo() {}
 // CHECK: template  int tmain(T argc, char **argv)
 // CHECK: static int a;
-// CHECK-NEXT: #pragma omp error at(execution)
+// CHECK-NEXT: #pragma omp error at(execution) severity(fatal
 // CHECK-NEXT: a = argv[0][0];
 // CHECK-NEXT: ++a;
-// CHECK-NEXT: #pragma omp error at(execution)
+// CHECK-NEXT: #pragma omp error at(execution) severity(warning)
 // CHECK-NEXT: {
 // CHECK-NEXT: i

[PATCH] D138179: MIPS: fix build from IR files, nan2008 and FpAbi

2022-11-17 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.

Rubber stamp. I try to find some mips folks who can verify, so maybe wait a day 
or so.

> When we use llc or lld to compiler IR files, the features +nan2008 and 
> +fpxx/+fp64 are not used. Thus wrong format files are produced.

Not sure lld is related. It just consumes the bitcode input when using LTO. Did 
you mean Clang?




Comment at: llvm/lib/Target/Mips/MipsAsmPrinter.cpp:402
   MipsTargetStreamer &TS = getTargetStreamer();
 
+  TS.updateABIInfo(*Subtarget);

Seems that you can group TS/MTM declaration together, and then place `TS.` 
calls together?



Comment at: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll:1
+; RUN: llc -filetype=asm %s -o - | FileCheck %s
+





Comment at: llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll:11
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="all" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="mips32r2" 
"target-features"="+fp64,+mips32r2,+nan2008,-noabicalls" }
+

Delete unrelated attributes from the list. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138179

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


[clang] 8adfa29 - [Pipelines] Introduce SROA after (final, run-time) loop unrolling

2022-11-17 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-17T21:31:30+03:00
New Revision: 8adfa29706e5407b62a4726e2172894e0dfdc1e8

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

LOG: [Pipelines] Introduce SROA after (final, run-time) loop unrolling

Now that we are done with loop unrolling, be it either by LoopVectorizer,
or LoopUnroll passes, some variable-offset GEP's into alloca's could have
become constant-offset, thus enabling SROA and alloca promotion,
yet we don't capitalize on that, which is surprizing.

While it would be good to not introduce one more SROA invocation,
but instead move the one from 
`PassBuilder::buildFunctionSimplificationPipeline()`,
the existing test coverage says that is a bad idea,
though it would be fine compile-time wise: 
https://llvm-compile-time-tracker.com/compare.php?from=b150d34c47efbd8fa09604bce805c0920360f8d7&to=5a9a5c855158b482552be8c7af3e73d67fa44805&stat=instructions

So instead, i add yet another SROA run.
I have checked, and it needs to be at least after said final loop unrolling.
This is still fine compile-time wise: 
https://llvm-compile-time-tracker.com/compare.php?from=70324cd88328c0924e605fa81b696572560aa5c9&to=fb489bbef687ad821c3173a931709f9cad9aee8a&stat=instructions

I've encountered this in a real code, `SROA-after-final-loop-unrolling.ll` has 
been reduced from https://godbolt.org/z/fsdMhETh3

Reviewed By: spatel

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

Added: 


Modified: 
clang/test/CodeGen/cleanup-destslot-simple.c
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll
llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling-2.ll
llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll

Removed: 




diff  --git a/clang/test/CodeGen/cleanup-destslot-simple.c 
b/clang/test/CodeGen/cleanup-destslot-simple.c
index 18d4c2138090e..2a0e682b0ab21 100644
--- a/clang/test/CodeGen/cleanup-destslot-simple.c
+++ b/clang/test/CodeGen/cleanup-destslot-simple.c
@@ -17,8 +17,8 @@
 // CHECK-LIFETIME-NEXT:store i32 3, ptr [[X]], align 4, !dbg 
[[DBG10:![0-9]+]], !tbaa [[TBAA11:![0-9]+]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.start.p0(i64 8, ptr 
nonnull [[P]]), !dbg [[DBG15:![0-9]+]]
 // CHECK-LIFETIME-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG16:![0-9]+]], !tbaa [[TBAA17:![0-9]+]]
-// CHECK-LIFETIME-NEXT:[[P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
-// CHECK-LIFETIME-NEXT:[[TMP0:%.*]] = load i32, ptr [[P_0_P_0_P_0_]], 
align 4, !dbg [[DBG20:![0-9]+]], !tbaa [[TBAA11]]
+// CHECK-LIFETIME-NEXT:[[P_0_P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
+// CHECK-LIFETIME-NEXT:[[TMP0:%.*]] = load i32, ptr [[P_0_P_0_P_0_P_0_]], 
align 4, !dbg [[DBG20:![0-9]+]], !tbaa [[TBAA11]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 8, ptr nonnull 
[[P]]), !dbg [[DBG21:![0-9]+]]
 // CHECK-LIFETIME-NEXT:call void @llvm.lifetime.end.p0(i64 4, ptr nonnull 
[[X]]) #[[ATTR2]], !dbg [[DBG21]]
 // CHECK-LIFETIME-NEXT:ret i32 [[TMP0]], !dbg [[DBG22:![0-9]+]]
@@ -49,7 +49,7 @@
 // CHECK-MSAN-NEXT:[[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr, !dbg 
[[DBG15]]
 // CHECK-MSAN-NEXT:store i64 0, ptr [[TMP5]], align 8, !dbg 
[[DBG16:![0-9]+]]
 // CHECK-MSAN-NEXT:store volatile ptr [[X]], ptr [[P]], align 8, !dbg 
[[DBG16]], !tbaa [[TBAA17:![0-9]+]]
-// CHECK-MSAN-NEXT:[[P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr [[P]], 
align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
+// CHECK-MSAN-NEXT:[[P_0_P_0_P_0_P_0_:%.*]] = load volatile ptr, ptr 
[[P]], align 8, !dbg [[DBG19:![0-9]+]], !tbaa [[TBAA17]]
 // CHECK-MSAN-NEXT:[[_MSLD:%.*]] = load i64, ptr [[TMP5]], align 8, !dbg 
[[DBG19]]
 // CHECK-MSAN-NEXT:[[_MSCMP_NOT:%.*]] = icmp eq i64 [[_MSLD]], 0, !dbg 
[[DBG20:![0-9]+]]
 // CHECK-MSAN-NEXT:br i1 [[_MSCMP_NOT]], label [[TMP7:%.*]], label 
[[TMP6:%.*]], !dbg [[DBG20]], !prof [[PROF21:![0-9]+]]
@@ -57,8 +57,8 @@
 // CHECK-MSAN-NEXT:call void @__msan_warning_noreturn() #[[ATTR3:[0-9]+]], 
!dbg [[DBG20]]
 // CHECK-MSAN-NEXT:unreachable, !dbg [[DBG20]]
 // CHECK-MSAN:   7:
-// CHECK-MSAN-NEXT:[[TMP8:%.*]] = load i32, ptr [[P_0_P_0_P_0_]], align 4, 
!dbg [[DBG20]], !tbaa [[TBAA11]]
-// CHECK-MSAN-NEXT:[[TMP9:%.*]] = ptrtoint ptr [

[PATCH] D136806: [Pipelines] Introduce SROA after (final, full) loop unrolling

2022-11-17 Thread Roman Lebedev 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 rG8adfa29706e5: [Pipelines] Introduce SROA after (final, 
run-time) loop unrolling (authored by lebedev.ri).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136806

Files:
  clang/test/CodeGen/cleanup-destslot-simple.c
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll
  llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling-2.ll
  llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
  llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll

Index: llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll
===
--- llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll
+++ llvm/test/Transforms/PhaseOrdering/single-iteration-loop-sroa.ll
@@ -13,17 +13,17 @@
 ; CHECK-NEXT:store i16 [[TMP0:%.*]], ptr [[DATA]], align 2
 ; CHECK-NEXT:br label [[BB6_I_I:%.*]]
 ; CHECK:   bb6.i.i:
-; CHECK-NEXT:[[ITER_SROA_0_07_I_I:%.*]] = phi i64 [ [[TMP2:%.*]], [[BB6_I_I]] ], [ 0, [[START:%.*]] ]
+; CHECK-NEXT:[[ITER_SROA_0_07_I_I:%.*]] = phi i64 [ [[TMP1:%.*]], [[BB6_I_I]] ], [ 0, [[START:%.*]] ]
 ; CHECK-NEXT:[[_40_I_I:%.*]] = sub nsw i64 0, [[ITER_SROA_0_07_I_I]]
-; CHECK-NEXT:[[TMP2]] = add nuw nsw i64 [[ITER_SROA_0_07_I_I]], 1
+; CHECK-NEXT:[[TMP1]] = add nuw nsw i64 [[ITER_SROA_0_07_I_I]], 1
 ; CHECK-NEXT:[[_34_I_I:%.*]] = getelementptr inbounds [0 x i8], ptr [[DATA]], i64 0, i64 [[ITER_SROA_0_07_I_I]]
-; CHECK-NEXT:[[TMP1:%.*]] = getelementptr [0 x i8], ptr [[DATA]], i64 0, i64 [[_40_I_I]]
-; CHECK-NEXT:[[_39_I_I:%.*]] = getelementptr i8, ptr [[TMP1:%.*]], i64 1
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr [0 x i8], ptr [[DATA]], i64 0, i64 [[_40_I_I]]
+; CHECK-NEXT:[[_39_I_I:%.*]] = getelementptr i8, ptr [[TMP2]], i64 1
 ; CHECK-NEXT:[[TMP_0_COPYLOAD_I_I_I_I:%.*]] = load i8, ptr [[_34_I_I]], align 1
 ; CHECK-NEXT:[[TMP2_0_COPYLOAD_I_I_I_I:%.*]] = load i8, ptr [[_39_I_I]], align 1
 ; CHECK-NEXT:store i8 [[TMP2_0_COPYLOAD_I_I_I_I]], ptr [[_34_I_I]], align 1
 ; CHECK-NEXT:store i8 [[TMP_0_COPYLOAD_I_I_I_I]], ptr [[_39_I_I]], align 1
-; CHECK-NEXT:[[EXITCOND_NOT_I_I:%.*]] = icmp eq i64 [[TMP2]], [[X:%.*]]
+; CHECK-NEXT:[[EXITCOND_NOT_I_I:%.*]] = icmp eq i64 [[TMP1]], [[X:%.*]]
 ; CHECK-NEXT:br i1 [[EXITCOND_NOT_I_I]], label [[EXIT:%.*]], label [[BB6_I_I]]
 ; CHECK:   exit:
 ; CHECK-NEXT:[[DOTSROA_0_0_COPYLOAD:%.*]] = load i16, ptr [[DATA]], align 2
Index: llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
===
--- llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
+++ llvm/test/Transforms/PhaseOrdering/X86/SROA-after-final-loop-unrolling.ll
@@ -13,38 +13,10 @@
 define void @wibble(ptr %arg) personality ptr null {
 ; CHECK-LABEL: @wibble(
 ; CHECK-NEXT:  bb:
-; CHECK-NEXT:[[I1:%.*]] = alloca [[T1:%.*]], align 16
 ; CHECK-NEXT:[[I10_3_I_PRE:%.*]] = load i8, ptr [[ARG:%.*]], align 1
-; CHECK-NEXT:[[VECTOR_RECUR_INIT:%.*]] = insertelement <4 x i8> poison, i8 [[I10_3_I_PRE]], i64 3
-; CHECK-NEXT:[[TMP0:%.*]] = getelementptr [64 x i8], ptr [[ARG]], i64 0, i64 1
-; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i8>, ptr [[TMP0]], align 1
-; CHECK-NEXT:[[TMP1:%.*]] = shufflevector <4 x i8> [[VECTOR_RECUR_INIT]], <4 x i8> [[WIDE_LOAD]], <4 x i32> 
-; CHECK-NEXT:[[TMP2:%.*]] = or <4 x i8> [[TMP1]], 
-; CHECK-NEXT:[[TMP3:%.*]] = zext <4 x i8> [[TMP2]] to <4 x i32>
-; CHECK-NEXT:store <4 x i32> [[TMP3]], ptr [[I1]], align 16
-; CHECK-NEXT:[[TMP4:%.*]] = getelementptr inbounds [16 x i32], ptr [[I1]], i64 0, i64 4
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr [64 x i8], ptr [[ARG]], i64 0, i64 5
-; CHECK-NEXT:[[WIDE_LOAD_1:%.*]] = load <4 x i8>, ptr [[TMP5]], align 1
-; CHECK-NEXT:[[TMP6:%.*]] = shufflevector <4 x i8> [[WIDE_LOAD]], <4 x i8> [[WIDE_LOAD_1]], <4 x i32> 
-; CHECK-NEXT:[[TMP7:%.*]] = or <4 x i8> [[TMP6]], 
-; CHECK-NEXT:[[TMP8:%.*]] = zext <4 x i8> [[TMP7]] to <4 x i32>
-; CHECK-NEXT:store <4 x i32> [[TMP8]], ptr [[TMP4]], align 16
-; CHECK-NEXT:[[TMP9:%.*]] = getelementptr inbounds [16 x i32], ptr [[I1]], i64 0, i64 8
-; CHECK-NEXT:[[TMP10:%.*]] = getelementptr [64 x i8], ptr [[ARG]], i64 0, i64 9
-; CHECK-NEXT:[[WIDE_LOAD_2:%.*]] = load <4 x i8>, ptr [[TMP10]], align 1
-; CHECK-NEXT:[[TMP11:%.*]] = shufflevector <4 x

[PATCH] D138217: [OpenMP] Initial parsing and semantic analysis support for 'strict' modifier with 'grainsize' clause of 'taskloop' construct

2022-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

1. Add full diff context
2. Add unsuccessful tests for the modifier (parsing and sema)




Comment at: clang/lib/Parse/ParseOpenMP.cpp:3811
+// Parse optional  ':'
+auto Modifier = getOpenMPSimpleClauseType(
+Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok), getLangOpts());

Use actual type instead of auto here



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16812
+  case OMPC_grainsize:
+assert(Argument.size() == 1 && ArgumentLoc.size() == 1);
+Res = ActOnOpenMPGrainsizeClause(

Add a message here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138217

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


[PATCH] D135987: [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`

2022-11-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D135987#3934387 , @vaibhav.y wrote:

> Great! Please use the following for patch attribution:
>
> - Name: Vaibhav Yenamandra
> - email address: vyenaman...@bloomberg.net

Happy to, can you rebase the patch on the top of tree? It doesn't apply cleanly 
for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135987

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


[PATCH] D138227: [OPENMP]Initial support for severity clause

2022-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMP.td:538-539
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];

Add a version where these clauses were introduced


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138227

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


[PATCH] D138073: [clang-doc] Move file layout to the generators.

2022-11-17 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 476183.
brettw marked 3 inline comments as done.

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

https://reviews.llvm.org/D138073

Files:
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/test/clang-doc/single-file-public.cpp
  clang-tools-extra/test/clang-doc/single-file.cpp

Index: clang-tools-extra/test/clang-doc/single-file.cpp
===
--- clang-tools-extra/test/clang-doc/single-file.cpp
+++ clang-tools-extra/test/clang-doc/single-file.cpp
@@ -3,7 +3,7 @@
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp -output=%t/docs
-// RUN: cat %t/docs/GlobalNamespace/index.yaml | FileCheck %s --check-prefix=CHECK
+// RUN: cat %t/docs/index.yaml | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 
 void function(int x);
Index: clang-tools-extra/test/clang-doc/single-file-public.cpp
===
--- clang-tools-extra/test/clang-doc/single-file-public.cpp
+++ clang-tools-extra/test/clang-doc/single-file-public.cpp
@@ -3,7 +3,9 @@
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp -output=%t/docs
-// RUN: cat %t/docs/GlobalNamespace/Record.yaml | FileCheck %s --check-prefix=CHECK
+//   This produces two files, index.yaml and one for the record named by its USR
+//   (which we don't know in advance). This checks the record file.
+// RUN: ls %t/docs | grep -v index.yaml | xargs -IYAML_RECORD_FILE cat %t/docs/YAML_RECORD_FILE | FileCheck %s --check-prefix=CHECK
 // RUN: rm -rf %t
 
 class Record {
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -130,54 +131,6 @@
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-bool CreateDirectory(const Twine &DirName, bool ClearDirectory = false) {
-  std::error_code OK;
-  llvm::SmallString<128> DocsRootPath;
-  if (ClearDirectory) {
-std::error_code RemoveStatus = llvm::sys::fs::remove_directories(DirName);
-if (RemoveStatus != OK) {
-  llvm::errs() << "Unable to remove existing documentation directory for "
-   << DirName << ".\n";
-  return true;
-}
-  }
-  std::error_code DirectoryStatus = llvm::sys::fs::create_directories(DirName);
-  if (DirectoryStatus != OK) {
-llvm::errs() << "Unable to create documentation directories.\n";
-return true;
-  }
-  return false;
-}
-
-// A function to extract the appropriate file name for a given info's
-// documentation. The path returned is a composite of the output directory, the
-// info's relative path and name and the extension. The relative path should
-// have been constructed in the serialization phase.
-//
-// Example: Given the below, the  path for class C will be
-// /A/B/C.
-//
-// namespace A {
-// namespace B {
-//
-// class C {};
-//
-// }
-// }
-llvm::Expected> getInfoOutputFile(StringRef Root,
- StringRef RelativePath,
- StringRef Name,
- StringRef Ext) {
-  llvm::SmallString<128> Path;
-  llvm::sys::path::native(Root, Path);
-  llvm::sys::path::append(Path, RelativePath);
-  if (CreateDirectory(Path))
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "failed to create directory");
-  llvm::sys::path::append(Path, Name + Ext);
-  return Path;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -274,6 +227,11 @@
 R.first->second.emplace_back(Value);
   });
 
+  // Collects all Infos according to their unique USR value. This map is added
+  // to from the thread pool below and is protected by the USRToInfoMutex.
+  llvm::sys::Mutex USRToInfoMutex;
+  llvm::StringMap> USRToInfo;
+
   // First reducing phase (reduce all decls into one info per decl).
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic Error;
@@ -304,31 +262,17 @@
 return;
   }
 
-  doc::Info *I = Reduced.get().get();
-  auto InfoPath =
-  getInfoOutputFile(OutDirectory, I->getRelativeFilePath(""),
-I->get

[PATCH] D138073: [clang-doc] Move file layout to the generators.

2022-11-17 Thread Brett Wilson via Phabricator via cfe-commits
brettw added inline comments.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:890-892
+// TODO If there are multiple Infos for this file name (for example,
+// template specializations), this will generate multiple complete web 
pages
+// (with  and , etc.) concatenated together. This generator

paulkirth wrote:
> So does this patch make HTML unusable? Currently, if there is a conflict, the 
> file gets replaced, right? 
> 
> I read this as we're going from a situation where we lost data, but still had 
> valid HTML pages to one where we have complete, but incorrect HTML, is that 
> correct?
> 
> Also, why does that happen under template specialization? USRs are SHA1 
> hashes of the symbol. I would expect that hashing the symbol would be 
> unambiguous and unique, given C++'s ODR. 
> 
> That last point made me wonder if an alternate way to handle this without 
> using the hash would be to use the mangled names?
I think this makes HTML strictly better (though not ideal).

Previously if there was a collision, they got written over the top of each 
other without truncation (not sure why). So if the longer page was written 
second, you got lucky and you get a complete valid page and just lost the 
shorter struct's definition. If you got unlucky the shorter page was written 
second and you get a corrupted file with the shorter content, followed by the 
end of the longer content peeking out from the end.

With this change, you get both content concatenated without corruption, you 
just have duplicate doctype and title tags in between them. Browsers should 
generally handle this so the page should be usable.

Fixing this requires a refactor of the HTML generator such that the concept of 
writing a struct is separate from writing a page. Even if I was going to work 
on the HTML generator, I would probably want to do this in a separate patch 
anyway.

The markdown generator does the same, but markdown doesn't have all of the 
headers stuff that shouldn't be in the middle of the file, you just get a new 
`# ...` for the second section and it should be reasonable.

The HTML and MD generators name files according to the `Name` of the structure. 
USR is not involved. So any time to things in the same namespace have the same 
name, you'll get a collision. This happens most commonly with template 
specialization because the names are identical (the name doesn't account for 
the template parameters).

All of this complexity is why I changed the YAML output to use USR which avoids 
the problem. I didn't want to make this change for the HTML and MD generators 
because it will make ugly file names that the user will see, and you probably 
want the template specializations to be in the same file anyway.



Comment at: clang-tools-extra/test/clang-doc/single-file-public.cpp:6
 // RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
-// RUN: cat %t/docs/GlobalNamespace/Record.yaml | FileCheck %s 
--check-prefix=CHECK
+// RUN: cat %t/docs/`ls %t/docs | grep -v index.yaml` | FileCheck %s 
--check-prefix=CHECK
 // RUN: rm -rf %t

paulkirth wrote:
> Its OK to use `ls` and `grep` in the runline, but you cannot use the backtick 
> syntax. It will cause problems on other platforms and I can't find any other 
> usage of that in our codebase. TBH I'm a bit surprised this works, since 
> `lit` has some interesting behavior around RUN. 
> 
> I think you can just use `cat < ls %t/docs | grep -v index.yaml` instead. I 
> haven't tried it, but that is certainly a more typical method of doing this 
> in a lit test. Using `find` may also work, but I only found one use in 
> `llvm/test/ExecutionEngine/MCJIT/load-object-a.ll`.
Your example doesn't work (it's trying to load a file named "ls") but I found 
another solution using xargs (which is hopefully supported on all of the 
platforms).


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

https://reviews.llvm.org/D138073

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-17 Thread Paul Eggert via cfe-commits

On 2022-11-16 10:40, Jeffrey Walton wrote:

This line of arguments is not persuasive. It is full of logical fallacies.


... none of which you stated.

No matter how we solve the problem, it will be a hack that exploits 
"logical fallacies" (whatever that means). However, a reaction "You 
violated the C standard! You deserve to be punished!" is not the best 
one for the overall software ecosystem. Lots of programs violate the C 
standard every day, and Clang supports them anyway.


Yesterday I dealt with this Autoconf bug report:

https://lists.gnu.org/r/autoconf/2022-11/msg00092.html

which basically said, "Here's some longstanding buggy code that uses 
Autoconf. This buggy code happened to work in the previous stable 
Autoconf version, but it stopped working in the bleeding-edge version."


Did I respond, "That's buggy code and it deserves to be punished?" No, I 
responded that it's buggy code that needs to be fixed (and gave a fix), 
but fixing this sort of thing is a hassle for distributors and so I also 
installed a minor hack to bleeding-edge Autoconf that lets the buggy 
code work again, at least for now. 



It would help if Clang developers could cooperate to address this 
potential problem with stricter compilation defaults. It's a real 
problem. And it shouldn't require much work on the Clang side to address it.

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


[PATCH] D135987: [clangBasic] Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`

2022-11-17 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y updated this revision to Diff 476186.
vaibhav.y added a comment.

Rebase on upstream/main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135987

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/Basic/Sarif.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/test/Frontend/sarif-diagnostics.cpp
  clang/unittests/Basic/SarifTest.cpp

Index: clang/unittests/Basic/SarifTest.cpp
===
--- clang/unittests/Basic/SarifTest.cpp
+++ clang/unittests/Basic/SarifTest.cpp
@@ -292,7 +292,7 @@
 TEST_F(SarifDocumentWriterTest, checkSerializingArtifacts) {
   // GIVEN:
   const std::string ExpectedOutput =
-  R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":40,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":14,"startColumn":14,"startLine":3}}}],"message":{"text":"expected ';' after top level declarator"},"ruleId":"clang.unittest","ruleIndex":0}],"tool":{"driver":{"fullName":"sarif test runner","informationUri":"https://clang.llvm.org/docs/UsersManual.html","language":"en-US","name":"sarif test","rules":[{"defaultConfiguration":{"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":"Example rule created during unit tests"},"id":"clang.unittest","name":"clang unit test"}],"version":"1.0.0"}}}],"version":"2.1.0"})";
+  R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":40,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:///main.cpp"},"region":{"endColumn":14,"startColumn":14,"startLine":3}}}],"message":{"text":"expected ';' after top level declarator"},"ruleId":"clang.unittest","ruleIndex":0}],"tool":{"driver":{"fullName":"sarif test runner","informationUri":"https://clang.llvm.org/docs/UsersManual.html","language":"en-US","name":"sarif test","rules":[{"defaultConfiguration":{"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":"Example rule created during unit tests"},"id":"clang.unittest","name":"clang unit test"}],"version":"1.0.0"}}}],"version":"2.1.0"})";
 
   SarifDocumentWriter Writer{SourceMgr};
   const SarifRule &Rule =
@@ -332,7 +332,7 @@
 TEST_F(SarifDocumentWriterTest, checkSerializingCodeflows) {
   // GIVEN:
   const std::string ExpectedOutput =
-  R"({"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length":27,"location":{"index":1,"uri":"file:///test-header-1.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":30,"location":{"index":2,"uri":"file:///test-header-2.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":28,"location":{"index":3,"uri":"file:///test-header-3.h"},"mimeType":"text/plain","roles":["resultFile"]},{"length":41,"location":{"index":0,"uri":"file:///main.cpp"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results":[{"codeFlows":[{"threadFlows":[{"locations":[{"importance":"essential","location":{"message":{"text":"Message #1"},"physicalLocation":{"artifactLocation":{"index":1},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"important","location":{"message":{"text":"Message #2"},"physicalLocation":{"artifactLocation":{"index":2},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1,{"importance":"unimportant","location":{"message":{"text":"Message #3"},"physicalLocation":{"artifactLocation":{"index":3},"region":{"endColumn":8,"endLine":2,"startColumn":1,"startLine":1]}]}],"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"index":0},"region":{"endColumn":8,"endLine":2,"startColumn":5,"startLine":2}}}],"message":{"text":"Redefinition of 'foo'"},"ruleId":"clang.unittest","ruleIndex":0}],"tool":{"driver":{"fullName":"sarif test runner","informationUri":"https://clang.llvm.org/docs/UsersManual.html","language":"en-US","name":"sarif test","rules":[{"defaultConfiguration":{"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":"Example rule created during unit tests"},"id":"clang.unittest","name":"clang unit test"}],"version":"1.0.0"}}}],"version":"2.1.0"})";
+  R"({"$schema":"https://docs.oasi

[PATCH] D137980: [ARM] Pretend atomics are always lock-free for small widths.

2022-11-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

So gcc has two different behaviors on ARM:

- On linux, prefers `__sync` calls, and generates inline code for load/store.
- On baremetal, gcc chooses what sort of atomic call to generate based on how 
the source code is written: if the user writes `__sync`, you get `__sync`, and 
if the user writes `__atomic`, the user gets `__atomic`.  But it generates 
inline code for load/store, so it's assuming the __atomic implementation is 
lock-free.

We'd have to hack clang IR generation to generate different IR for the two 
constructs.  I'm not sure what the underlying logic is, or if it's worth trying 
to emulate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137980

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


[PATCH] D138217: [OpenMP] Initial parsing and semantic analysis support for 'strict' modifier with 'grainsize' clause of 'taskloop' construct

2022-11-17 Thread Fazlay Rabbi via Phabricator via cfe-commits
mdfazlay updated this revision to Diff 476191.
mdfazlay marked 2 inline comments as done.
mdfazlay added a comment.

> 1. Add full diff context
> 2. Add unsuccessful tests for the modifier (parsing and sema)

1. Done
2. I am not quite sure about it it. We have two new tests for ast and message. 
We did test the unsuccessful tests in the message test. Can you please 
elaborate on this one?


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

https://reviews.llvm.org/D138217

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/masked_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/masked_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/master_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/master_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/parallel_masked_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_grainsize_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
  clang/test/OpenMP/taskloop_strict_modifier_ast_print.cpp
  clang/test/OpenMP/taskloop_strict_modifier_messages.cpp

Index: clang/test/OpenMP/taskloop_strict_modifier_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/taskloop_strict_modifier_messages.cpp
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -fopenmp-version=50 -ferror-limit 100 %s -Wuninitialized
+
+// RUN: %clang_cc1 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp -fopenmp-version=50 -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+template 
+int tmain(T argc, S **argv) {
+  T z;
+  #pragma omp taskloop grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp taskloop grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp taskloop grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+ foo();
+
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  int z;
+  #pragma omp masked taskloop grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+ foo();
+  
+  #pragma omp masked taskloop simd grainsize(strict 10) // omp51-error {{missing ':' after strict modifier}} omp50-error {{use of undeclared identifier 'strict'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop simd grainsize(aa 10) // omp51-error {{use of undeclared identifier 'aa'}} omp51-error {{expected ')'}} omp51-note {{to match this '('}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expected ')'}} omp50-note {{to match this '('}}
+  for (int i = 0; i < 10; ++i)
+foo();
+  #pragma omp masked taskloop simd grainsize(aa: 10) // omp51-error {{expected 'strict' in OpenMP clause 'grainsize'}} omp50-error {{use of undeclared identifier 'aa'}} omp50-error {{expect

[PATCH] D137762: [clang-format] avoid breaking )( with BlockIndent

2022-11-17 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:5007
   return false;
 }
 const FormatToken *Previous = Right.MatchingParen->Previous;

owenpan wrote:
> Can we simply add the above and leave the original `return` statement on line 
> 5009 unchanged?
Yes this seems to work. I'll push a diff shortly along with reverting the 
EXPECT_EQ outside of my new tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137762

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-17 Thread Paul Eggert via cfe-commits

On 2022-11-16 10:59, Zack Weinberg wrote:

I'm generally in agreement with Rich Felker's argument 
(inhttps://ewontfix.com/13/) that AC_CHECK_FUNC*should not*  just probe for 
linkability of a symbol


So am I. I'm not saying Autoconf should never change here, only that the 
change would not be trivial. It would require changing many configure.ac 
scripts scattered over many software projects, because Autoconf cannot 
be expected to know every signature of every function in every library.


Any such transition could not be done in a week, or a month, or even a 
year. I would guess it would take a decade at least. In the meantime if 
Clang becomes pickier by default it would be helpful if there were a 
well-defined way to shut off Clang's pickiness. If the Clang developers 
provide such a way we can use it; if not, Autoconf will just have to do 
what it always does, and figure a way out anyway (hey! it could drop 
into assembler...).


Things would be simpler if Clang became pickier by default only for 
declarations that are not "char foo();" or "char foo(void);". Then, 
existing 'configure' scripts would still work.

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


[PATCH] D138227: [OPENMP]Initial support for severity clause

2022-11-17 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 476194.
jyu2 added a comment.

Thanks Alexey for code review!  Address his comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138227

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/error_ast_print.cpp
  clang/test/OpenMP/error_message.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -304,6 +304,9 @@
 def OMPC_At : Clause<"at"> {
   let clangClass = "OMPAtClause";
 }
+def OMPC_Severity : Clause<"severity"> {
+  let clangClass = "OMPSeverityClause";
+}
 def OMPC_Allocate : Clause<"allocate"> {
   let clangClass = "OMPAllocateClause";
   let flangClass = "OmpAllocateClause";
@@ -532,7 +535,8 @@
 def OMP_Barrier : Directive<"barrier"> {}
 def OMP_Error : Directive<"error"> {
   let allowedClauses = [
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_TaskWait : Directive<"taskwait"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -1869,6 +1869,7 @@
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
 CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
 CHECK_SIMPLE_CLAUSE(At, OMPC_at)
+CHECK_SIMPLE_CLAUSE(Severity, OMPC_severity)
 CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
 CHECK_SIMPLE_CLAUSE(When, OMPC_when)
 CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2445,6 +2445,8 @@
 
 void OMPClauseEnqueue::VisitOMPAtClause(const OMPAtClause *) {}
 
+void OMPClauseEnqueue::VisitOMPSeverityClause(const OMPSeverityClause *) {}
+
 void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
   Visitor->AddStmt(C->getDevice());
 }
Index: clang/test/OpenMP/error_message.cpp
===
--- clang/test/OpenMP/error_message.cpp
+++ clang/test/OpenMP/error_message.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ferror-limit 100 %s -Wuninitialized
 
 template 
 T tmain(T argc) {
@@ -67,6 +67,20 @@
 #pragma omp error at(execution) // no error
 
 #pragma omp error at(compilation) // expected-error {{ERROR}}
+
+// expected-error@+1 {{ERROR}}
+#pragma omp error severity() // expected-error {{expected 'fatal' or 'warning' in OpenMP clause 'severity'}}
+// expected-error@+1 {{ERROR}}
+#pragma omp error severity(xyz) // expected-error {{expected 'fatal' or 'warning' in OpenMP clause 'severity'}}
+// expected-warning@+1 {{WARNING}}
+#pragma omp error severity(warning) // expected-warning {{WARNING}}
+#pragma omp error severity(fatal) // expected-error {{ERROR}}
+
+// expected-warning@+1 {{WARNING}}
+#pragma omp error at(compilation) severity(warning) // expected-warning {{WARNING}}
+#pragma omp error at(execution) severity(warning) // no error, diagnosic at runtime
+#pragma omp error at(compilation) severity(fatal) // expected-error {{ERROR}}
+#pragma omp error at(execution) severity(fatal) // no error, error at runtime
   return T();
 }
 
@@ -146,5 +160,5 @@
   label2:
 #pragma omp error // expected-error {{'#pragma omp error' cannot be an immediate substatement}}
 
-  return tmain(argc);
+  return tmain(argc);// expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
Index: clang/test/OpenMP/error_ast_print.cpp
===
--- clang/test/OpenMP/error_ast_print.cpp
+++ clang/test/OpenMP/error_ast_print.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-onl

  1   2   3   >