[PATCH] D140044: [CodeComplete] Complete members of dependent `auto` variables

2022-12-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeCompletion/member-access.cpp:121
 // CHECK-DEP-CHAIN: baseTemplateField : [#T#]baseTemplateField
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:111:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
 }

It feels horrible that we have to update all following line numbers whenever we 
add a new test, no action required here (we can always append a new test, but 
then tests are not grouped properly)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140044

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#3988902 , @manojgupta 
wrote:

> We use -Xcompiler and -Xlinker which are passed in programs and they raise 
> error now.

Sorry, I do not understand. `clang -Xlinker --verbose a.c` works well. 
`-Xcompiler` is invalid in GCC. How do your programs use `-Xlinker` or 
`-Xcompiler`.
If `-Xcompiler foo` is used similar to `-Xclang foo`, it seems very wrong to 
silently ignore `-Xcompiler` as `foo` will be seen as a positional argument...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D139717#3991765 , @rsundahl wrote:

> In D139717#3987963 , @MaskRay wrote:
>
>>> This change is breaking internal builds. We use the -Xfoo pattern but can 
>>> now no longer manage whether we allow an unused -Xfoo option to pass as a 
>>> warning or promote it to an error.
>>
>> Which `-Xfoo` is used? Do your internal builds reserve `-Xfoo` as a 
>> placeholder to do other non-upstream work? Then you can consider `-Gfoo` if 
>> your builds don't need the mips semantics.
>
> We use -Xparser

There are two cases.
First, your downstream projects incorrectly pass a previously-ignored 
`-Xparser`. Then it seems the right call is to remove it.
Second, there are many projects doing `-Xparser` and it was intentionally 
ignored. Another program would analyze `-Xparser`.

For the second case, we can add an ignored `Flag` called `-Xparser`, with a 
comment which tool uses it.
We should not call it `IgnoreGCCCompat` as GCC doesn't recognize `-Xparser`.

>> Is it possible to clean up the previously-ignored-with-a-warning `-Xfoo`?
>
> Possibly. Maybe preferably. Builds are breaking now though. Dependent 
> projects would have to be notified and changes scheduled. Was there a diff 
> that we should have been part of? It looks like at least two of us are 
> surprised with downstream consequences.

See the previous paragraph. And we need a clang/test/Driver test to catch 
accidental removal from other contributors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D140011: [clang][compiler-rt] Support LLVM_ENABLE_PER_TARGET_RUNTIME_DIR on Arm Linux and BSD

2022-12-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thanks for doing this!




Comment at: clang/lib/Driver/ToolChain.cpp:553
 
+  // armeb (big endian) is left out here on purpose so that we don't try to use
+  // little endian libraries in that case.

The comments can be combined. First state what this block does, then state that 
armeb is left out for a reason.

An example may be more descriptive than some words. Give an example of 
`getTriple()` and Arch values?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140011

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


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

2022-12-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

(On a trip so I will be slow.)

I wish that some mips experts like @atanasyan can some proper checks but this 
patch seems fine.
Landing in one minute after testing finishes.


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] 9739bb8 - MIPS: fix build from IR files, nan2008 and FpAbi

2022-12-15 Thread Fangrui Song via cfe-commits

Author: YunQiang Su
Date: 2022-12-15T09:04:36Z
New Revision: 9739bb81aed490bfcbcbbac6970da8fb7232fd34

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

LOG: MIPS: fix build from IR files, nan2008 and FpAbi

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.

In IR files, the attributes are only set for function while not the whole 
compile units.
So we output `.nan 2008` and `.module fp=xx/64` before every function.

`isFPXXDefault`: for o32, the FPXX should always be the default, no matter 
about the vendors.
Of course some distributions with FP64 default enabled should be listed 
explicit.
Let's add them in future if we know about one.

Reviewed By: MaskRay

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

Added: 
llvm/test/CodeGen/Mips/abiflags-2008-fp64.ll

Modified: 
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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 088eecf79adbc..7da00a8854006 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -467,11 +467,6 @@ bool mips::isFP64ADefault(const llvm::Triple &Triple, 
StringRef CPUName) {
 
 bool mips::isFPXXDefault(const llvm::Triple &Triple, StringRef CPUName,
  StringRef ABIName, mips::FloatABI FloatABI) {
-  if (Triple.getVendor() != llvm::Triple::ImaginationTechnologies &&
-  Triple.getVendor() != llvm::Triple::MipsTechnologies &&
-  !Triple.isAndroid())
-return false;
-
   if (ABIName != "32")
 return false;
 

diff  --git a/clang/test/Driver/mips-as.c b/clang/test/Driver/mips-as.c
index f4add636e9e89..14fbb18c93500 100644
--- a/clang/test/Driver/mips-as.c
+++ b/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_nonpic" "-EB" "-mfpxx" "-mmsa"
 //
 // RUN: %clang -target mips-linux-gnu -mmsa -mno-msa -### \
 // RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \

diff  --git a/clang/test/Driver/mips-integrated-as.s 
b/clang/test/Driver/mips-integrated-as.s
index 46ce5b6871f4e..e248ba7f77e91 100644
--- a/clang/test/Drive

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

2022-12-15 Thread Fangrui Song 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 rG9739bb81aed4: MIPS: fix build from IR files, nan2008 and 
FpAbi (authored by wzssyqa, committed by MaskRay).

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,13 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "mipsel-unknown-linux-gnu"
+
+define dso_local void @test() #0 {
+  ret void
+}
+
+attributes #0 = { "target-cpu"="mips32r2" "target-features"="+fp64,+mips32r2,+nan2008" }
+
+
+; 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
@@ -399,6 +399,14 @@
 
 void MipsAsmPrinter::emitFunctionEntryLabel() {
   MipsTargetStreamer &TS = getTargetStreamer();
+  bool IsO32 = (static_cast(TM)).getABI().IsO32();
+
+  TS.updateABIInfo(*Subtarget);
+  if (Subtarget->isNaN2008())
+TS.emitDirectiveNaN2008();
+  if ((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.
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" 

[PATCH] D139073: [X86] AMD Zen 4 Initial enablement

2022-12-15 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh updated this revision to Diff 483092.
GGanesh added a comment.

Update to use 'no' processor model.
Fixed the below tests
tools/llvm-mca/X86/cpus.s
tools/llvm-mca/X86/read-after-ld-1.s
tools/llvm-mca/X86/register-file-statistics.s
tools/llvm-mca/X86/scheduler-queue-usage.s

Addressed comments from @RKSimon


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139073

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Frontend/x86-target-cpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86PfmCounters.td
  llvm/test/CodeGen/X86/cpus-amd.ll
  llvm/test/CodeGen/X86/rdpru.ll
  llvm/test/CodeGen/X86/slow-unaligned-mem.ll
  llvm/test/CodeGen/X86/sqrt-fastmath-tune.ll
  llvm/test/CodeGen/X86/vector-shuffle-fast-per-lane.ll
  llvm/test/CodeGen/X86/x86-64-double-shifts-var.ll
  llvm/test/MC/X86/x86_long_nop.s
  llvm/test/tools/llvm-mca/X86/cpus.s
  llvm/test/tools/llvm-mca/X86/read-after-ld-1.s
  llvm/test/tools/llvm-mca/X86/register-file-statistics.s
  llvm/test/tools/llvm-mca/X86/scheduler-queue-usage.s

Index: llvm/test/tools/llvm-mca/X86/scheduler-queue-usage.s
===
--- llvm/test/tools/llvm-mca/X86/scheduler-queue-usage.s
+++ llvm/test/tools/llvm-mca/X86/scheduler-queue-usage.s
@@ -112,6 +112,12 @@
 # ZNVER3-NEXT: [3] Maximum number of used buffer entries.
 # ZNVER3-NEXT: [4] Total number of buffer entries.
 
+# ZNVER4:  Scheduler's queue usage:
+# ZNVER4-NEXT: [1] Resource name.
+# ZNVER4-NEXT: [2] Average number of used buffer entries.
+# ZNVER4-NEXT: [3] Maximum number of used buffer entries.
+# ZNVER4-NEXT: [4] Total number of buffer entries.
+
 # BARCELONA:[1][2][3][4]
 # BARCELONA-NEXT:  SBPortAny0  1  54
 
@@ -165,3 +171,9 @@
 # ZNVER3-NEXT: Zn3Int   0  1  96
 # ZNVER3-NEXT: Zn3Load  0  0  72
 # ZNVER3-NEXT: Zn3Store 0  0  64
+
+# ZNVER4:   [1][2][3][4]
+# ZNVER4-NEXT: Zn3FP0  0  64
+# ZNVER4-NEXT: Zn3Int   0  1  96
+# ZNVER4-NEXT: Zn3Load  0  0  72
+# ZNVER4-NEXT: Zn3Store 0  0  64
Index: llvm/test/tools/llvm-mca/X86/register-file-statistics.s
===
--- llvm/test/tools/llvm-mca/X86/register-file-statistics.s
+++ llvm/test/tools/llvm-mca/X86/register-file-statistics.s
@@ -54,6 +54,11 @@
 # ZNVER3-NEXT:   Total number of mappings created: 0
 # ZNVER3-NEXT:   Max number of mappings used:  0
 
+# ZNVER4: *  Register File #1 -- Zn3FpPRF:
+# ZNVER4-NEXT:   Number of physical registers: 160
+# ZNVER4-NEXT:   Total number of mappings created: 0
+# ZNVER4-NEXT:   Max number of mappings used:  0
+
 # BDVER2: *  Register File #2 -- PdIntegerPRF:
 # BDVER2-NEXT:   Number of physical registers: 96
 # BDVER2-NEXT:   Total number of mappings created: 2
@@ -78,3 +83,8 @@
 # ZNVER3-NEXT:   Number of physical registers: 192
 # ZNVER3-NEXT:   Total number of mappings created: 2
 # ZNVER3-NEXT:   Max number of mappings used:  2
+
+# ZNVER4: *  Register File #2 -- Zn3IntegerPRF:
+# ZNVER4-NEXT:   Number of physical registers: 192
+# ZNVER4-NEXT:   Total number of mappings created: 2
+# ZNVER4-NEXT:   Max number of mappings used:  2
Index: llvm/test/tools/llvm-mca/X86/read-after-ld-1.s
===
--- llvm/test/tools/llvm-mca/X86/read-after-ld-1.s
+++ llvm/test/tools/llvm-mca/X86/read-after-ld-1.s
@@ -47,6 +47,9 @@
 # ZNVER3-NEXT:Total Cycles:  17
 # ZNVER3-NEXT:Total uOps:2
 
+# ZNVER4-NEXT:Total Cycles:  17
+# ZNVER4-NEXT:Total uOps:2
+
 # BARCELONA:  Dispatch Width:4
 # BARCELONA-NEXT: uOps Per Cycle:0.15
 # BARCELONA-NEXT: IPC:   0.10
@@ -97,6 +100,11 @@
 # ZNVER3-NEXT:IPC:   0.12
 # ZNVER3-NEXT:Block RThroughput: 3.0
 
+# ZNVER4: Dispatch Width:6
+# ZNVER4-NEXT:uOps Per Cycle:0.12
+# ZNVER4-NEXT:IPC:   0.12
+# ZNVER4-NEXT:Block RThroughput: 3.0
+
 # ALL:Timeline view:
 
 # BARCELONA-NEXT: 0123456789
@@ -129,6 +137,9 @@
 # ZNVER3-NEXT:0123456
 # ZNVER3-NEXT:Index 0123456789
 
+# ZNVER4-NEXT:01

[clang-tools-extra] 8b61376 - YAMLParser: llvm::Optional => std::optional

2022-12-15 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-12-15T09:34:31Z
New Revision: 8b61376dfa1d67ef2776bcb4a5f92095132ce2fa

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

LOG: YAMLParser: llvm::Optional => std::optional

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
llvm/include/llvm/Support/YAMLParser.h
llvm/lib/Support/YAMLParser.cpp
llvm/lib/Support/YAMLTraits.cpp
llvm/unittests/Support/YAMLParserTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 6bb0b2ac32513..fedf3aa27169c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -92,7 +92,7 @@ ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef 
LocalName) const {
 static Optional getAsBool(StringRef Value,
 const llvm::Twine &LookupName) {
 
-  if (llvm::Optional Parsed = llvm::yaml::parseBool(Value))
+  if (std::optional Parsed = llvm::yaml::parseBool(Value))
 return *Parsed;
   // To maintain backwards compatability, we support parsing numbers as
   // booleans, even though its not supported in YAML.

diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 2cd40ed774a8a..524cd90105278 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -424,8 +424,7 @@ bool 
IdentifierNamingCheck::HungarianNotation::isOptionEnabled(
   if (Iter == StrMap.end())
 return false;
 
-  llvm::Optional Parsed = llvm::yaml::parseBool(Iter->getValue());
-  return *Parsed;
+  return *llvm::yaml::parseBool(Iter->getValue());
 }
 
 void IdentifierNamingCheck::HungarianNotation::loadFileConfig(

diff  --git a/llvm/include/llvm/Support/YAMLParser.h 
b/llvm/include/llvm/Support/YAMLParser.h
index 231cc1d28c9a0..8c5561e905502 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -78,7 +79,7 @@ bool scanTokens(StringRef Input);
 std::string escape(StringRef Input, bool EscapePrintable = true);
 
 /// Parse \p S as a bool according to https://yaml.org/type/bool.html.
-llvm::Optional parseBool(StringRef S);
+std::optional parseBool(StringRef S);
 
 /// This class represents a YAML stream potentially containing multiple
 ///documents.

diff  --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 7dbb16fe88f74..b85b1eb83ef89 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -760,7 +760,7 @@ std::string yaml::escape(StringRef Input, bool 
EscapePrintable) {
   return EscapedInput;
 }
 
-llvm::Optional yaml::parseBool(StringRef S) {
+std::optional yaml::parseBool(StringRef S) {
   switch (S.size()) {
   case 1:
 switch (S.front()) {

diff  --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 8cdd03149bcfa..4eb0b3afd5630 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -886,7 +886,7 @@ void ScalarTraits::output(const bool &Val, void *, 
raw_ostream &Out) {
 }
 
 StringRef ScalarTraits::input(StringRef Scalar, void *, bool &Val) {
-  if (llvm::Optional Parsed = parseBool(Scalar)) {
+  if (std::optional Parsed = parseBool(Scalar)) {
 Val = *Parsed;
 return StringRef();
   }

diff  --git a/llvm/unittests/Support/YAMLParserTest.cpp 
b/llvm/unittests/Support/YAMLParserTest.cpp
index 14def9c528875..b52a3850c02b7 100644
--- a/llvm/unittests/Support/YAMLParserTest.cpp
+++ b/llvm/unittests/Support/YAMLParserTest.cpp
@@ -343,7 +343,7 @@ TEST(YAMLParser, FlowSequenceTokensOutsideFlowSequence) {
 }
 
 static void expectCanParseBool(StringRef S, bool Expected) {
-  llvm::Optional Parsed = yaml::parseBool(S);
+  std::optional Parsed = yaml::parseBool(S);
   EXPECT_TRUE(Parsed.has_value());
   EXPECT_EQ(*Parsed, Expected);
 }



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


[PATCH] D140090: [Clang][CodeGen] Use poison instead of undef in CodeGen for ARM Builtins [NFC]

2022-12-15 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito created this revision.
ManuelJBrito added reviewers: peterwaller-arm, paulwalker-arm, david-arm.
Herald added subscribers: ctetreau, arphaman, kristof.beyls.
Herald added a project: All.
ManuelJBrito requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang.

In light of the efforts to remove undef, this patch changes the following 
instances of undef to poison in the CodeGen for ARM Builtins:

- `EmitCommonNeonSISDBuiltinExpr` : uses overloaded intrinsics to implement 
SISD expressions, ops go in first entry, the rest of the vector is irrelevant.

- `EmitAArch64SVEBuiltinExpr` : cast from fixed vector to scalable vector with 
the same size therefore undef/poison is hidden.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140090

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem.c
  clang/test/CodeGen/aarch64-neon-vsqadd-float-conversion.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-v8.1a-neon-intrinsics.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c

Index: clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
===
--- clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
+++ clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
@@ -16,13 +16,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s8(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z19test_svdup_neonq_s811__Int8x16_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -32,13 +32,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( undef, <8 x i16> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( poison, <8 x i16> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s1611__Int16x8_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( undef, <8 x i16> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( poison, <8 x i16> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -48,13 +48,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( undef, <4 x i32> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( poison, <4 x i32> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv4i32( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s3211__Int32x4_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( undef, <4 x i32> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( poison, <4 x i32> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv4i32( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -64,13 +64,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( undef, <2 x i64> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( poison, <2 x i64> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv2i64( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s6411__Int64x2_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.

[PATCH] D135247: [clang][analyzer] Add stream functions to StdLibraryFunctionsChecker.

2022-12-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 3 inline comments as done.
balazske added a comment.

In D135247#3993351 , @NoQ wrote:

> Also, similarly to `getenv()`, in these cases domain-specific knowledge may 
> help suppress some unwanted reports. Eg., if a file has been opened 
> successfully, this doesn't technically mean that it'll be open successfully 
> again, but it makes it more likely, and the user does not necessarily care 
> about time-of-check-time-of-use races. So maybe it'd make sense to eventually 
> move some of that stuff to StreamChecker anyway. Maybe not, hard to tell, 
> need to see the results.

This knowledge of "call history" can be implemented in an other checker, for 
the stream functions in `StreamChecker`, for `getenv` in a probably new checker 
(where the variable name could be stored). This `StdLibraryFunctionChecker` 
does not create the branch if the conditions (constraints) of a branch (summary 
case) are not satisfied. If another checker added branches in `evalCall` (for a 
success and failure case or only one of them) these are "selected" here only, 
not added.




Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1060-1064
+} else if (NewState == State) {
+  if (const auto *D = dyn_cast_or_null(Call.getDecl()))
+if (const NoteTag *NT =
+Case.getErrnoConstraint().describe(C, D->getNameAsString()))
+  C.addTransition(NewState, NT);

martong wrote:
> balazske wrote:
> > martong wrote:
> > > Why do we need this change?
> > It is possible that only the errno related state is changed, no new 
> > constraints are added (if the constraint is already here from `evalCall` 
> > but the errno was not set there, for example at `fclose` or other stream 
> > functions maybe no new state is created here). In such case the note tag is 
> > still needed.
> Okay, please add that as a comment to this new hunk.
The add of NoteTags could be improved. Probably a NoteTag should be displayed 
here if the return value (the "function call itself") is interesting. A text 
message should be specified for every function and the errno-related part added 
to it programatically if needed (if errno is interesting).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135247

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


[PATCH] D135247: [clang][analyzer] Add stream functions to StdLibraryFunctionsChecker.

2022-12-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 483106.
balazske marked an inline comment as done.
balazske edited the summary of this revision.
balazske added a comment.

Rebase to current main, fix of comment issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135247

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-errno.c
  clang/test/Analysis/stream-noopen.c

Index: clang/test/Analysis/stream-noopen.c
===
--- /dev/null
+++ clang/test/Analysis/stream-noopen.c
@@ -0,0 +1,97 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=alpha.unix.Stream \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+// enable only StdCLibraryFunctions checker
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+#include "Inputs/errno_var.h"
+
+void clang_analyzer_eval(int);
+
+const char *WBuf = "123456789";
+char RBuf[10];
+
+void test_freopen(FILE *F) {
+  F = freopen("xxx", "w", F);
+  if (F) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+}
+
+void test_fread(FILE *F) {
+  size_t Ret = fread(RBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fwrite(FILE *F) {
+  size_t Ret = fwrite(WBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fclose(FILE *F) {
+  int Ret = fclose(F);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fseek(FILE *F) {
+  int Ret = fseek(F, SEEK_SET, 1);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == -1); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void freadwrite_zerosize(FILE *F) {
+  fwrite(WBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fwrite(WBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fread(RBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fread(RBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+}
Index: clang/test/Analysis/stream-errno.c
===
--- /dev/null
+++ clang/test/Analysis/stream-errno.c
@@ -0,0 +1,138 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.Errno,apiModeling.StdCLibraryFunctions,debug.ExprInspection \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify %s
+
+#include "

[PATCH] D139507: [Intrinsic] Rename flt.rounds intrinsic to get.rounding

2022-12-15 Thread Nikita Popov via Phabricator via cfe-commits
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

(per previous comment, mostly looks good though)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139507

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


[PATCH] D140010: [clang][ExtractAPI] Fix naming of typedef'd anonymous enums

2022-12-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:174-175
+  StringRef Name = Decl->getName();
   if (Name.empty())
 Name = getTypedefName(Decl);
+  if (Name.empty()) {

zixuw wrote:
> dang wrote:
> > zixuw wrote:
> > > Aren't these two lines supposed to do this?
> > Qualified name is never empty, just contains some version of anonymous, 
> > whereas getName() is actually empty for anonymous types. The flow is now, 
> > try to populate with `getName` (which is unqualified and puts us in a 
> > better spot for the eventual support of c++ and nested types). and if that 
> > doesn't work fallback to the qualified name.
> Sorry I meant `getTypedefName(Decl)`, which also tries to get the typedef 
> name for an anonymous tag.
> The patch summary says "Anonymous enums that are typedef'd should take on the 
> name of the typedef." and I was a bit confused of the change.
> 
> Now we have three (two fallbacks) for Enum:
> 1. straightforward `Decl->getName()`, and if that's empty
> 2. `getTypedefName(Decl)`, which calls `Decl->getTypedefNameForAnonDecl()`, 
> and if that fails,
> 3. `Decl->printQualifiedName(OS)`
> 
> My questions:
> 1. Do we need all three? We should be able to get rid of at least one right? 
> The logic seems to be: if enum is named, use it. Otherwise get typedef name 
> if it's part of a typedef. And finally leave something like `(anonymous)` if 
> it's just an unattached anonymous enum.
> 2. For the `printQualifiedName` path, isn't `Name` referencing a local string 
> inside the method?
> 3. structs are also tags that can be anonymous and inside a typedef, do we 
> need similar changes there?
> 
> 
1. Yup that is exactly what I am trying to do here. If you can think of a way 
of removing a chunk then let's do it. The reason for the third fallback is to 
have a name for the container of an anonymous (without a typedef) top level 
enum (there is an example of that in the enum.c test case)
2. Not entirely sure what you mean. If you are referring to the fact that the 
backing storage for `Name` in this case is a local variable, this is fine 
because we copy the string into the `APISet` when constructing the record 
within this method a bit further down.
3. The struct case is a little different, It's not possible to have to have an 
anonymous struct without a typedef at the top level, whereas it is possible to 
do so with an enum (e.g. to introduce some constants). Currently for structs we 
only do `Decl->getName()` and falls back to `getTypedefName(Decl)`. If that 
fails we ignore the struct because it must be a nested anonymous struct (that 
logic is flawed and we should aim to support anonymous structs properly, but 
that would be a follow up patch to this one).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140010

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


[PATCH] D139073: [X86] AMD Zen 4 Initial enablement

2022-12-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

Thanks @GGanesh  - LGTM with one minor - the orphan ZNVER4 checks from the 
llvm-mca tests need removing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139073

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


[PATCH] D140044: [CodeComplete] Complete members of dependent `auto` variables

2022-12-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/test/CodeCompletion/member-access.cpp:121
 // CHECK-DEP-CHAIN: baseTemplateField : [#T#]baseTemplateField
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:111:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
 }

hokein wrote:
> It feels horrible that we have to update all following line numbers whenever 
> we add a new test, no action required here (we can always append a new test, 
> but then tests are not grouped properly)
+1, I would also love to a syntax like `$L-5` or `{{L-5}}` for this in 
FileCheck. Something short and easy to read.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140044

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


[PATCH] D140011: [clang][compiler-rt] Support LLVM_ENABLE_PER_TARGET_RUNTIME_DIR on Arm Linux and BSD

2022-12-15 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 483112.
DavidSpickett added a comment.

Expand the comment and show an example of changed triples.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140011

Files:
  clang/lib/Driver/ToolChain.cpp
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/arm-pc-windows-msvc/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/arm-unknown-linux-gnueabi/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/arm-unknown-linux-gnueabihf/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/armeb-unknown-linux-gnueabi/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/armeb-unknown-linux-gnueabihf/.keep
  clang/test/Driver/arm-float-abi-runtime-path.c
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  llvm/CMakeLists.txt

Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -816,7 +816,7 @@
 mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
 
 # Per target dir not yet supported on Arm 32 bit due to arm vs armhf handling
-if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
+if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux")
   set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
 else()
   set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -433,6 +433,25 @@
 string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}")
 string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
 set(target "${triple_cpu_mips}${triple_suffix_gnu}")
+  elseif("${arch}" MATCHES "^arm")
+# Arch is arm, armhf, armv6m (anything else would come from using
+# COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
+if (${arch} STREQUAL "armhf")
+  # If we are building for hard float but our ABI is soft float.
+  if ("${triple_suffix}" MATCHES ".*eabi$")
+# Change "eabi" -> "eabihf"
+set(triple_suffix "${triple_suffix}hf")
+  endif()
+  # ABI is already set in the triple, don't repeat it in the architecture.
+  set(arch "arm")
+else ()
+  # If we are building for soft float, but the triple's ABI is hard float.
+  if ("${triple_suffix}" MATCHES ".*eabihf$")
+# Change "eabihf" -> "eabi"
+string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}")
+  endif()
+endif()
+set(target "${arch}${triple_suffix}")
   else()
 set(target "${arch}${triple_suffix}")
   endif()
Index: clang/test/Driver/arm-float-abi-runtime-path.c
===
--- /dev/null
+++ clang/test/Driver/arm-float-abi-runtime-path.c
@@ -0,0 +1,33 @@
+/// Check that libraries built with the per target runtime directory layout
+/// are selected correctly when using variations of Arm triples.
+
+// REQUIRES: arm-registered-target
+
+// RUN: %clang %s --target=arm-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMHF %s
+/// "armv7l" should be normalised to just "arm".
+// RUN: %clang %s --target=armv7l-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMHF %s
+
+// RUN: %clang %s --target=arm-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARM %s
+// RUN: %clang %s --target=armv7l-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARM %s
+
+/// armeb triples should be unmodified.
+// RUN: %clang %s --target=armeb-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMEBHF %s
+// RUN: %clang %s --target=armeb-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMEB %s
+
+// RUN: %clang %s --target=arm-pc-windows-msvc -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=WINDOWS %s
+/// armhf-pc... isn't recognised so just check that the float-abi option is ignored
+// RUN: %clang %s --target=arm-pc-windows-msvc -mfloat-abi=hard -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=WINDOWS %s
+
+// ARMHF:   lib{{/|\\}}arm-unknown-linux-gnueabihf{{$}}
+// ARM: lib{{/|\\}}arm-unknown-linux-gnueabi{{$}}
+// ARMEBH

[PATCH] D139073: [X86] AMD Zen 4 Initial enablement

2022-12-15 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh added a comment.

In D139073#3997418 , @RKSimon wrote:

> Thanks @GGanesh  - LGTM with one minor - the orphan ZNVER4 checks from the 
> llvm-mca tests need removing

Thank you! I left them intentionally as this is a stop-gap patch. Agreed! Will 
remove them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139073

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


[PATCH] D137817: [clangd] Improve action `RemoveUsingNamespace` for user-defined literals

2022-12-15 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 483114.
v1nh1shungry added a comment.

apply review's suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137817

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -250,20 +250,33 @@
 foo + 10;
   }
 )cpp"},
-  {// Does not qualify user-defined literals
-   R"cpp(
-  namespace ns {
-  long double operator "" _w(long double);
+  {
+  R"cpp(
+  namespace a {
+  long double operator""_a(long double);
+  inline namespace b {
+  long double operator""_b(long double);
+  } // namespace b
+  } // namespace a
+  using namespace ^a;
+  int main() {
+1.0_a;
+1.0_b;
   }
-  using namespace n^s;
-  int main() { 1.5_w; }
 )cpp",
-   R"cpp(
-  namespace ns {
-  long double operator "" _w(long double);
-  }
+  R"cpp(
+  namespace a {
+  long double operator""_a(long double);
+  inline namespace b {
+  long double operator""_b(long double);
+  } // namespace b
+  } // namespace a
   
-  int main() { 1.5_w; }
+  int main() {using a::operator""_a;
+using a::operator""_b;
+1.0_a;
+1.0_b;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -144,6 +144,9 @@
   // Collect all references to symbols from the namespace for which we're
   // removing the directive.
   std::vector IdentsToQualify;
+  // Collect all using-declarations to add for user-defined literals declared
+  // in the namespace for which we're removing the directive
+  std::map> DeclsToAdd;
   for (auto &D : Inputs.AST->getLocalTopLevelDecls()) {
 findExplicitReferences(
 D,
@@ -164,15 +167,24 @@
 // Avoid adding qualifiers before user-defined literals, e.g.
 //   using namespace std;
 //   auto s = "foo"s; // Must not changed to auto s = "foo" std::s;
-// FIXME: Add a using-directive for user-defined literals
-// declared in an inline namespace, e.g.
-//   using namespace s^td;
-//   int main() { cout << "foo"s; }
-// change to
-//   using namespace std::literals;
-//   int main() { std::cout << "foo"s; }
-if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName)
+// Also add a using-declaration to keep codes well-formed, e.g.
+//   using namespace std;
+//   int main() {
+// auto s = "foo"s;
+//   }
+// will change to
+//   int main() {
+// using std::operator""_s;
+// auto s = "foo"s;
+//   }
+// FIXME: Currently this only works for functions and methods
+//declared right in the top-level
+if (Kind == DeclarationName::NameKind::CXXLiteralOperatorName) {
+  if (const Stmt *Body = D->getBody())
+DeclsToAdd[Body->getBeginLoc()].insert(
+T->getQualifiedNameAsString());
   return;
+}
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
@@ -217,6 +229,16 @@
   /*Length=*/0, Qualifier)))
   return std::move(Err);
   }
+  // Produce replacements to add the using-declarations
+  for (const auto &[Loc, Decls] : DeclsToAdd) {
+std::string UsingDecls;
+for (const auto &D : Decls)
+  UsingDecls += llvm::formatv("using {0};\n", D.getKey());
+UsingDecls.pop_back();
+if (auto Err = R.add(
+tooling::Replacement(SM, Loc.getLocWithOffset(1), 0, UsingDecls)))
+  return std::move(Err);
+  }
   return Effect::mainFileEdit(SM, std::move(R));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139749: Headers: use C++ inline semantics in C++ mode

2022-12-15 Thread Igor Zhukov via Phabricator via cfe-commits
fsb4000 added a subscriber: CaseyCarter.
fsb4000 added a comment.

@CaseyCarter created https://github.com/microsoft/STL/pull/3285
So MSVC STL don't use  with Clang now. It should fix the issues too 
because Clang overrides  (and doesn't override)


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

https://reviews.llvm.org/D139749

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


[PATCH] D140090: [Clang][CodeGen] Use poison instead of undef in CodeGen for ARM Builtins [NFC]

2022-12-15 Thread Manuel Brito via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84b4ff24e94b: [Clang][CodeGen] Use poison instead of undef 
in CodeGen for ARM Builtins [NFC] (authored by ManuelJBrito).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140090

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem.c
  clang/test/CodeGen/aarch64-neon-vsqadd-float-conversion.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-v8.1a-neon-intrinsics.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c

Index: clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
===
--- clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
+++ clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
@@ -16,13 +16,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s8(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z19test_svdup_neonq_s811__Int8x16_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -32,13 +32,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( undef, <8 x i16> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( poison, <8 x i16> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s1611__Int16x8_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( undef, <8 x i16> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv8i16.v8i16( poison, <8 x i16> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -48,13 +48,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( undef, <4 x i32> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( poison, <4 x i32> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv4i32( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s3211__Int32x4_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( undef, <4 x i32> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv4i32.v4i32( poison, <4 x i32> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv4i32( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -64,13 +64,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( undef, <2 x i64> [[N:%.*]], i64 0)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( poison, <2 x i64> [[N:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv2i64( [[TMP0]], i64 0)
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z20test_svdup_neonq_s6411__Int64x2_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( undef, <2 x i64> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.vector.insert.nxv2i64.v2i64( poison, <2 x i64> [[N:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.dupq.lane.nxv2i64( [[TMP0]], i64 0)
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
@@ -80,13 +80,13 @@
 
 // CHECK-LABEL: @test_svdup_neonq_u8(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail 

[clang] 84b4ff2 - [Clang][CodeGen] Use poison instead of undef in CodeGen for ARM Builtins [NFC]

2022-12-15 Thread via cfe-commits

Author: Manuel Brito
Date: 2022-12-15T12:00:53Z
New Revision: 84b4ff24e94bee91ff35f7f29bd748e0432e52ac

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

LOG: [Clang][CodeGen] Use poison instead of undef in CodeGen for ARM Builtins 
[NFC]

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-intrinsics.c
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem.c
clang/test/CodeGen/aarch64-neon-vsqadd-float-conversion.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
clang/test/CodeGen/aarch64-v8.1a-neon-intrinsics.c

clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index be1ce2796c8aa..bd96108d6dc00 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6774,7 +6774,7 @@ static Value *EmitCommonNeonSISDBuiltinExpr(
 Ops[j] = CGF.Builder.CreateTruncOrBitCast(
 Ops[j], cast(ArgTy)->getElementType());
 Ops[j] =
-CGF.Builder.CreateInsertElement(UndefValue::get(ArgTy), Ops[j], C0);
+CGF.Builder.CreateInsertElement(PoisonValue::get(ArgTy), Ops[j], C0);
   }
 
   Value *Result = CGF.EmitNeonCall(F, Ops, s);
@@ -9590,7 +9590,7 @@ Value 
*CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
 
 llvm::Type *OverloadedTy = getSVEVectorForElementType(EltTy);
 Value *InsertSubVec = Builder.CreateInsertVector(
-OverloadedTy, UndefValue::get(OverloadedTy), Vec, Builder.getInt64(0));
+OverloadedTy, PoisonValue::get(OverloadedTy), Vec, 
Builder.getInt64(0));
 
 Function *F =
 CGM.getIntrinsic(Intrinsic::aarch64_sve_dupq_lane, OverloadedTy);
@@ -9698,7 +9698,7 @@ Value 
*CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
   case SVE::BI__builtin_sve_svdup_neonq_f32:
   case SVE::BI__builtin_sve_svdup_neonq_f64:
   case SVE::BI__builtin_sve_svdup_neonq_bf16: {
-Value *Insert = Builder.CreateInsertVector(Ty, UndefValue::get(Ty), Ops[0],
+Value *Insert = Builder.CreateInsertVector(Ty, PoisonValue::get(Ty), 
Ops[0],
Builder.getInt64(0));
 return Builder.CreateIntrinsic(Intrinsic::aarch64_sve_dupq_lane, {Ty},
{Insert, Builder.getInt64(0)});

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics.c
index 35984ead7900f..7c53b9b0af6bb 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -8403,8 +8403,8 @@ uint64_t test_vsubd_u64(uint64_t a, uint64_t b) {
 }
 
 // CHECK-LABEL: @test_vqaddb_s8(
-// CHECK:   [[TMP0:%.*]] = insertelement <8 x i8> undef, i8 %a, i64 0
-// CHECK:   [[TMP1:%.*]] = insertelement <8 x i8> undef, i8 %b, i64 0
+// CHECK:   [[TMP0:%.*]] = insertelement <8 x i8> poison, i8 %a, i64 0
+// CHECK:   [[TMP1:%.*]] = insertelement <8 x i8> poison, i8 %b, i64 0
 // CHECK:   [[VQADDB_S8_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqadd.v8i8(<8 x i8> [[TMP0]], <8 x i8> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <8 x i8> [[VQADDB_S8_I]], i64 0
 // CHECK:   ret i8 [[TMP2]]
@@ -8413,8 +8413,8 @@ int8_t test_vqaddb_s8(int8_t a, int8_t b) {
 }
 
 // CHECK-LABEL: @test_vqaddh_s16(
-// CHECK:   [[TMP0:%.*]] = insertelement <4 x i16> undef, i16 %a, i64 0
-// CHECK:   [[TMP1:%.*]] = insertelement <4 x i16> undef, i16 %b, i64 0
+// CHECK:   [[TMP0:%.*]] = insertelement <4 x i16> poison, i16 %a, i64 0
+// CHECK:   [[TMP1:%.*]] = insertelement <4 x i16> poison, i16 %b, i64 0
 // CHECK:   [[VQADDH_S16_I:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.sqadd.v4i16(<4 x i16> [[TMP0]], <4 x i16> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <4 x i16> [[VQADDH_S16_I]], i64 0
 // CHECK:   ret i16 [[TMP2]]
@@ -8437,8 +8437,8 @@ int64_t test_vqaddd_s64(int64_t a, int64_t b) {
 }
 
 // CHECK-LABEL: @test_vqaddb_u8(
-// CHECK:   [[TMP0:%.*]] = insertelement <8 x i8> undef, i8 %a, i64 0
-// CHECK:   [[TMP1:%.*]] = insertelement <8 x i8> undef, i8 %b, i64 0
+// CHECK:   [[TMP0:%.*]] = insertelement <8 x i8> poison, i8 %a, i64 0
+// CHECK:   [[TMP1:%.*]] = insertelement <8 x i8> poison, i8 %b, i64 0
 // CHECK:   [[VQADDB_U8_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.uqadd.v8i8(<8 x i8> [[TMP0]], <8 x i8> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <8 x i8> [[VQADDB_U8_I]], i64 0
 // CHECK:   ret i8 [[TMP2]]
@@ -8447,8 +8447,8 @@ uint8_t test_vqaddb_u8(uint8_t a, uint8_t b) {
 }
 
 // CHECK-LABEL: @test_vqaddh_u16(
-// CHECK:   [[TMP0:%.*]] = insertelement <4 x i1

[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-15 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev updated this revision to Diff 483121.
dzhidzhoev added a comment.

clang-format'ed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/no-unique-address-3.cpp

Index: clang/test/CodeGenCXX/no-unique-address-3.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Empty (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Second
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   0:0-0 |   short A
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=2,
+// CHECK-NEXT: |  nvsize=1, nvalign=2]
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Foo
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second NZNoUnique
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   3 |   char B
+// CHECK-NEXT: | [sizeof=4, dsize=4, align=2,
+// CHECK-NEXT: |  nvsize=4, nvalign=2]
+
+class Empty {};
+
+// CHECK-LABEL: LLVMType:%class.Second = type { i8, i8 }
+// CHECK-NEXT:  NonVirtualBaseLLVMType:%class.Second.base = type { i8 }
+class Second : Empty {
+  short A : 1;
+};
+
+// CHECK-LABEL:   LLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+class Foo : Empty {
+  [[no_unique_address]] Second NZNoUnique;
+  char B;
+};
+Foo I;
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class SecondEmpty (empty)
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=0, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+class SecondEmpty: Empty {
+};
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Bar
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   1 |   class SecondEmpty ZNoUnique (empty)
+// CHECK-NEXT:   1 | class Empty (base) (empty)
+// CHECK-NEXT:   0 |   char C
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=2, nvalign=1]
+
+// CHECK-LABEL:  LLVMType:%class.Bar = type { i8, i8 }
+// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.Bar = type { i8, i8 }
+class Bar : Empty {
+  [[no_unique_address]] SecondEmpty ZNoUnique;
+  char C;
+};
+Bar J;
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class IntFieldClass
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second Field
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   4 |   int C
+// CHECK-NEXT: | [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT: |  nvsize=8, nvalign=4]
+
+// CHECK-LABEL:   LLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+class IntFieldClass : Empty {
+  [[no_unique_address]] Second Field;
+  int C;
+};
+IntFieldClass K;
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,9 +379,14 @@
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
+  // Use base subobject layout for the potentially-overlapping field,
+  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  getStorageType(*Field), *Field));
+  Field->isPotentiallyOverlapping()
+  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
+  : getStorageType(*Field),
+  *Field));
   ++Field;
 } else {
   ++Field;
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayout

[clang] 731abdf - [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2022-12-15T15:10:41+03:00
New Revision: 731abdfdcc33d813e6c3b4b89eff307aa5c18083

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

LOG: [clang][CodeGen] Use base subobject type layout for 
potentially-overlapping fields

RecordLayoutBuilder assumes the size of a potentially-overlapping field
with non-zero size as the size of the base subobject type corresponding
to the field type.
Make CGRecordLayoutBuilder to acknowledge that in order to avoid incorrect
padding insertion.

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

Added: 
clang/test/CodeGenCXX/no-unique-address-3.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index cd33fcef56619..268ec7deeb814 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3062,6 +3062,10 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
+  /// Determine if this field is of potentially-overlapping class type, that
+  /// is, subobject with the [[no_unique_address]] attribute
+  bool isPotentiallyOverlapping() const;
+
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index b1fdc897bf27e..0f15d7b3b6d33 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4339,6 +4339,10 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
+bool FieldDecl::isPotentiallyOverlapping() const {
+  return hasAttr() && getType()->getAsCXXRecordDecl();
+}
+
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 52bd3f20221f4..56cdbb75dd4b2 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,9 +1853,8 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
  bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
-  bool PotentiallyOverlapping = D->hasAttr() && 
FieldClass;
   bool IsOverlappingEmptyField =
-  PotentiallyOverlapping && FieldClass->isEmpty();
+  D->isPotentiallyOverlapping() && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
   (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1916,7 +1915,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
 // A potentially-overlapping field occupies its dsize or nvsize, whichever
 // is larger.
-if (PotentiallyOverlapping) {
+if (D->isPotentiallyOverlapping()) {
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
   EffectiveFieldSize =
   std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 6f85bca8a2013..0f2d764bc9498 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,9 +379,14 @@ void CGRecordLowering::accumulateFields() {
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
+  // Use base subobject layout for the potentially-overlapping field,
+  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  getStorageType(*Field), *Field));
+  Field->isPotentiallyOverlapping()
+  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
+  : getStorageType(*Field),
+  *Field));
   ++Field;
 } else {
   ++Field;

diff  --git a/clang/test/CodeGenCXX/no-unique-address-3.cpp 
b/clang/test/CodeGenCXX/no-unique-address-3.cpp
new file mode 100644
index 0..f21e9d1d2b01e
--- /dev/null
+++ b/clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm 
-fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Empty (e

[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2022-12-15 Thread Vladislav Dzhidzhoev 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 rG731abdfdcc33: [clang][CodeGen] Use base subobject type 
layout for potentially-overlapping… (authored by dzhidzhoev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/no-unique-address-3.cpp

Index: clang/test/CodeGenCXX/no-unique-address-3.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/no-unique-address-3.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Empty (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Second
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   0:0-0 |   short A
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=2,
+// CHECK-NEXT: |  nvsize=1, nvalign=2]
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Foo
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second NZNoUnique
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   3 |   char B
+// CHECK-NEXT: | [sizeof=4, dsize=4, align=2,
+// CHECK-NEXT: |  nvsize=4, nvalign=2]
+
+class Empty {};
+
+// CHECK-LABEL: LLVMType:%class.Second = type { i8, i8 }
+// CHECK-NEXT:  NonVirtualBaseLLVMType:%class.Second.base = type { i8 }
+class Second : Empty {
+  short A : 1;
+};
+
+// CHECK-LABEL:   LLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
+class Foo : Empty {
+  [[no_unique_address]] Second NZNoUnique;
+  char B;
+};
+Foo I;
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class SecondEmpty (empty)
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT: | [sizeof=1, dsize=0, align=1,
+// CHECK-NEXT: |  nvsize=1, nvalign=1]
+class SecondEmpty: Empty {
+};
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class Bar
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   1 |   class SecondEmpty ZNoUnique (empty)
+// CHECK-NEXT:   1 | class Empty (base) (empty)
+// CHECK-NEXT:   0 |   char C
+// CHECK-NEXT: | [sizeof=2, dsize=1, align=1,
+// CHECK-NEXT: |  nvsize=2, nvalign=1]
+
+// CHECK-LABEL:  LLVMType:%class.Bar = type { i8, i8 }
+// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.Bar = type { i8, i8 }
+class Bar : Empty {
+  [[no_unique_address]] SecondEmpty ZNoUnique;
+  char C;
+};
+Bar J;
+
+// CHECK:   *** Dumping AST Record Layout
+// CHECK-NEXT:   0 | class IntFieldClass
+// CHECK-NEXT:   0 |   class Empty (base) (empty)
+// CHECK-NEXT:   2 |   class Second Field
+// CHECK-NEXT:   2 | class Empty (base) (empty)
+// CHECK-NEXT:   2:0-0 | short A
+// CHECK-NEXT:   4 |   int C
+// CHECK-NEXT: | [sizeof=8, dsize=8, align=4,
+// CHECK-NEXT: |  nvsize=8, nvalign=4]
+
+// CHECK-LABEL:   LLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+// CHECK-NEXT:NonVirtualBaseLLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
+class IntFieldClass : Empty {
+  [[no_unique_address]] Second Field;
+  int C;
+};
+IntFieldClass K;
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,9 +379,14 @@
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
+  // Use base subobject layout for the potentially-overlapping field,
+  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  getStorageType(*Field), *Field));
+  Field->isPotentiallyOverlapping()
+  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
+  : getStorageType(*Field),
+  *Field));
   ++Field;
 } else {
   ++Field;
Index: clang/l

[PATCH] D136554: Implement CWG2631

2022-12-15 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D136554#3996643 , @rupprecht wrote:

> Here's a well-formed reproducer:

Thanks a lot.
We were transforming the initializer in a context where the this pointer was 
not set up properly, so if it was referring to this, explicitly or implicitly, 
it would crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D136554: Implement CWG2631

2022-12-15 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 483133.
cor3ntin added a comment.

Properly transform the this pointer in member initializers 
that need to be rewritten.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631";>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632";>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,73 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
+
+namespace check_immediate_invocations_in_templates {
+
+template 
+struct G {
+T line = __builtin_LINE();
+};
+template 
+struct S {
+int i = G{}.line;
+};
+static_assert(S{}.i != // intentional new line
+  S{}.i);
+
+template 
+constexpr int f(int i = G{}.line) {
+return i;
+}
+
+static_assert(f() != // intentional new line
+  f());
+}
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// RUN: %clang_cc1 -f

[PATCH] D140086: [analyzer][solver] Improve reasoning for not equal to operator

2022-12-15 Thread Manas Gupta via Phabricator via cfe-commits
manas updated this revision to Diff 483135.
manas added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140086

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -303,7 +303,8 @@
 
   if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
 // s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
-clang_analyzer_eval(u1 != s1); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+clang_analyzer_eval(s1 != u1); // expected-warning{{TRUE}}
   }
 
   if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
@@ -400,12 +401,10 @@
 clang_analyzer_eval(uch != sch); // expected-warning{{UNKNOWN}}
   }
 
-  // FIXME: Casting smaller signed types to unsigned one may leave us with
-  // overlapping values, falsely indicating UNKNOWN, where it is possible to
-  // assert TRUE.
   if (uch > 1 && sch < 1) {
 // uch: [2, UCHAR_MAX], sch: [SCHAR_MIN, 0]
-clang_analyzer_eval(uch != sch); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(uch != sch); // expected-warning{{TRUE}}
+clang_analyzer_eval(sch != uch); // expected-warning{{TRUE}}
   }
 
   if (uch <= 1 && uch >= 1 && sch <= 1 && sch >= 1) {
@@ -419,10 +418,9 @@
 clang_analyzer_eval(ush != ssh); // expected-warning{{UNKNOWN}}
   }
 
-  // FIXME: Casting leave us with overlapping values. Should be TRUE.
   if (ush > 1 && ssh < 1) {
 // ush: [2, USHRT_MAX], ssh: [SHRT_MIN, 0]
-clang_analyzer_eval(ush != ssh); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(ush != ssh); // expected-warning{{TRUE}}
   }
 
   if (ush <= 1 && ush >= 1 && ssh <= 1 && ssh >= 1) {
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1624,7 +1624,52 @@
   if (LHS.getAPSIntType() == RHS.getAPSIntType()) {
 if (intersect(RangeFactory, LHS, RHS).isEmpty())
   return getTrueRange(T);
+
   } else {
+// We can only lose information if we are casting smaller signed type to
+// bigger unsigned type. For e.g.,
+//LHS (unsigned short): [2, USHRT_MAX]
+//RHS   (signed short): [SHRT_MIN, 0]
+//
+// Casting RHS to LHS type will leave us with overlapping values
+//CastedRHS : [0, 0] U [SHRT_MAX + 1, USHRT_MAX]
+//
+// We can avoid this by checking if signed type's maximum value is lesser
+// than unsigned type's minimum value.
+
+// If both have different signs then only we can get more information.
+if (LHS.isUnsigned() ^ RHS.isUnsigned()) {
+  if (LHS.isUnsigned() && (LHS.getBitWidth() >= RHS.getBitWidth())) {
+
+// If signed range is =Zero, then maximum value of signed
+// type should be lesser than minimum value of unsigned type.
+const llvm::APSInt CastedRHSMax =
+LHS.getAPSIntType().convert(RHS.getMaxValue());
+
+if (CastedRHSMax < LHS.getMinValue())
+  return getTrueRange(T);
+
+  } else if (RHS.isUnsigned() && (LHS.getBitWidth() <= RHS.getBitWidth())) {
+
+llvm::APSInt Zero = LHS.getAPSIntType().getZeroValue();
+bool IsLHSNegative = LHS.getMaxValue() < Zero;
+if (IsLHSNegative)
+  return getTrueRange(T);
+
+const llvm::APSInt CastedLHSMax =
+RHS.getAPSIntType().convert(LHS.getMaxValue());
+if (CastedLHSMax < RHS.getMinValue())
+  return getTrueRange(T);
+  }
+}
+
 // Both RangeSets should be casted to bigger unsigned type.
 APSIntType CastingType(std::max(LHS.getBitWidth(), RHS.getBitWidth()),
LHS.isUnsigned() || RHS.isUnsigned());
@@ -2147,7 +2192,6 @@
   RangeSet::Factory &RangeFactory;
 };
 
-
 bool ConstraintAssignor::assignSymExprToConst(const SymExpr *Sym,
   const llvm::APSInt &Constraint) {
   llvm::SmallSet SimplifiedClasses;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7b36538 - [clang-format] make doc for SLS_Inline more clearly

2022-12-15 Thread via cfe-commits

Author: Backl1ght
Date: 2022-12-15T20:51:53+08:00
New Revision: 7b36538156b7742627b422c0e6a3a18ec13b99b3

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

LOG: [clang-format] make doc for SLS_Inline more clearly

Reviewed By: HazardyKnusperkeks, MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D139937

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 76ae54b6ef6da..969fce82781c2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@ the configuration (without a prefix: ``Auto``).
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 93b84e1bfddfb..b7fbe4b97c6db 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@ struct FormatStyle {
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a 
function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.



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


[PATCH] D139937: [clang-format] make doc for SLS_Inline more clearly

2022-12-15 Thread Zhikai Zeng 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 rG7b36538156b7: [clang-format] make doc for SLS_Inline more 
clearly (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139937

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a 
function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -688,12 +688,12 @@
 ///   };
 /// \endcode
 SLS_Empty,
-/// Merge lambda into a single line if argument of a function.
+/// Merge lambda into a single line if the lambda is argument of a function.
 /// \code
-///   auto lambda = [](int a) {
-///   return a;
+///   auto lambda = [](int x, int y) {
+///   return x < y;
 ///   };
-///   sort(a.begin(), a.end(), []() { return x < y; });
+///   sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 /// \endcode
 SLS_Inline,
 /// Merge all lambdas fitting on a single line.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1191,14 +1191,14 @@
   };
 
   * ``SLS_Inline`` (in configuration: ``Inline``)
-Merge lambda into a single line if argument of a function.
+Merge lambda into a single line if the lambda is argument of a function.
 
 .. code-block:: c++
 
-  auto lambda = [](int a) {
-  return a;
+  auto lambda = [](int x, int y) {
+  return x < y;
   };
-  sort(a.begin(), a.end(), []() { return x < y; });
+  sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
 
   * ``SLS_All`` (in configuration: ``All``)
 Merge all lambdas fitting on a single line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a subscriber: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140095

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -524,6 +524,10 @@
   return getAsSugar(this);
 }
 
+template <> const UsingType *Type::getAs() const {
+  return getAsSugar(this);
+}
+
 template <> const TemplateSpecializationType *Type::getAs() const {
   return getAsSugar(this);
 }
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2592,6 +2592,7 @@
 /// This will check for a TypedefType by removing any existing sugar
 /// until it reaches a TypedefType or a non-sugared type.
 template <> const TypedefType *Type::getAs() const;
+template <> const UsingType *Type::getAs() const;
 
 /// This will check for a TemplateSpecializationType by removing any
 /// existing sugar until it reaches a TemplateSpecializationType or a
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
@@ -210,6 +210,19 @@
   };
   struct Foo {};)cpp",
"void test(unique_ptr &V) { V.^release(); }");
+  // Respect the sugar type (typedef, using-type).
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using $explicit^Bar = ns::Foo;)cpp",
+   "void test(Bar b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void test(Foo b) { b.^a; }");
+  testWalk(R"cpp(
+  namespace ns { template struct Foo { int a; }; }
+  using ns::$explicit^Foo;)cpp",
+   "void k(Foo b) { b.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -27,16 +27,6 @@
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
 
-  bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
-// For using-templates, only mark the alias.
-if (auto *USD = TN.getAsUsingShadowDecl()) {
-  report(Loc, USD);
-  return true;
-}
-report(Loc, TN.getAsTemplateDecl());
-return true;
-  }
-
   void report(SourceLocation Loc, NamedDecl *ND,
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
@@ -44,9 +34,22 @@
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
+  NamedDecl *resolveTemplateName(TemplateName TN) {
+// For using-templates, only mark the alias.
+if (auto *USD = TN.getAsUsingShadowDecl())
+  return USD;
+return TN.getAsTemplateDecl();
+  }
   NamedDecl *resolveType(QualType Type) {
 if (Type->isPointerType())
   Type = Type->getPointeeType();
+if (const auto *TT = Type->getAs())
+  return TT->getDecl();
+if (const auto *UT = Type->getAs())
+  return UT->getFoundDecl();
+if (const auto *TST = Type->getAs())
+  return resolveTemplateName(TST->getTemplateName());
+
 return Type->getAsRecordDecl();
   }
 
@@ -126,15 +129,17 @@
 
   bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
 // FIXME: Handle explicit specializations.
-return handleTemplateName(TL.getTemplateNameLoc(),
-  TL.getTypePtr()->getTemplateName());
+report(TL.getTemplateNameLoc(),
+   resolveTemplateName(TL.getTypePtr()->getTemplateName()));
+return true;
   }
 
   bool VisitDeducedTemplateSpecializationTypeLoc(
   DeducedTemplateSpecializationTypeLoc TL) {
 // FIXME: Handle specializations.
-return handleTemplateName(TL.getTemplateNameLoc(),
-  TL.getTypePtr()->getTemplateName());
+report(TL.getTemplateNameLoc(),
+   resolveTemplateName(TL.getTypePtr()->getTemplateName()));
+return true;
   }
 
   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &TL) {
@@ -142,9 +147,11 @@
 // Template-template parameters require special attention, as there's no
 // TemplateNameLoc.
 if (Arg.getKind() == TemplateArgument::Template ||
-Arg.getKind() == TemplateArgument::TemplateExpansion)
-  return hand

[PATCH] D139073: [X86] AMD Zen 4 Initial enablement

2022-12-15 Thread Ganesh Gopalasubramanian via Phabricator via cfe-commits
GGanesh updated this revision to Diff 483141.
GGanesh added a comment.

Fixed the tests

tools/llvm-mca/X86/cpus.s
tools/llvm-mca/X86/read-after-ld-1.s
tools/llvm-mca/X86/register-file-statistics.s
tools/llvm-mca/X86/scheduler-queue-usage.s


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139073

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Frontend/x86-target-cpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86PfmCounters.td
  llvm/test/CodeGen/X86/cpus-amd.ll
  llvm/test/CodeGen/X86/rdpru.ll
  llvm/test/CodeGen/X86/slow-unaligned-mem.ll
  llvm/test/CodeGen/X86/sqrt-fastmath-tune.ll
  llvm/test/CodeGen/X86/vector-shuffle-fast-per-lane.ll
  llvm/test/CodeGen/X86/x86-64-double-shifts-var.ll
  llvm/test/MC/X86/x86_long_nop.s

Index: llvm/test/MC/X86/x86_long_nop.s
===
--- llvm/test/MC/X86/x86_long_nop.s
+++ llvm/test/MC/X86/x86_long_nop.s
@@ -17,6 +17,8 @@
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu %s -mcpu=znver2 | llvm-objdump -d --no-show-raw-insn - | FileCheck %s --check-prefix=LNOP15
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=x86_64-pc-linux-gnu -mcpu=znver3 %s | llvm-objdump -d --no-show-raw-insn - | FileCheck %s --check-prefix=LNOP15
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu %s -mcpu=znver3 | llvm-objdump -d --no-show-raw-insn - | FileCheck %s --check-prefix=LNOP15
+# RUN: llvm-mc -filetype=obj -arch=x86 -triple=x86_64-pc-linux-gnu -mcpu=znver4 %s | llvm-objdump -d --no-show-raw-insn - | FileCheck %s --check-prefix=LNOP15
+# RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu %s -mcpu=znver4 | llvm-objdump -d --no-show-raw-insn - | FileCheck %s --check-prefix=LNOP15
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu -mcpu=nehalem %s | llvm-objdump -d --no-show-raw-insn - | FileCheck --check-prefix=LNOP10 %s
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu -mcpu=westmere %s | llvm-objdump -d --no-show-raw-insn - | FileCheck --check-prefix=LNOP10 %s
 # RUN: llvm-mc -filetype=obj -arch=x86 -triple=i686-pc-linux-gnu -mcpu=sandybridge %s | llvm-objdump -d --no-show-raw-insn - | FileCheck --check-prefix=LNOP15 %s
Index: llvm/test/CodeGen/X86/x86-64-double-shifts-var.ll
===
--- llvm/test/CodeGen/X86/x86-64-double-shifts-var.ll
+++ llvm/test/CodeGen/X86/x86-64-double-shifts-var.ll
@@ -15,6 +15,7 @@
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver1 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver2 | FileCheck %s
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver3 | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver4 | FileCheck %s
 
 ; Verify that for the X86_64 processors that are known to have poor latency
 ; double precision shift instructions we do not generate 'shld' or 'shrd'
Index: llvm/test/CodeGen/X86/vector-shuffle-fast-per-lane.ll
===
--- llvm/test/CodeGen/X86/vector-shuffle-fast-per-lane.ll
+++ llvm/test/CodeGen/X86/vector-shuffle-fast-per-lane.ll
@@ -7,6 +7,7 @@
 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=znver1 | FileCheck %s --check-prefixes=FAST
 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=znver2 | FileCheck %s --check-prefixes=FAST
 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=znver3 | FileCheck %s --check-prefixes=FAST
+; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=znver4 | FileCheck %s --check-prefixes=FAST
 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=haswell | FileCheck %s --check-prefixes=FAST
 ; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=skx | FileCheck %s --check-prefixes=FAST
 
Index: llvm/test/CodeGen/X86/sqrt-fastmath-tune.ll
===
--- llvm/test/CodeGen/X86/sqrt-fastmath-tune.ll
+++ llvm/test/CodeGen/X86/sqrt-fastmath-tune.ll
@@ -5,6 +5,7 @@
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=skylake | FileCheck %s --check-prefixes=FAST-SCALAR,FAST-VECTOR
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver1  | FileCheck %s --check-prefixes=FAST-SCALAR,FAST-VECTOR
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver3  | FileCheck %s --check-prefixes=FAST-SCALAR,FAST-VECTOR
+; RUN: llc < %s -mtriple=x86_64-- -mcpu=znver4  | FileCheck %s --check-prefixes=FAST-SCALAR,FAST-VECTOR
 ; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64  | FileCheck %s --check-prefixes=X86-64
 
 define float @f32_no_daz(float %f) #0 {
Index: llvm/test/CodeGen/X86/slow-unaligned-mem.ll

[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/include/clang/AST/TemplateUtils.h:19
+namespace clang {
+namespace TemplateUtils {
+/// Make a best-effort determination of whether the type T can be produced by

dblaikie wrote:
> aprantl wrote:
> > It looks like all the other namespaces in Clang are all lowercase?
> Yeah, +1 to the naming.
> 
> & maybe not introducing a new "utils" bucket - they can be a bit of a dumping 
> ground. Could this operation belong elsewhere/in some existing type, or maybe 
> doesn't need a namespace wrapper - could be a free function in the `clang` 
> namespace?)
I suppose this could just be a static function on `clang::TypePrinter`. We use 
it from `CGDebugInfo` already anyway so it wouldn't be an extra dependency. 
Wdyt? @aprantl @dblaikie 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[PATCH] D140080: [clang][PPC] Supporting -mcpu=405

2022-12-15 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.
This revision is now accepted and ready to land.

I don't think the comments require another round of review. Thanks for fixing 
this.




Comment at: clang/lib/Driver/ToolChains/Arch/PPC.cpp:23-29
+static constexpr llvm::StringLiteral GenericCPUNames[] = {{"generic"}, 
{"405"}};
+
+/// Check if Name is known to be equivalent to "generic".
+static bool isGenericCPUName(const StringRef &Name) {
+  return llvm::is_contained(GenericCPUNames, Name);
+}
+

While I understand the motivation here, I think that this is overkill. We in 
fact hope not to have to grow the set of CPU ID's that we treat as generic.



Comment at: clang/lib/Driver/ToolChains/Arch/PPC.cpp:42
 
-if (CPUName == "generic")
   return getPPCGenericTargetCPU(T);

I think we should change this to check for `generic` or `405` and add a comment 
similar to the following:
```
// Clang/LLVM does not actually support code generation
// for the 405 CPU. However, there are uses of this CPU ID
// in projects that previously used GCC and rely on Clang
// accepting it. Clang has always ignored it and passed the
// generic CPU ID to the back end.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140080

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


[PATCH] D138668: Correct typos

2022-12-15 Thread Sprite via Phabricator via cfe-commits
Sprite added a comment.

@jpienaar Sorry, this is my first time using this platform. I just tried 
running `arc land --revision D138668` and it is trying to push my local commit 
(I have rebased manually) to the `main` branch on 
`https://github.com/llvm/llvm-project.git`, and apparently I don't have push 
access. What should I do?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138668

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


[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:2095-2097
+NamedDecl const *ND = Args.TList->getParam(i);
+defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());

dblaikie wrote:
> Could we pull this snipped out and do it before the switch - so we don't have 
> to repeat it for each different kind of template parameter type?
yup makes sense!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

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


[PATCH] D139073: [X86] AMD Zen 4 Initial enablement

2022-12-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.

cheers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139073

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


[PATCH] D140080: [clang][PPC] Supporting -mcpu=405

2022-12-15 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 483146.
qiongsiwu1 added a comment.

Addressing review comments. Thanks for the review @nemanjai !!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140080

Files:
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Driver/ppc-cpus.c


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | 
FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
-if (CPUName == "generic")
+// Clang/LLVM does not actually support code generation
+// for the 405 CPU. However, there are uses of this CPU ID
+// in projects that previously used GCC and rely on Clang
+// accepting it. Clang has always ignored it and passed the
+// generic CPU ID to the back end.
+if (CPUName == "generic" || CPUName == "405")
   return getPPCGenericTargetCPU(T);
 
 if (CPUName == "native") {


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s --check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
-if (CPUName == "generic")
+// Clang/LLVM does not actually support code generation
+// for the 405 CPU. However, there are uses of this CPU ID
+// in projects that previously used GCC and rely on Clang
+// accepting it. Clang has always ignored it and passed the
+// generic CPU ID to the back end.
+if (CPUName == "generic" || CPUName == "405")
   return getPPCGenericTargetCPU(T);
 
 if (CPUName == "native") {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-12-15 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D128372#3991516 , @MyDeveloperDay 
wrote:

> Ironically as an aside... looking back at the review because of the discource 
> article.
>
> The whole reason why I added the [[nodiscard]] checker to clang-tidy 4 years 
> ago was to cover exactly this use case...and many others like it where users 
> have a function which returns a boolean and takes no arguments are pointer or 
> reference (empty() included)
>
> https://reviews.llvm.org/D55433
>
> Shouldn't people be using this checker to add nodiscard and let the compiler 
> to the heavy lifting. Was there a use case as to why that solution doesn't 
> solve this?

That check is for library authors: this one is for library users. There are a 
non-insignificant number of cases where an unused call to `empty` pops up, 
hence the desire for this check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-12-15 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D125291#3548671 , @jyknight wrote:

> So, I've been spending some significant time looking into this. I found that 
> I couldn't really review this change for correctness, because I find it 
> basically impossible to figure out whether the intrinsic calls have actually 
> been added to all the right places in Clang or not. (And my intuition said 
> "not", but then couldn't tell me where it's wrong.)
>
> So, I started hacking up a prototype of a change to make the type of a TLS 
> global variable be `token` instead of `ptr`. This allows missing calls to 
> manifest as IR construction errors.
>
> So far the biggest missing piece that identified in this review is 
> function-local thread_locals (although I haven't actually gotten something 
> fully working). Sadly, the handling of function-local statics in Clang is 
> really rather hairy, what with objc blocks and openmp support both doing 
> things that seem rather ill-advised to me. I'm toying with some cleanups 
> there, to see if it can be simplified a bit. I don't have a full idea, yet, 
> what changes need to be made to this review.
>
> Anyhow -- I think the prototype I'm fiddling with is also along the path to 
> the ideal long-term state, but pushing it beyond a prototype seems like it'll 
> be a pain in the ass due to the bitcode compatibility requirement. (The 
> bitcode upgrader would need to know how to transform all constant expressions 
> using a TLS global into non-constant IR instructions, starting with a call to 
> llvm.threadlocal.address -- in every function where the "constant" is 
> referenced. For uses outside a function body, it transforms to an arbitrary 
> address (e.g. null), instead.)

Do you plan to pursue this? We now have the necessary infrastructure to make 
the bitcode upgrade simple, and I think it would be great to include this 
change in LLVM 16, so we directly introduce llvm.threadlocal.address in its 
final form.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125291

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


[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483155.
Michael137 added a comment.

- Hoist common code out of switch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -7,26 +7,33 @@
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
-// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i8 0)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
value: i1 false)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
 
 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
-// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]]}
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], 
![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
+// CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
-template 
+template 
+class bar {
+};
+
+template >
 class foo {
 };
 
 int main() {
-  foo f1;
+  foo f1;
   foo<> f2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateUtils.h"
 #include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -1999,35 +2000,23 @@
 const TemplateArgument &TA = Args.Args[i];
 StringRef Name;
 bool defaultParameter = false;
-if (Args.TList)
+if (Args.TList) {
   Name = Args.TList->getParam(i)->getName();
+
+  NamedDecl const *ND = Args.TList->getParam(i);
+  defaultParameter = TemplateUtils::isSubstitutedDefaultArgument(
+  CGM.getContext(), TA, ND, Args.Args, Args.TList->getDepth());
+}
+
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-
-  if (Args.TList)
-if (auto *templateType =
-
dyn_cast_or_null(Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
   TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
   TheCU, Name, TTy, defaultParameter));
 
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (Args.TList)
-if (auto *templateType = dyn_cast_or_null(
-Args.TList->getParam(i)))
-  if (templateType->hasDefaultArgument() &&
-  !templateType->getDefaultArgument()->isValueDependent())
-defaultParameter = llvm::APSInt::isSameValue(
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()),
-TA.getAsIntegral());
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;


Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 updated this revision to Diff 483156.
Michael137 added a comment.

- Remove now redundant `isSubstitutedDefaultArgument` call


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.h
===
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -518,10 +518,10 @@
 /// \param Name Value parameter name.
 /// \param Ty   Parameter type.
 /// \param Val  The fully qualified name of the template.
-DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
-  StringRef Name,
-  DIType *Ty,
-  StringRef Val);
+/// \param IsDefaultParameter is default or not.
+DITemplateValueParameter *
+createTemplateTemplateParameter(DIScope *Scope, StringRef Name, DIType *Ty,
+StringRef Val, bool IsDefault);
 
 /// Create debugging information for a template parameter pack.
 /// \param ScopeScope in which this type is defined.
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -23,17 +23,37 @@
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, 
defaulted: true, value: i1 true)
 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, 
defaulted: true)
 
+// CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B1_TYPE:[0-9]+]]
+// CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
+
+// CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[B2_TYPE:[0-9]+]]
+// CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateValueParameter(tag: 
DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
+
 template 
 class bar {
 };
 
+template 
+class qux {
+};
+
 template >
 class foo {
 };
 
+template  class CT = bar>
+class baz {
+};
+
 int main() {
   foo f1;
   foo<> f2;
+  baz b1;
+  baz<> b2;
   return 0;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2092,7 +2092,7 @@
   TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
   OS, getPrintingPolicy());
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-  TheCU, Name, nullptr, OS.str()));
+  TheCU, Name, nullptr, OS.str(), defaultParameter));
   break;
 }
 case TemplateArgument::Pack:


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -474,10 +474,11 @@
 
 DITemplateValueParameter *
 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name,
-   DIType *Ty, StringRef Val) {
+   DIType *Ty, StringRef Val,
+   bool IsDefault) {
   return createTemplateValueParameterHelper(
   VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty,
-  false, MDString::get(VMContext, Val));
+  IsDefault, MDString::get(VMContext, Val));
 }
 
 DITemplateValueParameter *
Index: llvm/include/llvm/IR/DIBuilder.

[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-15 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added subscribers: martong, kadircet, arphaman, xazax.hun.
Herald added a project: All.
merrymeerkat requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This change will allow users to call getNullability() without providing an 
ASTContext.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140104

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaType.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -1330,8 +1330,7 @@
   if (T.isNull())
 return CXTypeNullability_Invalid;
 
-  ASTContext &Ctx = cxtu::getASTUnit(GetTU(CT))->getASTContext();
-  if (auto nullability = T->getNullability(Ctx)) {
+  if (auto nullability = T->getNullability()) {
 switch (*nullability) {
   case NullabilityKind::NonNull:
 return CXTypeNullability_NonNull;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -4701,8 +4701,8 @@
 // inner pointers.
 complainAboutMissingNullability = CAMN_InnerPointers;
 
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   // Note that we allow but don't require nullability on dependent types.
   ++NumPointersRemaining;
 }
@@ -4923,8 +4923,8 @@
   // If the type itself could have nullability but does not, infer pointer
   // nullability and perform consistency checking.
   if (S.CodeSynthesisContexts.empty()) {
-if (T->canHaveNullability(/*ResultIfUnknown*/false) &&
-!T->getNullability(S.Context)) {
+if (T->canHaveNullability(/*ResultIfUnknown*/ false) &&
+!T->getNullability()) {
   if (isVaList(T)) {
 // Record that we've seen a pointer, but do nothing else.
 if (NumPointersRemaining > 0)
@@ -4947,9 +4947,8 @@
   }
 }
 
-if (complainAboutMissingNullability == CAMN_Yes &&
-T->isArrayType() && !T->getNullability(S.Context) && !isVaList(T) &&
-D.isPrototypeContext() &&
+if (complainAboutMissingNullability == CAMN_Yes && T->isArrayType() &&
+!T->getNullability() && !isVaList(T) && D.isPrototypeContext() &&
 !hasOuterPointerLikeChunk(D, D.getNumTypeObjects())) {
   checkNullabilityConsistency(S, SimplePointerKind::Array,
   D.getDeclSpec().getTypeSpecTypeLoc());
@@ -7389,7 +7388,7 @@
   // This (unlike the code above) looks through typedefs that might
   // have nullability specifiers on them, which means we cannot
   // provide a useful Fix-It.
-  if (auto existingNullability = desugared->getNullability(S.Context)) {
+  if (auto existingNullability = desugared->getNullability()) {
 if (nullability != *existingNullability) {
   S.Diag(nullabilityLoc, diag::err_nullability_conflicting)
 << DiagNullabilityKind(nullability, isContextSensitive)
@@ -7488,7 +7487,7 @@
   // If we started with an object pointer type, rebuild it.
   if (ptrType) {
 equivType = S.Context.getObjCObjectPointerType(equivType);
-if (auto nullability = type->getNullability(S.Context)) {
+if (auto nullability = type->getNullability()) {
   // We create a nullability attribute from the __kindof attribute.
   // Make sure that will make sense.
   assert(attr.getAttributeSpellingListIndex() == 0 &&
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -2754,7 +2754,7 @@
 
   if (Attributes & ObjCPropertyAttribute::kind_weak) {
 // 'weak' and 'nonnull' are mutually exclusive.
-if (auto nullability = PropertyTy->getNullability(Context)) {
+if (auto nullability = PropertyTy->getNullability()) {
   if (*nullability == NullabilityKind::NonNull)
 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
   << "nonnull" << "weak";
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@

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

2022-12-15 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 483167.
zahiraam marked an inline comment as done.

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

https://reviews.llvm.org/D136176

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGExprComplex.cpp
  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,34 @@
+// 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 i386 -fexcess-precision=16 -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang -### -target i386 -fexcess-precision=none -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-NONE %s
+
+// RUN: %clang -### -target x86_64 -fexcess-precision=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST %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=16 -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=none -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=CHECK-ERR-NONE %s
+
+// RUN: %clang -### -target aarch64 -fexcess-precision=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=standard -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=16 -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-16 %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=none -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-NONE %s
+
+// CHECK-FAST: "-ffloat16-excess-precision=fast"
+// CHECK-STD: "-ffloat16-excess-precision=standard"
+// CHECK-NONE: "-ffloat16-excess-precision=none"
+// CHECK-ERR-NONE: unsupported argument 'none' to option '-fexcess-precision='
+// CHECK: "-cc1"
+// CHECK-NOT: "-ffloat16-excess-precision=fast"
+// CHECK-ERR-16: unsupported argument '16' to option '-fexcess-precision='
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,387 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=fast -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=fast -target-feature +avx512fp16 \
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=standard -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=standard -target-feature +avx512fp16 \
+// RUN: -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=none -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -ffloat16-excess-precision=none -target-feature +avx512fp16 \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_c

[PATCH] D140095: [include-cleaner] Fix the member-expr-access usage for sugar type.

2022-12-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:50
+  return UT->getFoundDecl();
+if (const auto *TST = Type->getAs())
+  return resolveTemplateName(TST->getTemplateName());

Resolving a template type to only its template name (ignoring template args) 
seems dubious in general. `Foo` is an important part of `vector` and a 
critical part of `unique_ptr`.

Currently we're only using this for the base types of MemberExpr, and here what 
we really care about is: which decl is responsible for this member? For this, 
the template (as opposed to args) is a reasonable heuristic. The exceptions I 
can think of:

 - dependent base: `template  class Wrapper : public T {};` - this is 
rare I think
 - type aliases: `template  using raw_pointer = T*;`
 - smart pointers (non-exception): `unique_ptr`: the base of the member expr 
ends up being `T*` at least in non-dependent cases, so we're fine

So I'd suggest:
 - renaming this function to `getMemberProvider(QualType Base)` or so
 - adding a comment explicitly stating that the template name rather than 
params generally provide the members



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:66
 // A member expr implies a usage of the class type
 // (e.g., to prevent inserting a header of base class when using base
 // members from a derived object).

this comment is confusing: it suggests that reporting a usage preverts 
inserting a header!
Would be nice to clarify:
 - we report a usage so that code `returnFoo().bar` can keep `#include "foo.h"`
 - reporting the member decl would cause problems (inheritance, aliases)



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:70
 QualType Type = E->getBase()->IgnoreImpCasts()->getType();
 report(E->getMemberLoc(), resolveType(Type));
 return true;

only tangentially related, but should these be implicit references?

I don't think we actually want to insert headers based on them, right? Just 
allow people to keep the ones that they have inserted that are required for 
compilation?

This would also make it less severe if our heuristic above goes wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140095

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


[clang] 948bb35 - [PPC] Convert tests to check 'target='

2022-12-15 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-15T07:01:14-08:00
New Revision: 948bb35d747419651fa5bcf86d5b6563bbb56119

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

LOG: [PPC] Convert tests to check 'target='

Two tests checked 'ppc64be' which appears not to exist; the tests
pass on clang-ppc64be-linux-multistage so I assume they are fine
and just removed those UNSUPPORTED lines. All others were converted
to the new target= format, and get the same results on ppc bots as
before.

Part of the project to eliminate special handling for triples in lit
expressions.

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

Added: 


Modified: 
clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
clang/test/CodeGen/no-builtin.cpp
clang/test/CodeGenCoroutines/pr56329.cpp
clang/test/Sema/no-builtin.cpp
llvm/test/DebugInfo/debuglineinfo-path.ll

Removed: 




diff  --git a/clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c 
b/clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
index 387c0049a461..093f116c8653 100644
--- a/clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
+++ b/clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: native, powerpc-registered-target
-// UNSUPPORTED: !powerpc64le-
+// REQUIRES: native, target=powerpc64le-{{.*}}
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may
 // require installing target headers in build env, otherwise expecting

diff  --git a/clang/test/CodeGen/PowerPC/ppc-mm-malloc.c 
b/clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
index 27b29b658aa7..57cf28f5bccc 100644
--- a/clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
+++ b/clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: native, powerpc-registered-target
-// UNSUPPORTED: !powerpc64-
+// REQUIRES: native, target=powerpc64-{{.*}}
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may
 // require installing target headers in build env, otherwise expecting

diff  --git a/clang/test/CodeGen/no-builtin.cpp 
b/clang/test/CodeGen/no-builtin.cpp
index 0dc734580d61..cca13aa486d8 100644
--- a/clang/test/CodeGen/no-builtin.cpp
+++ b/clang/test/CodeGen/no-builtin.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -S -emit-llvm 
-o - %s | FileCheck %s
-// UNSUPPORTED: ppc64be
 
 // CHECK-LABEL: define{{.*}} void @foo_no_mempcy() #0
 extern "C" void foo_no_mempcy() __attribute__((no_builtin("memcpy"))) {}

diff  --git a/clang/test/CodeGenCoroutines/pr56329.cpp 
b/clang/test/CodeGenCoroutines/pr56329.cpp
index 855755d05f84..31d4849af4e7 100644
--- a/clang/test/CodeGenCoroutines/pr56329.cpp
+++ b/clang/test/CodeGenCoroutines/pr56329.cpp
@@ -2,7 +2,7 @@
 //
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -O3 -S -emit-llvm 
-o - | FileCheck %s
 // This test is expected to fail on PowerPC.
-// XFAIL: powerpc
+// XFAIL: target=powerpc{{.*}}
 
 #include "Inputs/coroutine.h"
 

diff  --git a/clang/test/Sema/no-builtin.cpp b/clang/test/Sema/no-builtin.cpp
index 392d847f98aa..1312d32e22b0 100644
--- a/clang/test/Sema/no-builtin.cpp
+++ b/clang/test/Sema/no-builtin.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
-// UNSUPPORTED: ppc64be
 
 /// Prevent use of all builtins.
 void valid_attribute_all_1() __attribute__((no_builtin)) {}

diff  --git a/llvm/test/DebugInfo/debuglineinfo-path.ll 
b/llvm/test/DebugInfo/debuglineinfo-path.ll
index affb973bdec7..f6574a2a46f1 100644
--- a/llvm/test/DebugInfo/debuglineinfo-path.ll
+++ b/llvm/test/DebugInfo/debuglineinfo-path.ll
@@ -2,7 +2,7 @@
 
 ; On powerpc llvm-nm describes win_func as a global variable, not a function. 
It breaks the test.
 ; It is not essential to DWARF path handling code we're testing here.
-; UNSUPPORTED: powerpc
+; UNSUPPORTED: target=powerpc{{.*}}
 ; REQUIRES: object-emission
 ; RUN: %llc_dwarf -O0 -filetype=obj -o %t < %s
 ; RUN: llvm-nm --radix=o %t | grep posix_absolute_func > %t.posix_absolute_func



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


[PATCH] D138954: [PPC] Convert tests to check 'target='

2022-12-15 Thread Paul Robinson 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 rG948bb35d7474: [PPC] Convert tests to check 
'target=' (authored by probinson).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138954

Files:
  clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
  clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGenCoroutines/pr56329.cpp
  clang/test/Sema/no-builtin.cpp
  llvm/test/DebugInfo/debuglineinfo-path.ll


Index: llvm/test/DebugInfo/debuglineinfo-path.ll
===
--- llvm/test/DebugInfo/debuglineinfo-path.ll
+++ llvm/test/DebugInfo/debuglineinfo-path.ll
@@ -2,7 +2,7 @@
 
 ; On powerpc llvm-nm describes win_func as a global variable, not a function. 
It breaks the test.
 ; It is not essential to DWARF path handling code we're testing here.
-; UNSUPPORTED: powerpc
+; UNSUPPORTED: target=powerpc{{.*}}
 ; REQUIRES: object-emission
 ; RUN: %llc_dwarf -O0 -filetype=obj -o %t < %s
 ; RUN: llvm-nm --radix=o %t | grep posix_absolute_func > %t.posix_absolute_func
Index: clang/test/Sema/no-builtin.cpp
===
--- clang/test/Sema/no-builtin.cpp
+++ clang/test/Sema/no-builtin.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
-// UNSUPPORTED: ppc64be
 
 /// Prevent use of all builtins.
 void valid_attribute_all_1() __attribute__((no_builtin)) {}
Index: clang/test/CodeGenCoroutines/pr56329.cpp
===
--- clang/test/CodeGenCoroutines/pr56329.cpp
+++ clang/test/CodeGenCoroutines/pr56329.cpp
@@ -2,7 +2,7 @@
 //
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -O3 -S -emit-llvm 
-o - | FileCheck %s
 // This test is expected to fail on PowerPC.
-// XFAIL: powerpc
+// XFAIL: target=powerpc{{.*}}
 
 #include "Inputs/coroutine.h"
 
Index: clang/test/CodeGen/no-builtin.cpp
===
--- clang/test/CodeGen/no-builtin.cpp
+++ clang/test/CodeGen/no-builtin.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-linux-gnu -S -emit-llvm 
-o - %s | FileCheck %s
-// UNSUPPORTED: ppc64be
 
 // CHECK-LABEL: define{{.*}} void @foo_no_mempcy() #0
 extern "C" void foo_no_mempcy() __attribute__((no_builtin("memcpy"))) {}
Index: clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
===
--- clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
+++ clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: native, powerpc-registered-target
-// UNSUPPORTED: !powerpc64-
+// REQUIRES: native, target=powerpc64-{{.*}}
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may
 // require installing target headers in build env, otherwise expecting
Index: clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
===
--- clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
+++ clang/test/CodeGen/PowerPC/ppc-mm-malloc-le.c
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// REQUIRES: native, powerpc-registered-target
-// UNSUPPORTED: !powerpc64le-
+// REQUIRES: native, target=powerpc64le-{{.*}}
 // The stdlib.h included in mm_malloc.h references native system header
 // like: bits/libc-header-start.h or features.h, cross-compile it may
 // require installing target headers in build env, otherwise expecting


Index: llvm/test/DebugInfo/debuglineinfo-path.ll
===
--- llvm/test/DebugInfo/debuglineinfo-path.ll
+++ llvm/test/DebugInfo/debuglineinfo-path.ll
@@ -2,7 +2,7 @@
 
 ; On powerpc llvm-nm describes win_func as a global variable, not a function. It breaks the test.
 ; It is not essential to DWARF path handling code we're testing here.
-; UNSUPPORTED: powerpc
+; UNSUPPORTED: target=powerpc{{.*}}
 ; REQUIRES: object-emission
 ; RUN: %llc_dwarf -O0 -filetype=obj -o %t < %s
 ; RUN: llvm-nm --radix=o %t | grep posix_absolute_func > %t.posix_absolute_func
Index: clang/test/Sema/no-builtin.cpp
===
--- clang/test/Sema/no-builtin.cpp
+++ clang/test/Sema/no-builtin.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
-// UNSUPPORTED: ppc64be
 
 /// Prevent use of all builtins.
 void valid_attribute_all_1() __attribute__((no_builtin)) {}
Index: clang/test/CodeGenCoroutines/pr56329.cpp
==

[PATCH] D140084: [llvm][test] Split DW_AT_default_value check out of clang/test/

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D140084#3997123 , @dblaikie wrote:

> Sorry, should've caught this in review. The clang change needs test coverage 
> in clang, but should verify the emitted it, rather than going all the way 
> down to object code.
>
> The llvm functionality is already tested (since it's just the flag on a 
> template parameter - it's not interesting to test that for different kinds of 
> templates if the flag handling is kind-agnostic anyway)

I couldn't find any test inside `llvm/test` which verifies that 
`DW_AT_default_value` is being emitted correctly. Sure we don't need a test 
like that?

> So instead of this could you adjust the existing clang test to verify IR 
> instead of dwarfdump?

@dblaikie Isn't the clang test already doing that? In this test I mainly wanted 
to check that the `gstrict-dwarf` attribute works as expected. The IR will 
always have the default attribute attached to it, which the `clang/test/` 
already tests.

But if this is redundant I don't mind just removing this test altogether


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140084

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


[PATCH] D136743: [HLSL] support ConstantBuffer

2022-12-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 483171.
python3kgae added a comment.
Herald added a reviewer: aaron.ballman.

Change CBV implementation to
template
using ConstantBuffer = T;

Added new internal attribute HLSLConstantBufferView to mark CBV with 
AttributedType.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136743

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/HLSL/CBV.hlsl
  clang/test/SemaHLSL/BuiltIns/CBV.hlsl

Index: clang/test/SemaHLSL/BuiltIns/CBV.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/CBV.hlsl
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -verify %s
+
+// expected-error@+2{{'float' cannot be used as a type parameter where a struct is required}}
+// expected-note@+1{{in instantiation of template type alias 'ConstantBuffer' requested here}}
+ConstantBuffer CB;
Index: clang/test/AST/HLSL/CBV.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/CBV.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s
+
+// CHECK:TypeAliasTemplateDecl 0x{{[0-9a-f]+}} <>  implicit ConstantBuffer
+// CHECK-NEXT:-TemplateTypeParmDecl 0x[[T:[0-9a-f]+]] <>  class depth 0 index 0 element
+// CHECK-NEXT:-TypeAliasDecl 0x{{[0-9a-f]+}}  <>  implicit ConstantBuffer 'element  {{(.{2})}}hlsl::ConstantBufferView{{(.{2})}}':'element'
+// CHECK-NEXT:-AttributedType 0x{{[0-9a-f]+}} 'element {{(.{2})}}hlsl::ConstantBufferView{{(.{2})}}' sugar dependent
+// CHECK-NEXT: -TemplateTypeParmType 0x{{[0-9a-f]+}} 'element' dependent depth 0 index 0
+// CHECK-NEXT: -TemplateTypeParm 0x[[T]] 'element'
+
+// CHECK:-CXXRecordDecl 0x{{[0-9a-f]+}}  col:8 implicit struct S
+// CHECK-NEXT:-FieldDecl 0x[[A:[0-9a-f]+]]  col:11 referenced a 'float'
+struct S {
+float a;
+};
+
+// CHECK:VarDecl 0x[[CB:[0-9a-f]+]]  col:19 used CB 'ConstantBuffer':'S'
+ConstantBuffer CB;
+
+float foo() {
+// CHECK:ReturnStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK-NEXT:-MemberExpr 0x{{[0-9a-f]+}}  'float' lvalue .a 0x[[A]]
+// CHECK-NEXT:-DeclRefExpr 0x{{[0-9a-f]+}}  'ConstantBuffer':'S' lvalue Var 0x[[CB]] 'CB' 'ConstantBuffer'
+return CB.a;
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3815,6 +3815,31 @@
   return { FailedCond, Description };
 }
 
+bool Sema::CheckHLSLConstantBufferView(TypeAliasDecl *Pattern,
+   TemplateArgumentListInfo &TemplateArgs,
+   SourceLocation TemplateLoc) {
+  if (TemplateArgs.size() != 1)
+return true;
+  QualType PatType = Pattern->getUnderlyingType();
+  const auto *AttrTy = PatType->getAs();
+  if (!AttrTy)
+return true;
+
+  if (AttrTy->getAttrKind() != attr::HLSLConstantBufferView)
+return true;
+  // Make sure ConstantBufferView element type is record.
+  const TemplateArgument &Arg = TemplateArgs.arguments()[0].getArgument();
+  if (Arg.getKind() == TemplateArgument::ArgKind::Type) {
+const auto *RD = Arg.getAsType()->getAsCXXRecordDecl();
+if (!RD) {
+  Diag(TemplateLoc, diag::err_hlsl_typeintemplateargument_requires_struct)
+  << Arg.getAsType();
+  return false;
+}
+  }
+  return true;
+}
+
 QualType Sema::CheckTemplateIdType(TemplateName Name,
SourceLocation TemplateLoc,
TemplateArgumentListInfo &TemplateArgs) {
@@ -3878,6 +3903,10 @@
 if (Inst.isInvalid())
   return QualType();
 
+if (getLangOpts().HLSL &&
+!CheckHLSLConstantBufferView(Pattern, TemplateArgs, TemplateLoc))
+  return QualType();
+
 CanonType = SubstType(Pattern->getUnderlyingType(),
   TemplateArgLists, AliasTemplate->getLocation(),
   AliasTemplate->getDeclName());
Index: clang/lib/Sema/HLSLExternalSemaSource.cpp
===
--- clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -462,14 +462,66 @@
   HLSLNamespace->addDecl(Template);
 }
 
+void HLSLExternalSemaSource::defineConstantBufferView() {
+  // Add CBV as
+  // template
+  // using ConstantBuffer = T;
+
+  // TypeAliasTemplateDecl ConstantBuf
+  //| |-TemplateTypeParmDecl  referenced typename depth 0 index 0 T
+  //| `- TypeAliasDecl ConstantBuf 'T'
+  //|

[PATCH] D140105: [clang-format] add missing config parse test for short lambda

2022-12-15 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght created this revision.
Backl1ght added a project: clang-format.
Herald added a project: All.
Backl1ght 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/D140105

Files:
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,20 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -533,6 +533,20 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 
+  Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: None",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Empty",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Empty);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: Inline",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_Inline);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: All",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 33e3edd - [CodeComplete] Complete members of dependent `auto` variables

2022-12-15 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-12-15T16:10:19+01:00
New Revision: 33e3edde44952ed2be44ad00e6cb73208580bb85

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

LOG: [CodeComplete] Complete members of dependent `auto` variables

When the initializer of an `auto` variable is dependent, clang doesn't give the
DeclRefExpr a useful dependent type that we can apply heuristics to.
However we can dig one up by looking at the initializer.

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

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/member-access.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 0745677efb12..2cd679a93394 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5512,11 +5512,16 @@ class ConceptInfo {
 // We accept some lossiness (like dropping parameters).
 // We only try to handle common expressions on the LHS of MemberExpr.
 QualType getApproximateType(const Expr *E) {
+  if (E->getType().isNull())
+return QualType();
+  E = E->IgnoreParenImpCasts();
   QualType Unresolved = E->getType();
-  if (Unresolved.isNull() ||
-  !Unresolved->isSpecificBuiltinType(BuiltinType::Dependent))
-return Unresolved;
-  E = E->IgnoreParens();
+  // We only resolve DependentTy, or undeduced autos (including auto* etc).
+  if (!Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
+AutoType *Auto = Unresolved->getContainedAutoType();
+if (!Auto || !Auto->isUndeducedAutoType())
+  return Unresolved;
+  }
   // A call: approximate-resolve callee to a function type, get its return type
   if (const CallExpr *CE = llvm::dyn_cast(E)) {
 QualType Callee = getApproximateType(CE->getCallee());
@@ -5579,6 +5584,13 @@ QualType getApproximateType(const Expr *E) {
   }
 }
   }
+  // A reference to an `auto` variable: approximate-resolve its initializer.
+  if (const auto *DRE = llvm::dyn_cast(E)) {
+if (const auto *VD = llvm::dyn_cast(DRE->getDecl())) {
+  if (VD->hasInit())
+return getApproximateType(VD->getInit());
+}
+  }
   return Unresolved;
 }
 

diff  --git a/clang/test/CodeCompletion/member-access.cpp 
b/clang/test/CodeCompletion/member-access.cpp
index 4a5d1c66a25a..fdc9cde6ad3e 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -108,9 +108,17 @@ void completeDependentMembers(TemplateClass &object,
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:97:10 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:98:12 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
 
+  auto copy_object = object;
+  auto copy_object2 = object2;
+  object.field;
+  object2->field;
+// CHECK-AUTO: field : [#T#]field
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:113:10 %s -o - | 
FileCheck -check-prefix=CHECK-AUTO %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:114:12 %s -o - | 
FileCheck -check-prefix=CHECK-AUTO %s
+
   object.relatedField.relatedFunction().baseTemplateField;
 // CHECK-DEP-CHAIN: baseTemplateField : [#T#]baseTemplateField
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:111:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:41 %s -o - | 
FileCheck -check-prefix=CHECK-DEP-CHAIN %s
 }
 
 
@@ -127,8 +135,8 @@ void completeDependentSpecializedMembers(TemplateClass &object,
 // CHECK-CC3: overload1 : [#void#]overload1(<#const int &#>)
 // CHECK-CC3: overload1 : [#void#]overload1(<#const double &#>)
 
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:10 %s -o - | 
FileCheck -check-prefix=CHECK-CC3 %s
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:120:12 %s -o - | 
FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:127:10 %s -o - | 
FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:128:12 %s -o - | 
FileCheck -check-prefix=CHECK-CC3 %s
 }
 
 template 
@@ -142,17 +150,17 @@ class Template {
 // CHECK-CC4: BaseTemplate : BaseTemplate::
 // CHECK-CC4: baseTemplateField : [#int#]baseTemplateField
 // CHECK-CC4: baseTemplateFunction : [#int#]baseTemplateFunction()
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:141:8 %s -o - | 
FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:149:8 %s -o - | 
FileCheck -check-prefix=CHECK-CC4 %s
 o2.baseTemplateField;
 // CHECK-CC5: BaseTemplate : BaseTemplate::
 // CHECK-CC5: baseTemplateField : [#T#]baseTemplateField
 // CHECK-CC5: baseTemplateFunction : [#T#]baseTemplateFunction()
-// RUN: %cla

[PATCH] D140044: [CodeComplete] Complete members of dependent `auto` variables

2022-12-15 Thread Sam McCall 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 rG33e3edde4495: [CodeComplete] Complete members of dependent 
`auto` variables (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140044

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp

Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -108,9 +108,17 @@
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:97:10 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:98:12 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
 
+  auto copy_object = object;
+  auto copy_object2 = object2;
+  object.field;
+  object2->field;
+// CHECK-AUTO: field : [#T#]field
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:113:10 %s -o - | FileCheck -check-prefix=CHECK-AUTO %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:114:12 %s -o - | FileCheck -check-prefix=CHECK-AUTO %s
+
   object.relatedField.relatedFunction().baseTemplateField;
 // CHECK-DEP-CHAIN: baseTemplateField : [#T#]baseTemplateField
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:111:41 %s -o - | FileCheck -check-prefix=CHECK-DEP-CHAIN %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:41 %s -o - | FileCheck -check-prefix=CHECK-DEP-CHAIN %s
 }
 
 
@@ -127,8 +135,8 @@
 // CHECK-CC3: overload1 : [#void#]overload1(<#const int &#>)
 // CHECK-CC3: overload1 : [#void#]overload1(<#const double &#>)
 
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:119:10 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:120:12 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:127:10 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:128:12 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
 }
 
 template 
@@ -142,17 +150,17 @@
 // CHECK-CC4: BaseTemplate : BaseTemplate::
 // CHECK-CC4: baseTemplateField : [#int#]baseTemplateField
 // CHECK-CC4: baseTemplateFunction : [#int#]baseTemplateFunction()
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:141:8 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:149:8 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
 o2.baseTemplateField;
 // CHECK-CC5: BaseTemplate : BaseTemplate::
 // CHECK-CC5: baseTemplateField : [#T#]baseTemplateField
 // CHECK-CC5: baseTemplateFunction : [#T#]baseTemplateFunction()
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:146:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:154:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
 this->o1;
 // CHECK-CC6: [#void#]function()
 // CHECK-CC6: o1 : [#BaseTemplate#]o1
 // CHECK-CC6: o2 : [#BaseTemplate#]o2
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:151:11 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:159:11 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
   }
 
   static void staticFn(T &obj);
@@ -169,9 +177,9 @@
 // CHECK-CC7: o2 : [#BaseTemplate#]o2
 // CHECK-CC7: staticFn : [#void#]staticFn(<#T &obj#>)
 // CHECK-CC7: Template : Template
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:165:16 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:173:16 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
   typename Template::Nested m;
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:173:25 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:181:25 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
 }
 
 class Proxy2 {
@@ -188,34 +196,34 @@
   p.
 }
 
-// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:184:6 %s -o - | FileCheck -check-prefix=CHECK-CC8 --implicit-check-not="Derived : Derived(" %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:192:6 %s -o - | FileCheck -check-prefix=CHECK-CC8 --implicit-check-not="Derived : Derived(" %s
 // CHECK-CC8: Base1 (InBase) : Base1::
 // CHECK-CC8: member1 (InBase) : [#int#][#Base1::#]member1
 // CHECK-CC8: member1 (InBase) : [#int#][#Base2::#]member1
 // CHECK-CC8: member2 (InBase) : [#float#][#Base1::#]member2
 // CHECK-CC8: member3 (InBase) : [#double#][#Base2::#]member3
 // CHECK-CC8: member4 : [#int#]member4
-// CHECK-CC8: member5 : [#int#]member5 (requires fix-it: {184:4-184:6} to ".")
+// CHECK-CC8: member5 : [#int#]member5 (requires fix-it: 

[clang] 19d300f - Revert "[clang][CodeGen] Use base subobject type layout for potentially-overlapping fields"

2022-12-15 Thread Vladislav Dzhidzhoev via cfe-commits

Author: Vladislav Dzhidzhoev
Date: 2022-12-15T18:12:26+03:00
New Revision: 19d300fb4150b94f6dc7d8d230553d36349a3002

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

LOG: Revert "[clang][CodeGen] Use base subobject type layout for 
potentially-overlapping fields"

This reverts commit 731abdfdcc33d813e6c3b4b89eff307aa5c18083.

This commit breaks some tests in libcxx, e.g.
`std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp`

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 
clang/test/CodeGenCXX/no-unique-address-3.cpp



diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 268ec7deeb81..cd33fcef5661 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3062,10 +3062,6 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
-  /// Determine if this field is of potentially-overlapping class type, that
-  /// is, subobject with the [[no_unique_address]] attribute
-  bool isPotentiallyOverlapping() const;
-
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0f15d7b3b6d3..b1fdc897bf27 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4339,10 +4339,6 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
-bool FieldDecl::isPotentiallyOverlapping() const {
-  return hasAttr() && getType()->getAsCXXRecordDecl();
-}
-
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 56cdbb75dd4b..52bd3f20221f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,8 +1853,9 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
  bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
+  bool PotentiallyOverlapping = D->hasAttr() && 
FieldClass;
   bool IsOverlappingEmptyField =
-  D->isPotentiallyOverlapping() && FieldClass->isEmpty();
+  PotentiallyOverlapping && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
   (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1915,7 +1916,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
 
 // A potentially-overlapping field occupies its dsize or nvsize, whichever
 // is larger.
-if (D->isPotentiallyOverlapping()) {
+if (PotentiallyOverlapping) {
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
   EffectiveFieldSize =
   std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 0f2d764bc949..6f85bca8a201 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,14 +379,9 @@ void CGRecordLowering::accumulateFields() {
   for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
   accumulateBitFields(Start, Field);
 } else if (!Field->isZeroSize(Context)) {
-  // Use base subobject layout for the potentially-overlapping field,
-  // as it is done in RecordLayoutBuilder
   Members.push_back(MemberInfo(
   bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-  Field->isPotentiallyOverlapping()
-  ? getStorageType(Field->getType()->getAsCXXRecordDecl())
-  : getStorageType(*Field),
-  *Field));
+  getStorageType(*Field), *Field));
   ++Field;
 } else {
   ++Field;

diff  --git a/clang/test/CodeGenCXX/no-unique-address-3.cpp 
b/clang/test/CodeGenCXX/no-unique-address-3.cpp
deleted file mode 100644
index f21e9d1d2b01..
--- a/clang/test/CodeGenCXX/no-unique-address-3.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm 
-fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
-
-// CHECK:   *** Dumping AST Record Layout
-// CHECK-NEXT:   0 | class Empty (empty)
-// CHECK-NEXT: | [sizeof=1, dsize=1, align=1,
-// CHECK-NEXT: |  nvsize=1, nvalign=1]
-// CHECK: 

[PATCH] D140080: [clang][PPC] Supporting -mcpu=405

2022-12-15 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

The pre-commit CI crashes do not seem to relate to this patch. I will land it 
soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140080

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


[clang] 5d22d1f - [clang][dataflow] Improve optional model's support for ignoring smart pointers.

2022-12-15 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-12-15T15:39:52Z
New Revision: 5d22d1f54836263ead1971ef8128f5128290dfa7

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

LOG: [clang][dataflow] Improve optional model's support for ignoring smart 
pointers.

The optional model has an option to ignore optionals accessed through smart
pointer types (other than optional itself). This patch improves this feature in
two ways:

1. We extend support to optionals accessed directly through the smart pointer,
like `ptr->value()`. Previously, support was limited to cases that went through
an intermediate field.

2. We clean up the implementation by removing the option from the analysis,
leaving it only in the diagnostic phase (where it is relevant).

3. Adjusts a test which was misleading in what it was testing.

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

Added: 


Modified: 

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index b053a10327c3f..037858fe752e9 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -30,11 +30,12 @@ namespace dataflow {
 // analysis are always enabled and additional constructs are enabled through 
the
 // `Options`.
 struct UncheckedOptionalAccessModelOptions {
-  /// Ignore optionals reachable through overloaded `operator*` or `operator->`
-  /// (other than those of the optional type itself). The analysis does not
-  /// equate the results of such calls, so it can't identify when their results
-  /// are used safely (across calls), resulting in false positives in all such
-  /// cases. Note: this option does not cover access through `operator[]`.
+  /// In generating diagnostics, ignore optionals reachable through overloaded
+  /// `operator*` or `operator->` (other than those of the optional type
+  /// itself). The analysis does not equate the results of such calls, so it
+  /// can't identify when their results are used safely (across calls),
+  /// resulting in false positives in all such cases. Note: this option does 
not
+  /// cover access through `operator[]`.
   bool IgnoreSmartPointerDereference = false;
 };
 
@@ -44,8 +45,7 @@ struct UncheckedOptionalAccessModelOptions {
 class UncheckedOptionalAccessModel
 : public DataflowAnalysis {
 public:
-  UncheckedOptionalAccessModel(
-  ASTContext &Ctx, UncheckedOptionalAccessModelOptions Options = {});
+  UncheckedOptionalAccessModel(ASTContext &Ctx);
 
   /// Returns a matcher for the optional classes covered by this model.
   static ast_matchers::DeclarationMatcher optionalClassDecl();

diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 44a6f46c0f447..da3ffce1d1d8e 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -56,7 +56,7 @@ auto hasOptionalType() { return 
hasType(optionalOrAliasType()); }
 
 auto isOptionalMemberCallWithName(
 llvm::StringRef MemberName,
-llvm::Optional Ignorable = std::nullopt) {
+const llvm::Optional &Ignorable = std::nullopt) {
   auto Exception = unless(Ignorable ? expr(anyOf(*Ignorable, cxxThisExpr()))
 : cxxThisExpr());
   return cxxMemberCallExpr(
@@ -66,7 +66,7 @@ auto isOptionalMemberCallWithName(
 
 auto isOptionalOperatorCallWithName(
 llvm::StringRef operator_name,
-llvm::Optional Ignorable = std::nullopt) {
+const llvm::Optional &Ignorable = std::nullopt) {
   return cxxOperatorCallExpr(
   hasOverloadedOperatorName(operator_name),
   callee(cxxMethodDecl(ofClass(optionalClass(,
@@ -612,31 +612,31 @@ void transferOptionalAndValueCmp(const 
clang::CXXOperatorCallExpr *CmpExpr,
 
 llvm::Optional
 ignorableOptional(const UncheckedOptionalAccessModelOptions &Options) {
-  if (Options.IgnoreSmartPointerDereference)
-return memberExpr(hasObjectExpression(ignoringParenImpCasts(
-cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("->"),
-  hasOverloadedOperatorName("*")),
-unless(hasArgument(0, 
expr(hasOptionalType(;
+  if (Options.IgnoreSmartPointerDereference) {
+auto 

[PATCH] D140020: [clang][dataflow] Improve optional model's support for ignoring smart pointers.

2022-12-15 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d22d1f54836: [clang][dataflow] Improve optional 
model's support for ignoring smart pointers. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140020

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1307,8 +1307,8 @@
 llvm::Error Error = checkDataflow(
 AnalysisInputs(
 SourceCode, std::move(FuncMatcher),
-[Options](ASTContext &Ctx, Environment &) {
-  return UncheckedOptionalAccessModel(Ctx, Options);
+[](ASTContext &Ctx, Environment &) {
+  return UncheckedOptionalAccessModel(Ctx);
 })
 .withPostVisitCFG(
 [&Diagnostics,
@@ -2107,9 +2107,30 @@
   )");
 }
 
+TEST_P(UncheckedOptionalAccessTest, UniquePtrToOptional) {
+  // We suppress diagnostics for optionals in smart pointers (other than
+  // `optional` itself).
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+template 
+struct smart_ptr {
+  T& operator*() &;
+  T* operator->();
+};
+
+void target() {
+  smart_ptr<$ns::$optional> foo;
+  foo->value();
+  (*foo).value();
+}
+  )");
+}
+
 TEST_P(UncheckedOptionalAccessTest, UniquePtrToStructWithOptionalField) {
-  // We suppress diagnostics for values reachable from smart pointers (other
-  // than `optional` itself).
+  // We suppress diagnostics for optional fields reachable from smart pointers
+  // (other than `optional` itself) through (exactly) one member access.
   ExpectDiagnosticsFor(
   R"(
 #include "unchecked_optional_access_test.h"
@@ -2601,6 +2622,10 @@
   )");
 }
 
+// This test is aimed at the core model, not the diagnostic. It is a regression
+// test against a crash when using non-trivial smart pointers, like
+// `std::unique_ptr`. As such, it doesn't test the access itself, which would be
+// ignored regardless because of `IgnoreSmartPointerDereference = true`, above.
 TEST_P(UncheckedOptionalAccessTest, AssignThroughLvalueReferencePtr) {
   ExpectDiagnosticsFor(
   R"(
@@ -2612,9 +2637,9 @@
 };
 
 void target() {
-  smart_ptr<$ns::$optional> x;
-  *x = $ns::nullopt;
-  (*x).value(); // [[unsafe]]
+  smart_ptr<$ns::$optional> x;
+  // Verify that this assignment does not crash.
+  *x = 3;
 }
   )");
 }
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -56,7 +56,7 @@
 
 auto isOptionalMemberCallWithName(
 llvm::StringRef MemberName,
-llvm::Optional Ignorable = std::nullopt) {
+const llvm::Optional &Ignorable = std::nullopt) {
   auto Exception = unless(Ignorable ? expr(anyOf(*Ignorable, cxxThisExpr()))
 : cxxThisExpr());
   return cxxMemberCallExpr(
@@ -66,7 +66,7 @@
 
 auto isOptionalOperatorCallWithName(
 llvm::StringRef operator_name,
-llvm::Optional Ignorable = std::nullopt) {
+const llvm::Optional &Ignorable = std::nullopt) {
   return cxxOperatorCallExpr(
   hasOverloadedOperatorName(operator_name),
   callee(cxxMethodDecl(ofClass(optionalClass(,
@@ -612,31 +612,31 @@
 
 llvm::Optional
 ignorableOptional(const UncheckedOptionalAccessModelOptions &Options) {
-  if (Options.IgnoreSmartPointerDereference)
-return memberExpr(hasObjectExpression(ignoringParenImpCasts(
-cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("->"),
-  hasOverloadedOperatorName("*")),
-unless(hasArgument(0, expr(hasOptionalType(;
+  if (Options.IgnoreSmartPointerDereference) {
+auto SmartPtrUse = expr(ignoringParenImpCasts(cxxOperatorCallExpr(
+anyOf(hasOverloadedOperatorName("->"), hasOverloadedOperatorName("*")),
+unless(hasArgument(0, expr(hasOptionalType()));
+return expr(
+anyOf(SmartPtrUse, memberExpr(hasObjectExpression(SmartPtrUse;
+  }
   return std::nullopt;
 }
 
 StatementMatcher
-valueCall(llvm::Optional &IgnorableOptional) {
+valueCall(const llvm::Optional &IgnorableOptional) {
   return isOptionalMemberCallWithName("value"

[clang-tools-extra] 98550df - [clang-tidy] Add configuration option to bugprone-unchecked-optional-access check.

2022-12-15 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-12-15T15:43:21Z
New Revision: 98550df7b7bbce0e38a1ec558287d759163c64ba

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

LOG: [clang-tidy] Add configuration option to 
bugprone-unchecked-optional-access check.

The underlying model already supports ignoring accesses to optionals through
smart pointers. This patch exposes that option through ClangTidy's configuration
options.

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-smart.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
index 7137b78640ff2..c97917ebc3e05 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -9,18 +9,15 @@
 #include "UncheckedOptionalAccessCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
 #include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/Any.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Error.h"
@@ -33,12 +30,14 @@ namespace bugprone {
 using ast_matchers::MatchFinder;
 using dataflow::UncheckedOptionalAccessDiagnoser;
 using dataflow::UncheckedOptionalAccessModel;
+using dataflow::UncheckedOptionalAccessModelOptions;
 using llvm::Optional;
 
 static constexpr llvm::StringLiteral FuncID("fun");
 
 static Optional>
-analyzeFunction(const FunctionDecl &FuncDecl, ASTContext &ASTCtx) {
+analyzeFunction(const FunctionDecl &FuncDecl, ASTContext &ASTCtx,
+UncheckedOptionalAccessModelOptions ModelOptions) {
   using dataflow::ControlFlowContext;
   using dataflow::DataflowAnalysisState;
   using llvm::Expected;
@@ -52,7 +51,7 @@ analyzeFunction(const FunctionDecl &FuncDecl, ASTContext 
&ASTCtx) {
   std::make_unique());
   dataflow::Environment Env(AnalysisContext, FuncDecl);
   UncheckedOptionalAccessModel Analysis(ASTCtx);
-  UncheckedOptionalAccessDiagnoser Diagnoser;
+  UncheckedOptionalAccessDiagnoser Diagnoser(ModelOptions);
   std::vector Diagnostics;
   Expected>>>
@@ -98,7 +97,7 @@ void UncheckedOptionalAccessCheck::check(
 return;
 
   if (Optional> Errors =
-  analyzeFunction(*FuncDecl, *Result.Context))
+  analyzeFunction(*FuncDecl, *Result.Context, ModelOptions))
 for (const SourceLocation &Loc : *Errors)
   diag(Loc, "unchecked access to optional value");
 }

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
index c00b0d7b14d19..ae583fd0e940f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
@@ -11,6 +11,7 @@
 
 #include "../ClangTidyCheck.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"
 
 namespace clang {
 namespace tidy {
@@ -24,12 +25,21 @@ namespace bugprone {
 class UncheckedOptionalAccessCheck : public ClangTidyCheck {
 public:
   UncheckedOptionalAccessCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context),
+ModelOptions{
+Options.getLocalOrGlobal("IgnoreSmartPointerDereference", false)} 
{}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
+Options.store(Opts, "IgnoreSmartPointerDereference",
+  ModelOptions.IgnoreSmartPointerDereference);
+  }
+
+private:
+  dataflow::UncheckedOptionalAccessModelOptions ModelOp

[PATCH] D140021: [clang-tidy] Add configuration option to bugprone-unchecked-optional-access check.

2022-12-15 Thread Yitzhak Mandelbaum 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 rG98550df7b7bb: [clang-tidy] Add configuration option to 
bugprone-unchecked-optional-access… (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140021

Files:
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-smart.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-smart.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access-ignore-smart.cpp
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- \
+// RUN:   -config="{CheckOptions: [ \
+// RUN: {key: bugprone-unchecked-optional-access.IgnoreSmartPointerDereference, value: true}]}" -- \
+// RUN:   -I %S/Inputs/unchecked-optional-access
+
+#include "absl/types/optional.h"
+
+// Include some basic cases to ensure that IgnoreSmartPointerDereference doesn't
+// disable everything. Then check the relevant smart-pointer cases.
+
+void unchecked_deref_operator_access(const absl::optional &opt) {
+  *opt;
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: unchecked access to optional value
+}
+
+void unchecked_value_access(const absl::optional &opt) {
+  opt.value();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional value [bugprone-unchecked-optional-access]
+}
+
+struct Foo {
+  void foo() const {}
+};
+
+void unchecked_arrow_operator_access(const absl::optional &opt) {
+  opt->foo();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: unchecked access to optional value
+}
+
+template 
+struct SmartPtr {
+  T& operator*() &;
+  T* operator->();
+};
+
+struct Bar {
+  absl::optional opt;
+};
+
+
+void unchecked_value_access_through_smart_ptr(SmartPtr> s) {
+  s->value();
+  (*s).value();
+
+}
+
+void unchecked_value_access_through_smart_ptr_field(SmartPtr s) {
+  s->opt.value();
+  (*s).opt.value();
+
+}
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h
@@ -11,6 +11,7 @@
 
 #include "../ClangTidyCheck.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"
 
 namespace clang {
 namespace tidy {
@@ -24,12 +25,21 @@
 class UncheckedOptionalAccessCheck : public ClangTidyCheck {
 public:
   UncheckedOptionalAccessCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context),
+ModelOptions{
+Options.getLocalOrGlobal("IgnoreSmartPointerDereference", false)} {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
+Options.store(Opts, "IgnoreSmartPointerDereference",
+  ModelOptions.IgnoreSmartPointerDereference);
+  }
+
+private:
+  dataflow::UncheckedOptionalAccessModelOptions ModelOptions;
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -9,18 +9,15 @@
 #include "UncheckedOptionalAccessCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
 #include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/Any.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Error.h"
@@ -33,12 +30,14 @@
 using ast_matchers::MatchFinder;
 using dataflow::UncheckedOptionalAccessDiagnoser;

[clang] de8deb5 - [clang][PPC] Supporting -mcpu=405

2022-12-15 Thread Qiongsi Wu via cfe-commits

Author: Qiongsi Wu
Date: 2022-12-15T10:55:26-05:00
New Revision: de8deb5189c948db89c753ff2dff65b8e7840e8b

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

LOG: [clang][PPC] Supporting -mcpu=405

The  ClangBuiltLinux  project relies on `-mcpu=405`. Before 
https://reviews.llvm.org/D139720, `clang` treated `-mcpu=405` implicitly in the 
same way as `-mcpu=generic`, because `405` was an unknown value and `clang` did 
not validate unknown input values. https://reviews.llvm.org/D139720 added the 
validation of `-mcpu` input value, and `clang` now generates an error with 
`-mcpu=405`. For further details of the problem, see 
https://github.com/ClangBuiltLinux/linux/issues/1771.

This patch adds support of `-mcpu=405` explicitly, and treats it as an 
equivalent of `-mcpu=generic`.

Reviewed By: nemanjai

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/PPC.cpp
clang/test/Driver/ppc-cpus.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index f90a772ed5a21..6ec736bc701bb 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@ std::string ppc::getPPCTargetCPU(const ArgList &Args, const 
llvm::Triple &T) {
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
-if (CPUName == "generic")
+// Clang/LLVM does not actually support code generation
+// for the 405 CPU. However, there are uses of this CPU ID
+// in projects that previously used GCC and rely on Clang
+// accepting it. Clang has always ignored it and passed the
+// generic CPU ID to the back end.
+if (CPUName == "generic" || CPUName == "405")
   return getPPCGenericTargetCPU(T);
 
 if (CPUName == "native") {

diff  --git a/clang/test/Driver/ppc-cpus.c b/clang/test/Driver/ppc-cpus.c
index 08da07ec7b176..d623b25e88d95 100644
--- a/clang/test/Driver/ppc-cpus.c
+++ b/clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | 
FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"



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


[PATCH] D140080: [clang][PPC] Supporting -mcpu=405

2022-12-15 Thread 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 rGde8deb5189c9: [clang][PPC] Supporting -mcpu=405 (authored by 
Qiongsi Wu ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140080

Files:
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Driver/ppc-cpus.c


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | 
FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s 
--check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
-if (CPUName == "generic")
+// Clang/LLVM does not actually support code generation
+// for the 405 CPU. However, there are uses of this CPU ID
+// in projects that previously used GCC and rely on Clang
+// accepting it. Clang has always ignored it and passed the
+// generic CPU ID to the back end.
+if (CPUName == "generic" || CPUName == "405")
   return getPPCGenericTargetCPU(T);
 
 if (CPUName == "native") {


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405 2>&1 | FileCheck %s --check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
 StringRef CPUName = A->getValue();
 
-if (CPUName == "generic")
+// Clang/LLVM does not actually support code generation
+// for the 405 CPU. However, there are uses of this CPU ID
+// in projects that previously used GCC and rely on Clang
+// accepting it. Clang has always ignored it and passed the
+// generic CPU ID to the back end.
+if (CPUName == "generic" || CPUName == "405")
   return getPPCGenericTargetCPU(T);
 
 if (CPUName == "native") {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Xlinker still works. Xcompiler is failing.

A google search will show that Xcompiler is a wide-spread option used by many 
packages. Whether or not GCC supports it is not relevant. Please do not remove 
options just because you do not use them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 483203.
pmatos added a comment.

Force mem2reg on all optimization levels to avoid allocas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/Mem2Reg.cpp

Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
===
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -74,15 +74,19 @@
 struct PromoteLegacyPass : public FunctionPass {
   // Pass identification, replacement for typeid
   static char ID;
+  bool ForcePass; /// If true, forces pass to execute, instead of skipping.
 
-  PromoteLegacyPass() : FunctionPass(ID) {
+  PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) {
+initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
+  }
+  PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) {
 initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
   // runOnFunction - To run this pass, first we calculate the alloca
   // instructions that are safe for promotion, then we promote each one.
   bool runOnFunction(Function &F) override {
-if (skipFunction(F))
+if (!ForcePass && skipFunction(F))
   return false;
 
 DominatorTree &DT = getAnalysis().getDomTree();
@@ -96,6 +100,7 @@
 AU.addRequired();
 AU.setPreservesCFG();
   }
+
 };
 
 } // end anonymous namespace
@@ -111,6 +116,6 @@
 false, false)
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.
-FunctionPass *llvm::createPromoteMemoryToRegisterPass() {
-  return new PromoteLegacyPass();
+FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) {
+  return new PromoteLegacyPass(IsForced);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -16,6 +16,7 @@
 #include "TargetInfo/WebAssemblyTargetInfo.h"
 #include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
+#include "WebAssemblyISelLowering.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
 #include "WebAssemblyTargetTransformInfo.h"
@@ -453,6 +454,14 @@
 }
 
 void WebAssemblyPassConfig::addISelPrepare() {
+  WebAssemblyTargetMachine *WasmTM = static_cast(TM);
+  const WebAssemblySubtarget *Subtarget = WasmTM
+->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
+   std::string(WasmTM->getTargetFeatureString()));
+  if(Subtarget->hasReferenceTypes()) {
+// We need to remove allocas for reference types
+addPass(createPromoteMemoryToRegisterPass(true));
+  }
   // Lower atomics and TLS if necessary
   addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
 
Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_E

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D122215#3991648 , @MoritzS wrote:

> Thanks for the patch! I just tried it out and I think this enables many 
> interesting use cases for WebAssembly when using C/C++.
>
> Currently the lowering to wasm does not work when using externrefs when 
> compiling without optimizations. Is that intended behavior?

I have posted a new patch that fixed this. Can you please try it again and see 
if it works as you expect?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D139458: [clangd] Full support for #import insertions

2022-12-15 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 483205.
dgoldman added a comment.

Don't pass ASTSignals through ParsedAST


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139458

Files:
  clang-tools-extra/clangd/ASTSignals.cpp
  clang-tools-extra/clangd/ASTSignals.h
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2718,17 +2718,21 @@
   Sym.CanonicalDeclaration.FileURI = DeclFile.c_str();
   Sym.IncludeHeaders.emplace_back("\"bar.h\"", 1000,
   Symbol::Include | Symbol::Import);
-
-  auto Results = completions("Fun^", {Sym}).Completions;
+  CodeCompleteOptions Opts;
+  // Should only take effect in import contexts.
+  Opts.ImportInsertions = true;
+  auto Results = completions("Fun^", {Sym}, Opts).Completions;
   assert(!Results.empty());
   EXPECT_THAT(Results[0],
   AllOf(named("Func"), insertIncludeText("#include \"bar.h\"\n")));
 
-  Results = completions("Fun^", {Sym}, {}, "Foo.m").Completions;
+  ASTSignals Signals;
+  Signals.InsertionDirective = Symbol::IncludeDirective::Import;
+  Opts.MainFileSignals = &Signals;
+  Results = completions("Fun^", {Sym}, Opts, "Foo.m").Completions;
   assert(!Results.empty());
-  // TODO: Once #import integration support is done this should be #import.
   EXPECT_THAT(Results[0],
-  AllOf(named("Func"), insertIncludeText("#include \"bar.h\"\n")));
+  AllOf(named("Func"), insertIncludeText("#import \"bar.h\"\n")));
 
   Sym.IncludeHeaders[0].SupportedDirectives = Symbol::Import;
   Results = completions("Fun^", {Sym}).Completions;
Index: clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTSignalsTests.cpp
@@ -68,7 +68,44 @@
   Pair(sym("Y", index::SymbolKind::Variable, "@N@tar@S@X@FI@\\0").ID,
2),
   Pair(_ /*a*/, 3)));
+  EXPECT_EQ(Signals.InsertionDirective, Symbol::IncludeDirective::Include);
 }
+
+TEST(ASTSignals, DeriveInsertionDirective) {
+  TestTU ObjCTU = TestTU::withCode(R"cpp(
+  int main() {}
+  )cpp");
+  ObjCTU.Filename = "TestTU.m";
+  ASTSignals Signals = ASTSignals::derive(ObjCTU.build());
+  EXPECT_EQ(Signals.InsertionDirective, Symbol::IncludeDirective::Import);
+
+  TestTU HeaderTU = TestTU::withCode(R"cpp(
+  #import "TestTU.h"
+  )cpp");
+  HeaderTU.Filename = "TestTUHeader.h";
+  HeaderTU.ExtraArgs = {"-xobjective-c++-header"};
+  Signals = ASTSignals::derive(HeaderTU.build());
+  EXPECT_EQ(Signals.InsertionDirective, Symbol::IncludeDirective::Import);
+
+  // ObjC language option is not enough for headers.
+  HeaderTU.Code = R"cpp(
+  #include "TestTU.h"
+  )cpp";
+  Signals = ASTSignals::derive(HeaderTU.build());
+  EXPECT_EQ(Signals.InsertionDirective, Symbol::IncludeDirective::Include);
+
+  HeaderTU.Code = R"cpp(
+  #include "TestTU.h"
+
+  @interface Foo
+  @end
+
+  Foo * getFoo();
+  )cpp";
+  Signals = ASTSignals::derive(HeaderTU.build());
+  EXPECT_EQ(Signals.InsertionDirective, Symbol::IncludeDirective::Import);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -85,7 +85,7 @@
   /// This function returns top-level decls present in the main file of the AST.
   /// The result does not include the decls that come from the preamble.
   /// (These should be const, but RecursiveASTVisitor requires Decl*).
-  ArrayRef getLocalTopLevelDecls();
+  ArrayRef getLocalTopLevelDecls() const;
 
   const llvm::Optional> &getDiagnostics() const {
 return Diags;
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -11,6 +11,7 @@
 #include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
 #include "AST.h"
+#include "ASTSignals.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -25,6 +26,7 @@
 #include "TidyProvider.h"
 #include "index/CanonicalIncludes.h"
 #include "index/Index.h"
+#include "index/Symbol.h"
 #include "support/Logger.h"
 #include "suppo

[PATCH] D139749: Headers: use C++ inline semantics in C++ mode

2022-12-15 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Thanks @fsb4000 (and @CaseyCarter)!  I think that due to the shipped version, 
it makes sense to do this still.  Using standard semantics in general I think 
is preferable, since nothing prevents another compiler implementation to still 
do something similar.


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

https://reviews.llvm.org/D139749

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


[PATCH] D139986: [WIP][clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 updated this revision to Diff 483168.
Michael137 added a comment.
Michael137 updated this revision to Diff 483184.
Michael137 published this revision for review.
Michael137 added a subscriber: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Simplify


Michael137 added a comment.

- Fix another test




Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

@aprantl any idea if this is good/OK? (I guess it probably is - but maybe these 
strings were never meant to ignore/suppress default arguments of any kind? or 
maybe this is an ABI sort of thing where it suppressing some but not others is 
now unchangeable?)



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

dblaikie wrote:
> @aprantl any idea if this is good/OK? (I guess it probably is - but maybe 
> these strings were never meant to ignore/suppress default arguments of any 
> kind? or maybe this is an ABI sort of thing where it suppressing some but not 
> others is now unchangeable?)
Good point. There was a thread on the cfe mailing list a while ago about the 
last time this broke: 
https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html

This was @rsmith's stance:
```
I think some of the other recent TypePrinter changes might also risk
changing the @encode output. Generally it seems unwise for @encode to be
using the type pretty-printer if it wants to be ABI-stable; I don't think
it's reasonable to expect any guarantees as to the stability of
pretty-printed type names. I think USR generation suffers from similar
problems; it too uses the type pretty-printer to generate
supposedly-ABI-stable keys in at least some cases.
```


This patch handles default integral non-type template parameters.

After this patch the clang TypePrinter will omit default integral
template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs`
option is specified and sets us up to be able to re-use `TemplateUtils`
from with the DWARF CodeGen component.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139986

Files:
  clang/lib/AST/TemplateUtils.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  clang/test/CodeGenObjCXX/encode.mm
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/Misc/diag-template.cpp
  clang/test/SemaCUDA/device-use-host-var.cu
  clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp
  clang/test/SemaCXX/co_await-range-for.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/dependent-names.cpp

Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -338,7 +338,7 @@
   struct Y: Y { }; // expected-error{{circular inheritance between 'Y' and 'Y'}}
 };
 typedef X<3> X3;
-X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<3>'}}
+X3::Y<>::iterator it; // expected-error {{no type named 'iterator' in 'PR11421::X<3>::Y<>'}}
 }
 
 namespace rdar12629723 {
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -232,7 +232,7 @@
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (type-parameter-0-1) -> F<>'
 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1'
-// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) -> F<'x'>'
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit  'auto (int) ->

[PATCH] D135247: [clang][analyzer] Add stream functions to StdLibraryFunctionsChecker.

2022-12-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 483213.
balazske added a comment.

Removed change of errno state from StreamChecker.
Added cases for zero buffer size in `fread` and `fwrite`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135247

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-errno.c
  clang/test/Analysis/stream-error.c
  clang/test/Analysis/stream-noopen.c

Index: clang/test/Analysis/stream-noopen.c
===
--- /dev/null
+++ clang/test/Analysis/stream-noopen.c
@@ -0,0 +1,97 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=alpha.unix.Stream \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+// enable only StdCLibraryFunctions checker
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.unix.Errno \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+#include "Inputs/errno_var.h"
+
+void clang_analyzer_eval(int);
+
+const char *WBuf = "123456789";
+char RBuf[10];
+
+void test_freopen(FILE *F) {
+  F = freopen("xxx", "w", F);
+  if (F) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+}
+
+void test_fread(FILE *F) {
+  size_t Ret = fread(RBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fwrite(FILE *F) {
+  size_t Ret = fwrite(WBuf, 1, 10, F);
+  if (Ret == 10) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fclose(FILE *F) {
+  int Ret = fclose(F);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void test_fseek(FILE *F) {
+  int Ret = fseek(F, SEEK_SET, 1);
+  if (Ret == 0) {
+if (errno) {} // expected-warning{{undefined}}
+  } else {
+clang_analyzer_eval(Ret == -1); // expected-warning {{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning {{TRUE}}
+  }
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+}
+
+void freadwrite_zerosize(FILE *F) {
+  fwrite(WBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fwrite(WBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fread(RBuf, 1, 0, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+  fread(RBuf, 0, 1, F);
+  clang_analyzer_eval(feof(F)); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{UNKNOWN}}
+  if (errno) {} // no-warning
+}
Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -7,6 +7,7 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 void clang_analyzer_warnIfReached(void);
 void StreamTesterChecker_make_feof_stream(FILE *);
 void 

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

Michael137 wrote:
> dblaikie wrote:
> > @aprantl any idea if this is good/OK? (I guess it probably is - but maybe 
> > these strings were never meant to ignore/suppress default arguments of any 
> > kind? or maybe this is an ABI sort of thing where it suppressing some but 
> > not others is now unchangeable?)
> Good point. There was a thread on the cfe mailing list a while ago about the 
> last time this broke: 
> https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> 
> This was @rsmith's stance:
> ```
> I think some of the other recent TypePrinter changes might also risk
> changing the @encode output. Generally it seems unwise for @encode to be
> using the type pretty-printer if it wants to be ABI-stable; I don't think
> it's reasonable to expect any guarantees as to the stability of
> pretty-printed type names. I think USR generation suffers from similar
> problems; it too uses the type pretty-printer to generate
> supposedly-ABI-stable keys in at least some cases.
> ```
see https://reviews.llvm.org/D90622


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Davide Italiano via Phabricator via cfe-commits
davide added a comment.

In D139717#3997193 , @MaskRay wrote:

> In D139717#3991765 , @rsundahl 
> wrote:
>
>> In D139717#3987963 , @MaskRay 
>> wrote:
>>
 This change is breaking internal builds. We use the -Xfoo pattern but can 
 now no longer manage whether we allow an unused -Xfoo option to pass as a 
 warning or promote it to an error.
>>>
>>> Which `-Xfoo` is used? Do your internal builds reserve `-Xfoo` as a 
>>> placeholder to do other non-upstream work? Then you can consider `-Gfoo` if 
>>> your builds don't need the mips semantics.
>>
>> We use -Xparser
>
> There are two possibilities.
>
> First, your downstream projects incorrectly pass a previously-ignored 
> `-Xparser`. Then it seems the right call is to remove it.

It is not. You first deprecate and then you remove. This commit needs to be 
reverted.

HTH,

-

D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D140068: [NFC] Rename Function::insertBasicBlockAt() to Function::insert().

2022-12-15 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea accepted this revision.
asbirlea added a comment.
This revision is now accepted and ready to land.

lgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140068

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


[PATCH] D140085: [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()

2022-12-15 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea accepted this revision.
asbirlea added a comment.
This revision is now accepted and ready to land.

Rebase to trigger pre-merge checks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140085

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


[clang-tools-extra] 40cc041 - [clang-tools-extra] Convert tests to check 'target=...'

2022-12-15 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-15T09:51:06-08:00
New Revision: 40cc041d4eec7306a67bfdbfeaa8796b8d856b60

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

LOG: [clang-tools-extra] Convert tests to check 'target=...'

Part of the project to eliminate special handling for triples in lit
expressions.

Added: 


Modified: 
clang-tools-extra/clangd/test/dependency-output.test
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/test/test-uri-posix.test
clang-tools-extra/clangd/test/test-uri-windows.test
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/dependency-output.test 
b/clang-tools-extra/clangd/test/dependency-output.test
index ed289bbcdbe44..32b439e520e5e 100644
--- a/clang-tools-extra/clangd/test/dependency-output.test
+++ b/clang-tools-extra/clangd/test/dependency-output.test
@@ -1,4 +1,4 @@
-# UNSUPPORTED: windows-gnu,windows-msvc
+# UNSUPPORTED: target={{.*-windows-(gnu|msvc)}}
 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---

diff  --git 
a/clang-tools-extra/clangd/test/did-change-configuration-params.test 
b/clang-tools-extra/clangd/test/did-change-configuration-params.test
index 29cf1786a835a..fd33f63818a28 100644
--- a/clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ b/clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -1,6 +1,6 @@
 # RUN: clangd -compile_args_from=lsp -lit-test < %s 2> %t | FileCheck 
-strict-whitespace %s
 # RUN: FileCheck --check-prefix=ERR --input-file=%t %s
-# UNSUPPORTED: windows-gnu,windows-msvc
+# UNSUPPORTED: target={{.*-windows-(gnu|msvc)}}
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 
{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabaseChanges":{"/clangd-test/foo.c":
 {"workingDirectory":"/clangd-test", "compilationCommand": ["clang", "-c", 
"foo.c"]}

diff  --git a/clang-tools-extra/clangd/test/test-uri-posix.test 
b/clang-tools-extra/clangd/test/test-uri-posix.test
index 2b67fa03e0f09..37d8a3d8e7a63 100644
--- a/clang-tools-extra/clangd/test/test-uri-posix.test
+++ b/clang-tools-extra/clangd/test/test-uri-posix.test
@@ -1,5 +1,5 @@
 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
-# UNSUPPORTED: windows-gnu,windows-msvc
+# UNSUPPORTED: target={{.*-windows-(gnu|msvc)}}
 # Test authority-less URI
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---

diff  --git a/clang-tools-extra/clangd/test/test-uri-windows.test 
b/clang-tools-extra/clangd/test/test-uri-windows.test
index 3f03b2985a70f..8c8d04824538a 100644
--- a/clang-tools-extra/clangd/test/test-uri-windows.test
+++ b/clang-tools-extra/clangd/test/test-uri-windows.test
@@ -1,5 +1,5 @@
 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
-# UNSUPPORTED: !(windows-gnu || windows-msvc)
+# REQUIRES: target={{.*-windows-(gnu|msvc)}}
 # Test authority-less URI
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index 08287e9b51e41..a6a4f6e84cc90 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -1,6 +1,6 @@
 // Remove UNSUPPORTED for powerpc64le when the problem introduced by
 // r288563 is resolved.
-// UNSUPPORTED: powerpc64le
+// UNSUPPORTED: target=powerpc64le{{.*}}
 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: readability-identifier-naming.AbstractClassCase, value: 
CamelCase}, \



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


[clang] 80f2f1e - [NFC] Rename Function::insertBasicBlockAt() to Function::insert().

2022-12-15 Thread Vasileios Porpodas via cfe-commits

Author: Vasileios Porpodas
Date: 2022-12-15T10:03:37-08:00
New Revision: 80f2f1eabc491cde39d543e4ebda93e2d2974d1f

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

LOG: [NFC] Rename Function::insertBasicBlockAt() to Function::insert().

I think this is a better name because it is what STL uses.

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
llvm/examples/Kaleidoscope/Chapter5/toy.cpp
llvm/examples/Kaleidoscope/Chapter6/toy.cpp
llvm/examples/Kaleidoscope/Chapter7/toy.cpp
llvm/examples/Kaleidoscope/Chapter8/toy.cpp
llvm/examples/Kaleidoscope/Chapter9/toy.cpp
llvm/include/llvm/IR/Function.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/Core.cpp
llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
llvm/lib/Transforms/Utils/LowerSwitch.cpp
llvm/unittests/IR/FunctionTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index f3264cf87552f..f0e1d97b2676d 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -574,9 +574,9 @@ void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB, bool 
IsFinished) {
   // Place the block after the current block, if possible, or else at
   // the end of the function.
   if (CurBB && CurBB->getParent())
-CurFn->insertBasicBlockAt(std::next(CurBB->getIterator()), BB);
+CurFn->insert(std::next(CurBB->getIterator()), BB);
   else
-CurFn->insertBasicBlockAt(CurFn->end(), BB);
+CurFn->insert(CurFn->end(), BB);
   Builder.SetInsertPoint(BB);
 }
 
@@ -601,15 +601,14 @@ void CodeGenFunction::EmitBlockAfterUses(llvm::BasicBlock 
*block) {
   bool inserted = false;
   for (llvm::User *u : block->users()) {
 if (llvm::Instruction *insn = dyn_cast(u)) {
-  CurFn->insertBasicBlockAt(std::next(insn->getParent()->getIterator()),
-block);
+  CurFn->insert(std::next(insn->getParent()->getIterator()), block);
   inserted = true;
   break;
 }
   }
 
   if (!inserted)
-CurFn->insertBasicBlockAt(CurFn->end(), block);
+CurFn->insert(CurFn->end(), block);
 
   Builder.SetInsertPoint(block);
 }
@@ -1469,7 +1468,7 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S,
   llvm::BasicBlock *FalseDest = CaseRangeBlock;
   CaseRangeBlock = createBasicBlock("sw.caserange");
 
-  CurFn->insertBasicBlockAt(CurFn->end(), CaseRangeBlock);
+  CurFn->insert(CurFn->end(), CaseRangeBlock);
   Builder.SetInsertPoint(CaseRangeBlock);
 
   // Emit range check.

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 09dc638a2ac32..ad5ffece8cae3 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -320,7 +320,7 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {
 static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {
   if (!BB) return;
   if (!BB->use_empty()) {
-CGF.CurFn->insertBasicBlockAt(CGF.CurFn->end(), BB);
+CGF.CurFn->insert(CGF.CurFn->end(), BB);
 return;
   }
   delete BB;

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp 
b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index 1f0036922b67d..e29de191515ae 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -863,7 +863,7 @@ Value *IfExprAST::codegen() {
   ThenBB = Builder->GetInsertBlock();
 
   // Emit else block.
-  TheFunction->insertBasicBlockAt(TheFunction->end(), ElseBB);
+  TheFunction->insert(TheFunction->end(), ElseBB);
   Builder->SetInsertPoint(ElseBB);
 
   Value *ElseV = Else->codegen();
@@ -875,7 +875,7 @@ Value *IfExprAST::codegen() {
   ElseBB = Builder->GetInsertBlock();
 
   // Emit merge block.
-  TheFunction->insertBasicBlockAt(TheFunction->end(), MergeBB);
+  TheFunction->insert(TheFunction->end(), MergeBB);
   Builder->SetInsertPoint(MergeBB);
   PHINode *PN = Builder->CreatePHI(Type::getDoubleTy(*TheContext), 2, "iftmp");
 

diff  --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp 
b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
index 1f0036922b67d..e29de191515ae 100644
--- a/llvm/examples/Kaleidosco

[PATCH] D140068: [NFC] Rename Function::insertBasicBlockAt() to Function::insert().

2022-12-15 Thread Vasileios Porpodas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80f2f1eabc49: [NFC] Rename Function::insertBasicBlockAt() to 
Function::insert(). (authored by vporpo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140068

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
  llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
  llvm/examples/Kaleidoscope/Chapter5/toy.cpp
  llvm/examples/Kaleidoscope/Chapter6/toy.cpp
  llvm/examples/Kaleidoscope/Chapter7/toy.cpp
  llvm/examples/Kaleidoscope/Chapter8/toy.cpp
  llvm/examples/Kaleidoscope/Chapter9/toy.cpp
  llvm/include/llvm/IR/Function.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/IR/BasicBlock.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
  llvm/lib/Transforms/Utils/CloneFunction.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/lib/Transforms/Utils/LoopUnroll.cpp
  llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
  llvm/lib/Transforms/Utils/LowerSwitch.cpp
  llvm/unittests/IR/FunctionTest.cpp

Index: llvm/unittests/IR/FunctionTest.cpp
===
--- llvm/unittests/IR/FunctionTest.cpp
+++ llvm/unittests/IR/FunctionTest.cpp
@@ -206,34 +206,34 @@
 
   // Insert foo_bb0 into bar() at the very top.
   FooBB0->removeFromParent();
-  auto It = BarF->insertBasicBlockAt(BarF->begin(), FooBB0);
+  auto It = BarF->insert(BarF->begin(), FooBB0);
   EXPECT_EQ(BarBB0->getPrevNode(), FooBB0);
   EXPECT_EQ(It, FooBB0->getIterator());
 
   // Insert foo_bb0 into bar() at the very end.
   FooBB0->removeFromParent();
-  It = BarF->insertBasicBlockAt(BarF->end(), FooBB0);
+  It = BarF->insert(BarF->end(), FooBB0);
   EXPECT_EQ(FooBB0->getPrevNode(), BarBB2);
   EXPECT_EQ(FooBB0->getNextNode(), nullptr);
   EXPECT_EQ(It, FooBB0->getIterator());
 
   // Insert foo_bb0 into bar() just before bar_bb0.
   FooBB0->removeFromParent();
-  It = BarF->insertBasicBlockAt(BarBB0->getIterator(), FooBB0);
+  It = BarF->insert(BarBB0->getIterator(), FooBB0);
   EXPECT_EQ(FooBB0->getPrevNode(), nullptr);
   EXPECT_EQ(FooBB0->getNextNode(), BarBB0);
   EXPECT_EQ(It, FooBB0->getIterator());
 
   // Insert foo_bb0 into bar() just before bar_bb1.
   FooBB0->removeFromParent();
-  It = BarF->insertBasicBlockAt(BarBB1->getIterator(), FooBB0);
+  It = BarF->insert(BarBB1->getIterator(), FooBB0);
   EXPECT_EQ(FooBB0->getPrevNode(), BarBB0);
   EXPECT_EQ(FooBB0->getNextNode(), BarBB1);
   EXPECT_EQ(It, FooBB0->getIterator());
 
   // Insert foo_bb0 into bar() just before bar_bb2.
   FooBB0->removeFromParent();
-  It = BarF->insertBasicBlockAt(BarBB2->getIterator(), FooBB0);
+  It = BarF->insert(BarBB2->getIterator(), FooBB0);
   EXPECT_EQ(FooBB0->getPrevNode(), BarBB1);
   EXPECT_EQ(FooBB0->getNextNode(), BarBB2);
   EXPECT_EQ(It, FooBB0->getIterator());
Index: llvm/lib/Transforms/Utils/LowerSwitch.cpp
===
--- llvm/lib/Transforms/Utils/LowerSwitch.cpp
+++ llvm/lib/Transforms/Utils/LowerSwitch.cpp
@@ -160,7 +160,7 @@
  BasicBlock *Default) {
   Function *F = OrigBlock->getParent();
   BasicBlock *NewLeaf = BasicBlock::Create(Val->getContext(), "LeafBlock");
-  F->insertBasicBlockAt(++OrigBlock->getIterator(), NewLeaf);
+  F->insert(++OrigBlock->getIterator(), NewLeaf);
 
   // Emit comparison
   ICmpInst *Comp = nullptr;
@@ -300,7 +300,7 @@
   SwitchConvert(RHS.begin(), RHS.end(), NewLowerBound, UpperBound, Val,
 NewNode, OrigBlock, Default, UnreachableRanges);
 
-  F->insertBasicBlockAt(++OrigBlock->getIterator(), NewNode);
+  F->insert(++OrigBlock->getIterator(), NewNode);
   Comp->insertAt(NewNode, NewNode->end());
 
   BranchInst::Create(LBranch, RBranch, Comp, NewNode);
Index: llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
===
--- llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -374,7 +374,7 @@
 for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
   ValueToValueMapTy VMap;
   BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It));
-  Header->getParent()->insertBasicBlockAt(Header->getParent()->end(), New);
+  Header->getParent()->insert(Header->getParent()->end(), New);
 
   // Tell LI about New.
   addClonedBlockToLoopInfo(*BB, New, LI, NewLoops);
Index: llvm/lib/Transforms/Utils/LoopUnroll.cpp
===
--- llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -539,7 +539,7 @@
 for (LoopBlocksDFS::RP

[PATCH] D140085: [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()

2022-12-15 Thread Vasileios Porpodas via Phabricator via cfe-commits
vporpo updated this revision to Diff 483222.
vporpo added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140085

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  llvm/docs/ProgrammersManual.rst
  llvm/examples/BrainF/BrainF.cpp
  llvm/examples/ModuleMaker/ModuleMaker.cpp
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/WinEHPrepare.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
  llvm/lib/Transforms/IPO/IROutliner.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
  llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
  llvm/lib/Transforms/Scalar/JumpThreading.cpp
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
  llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/lib/Transforms/Utils/CloneFunction.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
  llvm/lib/Transforms/Utils/LowerSwitch.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
  llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
  llvm/unittests/Analysis/MemorySSATest.cpp
  llvm/unittests/Analysis/ValueTrackingTest.cpp
  llvm/unittests/IR/InstructionsTest.cpp

Index: llvm/unittests/IR/InstructionsTest.cpp
===
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -1695,7 +1695,7 @@
   BasicBlock *BB = &*F->begin();
   Instruction *Ret = &*BB->begin();
   Instruction *I = BinaryOperator::CreateAdd(ArgA, ArgB);
-  auto It = I->insertAt(BB, BB->begin());
+  auto It = I->insertInto(BB, BB->begin());
   EXPECT_EQ(&*It, I);
   EXPECT_EQ(I->getNextNode(), Ret);
 }
@@ -1714,7 +1714,7 @@
   BasicBlock *BB = &*F->begin();
   Instruction *Ret = &*BB->begin();
   Instruction *I = BinaryOperator::CreateAdd(ArgA, ArgB);
-  auto It = I->insertAt(BB, BB->end());
+  auto It = I->insertInto(BB, BB->end());
   EXPECT_EQ(&*It, I);
   EXPECT_EQ(Ret->getNextNode(), I);
 }
Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1624,7 +1624,7 @@
   EXPECT_EQ(Known.Zero.getZExtValue(), 0u);
 
   BasicBlock *BB = BasicBlock::Create(Context);
-  CI->insertAt(BB, BB->end());
+  CI->insertInto(BB, BB->end());
   Known = computeKnownBits(CI, M.getDataLayout(), /* Depth */ 0);
   // There is no parent function so we cannot look up the vscale_range
   // attribute to determine the number of bits.
Index: llvm/unittests/Analysis/MemorySSATest.cpp
===
--- llvm/unittests/Analysis/MemorySSATest.cpp
+++ llvm/unittests/Analysis/MemorySSATest.cpp
@@ -282,7 +282,7 @@
   // - remove from original block
 
   LoadInst *LoadInstClone = cast(LoadInst1->clone());
-  LoadInstClone->insertAt(Merge, Merge->begin());
+  LoadInstClone->insertInto(Merge, Merge->begin());
   MemoryAccess * NewLoadAccess =
   Updater.createMemoryAccessInBB(LoadInstClone, nullptr,
  LoadInstClone->getParent(),
Index: llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
===
--- llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
+++ llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
@@ -429,7 +429,7 @@
   BasicBlock *BB = BasicBlock::Create(C);
   BB->insertInto(F);
   Instruction *Ret = ReturnInst::Create(C);
-  Ret->insertAt(BB, BB->begin());
+  Ret->insertInto(BB, BB->begin());
   Function *FnAssume = Intrinsic::getDeclaration(Mod.get(), Intrinsic::assume);
 
   std::vector ShuffledArgs;
Index: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
===
--- llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -90,7 +90,7 @@
 // If the function doesn't return void... add a PHI node to the block...
 PN = PHINode::Create(F.getReturnType(), ReturningBlocks.size(),
  "UnifiedRetVal");
-PN->insertAt(NewRetBlock, NewRetBlock->end());
+PN->insertInto(NewRetBlock, New

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

2022-12-15 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added inline comments.



Comment at: clang/test/CodeGen/X86/fexcess-precision.c:89
+// CHECK-EXT-NEXT:[[EXT1:%.*]] = fpext half [[TMP1]] to float
+// CHECK-EXT-NEXT:[[MUL:%.*]] = fmul float [[EXT]], [[EXT1]]
+// CHECK-EXT-NEXT:[[TMP2:%.*]] = load half, ptr [[C_ADDR]]

pengfei wrote:
> andrew.w.kaylor wrote:
> > I apologize for taking so long to get back to this. I'm not sure how to get 
> > this comment to show up as a response to the questions @rjmccall asked 
> > about my earlier remarks here. Apologies if this ends up being redundant.
> > 
> > I said:
> > 
> > > This is not what I'd expect to see. I'd expect the operations to use the 
> > > half type with explicit truncation inserted where needed.
> > 
> > 
> > @rjmccall said:
> > 
> > > Are you suggesting that the frontend emit half operations normally, with 
> > > some intrinsic to force half precision on casts and assignments, and that 
> > > a backend pass would aggressively promote operations between those 
> > > intrinsics? I think that would be a pretty error-prone representation, 
> > > both in terms of guaranteeing the use of excess precision in some 
> > > situations (and thus getting stable behavior across compiler releases) 
> > > and guaranteeing truncation in others (and thus preserving correctness). 
> > > The frontend would have to carefully emit intrinsics in a bunch of places 
> > > or else default to introducing a bug.
> > 
> > 
> > Maybe I'm asking that -fexcess-precision=fast not be an alias of 
> > -fexcess-precision=standard. The idea behind 'fast' as I understand it is 
> > to allow the compiler to generate whatever instructions are most efficient 
> > for the target. If the target supports native fp16 operations, the fastest 
> > code will use those instructions and not use excess precision. If the 
> > target does not support fp16, the fastest code would be to perform the 
> > calculations at 32-bit precision and only truncate on casts and assignments 
> > (or, even faster, not even then). You can see an analogy for what I mean by 
> > looking at what gcc does with 32-bit floats when SSE is disabled: 
> > https://godbolt.org/z/xhEGbjG4G
> > 
> > With -fexcess-precision=fast, gcc takes liberties to make the code run as 
> > fast as possible. With -fexcess-precision=standard, it truncates to the 
> > source value on assignments, casts, or return.
> > 
> > If you generate code using the half type here, the backend will legalize it 
> > and **should** make it as fast as possible. In fact, it looks like 
> > currently the X86 backend will insert calls to extend and truncate the 
> > values to maintain the semantics of the IR 
> > (https://godbolt.org/z/YGnj4cqvv). That's sensible, but it's not what the 
> > X86 backend does in the 32-bit float + no SSE case.
> > 
> > The main thing I'd want to say here is that the front end has no business 
> > trying to decide what will be fastest for the target and encoding that. At 
> > most, the front end should be encoding the semantics in the source and 
> > setting some flag in the IR to indicate the excess precision handling 
> > that's allowed. This feels to me like it requires a new fast-math flag, 
> > maybe 'axp' = "allow excess precision".
> > 
> > The case where the front end is encoding excess precision into the IR feels 
> > much more like -ffp-eval-method. When the front end encodes an fpext to 
> > float and does a calculation, the optimizer is forced to respect that 
> > unless it can prove that doing the calculation at lower precision won't 
> > change the result (and it rarely does that). For targets that have native 
> > FP16 support, this will mean that -fexcess-precision=fast results in slower 
> > code.
> > For targets that have native FP16 support, this will mean that 
> > -fexcess-precision=fast results in slower code.
> 
> This won't be true. We checked `TI.hasLegalHalfType()` before doing excess 
> precision. Maybe better to add a RUN for `avx512fp16` case to address the 
> concern.
> 
> > At most, the front end should be encoding the semantics in the source and 
> > setting some flag in the IR to indicate the excess precision handling 
> > that's allowed.
> 
> I think encoding excess precision into the IR is the easy way to encode the 
> information of the casts and assignments. Otherwise, we have to use 
> intrinsics to tell such information to the backend. As @rjmccall explained, 
> it's more error-prone.
> 
> > If you generate code using the half type here, the backend will legalize it 
> > and should make it as fast as possible.
> 
> I think the current backend implementations in both GCC and LLVM have already 
> tried to make it as fast as possible in the condition of not to make the code 
> too complicated.
> The behavior in 32-bit float + no SSE case is benefited from x87 feature that 
> always does excess precision. It is somehow taking bugs as feature from the 
> semantics of the IR.
> That says, it i

[PATCH] D140086: [analyzer][solver] Improve reasoning for not equal to operator

2022-12-15 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Thanks for going the extra mile to address this last thing. I really appreciate 
it.
I've got only a few minor comments and suggestions.

I'd recommend spell-checking the comments and the summary of this revision.
See my technical comments inline.

The test coverage looks good to me.

Good job.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1641
+// If both have different signs then only we can get more information.
+if (LHS.isUnsigned() ^ RHS.isUnsigned()) {
+  if (LHS.isUnsigned() && (LHS.getBitWidth() >= RHS.getBitWidth())) {

I think in this context `!=` should achieve the same, and we usually prefer 
this operator for this.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1641-1642
+// If both have different signs then only we can get more information.
+if (LHS.isUnsigned() ^ RHS.isUnsigned()) {
+  if (LHS.isUnsigned() && (LHS.getBitWidth() >= RHS.getBitWidth())) {
+

steakhal wrote:
> I think in this context `!=` should achieve the same, and we usually prefer 
> this operator for this.
I was thinking that maybe `if (LHS.isUnsigned() && RHS.isSigned()) {} ... else 
if (LHS.isSigned() && RHS.isUnsigned())` results in cleaner code, as it would 
require one level fewer indentations.
The control-flow looks complicated already enough.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1642
+if (LHS.isUnsigned() ^ RHS.isUnsigned()) {
+  if (LHS.isUnsigned() && (LHS.getBitWidth() >= RHS.getBitWidth())) {
+

Why do we need this additional condition?
If I remove these, I get no test failures, which suggests to me that we have 
some undertested code paths here.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1644-1649
+// If signed range is https://reviews.llvm.org/D140086/new/

https://reviews.llvm.org/D140086

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


[PATCH] D140125: [clang] splits diagnostic message into summary and reason

2022-12-15 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: dblaikie, erichkeane.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added projects: clang, libc++abi, clang-tools-extra.
Herald added subscribers: cfe-commits, libcxx-commits.
Herald added a reviewer: libc++abi.

Structured diagnostics enable us to have diagnostics that contain a headline
description and a detailed description. DiagReason represents the latter,
although some subengines might combine the two into a single message.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140125

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang/include/clang/Basic/Diagnostic.h
  clang/include/clang/Basic/Diagnostic.td
  clang/include/clang/Basic/DiagnosticAST.h
  clang/include/clang/Basic/DiagnosticAnalysis.h
  clang/include/clang/Basic/DiagnosticComment.h
  clang/include/clang/Basic/DiagnosticCrossTU.h
  clang/include/clang/Basic/DiagnosticDriver.h
  clang/include/clang/Basic/DiagnosticFrontend.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/include/clang/Basic/DiagnosticLex.h
  clang/include/clang/Basic/DiagnosticParse.h
  clang/include/clang/Basic/DiagnosticRefactoring.h
  clang/include/clang/Basic/DiagnosticSema.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/DiagnosticSerialization.h
  clang/include/clang/Frontend/ASTUnit.h
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Frontend/ASTUnit.cpp
  clang/test/TableGen/DiagnosticBase.inc
  clang/test/TableGen/deferred-diag.td
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  libcxxabi/test/test_demangle.pass.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -604,7 +604,7 @@
 
   std::vector buildForDocumentation(StringRef Role,
  const Record *R);
-  std::string buildForDefinition(const Record *R);
+  std::string buildForDefinition(const Record *R, StringRef Field);
 
   Piece *getSubstitution(SubstitutionPiece *S) const {
 auto It = Substitutions.find(S->Name);
@@ -1182,9 +1182,10 @@
   return Result;
 }
 
-std::string DiagnosticTextBuilder::buildForDefinition(const Record *R) {
+std::string DiagnosticTextBuilder::buildForDefinition(const Record *R,
+  StringRef Field) {
   EvaluatingRecordGuard Guard(&EvaluatingRecord, R);
-  StringRef Text = R->getValueAsString("Summary");
+  StringRef Text = R->getValueAsString(Field);
   DiagText D(*this, Text);
   std::string Result;
   DiagTextPrinter{*this, Result}.Visit(D.Root);
@@ -1276,7 +1277,7 @@
 
 // Description string.
 OS << ", \"";
-OS.write_escaped(DiagTextBuilder.buildForDefinition(&R)) << '"';
+OS.write_escaped(DiagTextBuilder.buildForDefinition(&R, "Summary")) << '"';
 
 // Warning group associated with the diagnostic. This is stored as an index
 // into the alphabetically sorted warning group table.
@@ -1320,6 +1321,12 @@
 
 // Category number.
 OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap));
+
+// Reasons
+OS << ", /*Reason=*/\"";
+OS.write_escaped(DiagTextBuilder.buildForDefinition(
+R.getValueAsDef("Reason"), "Value"))
+<< '"';
 OS << ")\n";
   }
 }
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -28,7 +28,7 @@
 // out of sync easily?
 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
 #define DIAG(ENUM, CLASS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, NOWERROR,  \
- SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY) \
+ SHOWINSYSHEADER, SHOWINSYSMACRO, DEFER, CATEGORY, REASON) \
   {#ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t)},
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticCrossTUKinds.inc"
Index: clang/test/TableGen/deferred-diag.td
===
--- clang/test/TableGen/deferred-diag.td
+++ clang/test/TableGen/deferred-diag.td
@@ -5,23 +5,23 @@
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
 def test_default : Error<"This error is non-deferrable by default">;
-// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0)
+// CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, true, true, false, 0, /*Reason=*/"")
 
 def test_deferrable : Error<"This error is deferrable">, Deferrable;
-// CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, true, true, true, 0)
+// CHECK-DAG: 

[PATCH] D140105: [clang-format] add missing config parse test for short lambda

2022-12-15 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:545
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
+  CHECK_PARSE("AllowShortLambdasOnASingleLine: false",
+  AllowShortLambdasOnASingleLine, FormatStyle::SLS_None);

Please add this comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140105

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


[PATCH] D139586: [Clang][C++23] Lifetime extension in range-based for loops

2022-12-15 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D139586#3987252 , @royjacobson 
wrote:

> The (non-wording) paper makes a pretty convincing case to just apply this 
> retroactively to any C++11 code 
> (https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2644r1.pdf). I 
> think we should apply this retroactively, maybe add a pedantic warning when 
> we do a lifetime extension on code before C++23.

Just noting that the committee did not vote this in as a Defect Report, but I 
mostly agree that people should code for the new behaviour and that the old 
behaviour is unlikely to be relied on. I suspect this should be highlighted as 
technically a breaking change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139586

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

Michael137 wrote:
> Michael137 wrote:
> > dblaikie wrote:
> > > @aprantl any idea if this is good/OK? (I guess it probably is - but maybe 
> > > these strings were never meant to ignore/suppress default arguments of 
> > > any kind? or maybe this is an ABI sort of thing where it suppressing some 
> > > but not others is now unchangeable?)
> > Good point. There was a thread on the cfe mailing list a while ago about 
> > the last time this broke: 
> > https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> > 
> > This was @rsmith's stance:
> > ```
> > I think some of the other recent TypePrinter changes might also risk
> > changing the @encode output. Generally it seems unwise for @encode to be
> > using the type pretty-printer if it wants to be ABI-stable; I don't think
> > it's reasonable to expect any guarantees as to the stability of
> > pretty-printed type names. I think USR generation suffers from similar
> > problems; it too uses the type pretty-printer to generate
> > supposedly-ABI-stable keys in at least some cases.
> > ```
> see https://reviews.llvm.org/D90622
To me it really looks like the intention of the feature is to not substitute 
default parameters. But if we stop doing this now it will likely result in a 
surprising code size increase, that may not be considered worth it compared to 
the risk of breaking ABI by changing a default template parameter.

As far as this patch is concerned, it's neutral to this decision (which may not 
have been a conscious one).
It's certainly not good that every type printer change is an ABI break.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D140010: [clang][ExtractAPI] Fix naming of typedef'd anonymous enums

2022-12-15 Thread Zixu Wang via Phabricator via cfe-commits
zixuw accepted this revision.
zixuw added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:174-175
+  StringRef Name = Decl->getName();
   if (Name.empty())
 Name = getTypedefName(Decl);
+  if (Name.empty()) {

dang wrote:
> zixuw wrote:
> > dang wrote:
> > > zixuw wrote:
> > > > Aren't these two lines supposed to do this?
> > > Qualified name is never empty, just contains some version of anonymous, 
> > > whereas getName() is actually empty for anonymous types. The flow is now, 
> > > try to populate with `getName` (which is unqualified and puts us in a 
> > > better spot for the eventual support of c++ and nested types). and if 
> > > that doesn't work fallback to the qualified name.
> > Sorry I meant `getTypedefName(Decl)`, which also tries to get the typedef 
> > name for an anonymous tag.
> > The patch summary says "Anonymous enums that are typedef'd should take on 
> > the name of the typedef." and I was a bit confused of the change.
> > 
> > Now we have three (two fallbacks) for Enum:
> > 1. straightforward `Decl->getName()`, and if that's empty
> > 2. `getTypedefName(Decl)`, which calls `Decl->getTypedefNameForAnonDecl()`, 
> > and if that fails,
> > 3. `Decl->printQualifiedName(OS)`
> > 
> > My questions:
> > 1. Do we need all three? We should be able to get rid of at least one 
> > right? The logic seems to be: if enum is named, use it. Otherwise get 
> > typedef name if it's part of a typedef. And finally leave something like 
> > `(anonymous)` if it's just an unattached anonymous enum.
> > 2. For the `printQualifiedName` path, isn't `Name` referencing a local 
> > string inside the method?
> > 3. structs are also tags that can be anonymous and inside a typedef, do we 
> > need similar changes there?
> > 
> > 
> 1. Yup that is exactly what I am trying to do here. If you can think of a way 
> of removing a chunk then let's do it. The reason for the third fallback is to 
> have a name for the container of an anonymous (without a typedef) top level 
> enum (there is an example of that in the enum.c test case)
> 2. Not entirely sure what you mean. If you are referring to the fact that the 
> backing storage for `Name` in this case is a local variable, this is fine 
> because we copy the string into the `APISet` when constructing the record 
> within this method a bit further down.
> 3. The struct case is a little different, It's not possible to have to have 
> an anonymous struct without a typedef at the top level, whereas it is 
> possible to do so with an enum (e.g. to introduce some constants). Currently 
> for structs we only do `Decl->getName()` and falls back to 
> `getTypedefName(Decl)`. If that fails we ignore the struct because it must be 
> a nested anonymous struct (that logic is flawed and we should aim to support 
> anonymous structs properly, but that would be a follow up patch to this one).
Ah I see. So before this patch we had `getQualifiedNameAsString` which would 
always bypass the following `getTypedefName` even if it's an anonymous within a 
typedef. This patch cleared out the logic and ordering.

> we copy the string into the APISet when constructing the record within this 
> method a bit further down.
😅 right, that part was folded in the diff view and I totally forgot we had that 
there...

LGTM. Thanks Daniel!





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140010

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


[PATCH] D140035: [X86] Prevent -mibt-seal to work together with -flto=thin

2022-12-15 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen accepted this revision.
samitolvanen added a comment.
This revision is now accepted and ready to land.

In D140035#3996066 , @joaomoreira 
wrote:

> Regarding not being able to reproduce this in kernel -- never mind... I was 
> misled by setup issues while running IBT kernels in QEMU. I managed to fix 
> the setup and confirm that kernel won't boot.

OK, great. Thanks for double checking!

The patch itself looks good to me, but I suspect ibt-seal in general has the 
same issue as D138337  where it can drop 
endbr instructions from `isUsedInRegularObj` symbols that are not address-taken 
in the bitcode (e.g. functions whose address is only taken in stand-alone 
assembly). I saw this issue only in the arm64 Linux kernel, but there's always 
a chance a similar code pattern emerges on the x86 side at some point in future 
too. This can obviously be worked around in the kernel, but just something to 
keep in mind.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1856
 
-  if (Opts.PrepareForLTO && Args.hasArg(OPT_mibt_seal))
+  if (Opts.PrepareForLTO &&
+  !Opts.PrepareForThinLTO &&

Please run `git clang-format` for the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140035

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


[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-15 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/include/clang/AST/TemplateUtils.h:19
+namespace clang {
+namespace TemplateUtils {
+/// Make a best-effort determination of whether the type T can be produced by

Michael137 wrote:
> dblaikie wrote:
> > aprantl wrote:
> > > It looks like all the other namespaces in Clang are all lowercase?
> > Yeah, +1 to the naming.
> > 
> > & maybe not introducing a new "utils" bucket - they can be a bit of a 
> > dumping ground. Could this operation belong elsewhere/in some existing 
> > type, or maybe doesn't need a namespace wrapper - could be a free function 
> > in the `clang` namespace?)
> I suppose this could just be a static function on `clang::TypePrinter`. We 
> use it from `CGDebugInfo` already anyway so it wouldn't be an extra 
> dependency. Wdyt? @aprantl @dblaikie 
I don't have any strong opinions either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[clang] 678ded0 - [clang] Support for read-only types

2022-12-15 Thread via cfe-commits

Author: MalavikaSamak
Date: 2022-12-15T12:09:01-08:00
New Revision: 678ded017f21b22da3ab20ffafe2bc2dc4457493

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

LOG: [clang] Support for read-only types

The main goal of this work is to allow developers to express the need to place 
instances
of a class or structure in the read-only part of the program memory. Such a 
placement is
desirable to prevent any further modifications to the instances of a given 
structure, by
leveraging the read-only run time protection.

To achieve this, we are introducing a new attribute that can be attached to any 
record
definition or a declaration. The compiler enforces that every instance of this 
type can
be placed in the read-only segment of the program memory, provided the target 
triplet
supports such a placement. If an instance of a given type bearing this 
attribute doesn’t
satisfy such a placement, the compiler attaches an appropriate warning at 
suitable program
locations. In other words, adding this attribute to a type requires every 
instance of this
type to be a global const, which are placed in the read-only segments for most 
target
triplets. However, this is *not a language feature* and it *need not* be true 
for
*all target triplets*.

The current patch emits a warning at global variable declaration sites of types 
bearing
the attribute without const qualification and corresponding note attached to 
the type
definition/declaration.

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

Added: 
clang/test/Sema/attr-read-only-placement.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae6a52f57209..0da79fc1a2a9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -546,6 +546,11 @@ Attribute Changes in Clang
   used ``201904L`` (the date the proposal was seen by the committee) by 
mistake.
   There were no other changes to the attribute behavior.
 
+- Introduced a new record declaration attribute 
``__attribute__((enforce_read_only_placement))``
+  to support analysis of instances of a given type focused on read-only program
+  memory placement. It emits a warning if something in the code provably 
prevents
+  an instance from a read-only memory placement.
+
 Windows Support
 ---
 - For the MinGW driver, added the options ``-mguard=none``, ``-mguard=cf`` and

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index eaf4a6db3600..aef3356ed405 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4096,3 +4096,8 @@ def FunctionReturnThunks : InheritableAttr,
   let Subjects = SubjectList<[Function]>;
   let Documentation = [FunctionReturnThunksDocs];
 }
+def ReadOnlyPlacement : InheritableAttr {
+  let Spellings = [Clang<"enforce_read_only_placement">];
+  let Subjects = SubjectList<[Record]>;
+  let Documentation = [ReadOnlyPlacementDocs];
+}

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a5ea3915a94d..77f72d2b2bd4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6782,3 +6782,42 @@ The symbol used for ``thunk-extern`` is target specific:
 As such, this function attribute is currently only supported on X86 targets.
   }];
 }
+
+def ReadOnlyPlacementDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{This attribute is attached to a structure, class or union 
declaration.
+  When attached to a record declaration/definition, it checks if all instances
+  of this type can be placed in the read-only data segment of the program. If 
it
+  finds an instance that can not be placed in a read-only segment, the compiler
+  emits a warning at the source location where the type was used.
+
+  Examples:
+  * ``struct __attribute__((enforce_read_only_placement)) Foo;``
+  * ``struct __attribute__((enforce_read_only_placement)) Bar { ... };``
+
+  Both ``Foo`` and ``Bar`` types have the ``enforce_read_only_placement`` 
attribute.
+
+  The goal of introducing this attribute is to assist developers with writing 
secure
+  code. A ``const``-qualified global is generally placed in the read-only 
section
+  of the memory that has additional run time protection from malicious writes. 
By
+  attaching this attribute to a declaration, the developer can express the 
intent
+  to place a

[PATCH] D135851: [clang] Support for read-only types

2022-12-15 Thread Malavika Samak 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 rG678ded017f21: [clang] Support for read-only types (authored 
by malavikasamak).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D135851?vs=481148&id=483289#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135851

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-read-only-placement.cpp

Index: clang/test/Sema/attr-read-only-placement.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-read-only-placement.cpp
@@ -0,0 +1,170 @@
+// RUN: %clang_cc1 -Wread-only-types %s -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++2a -Wread-only-types %s -verify -fsyntax-only
+// RUN: %clang_cc1 -std=c++17 -Wread-only-types %s -verify -fsyntax-only
+
+struct __attribute__((enforce_read_only_placement)) A { // #A_DECL
+};
+
+A a1; // expected-warning {{object of type 'A' cannot be placed in read-only memory}}
+  // expected-note@#A_DECL {{type was declared read-only here}}
+const A a2[10]; // no-warning
+A a3[20]; // expected-warning {{object of type 'A' cannot be placed in read-only memory}}
+  // expected-note@#A_DECL {{type was declared read-only here}}
+
+
+
+struct B;
+struct __attribute__((enforce_read_only_placement)) B { //#B_DECL
+};
+
+B b1; // expected-warning {{object of type 'B' cannot be placed in read-only memory}}
+  // expected-note@#B_DECL {{type was declared read-only here}}
+const B b2; // no-warning
+const B b3[4]; // no-warning
+B b4[5]; // expected-warning {{object of type 'B' cannot be placed in read-only memory}}
+ // expected-note@#B_DECL {{type was declared read-only here}}
+B b5[5][5]; // expected-warning {{object of type 'B' cannot be placed in read-only memory}}
+// expected-note@#B_DECL {{type was declared read-only here}}
+B b10[5][5][5]; // expected-warning {{object of type 'B' cannot be placed in read-only memory}}
+// expected-note@#B_DECL {{type was declared read-only here}}
+
+void method1() {
+static const B b6;
+static B b7;// expected-warning {{object of type 'B' cannot be placed in read-only memory}}
+// expected-note@#B_DECL {{type was declared read-only here}}
+B b8; // no-warning
+const B b9; // no-warning
+}
+
+struct C;
+struct __attribute__((enforce_read_only_placement)) C; // expected-note {{type was declared read-only here}}
+struct C { // no-note. The note should be attached to the definition/declaration bearing the attribute
+};
+
+C c1; // expected-warning {{object of type 'C' cannot be placed in read-only memory}}
+
+// Cases to be handled by the follow-up patches.
+
+// Attaching and checking the attribute in reverse, where the attribute is attached after the
+// type definition
+struct D;
+struct D { //expected-note{{previous definition is here}}
+};
+struct __attribute__((enforce_read_only_placement)) D; // #3
+// expected-warning@#3{{attribute declaration must precede definition}}
+
+D d1; // We do not  emit a warning here, as there is another warning for declaring
+  // a type after the definition
+
+
+// Cases where the attribute must be explicitly attached to another type
+// Case 1: Inheriting from a type that has the attribute
+struct E : C { // FIXME: warn the user declarations of type `E`, that extends `C`, won't be
+   // checked for read only placement because `E` is not marked as `C` is.
+};
+
+// Case 2: Declaring a field of the type that has the attribute
+struct F {
+C c1; // FIXME: warn the user type `F` that wraps type `C` won't be checked for
+  // read only placement
+};
+
+struct BaseWithoutAttribute {
+int a;
+};
+
+struct  __attribute__((enforce_read_only_placement)) J : BaseWithoutAttribute { // no-warning
+};
+
+struct __attribute__((enforce_read_only_placement)) BaseWithAttribute {
+int i;
+};
+
+struct __attribute__((enforce_read_only_placement)) Derived : BaseWithAttribute { // no-warning
+int j;
+};
+
+struct __attribute__((enforce_read_only_placement)) WrapperToAttributeInstance { // no-warning
+BaseWithAttribute b;
+};
+
+struct __attribute__((enforce_read_only_placement)) WrapperToNoAttributeInstance { // no-warning
+BaseWithoutAttribute b;
+};
+
+// Cases where the const qualification doesn't ensure read-only memory placement
+// of an instance.
+
+// Case 1: The type defines/inherits mutable data members
+struct __att

[PATCH] D140104: [clang][dataflow] Remove unused argument in getNullability

2022-12-15 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang/AST/Type.h:2550
   /// be lost by canonicalization and desugaring.
-  Optional getNullability(const ASTContext &context) const;
+  Optional getNullability() const;
 

Could you add a temporary deprecated overload with the old signature that calls 
the no-arg function?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140104

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


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl updated this revision to Diff 483297.
rsundahl added a comment.

Added the test warn-not-error-Xfoo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Misc/warn-not-error-Xfoo.c


Index: clang/test/Misc/warn-not-error-Xfoo.c
===
--- /dev/null
+++ clang/test/Misc/warn-not-error-Xfoo.c
@@ -0,0 +1,14 @@
+// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck 
--check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck 
--check-prefix=CHECK_JOINED_FOO %s
+
+// This test ensures that we only warn on -X and -X
+// in case it is used downstream. If we error, we can't ignore it and some
+// use of these (ignored) flags are in legacy use.
+// TODO: Deprecate with timebox warning so consumers can respond.
+
+// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' 
[-Wunused-command-line-argument]
+// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' 
[-Wunused-command-line-argument]
+
+// CHECK-NOT: clang{.*}: error: unknown argument:
+
+void f(void) {}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -846,6 +846,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, 
Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;


Index: clang/test/Misc/warn-not-error-Xfoo.c
===
--- /dev/null
+++ clang/test/Misc/warn-not-error-Xfoo.c
@@ -0,0 +1,14 @@
+// RUN: %clang -c -Xfoo %s 2>&1 | FileCheck --check-prefix=CHECK_STANDALONE_FOO %s
+// RUN: %clang -c -Xfoo=bar %s 2>&1 | FileCheck --check-prefix=CHECK_JOINED_FOO %s
+
+// This test ensures that we only warn on -X and -X
+// in case it is used downstream. If we error, we can't ignore it and some
+// use of these (ignored) flags are in legacy use.
+// TODO: Deprecate with timebox warning so consumers can respond.
+
+// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' [-Wunused-command-line-argument]
+// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' [-Wunused-command-line-argument]
+
+// CHECK-NOT: clang{.*}: error: unknown argument:
+
+void f(void) {}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -846,6 +846,7 @@
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group,
   HelpText<"Pass  to the preprocessor">, MetaVarName<"">;
 def X_Flag : Flag<["-"], "X">, Group;
+def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139717: Revert "[Driver] Remove Joined -X"

2022-12-15 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl added a comment.

I added a test so we can catch any regression. If we choose to deprecate then 
we can modify the test to watch for the "is deprecated" message that should be 
asserted for "some time" appropriate. Thank you all for your input.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139717

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


[PATCH] D139988: [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters

2022-12-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Looks good to me, thanks!

Patch description might need a tweak, this bit:

> Type template parameters where the type is itself a template instantiation 
> (e.g., `template>`)

The quoted example is impossible (infinitely recursive) & the description might 
be less specific than necessary - is any template instantiation a problem (eg: 
`template`) for the existing code/addressed by this 
patch, or only defaults that are instantiated with a prior template parameter 
in the same template parameter list? If it's the latter, would be good to 
include that nuance, if it's the former might be worth clarifying that/using 
some `Foo` in the example insetad of `Foo`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139988

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


[clang] e0f2150 - [clang] Convert tests to check 'target=...'

2022-12-15 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-15T12:26:33-08:00
New Revision: e0f2150e99e5e429c33047f25e3da2ab146d0f57

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

LOG: [clang] Convert tests to check 'target=...'

Part of the project to eliminate special handling for triples in lit
expressions.

Added: 


Modified: 
clang/test/Analysis/checker-plugins.c
clang/test/CodeGen/c-strings.c
clang/test/PCH/leakfiles.test

Removed: 




diff  --git a/clang/test/Analysis/checker-plugins.c 
b/clang/test/Analysis/checker-plugins.c
index 69fab8fa6eed1..92a48de87f772 100644
--- a/clang/test/Analysis/checker-plugins.c
+++ b/clang/test/Analysis/checker-plugins.c
@@ -2,7 +2,7 @@
 
 // FIXME: This test fails on clang-stage2-cmake-RgSan,
 // see also https://reviews.llvm.org/D62445#1613268
-// UNSUPPORTED: darwin
+// UNSUPPORTED: target={{.*darwin.*}}
 
 // RUN: %clang_analyze_cc1 -verify %s \
 // RUN:   -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext \

diff  --git a/clang/test/CodeGen/c-strings.c b/clang/test/CodeGen/c-strings.c
index 687394168534d..9e1ac0f02b5e9 100644
--- a/clang/test/CodeGen/c-strings.c
+++ b/clang/test/CodeGen/c-strings.c
@@ -1,4 +1,4 @@
-// XFAIL: aarch64-pc-windows-msvc
+// XFAIL: taraget=aarch64-pc-windows-msvc
 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck 
%s --check-prefix=CHECK --check-prefix=ITANIUM
 // RUN: %clang_cc1 -triple %ms_abi_triple -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSABI
 
@@ -21,7 +21,7 @@
 // fails the check for "@f3.x = ... align [ALIGN]", since ALIGN is derived
 // from the alignment of a single i8, which is still 1.
 
-// XFAIL: csky
+// XFAIL: target=csky{{.*}}
 // CSKY aligns arrays of size 4+ bytes to a 32-bit boundary, which
 // fails the check for "@f2.x = ... align [ALIGN]", since ALIGN is derived
 // from the alignment of a single i8, which is still 1.

diff  --git a/clang/test/PCH/leakfiles.test b/clang/test/PCH/leakfiles.test
index 90b279026bc1a..dc4047ac3ff48 100644
--- a/clang/test/PCH/leakfiles.test
+++ b/clang/test/PCH/leakfiles.test
@@ -3,7 +3,7 @@
 //
 // This test requires bash loops and ulimit.
 // REQUIRES: shell
-// UNSUPPORTED: win32
+// UNSUPPORTED: target={{.*win32.*}}
 //
 // Set up source files. lib/lib.h includes lots of lib*.h files in that dir.
 // client.c includes lib/lib.h, and also the individual files directly.



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


[clang] 32b38d2 - [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()

2022-12-15 Thread Vasileios Porpodas via cfe-commits

Author: Vasileios Porpodas
Date: 2022-12-15T12:27:45-08:00
New Revision: 32b38d248fd3c75abc5c86ab6677b6cb08a703cc

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

LOG: [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be 
consistent with BasicBlock::insertInto()

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

Added: 


Modified: 
clang/lib/CodeGen/CGCleanup.cpp
llvm/docs/ProgrammersManual.rst
llvm/examples/BrainF/BrainF.cpp
llvm/examples/ModuleMaker/ModuleMaker.cpp
llvm/include/llvm/IR/BasicBlock.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/CodeGen/WinEHPrepare.cpp
llvm/lib/IR/Instruction.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/lib/Transforms/Utils/CodeExtractor.cpp
llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
llvm/lib/Transforms/Utils/LowerSwitch.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
llvm/unittests/Analysis/MemorySSATest.cpp
llvm/unittests/Analysis/ValueTrackingTest.cpp
llvm/unittests/IR/InstructionsTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 94e25ae8f4476..43758ac27e439 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -942,7 +942,7 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
   // Append the prepared cleanup prologue from above.
   llvm::BasicBlock *NormalExit = Builder.GetInsertBlock();
   for (unsigned I = 0, E = InstsToAppend.size(); I != E; ++I)
-InstsToAppend[I]->insertAt(NormalExit, NormalExit->end());
+InstsToAppend[I]->insertInto(NormalExit, NormalExit->end());
 
   // Optimistically hope that any fixups will continue falling through.
   for (unsigned I = FixupDepth, E = EHStack.getNumBranchFixups();

diff  --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index 242b87e3dbe32..868e6851944b1 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -2861,7 +2861,7 @@ sequence of instructions that form a ``BasicBlock``:
 BasicBlock *pb = ...;
 auto *newInst = new Instruction(...);
 
-newInst->insertAt(pb, pb->end()); // Appends newInst to pb
+newInst->insertInto(pb, pb->end()); // Appends newInst to pb
 
   becomes:
 

diff  --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp
index 5d0cbd8d8f87e..b3ff5574d3fc7 100644
--- a/llvm/examples/BrainF/BrainF.cpp
+++ b/llvm/examples/BrainF/BrainF.cpp
@@ -96,7 +96,7 @@ void BrainF::header(LLVMContext& C) {
   allocsize = ConstantExpr::getTruncOrBitCast(allocsize, IntPtrTy);
   ptr_arr = CallInst::CreateMalloc(BB, IntPtrTy, Int8Ty, allocsize, val_mem, 
nullptr, "arr");
-  cast(ptr_arr)->insertAt(BB, BB->end());
+  cast(ptr_arr)->insertInto(BB, BB->end());
 
   //call void @llvm.memset.p0i8.i32(i8 *%arr, i8 0, i32 %d, i1 0)
   {
@@ -128,7 +128,7 @@ void BrainF::header(LLVMContext& C) {
   endbb = BasicBlock::Create(C, label, brainf_func);
 
   //call free(i8 *%arr)
-  CallInst::CreateFree(ptr_arr, endbb)->insertAt(endbb, endbb->end());
+  CallInst::CreateFree(ptr_arr, endbb)->insertInto(endbb, endbb->end());
 
   //ret void
   ReturnInst::Create(C, endbb);

diff  --git a/llvm/examples/ModuleMaker/ModuleMaker.cpp 
b/llvm/examples/ModuleMaker/ModuleMaker.cpp
index 033f91d0830f2..a43b344a79335 100644
--- a/llvm/examples/ModuleMaker/ModuleMaker.cpp
+++ b/llvm/examples/ModuleMaker/ModuleMaker.cpp
@@ -55,10 +55,10 @@ int main() {
 "addresult");
 
   // explicitly insert it into the basic block...
-  Add->insertAt(BB, 

[PATCH] D140085: [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()

2022-12-15 Thread Vasileios Porpodas 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 rG32b38d248fd3: [NFC] Rename Instruction::insertAt() to 
Instruction::insertInto(), to be… (authored by vporpo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140085

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  llvm/docs/ProgrammersManual.rst
  llvm/examples/BrainF/BrainF.cpp
  llvm/examples/ModuleMaker/ModuleMaker.cpp
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/WinEHPrepare.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
  llvm/lib/Transforms/IPO/IROutliner.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
  llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
  llvm/lib/Transforms/Scalar/JumpThreading.cpp
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
  llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/lib/Transforms/Utils/CloneFunction.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
  llvm/lib/Transforms/Utils/LowerSwitch.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
  llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
  llvm/unittests/Analysis/MemorySSATest.cpp
  llvm/unittests/Analysis/ValueTrackingTest.cpp
  llvm/unittests/IR/InstructionsTest.cpp

Index: llvm/unittests/IR/InstructionsTest.cpp
===
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -1695,7 +1695,7 @@
   BasicBlock *BB = &*F->begin();
   Instruction *Ret = &*BB->begin();
   Instruction *I = BinaryOperator::CreateAdd(ArgA, ArgB);
-  auto It = I->insertAt(BB, BB->begin());
+  auto It = I->insertInto(BB, BB->begin());
   EXPECT_EQ(&*It, I);
   EXPECT_EQ(I->getNextNode(), Ret);
 }
@@ -1714,7 +1714,7 @@
   BasicBlock *BB = &*F->begin();
   Instruction *Ret = &*BB->begin();
   Instruction *I = BinaryOperator::CreateAdd(ArgA, ArgB);
-  auto It = I->insertAt(BB, BB->end());
+  auto It = I->insertInto(BB, BB->end());
   EXPECT_EQ(&*It, I);
   EXPECT_EQ(Ret->getNextNode(), I);
 }
Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1624,7 +1624,7 @@
   EXPECT_EQ(Known.Zero.getZExtValue(), 0u);
 
   BasicBlock *BB = BasicBlock::Create(Context);
-  CI->insertAt(BB, BB->end());
+  CI->insertInto(BB, BB->end());
   Known = computeKnownBits(CI, M.getDataLayout(), /* Depth */ 0);
   // There is no parent function so we cannot look up the vscale_range
   // attribute to determine the number of bits.
Index: llvm/unittests/Analysis/MemorySSATest.cpp
===
--- llvm/unittests/Analysis/MemorySSATest.cpp
+++ llvm/unittests/Analysis/MemorySSATest.cpp
@@ -282,7 +282,7 @@
   // - remove from original block
 
   LoadInst *LoadInstClone = cast(LoadInst1->clone());
-  LoadInstClone->insertAt(Merge, Merge->begin());
+  LoadInstClone->insertInto(Merge, Merge->begin());
   MemoryAccess * NewLoadAccess =
   Updater.createMemoryAccessInBB(LoadInstClone, nullptr,
  LoadInstClone->getParent(),
Index: llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
===
--- llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
+++ llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
@@ -429,7 +429,7 @@
   BasicBlock *BB = BasicBlock::Create(C);
   BB->insertInto(F);
   Instruction *Ret = ReturnInst::Create(C);
-  Ret->insertAt(BB, BB->begin());
+  Ret->insertInto(BB, BB->begin());
   Function *FnAssume = Intrinsic::getDeclaration(Mod.get(), Intrinsic::assume);
 
   std::vector ShuffledArgs;
Index: llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
===
--- llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ llvm/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -90,7 +90,7 @@
 // If the function doesn't return void... add a PHI node to the block...
 PN = PHINode::

[PATCH] D139989: [clang][DebugInfo] Add DW_AT_default_value support for template template parameters

2022-12-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Looks good to me - we'd usually split the LLVM part from the Clang part, but I 
don't think we have fine grained unit tests for DIBuilder (could you check - if 
we do, then the LLVM part should go separately, with unit test coverage, then 
the Clang part can go in that uses it) & /maybe/ it's worth having a default 
value for the `IsDefault` argument, so any existing callers aren't broken, but 
I don't feel strongly about it if it all works, the number of external callers 
is probably quite small/not a big deal.

(if you do split up the clang/llvm parts into separate commits, no need to send 
them as separate reviews - you can commit them directly)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139989

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


[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good to me




Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

aprantl wrote:
> Michael137 wrote:
> > Michael137 wrote:
> > > dblaikie wrote:
> > > > @aprantl any idea if this is good/OK? (I guess it probably is - but 
> > > > maybe these strings were never meant to ignore/suppress default 
> > > > arguments of any kind? or maybe this is an ABI sort of thing where it 
> > > > suppressing some but not others is now unchangeable?)
> > > Good point. There was a thread on the cfe mailing list a while ago about 
> > > the last time this broke: 
> > > https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> > > 
> > > This was @rsmith's stance:
> > > ```
> > > I think some of the other recent TypePrinter changes might also risk
> > > changing the @encode output. Generally it seems unwise for @encode to be
> > > using the type pretty-printer if it wants to be ABI-stable; I don't think
> > > it's reasonable to expect any guarantees as to the stability of
> > > pretty-printed type names. I think USR generation suffers from similar
> > > problems; it too uses the type pretty-printer to generate
> > > supposedly-ABI-stable keys in at least some cases.
> > > ```
> > see https://reviews.llvm.org/D90622
> To me it really looks like the intention of the feature is to not substitute 
> default parameters. But if we stop doing this now it will likely result in a 
> surprising code size increase, that may not be considered worth it compared 
> to the risk of breaking ABI by changing a default template parameter.
> 
> As far as this patch is concerned, it's neutral to this decision (which may 
> not have been a conscious one).
> It's certainly not good that every type printer change is an ABI break.
Awesome, thanks for tracking down that context @Michael137.

Not quite sure I'm following you @aprantl, but I think you're saying this 
change is OK/seems consistent with other changes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D139985: [clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component

2022-12-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/include/clang/AST/TemplateUtils.h:19
+namespace clang {
+namespace TemplateUtils {
+/// Make a best-effort determination of whether the type T can be produced by

aprantl wrote:
> Michael137 wrote:
> > dblaikie wrote:
> > > aprantl wrote:
> > > > It looks like all the other namespaces in Clang are all lowercase?
> > > Yeah, +1 to the naming.
> > > 
> > > & maybe not introducing a new "utils" bucket - they can be a bit of a 
> > > dumping ground. Could this operation belong elsewhere/in some existing 
> > > type, or maybe doesn't need a namespace wrapper - could be a free 
> > > function in the `clang` namespace?)
> > I suppose this could just be a static function on `clang::TypePrinter`. We 
> > use it from `CGDebugInfo` already anyway so it wouldn't be an extra 
> > dependency. Wdyt? @aprantl @dblaikie 
> I don't have any strong opinions either way.
Sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139985

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


[PATCH] D140155: [OpenMP] Allow host call to nohost function with host variant

2022-12-15 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 created this revision.
doru1004 added reviewers: carlo.bertolli, ronl, gregrodgers, jdoerfert, 
jhuber6, ABataev.
doru1004 added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
doru1004 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

In OpenMP 5.2 when a nohost function is called from the host, the host variant 
of that function is called if one is declared.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140155

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_messages.cpp

Index: clang/test/OpenMP/declare_target_messages.cpp
===
--- clang/test/OpenMP/declare_target_messages.cpp
+++ clang/test/OpenMP/declare_target_messages.cpp
@@ -11,10 +11,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
 
-int a, b, z; // omp5-error {{variable captured in declare target region must appear in a to clause}} // omp51-error {{variable captured in declare target region must appear in a to clause}}
+int a, b, z; // omp5-error {{variable captured in declare target region must appear in a to clause}} // omp51-error {{variable captured in declare target region must appear in a to clause}} omp52-error {{variable captured in declare target region must appear in a to clause}}
 __thread int t; // expected-note {{defined as threadprivate or thread local}}
 
 #pragma omp declare target . // expected-error {{expected '(' after 'declare target'}}
@@ -23,16 +25,16 @@
 void f();
 #pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
 
-#pragma omp declare target map(a) // omp45-error {{expected at least one 'to' or 'link' clause}} omp5-error {{expected at least one 'to' or 'link' clause}} omp51-error {{expected at least one 'to', 'link' or 'indirect' clause}} omp45-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}} omp5-error {{unexpected 'map' clause, only 'to', 'link' or 'device_type' clauses expected}} omp51-error {{unexpected 'map' clause, only 'to', 'link', 'device_type' or 'indirect' clauses expected}}
+#pragma omp declare target map(a) // omp45-error {{expected at least one 'to' or 'link' clause}} omp5-error {{expected at least one 'to' or 'link' clause}} omp51-error {{expected at least one 'to', 'link' or 'indirect' clause}} omp45-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}} omp5-error {{unexpected 'map' clause, only 'to', 'link' or 'device_type' clauses expected}} omp51-error {{unexpected 'map' clause, only 'to', 'link', 'device_type' or 'indirect' clauses expected}} omp52-error {{unexpected 'map' clause, only 'enter', 'link', 'device_type' or 'indirect' clauses expected}} omp52-error {{expected at least one 'enter', 'link' or 'indirect' clause}}
 
-#pragma omp declare target to(foo1) // expected-error {{use of undeclared identifier 'foo1'}}
+#pragma omp declare target to(foo1) // omp45-error {{use of undeclared identifier 'foo1'}} omp5-error {{use of undeclared identifier 'foo1'}} omp51-error {{use of undeclared identifier 'foo1'}} omp52-error {{unexpected 'to' clause, use 'enter' instead}} omp52-error {{expected at least one 'enter', 'link' or 'indirect' clause}}
 
 #pragma omp declare target link(foo2) // expected-error {{use of undeclared identifier 'foo2'}}
 
-#pragma omp declare target to(f) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note {{marked as 'device_type(host)' here}}
+#pragma omp declare target to(f) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note {{marked as 'device_type(host)' here}} omp52-error {{unexpected 'to' clause, use 'enter' instead}} omp52-error {{expected at least one 'enter', 'link' or 'indirect' clause}}
 
 void q();
-#pragma omp declare target to(q) device_type(any) device_type(any) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-warning {{more than one 'device_type' clause is specified}} // omp51-warning {{more than one 'device_type' clause is specified}}
+#pragma omp declare target to(q) devic

[PATCH] D139986: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types

2022-12-15 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/test/CodeGenObjCXX/encode.mm:93-94
   // FIXME: This difference is due to D76801. It was probably an unintentional 
change. Maybe we want to undo it?
-  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [49 x i8] 
c"{vector >=[4f]}\00"
-  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [48 x i8] 
c"{vector>=[4f]}\00"
+  // CHECKCXX98: @_ZN11rdar93574002ggE ={{.*}} constant [45 x i8] 
c"{vector >=[4f]}\00"
+  // CHECKCXX20: @_ZN11rdar93574002ggE ={{.*}} constant [44 x i8] 
c"{vector>=[4f]}\00"
   extern const char gg[] = @encode(vector4f);

dblaikie wrote:
> aprantl wrote:
> > Michael137 wrote:
> > > Michael137 wrote:
> > > > dblaikie wrote:
> > > > > @aprantl any idea if this is good/OK? (I guess it probably is - but 
> > > > > maybe these strings were never meant to ignore/suppress default 
> > > > > arguments of any kind? or maybe this is an ABI sort of thing where it 
> > > > > suppressing some but not others is now unchangeable?)
> > > > Good point. There was a thread on the cfe mailing list a while ago 
> > > > about the last time this broke: 
> > > > https://lists.llvm.org/pipermail/cfe-dev/2020-November/067194.html
> > > > 
> > > > This was @rsmith's stance:
> > > > ```
> > > > I think some of the other recent TypePrinter changes might also risk
> > > > changing the @encode output. Generally it seems unwise for @encode to be
> > > > using the type pretty-printer if it wants to be ABI-stable; I don't 
> > > > think
> > > > it's reasonable to expect any guarantees as to the stability of
> > > > pretty-printed type names. I think USR generation suffers from similar
> > > > problems; it too uses the type pretty-printer to generate
> > > > supposedly-ABI-stable keys in at least some cases.
> > > > ```
> > > see https://reviews.llvm.org/D90622
> > To me it really looks like the intention of the feature is to not 
> > substitute default parameters. But if we stop doing this now it will likely 
> > result in a surprising code size increase, that may not be considered worth 
> > it compared to the risk of breaking ABI by changing a default template 
> > parameter.
> > 
> > As far as this patch is concerned, it's neutral to this decision (which may 
> > not have been a conscious one).
> > It's certainly not good that every type printer change is an ABI break.
> Awesome, thanks for tracking down that context @Michael137.
> 
> Not quite sure I'm following you @aprantl, but I think you're saying this 
> change is OK/seems consistent with other changes?
The current code (for @encode and USRs) seems to assume that TypePrinter output 
is stable.

I (personally) think that assumption ought to be wrong, because otherwise we'd 
never be able to make improvements such as this patch.

Aside from my personal preferences, practically this patch causes a problem for 
shipping an Objective-C compiler, since this is an ABI-breaking change. That's 
why I'd like to hear from someone with more insight into how `@encoding` is 
used in Objective-C wether this is something we need to be concerned about. If 
it is a concern we may need to add a TypePrinter configuration optimized for 
stability that preserves the current output format in eternity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139986

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


[PATCH] D140158: [CUDA] Allow targeting NVPTX directly without a host toolchain

2022-12-15 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: tra, yaxunl, JonChesterfield.
Herald added subscribers: mattd, gchakrabarti, carlosgalvezp, asavonic.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Currently, the NVPTX compilation toolchain can only be invoked either
through CUDA or OpenMP via `--offload-device-only`. This is because we
cannot build a CUDA toolchain without an accompanying host toolchain for
the offloading. When using `--target=nvptx64-nvidia-cuda` this results
in generating calls to the GNU assembler and linker, leading to errors.

This patch abstracts the portions of the CUDA toolchain that are
independent of the host toolchain or offloading kind into a new base
class called `NVPTXToolChain`. We still need to read the host's triple
to build the CUDA installation, so if not present we just assume it will
match the host's system for now, or the user can provide the path
explicitly.

This should allow the compiler driver to create NVPTX device images
directly from C/C++ code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140158

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c

Index: clang/test/Driver/cuda-cross-compiling.c
===
--- /dev/null
+++ clang/test/Driver/cuda-cross-compiling.c
@@ -0,0 +1,48 @@
+// Tests the driver when targeting the NVPTX architecture directly without a
+// host toolchain to perform CUDA mappings.
+
+// REQUIRES: nvptx-registered-target
+
+//
+// Test the generated phases when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=PHASES %s
+
+//  PHASES: 0: input, "[[INPUT:.+]]", c
+// PHASES-NEXT: 1: preprocessor, {0}, cpp-output
+// PHASES-NEXT: 2: compiler, {1}, ir
+// PHASES-NEXT: 3: backend, {2}, assembler
+// PHASES-NEXT: 4: assembler, {3}, object
+// PHASES-NEXT: 5: linker, {4}, image
+
+//
+// Test the generated bindings when targeting NVPTX.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=BINDINGS %s
+
+//  BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
+// BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
+
+//
+// Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
+// Ensure that the '.o' files are converted to '.cubin' as well.
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=ARGS %s
+
+//  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// ARGS-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
+// ARGS-NEXT: nvlink" "-o" "a.out" "-arch" "sm_61" {{.*}} "{{.*}}.cubin"
+
+//
+// Test the generated arguments default to a value with no architecture. 
+//
+// RUN: %clang -target nvptx64-nvidia-cuda -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DEFAULT %s
+
+//  DEFAULT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_35" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// DEFAULT-NEXT: ptxas" "-m64" "-O0" "--gpu-name" "sm_35" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
+// DEFAULT-NEXT: nvlink" "-o" "a.out" "-arch" "sm_35" {{.*}} "{{.*}}.cubin"
Index: clang/lib/Driver/ToolChains/Cuda.h
===
--- clang/lib/Driver/ToolChains/Cuda.h
+++ clang/lib/Driver/ToolChains/Cuda.h
@@ -96,11 +96,25 @@
  const char *LinkingOutput) const override;
 };
 
+// Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
+// assembly into a single output file.
+class LLVM_LIBRARY_VISIBILITY FatBinary : public Tool {
+ public:
+   FatBinary(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+
+   bool hasIntegratedCPP() const override { return false; }
+
+   void ConstructJob(Compilation &C, const JobAction &JA,
+ const InputInfo &Output, const InputInfoList &Inputs,
+ const llvm::opt::ArgList &TCArgs,
+ const char *LinkingOutput) const override;
+};
+
 // Runs fatbinary, which combines GPU object files ("cubin" files) and/or PTX
 // assembly into a single output file.
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
  public:
-   Linker(const ToolChain &TC) : Tool("NVPTX::Linker", "fatbinary", TC) {}
+   Linker(const ToolChain &TC) : To

[PATCH] D140159: [clang][nfc] Fixes for D129531

2022-12-15 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao created this revision.
ayzhao added a reviewer: shafik.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Additional fixes for review comments made in
https://reviews.llvm.org/D129531 after the patch was submitted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140159

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/cxx_paren_init.cpp
  clang/test/PCH/cxx_paren_init.h

Index: clang/test/PCH/cxx_paren_init.h
===
--- clang/test/PCH/cxx_paren_init.h
+++ clang/test/PCH/cxx_paren_init.h
@@ -1,5 +1,9 @@
 struct S { int i, j; };
 
-constexpr S foo(int i, int j) { return S(i, j); };
+union U { unsigned : 8; int i; char j; };
 
-void bar(int i, int j) { int arr[4](i, j); };
+constexpr S foo(int i, int j) { return S(i, j); }
+
+void bar(int i, int j) { int arr[4](i, j); }
+
+constexpr U baz(int i) { return U(i); }
Index: clang/test/PCH/cxx_paren_init.cpp
===
--- clang/test/PCH/cxx_paren_init.cpp
+++ clang/test/PCH/cxx_paren_init.cpp
@@ -5,6 +5,10 @@
 // CHECK-DAG: @{{.*s.*}} = {{(dso_local )?}}global [[STRUCT_S]] { i32 1, i32 2 }, align 4
 S s = foo(1, 2);
 
+// CHECK-DAG: [[UNION_U:%.*]] = type { i32 }
+// CHECK-DAG: @{{.*u.*}} = {{(dso_local )?}}global [[UNION_U]] { i32 3 }, align 4
+U u = baz(3);
+
 // CHECK: define dso_local void @{{.*bar.*}}
 // CHECK-NEXT: entry:
 // CHECK-NEXT: [[I_ADDR:%.*]] = alloca i32, align 4
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2091,10 +2091,17 @@
   Record.AddSourceLocation(E->getEndLoc());
   for (Expr *InitExpr : E->getInitExprs())
 Record.AddStmt(InitExpr);
-  bool HasArrayFiller = E->getArrayFiller();
-  Record.push_back(HasArrayFiller);
-  if (HasArrayFiller)
-Record.AddStmt(E->getArrayFiller());
+  Expr *ArrayFiller = E->getArrayFiller();
+  FieldDecl *UnionField = E->getInitializedFieldInUnion();
+  bool HasArrayFillerOrUnionDecl = ArrayFiller || UnionField;
+  Record.push_back(HasArrayFillerOrUnionDecl);
+  if (HasArrayFillerOrUnionDecl) {
+Record.push_back(static_cast(ArrayFiller));
+if (ArrayFiller)
+  Record.AddStmt(ArrayFiller);
+else
+  Record.AddDeclRef(UnionField);
+  }
   Code = serialization::EXPR_CXX_PAREN_LIST_INIT;
 }
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2180,9 +2180,14 @@
   for (unsigned I = 0; I < ExpectedNumExprs; I++)
 E->getTrailingObjects()[I] = Record.readSubExpr();
 
-  bool HasArrayFiller = Record.readBool();
-  if (HasArrayFiller) {
-E->setArrayFiller(Record.readSubExpr());
+  bool HasArrayFillerOrUnionDecl = Record.readBool();
+  if (HasArrayFillerOrUnionDecl) {
+bool HasArrayFiller = Record.readBool();
+if (HasArrayFiller) {
+  E->setArrayFiller(Record.readSubExpr());
+} else {
+  E->setInitilazedFieldInUnion(readDeclAs());
+}
   }
   E->updateDependence();
 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5277,22 +5277,25 @@
   SmallVector InitExprs;
   QualType ResultType;
   Expr *ArrayFiller = nullptr;
+  FieldDecl *InitializedFieldInUnion = nullptr;
 
   // Process entities (i.e. array members, base classes, or class fields) by
   // adding an initialization expression to InitExprs for each entity to
   // initialize.
   auto ProcessEntities = [&](auto Range) -> bool {
+bool IsUnionType = Entity.getType()->isUnionType();
 for (InitializedEntity SubEntity : Range) {
   // Unions should only have one initializer expression.
   // If there are more initializers than it will be caught when we check
   // whether Index equals Args.size().
-  if (ArgIndexToProcess == 1 && Entity.getType()->isUnionType())
+  if (ArgIndexToProcess == 1 && IsUnionType)
 return true;
 
+  bool IsMember = SubEntity.getKind() == InitializedEntity::EK_Member;
+
   // Unnamed bitfields should not be initialized at all, either with an arg
   // or by default.
-  if (SubEntity.getKind() == InitializedEntity::EK_Member &&
-  cast(SubEntity.getDecl())->isUnnamedBitfield())
+  if (IsMember && cast(SubEntity.getDecl())->isUnnamedBitfield())
 continue;
 
   if (ArgIndexToProcess < Args.size()) {
@@ -5303,7 +5306,7 @@
 // Incomplete array t

  1   2   >