[PATCH] D148767: Restore CodeGen/LowLevelType

2023-05-01 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

In D148767#4311529 , @MaskRay wrote:

> Add some information why this is restored? Assume that people may not read 
> the depended patches (`Depends on D145937, D146352, and D148768.`).

Yes sure. This was just an isolated diff with similar changes at first.

In D148767#4311564 , @barannikov88 
wrote:

> Adding CodeGen dependency to MCTargetDesc/AsmParser/Disassembler does not 
> seem right. Why is it necessary?

This commit shows they may depend on `CodeGen` theoretically and actually (but 
not efficient)
I will decouple again in D148769 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148767

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


[PATCH] D148066: [RISCV] Add Smaia and Ssaia extensions support

2023-05-01 Thread Brandon Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74c1fa60b5f5: [RISCV] Add Smaia and Ssaia extensions support 
(authored by 4vtomat).

Changed prior to commit:
  https://reviews.llvm.org/D148066?vs=516137=518634#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148066

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVSystemOperands.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/hypervisor-csr-names.s
  llvm/test/MC/RISCV/machine-csr-names.s
  llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
  llvm/test/MC/RISCV/rv32-machine-csr-names.s
  llvm/test/MC/RISCV/rv32-only-csr-names.s
  llvm/test/MC/RISCV/rv32-supervisor-csr-names.s
  llvm/test/MC/RISCV/rvi-aliases-valid.s
  llvm/test/MC/RISCV/supervisor-csr-names.s

Index: llvm/test/MC/RISCV/supervisor-csr-names.s
===
--- llvm/test/MC/RISCV/supervisor-csr-names.s
+++ llvm/test/MC/RISCV/supervisor-csr-names.s
@@ -291,3 +291,63 @@
 csrrs t1, sstateen3, zero
 # uimm12
 csrrs t2, 0x10F, zero
+
+#
+# Advanced Interrupt Architecture (Smaia and Ssaia)
+#
+
+# siselect
+# name
+# CHECK-INST: csrrs t1, siselect, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x00,0x15]
+# CHECK-INST-ALIAS: csrr t1, siselect
+# uimm12
+# CHECK-INST: csrrs t2, siselect, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x00,0x15]
+# CHECK-INST-ALIAS: csrr t2, siselect
+# name
+csrrs t1, siselect, zero
+# uimm12
+csrrs t2, 0x150, zero
+
+# sireg
+# name
+# CHECK-INST: csrrs t1, sireg, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x10,0x15]
+# CHECK-INST-ALIAS: csrr t1, sireg
+# uimm12
+# CHECK-INST: csrrs t2, sireg, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x10,0x15]
+# CHECK-INST-ALIAS: csrr t2, sireg
+# name
+csrrs t1, sireg, zero
+# uimm12
+csrrs t2, 0x151, zero
+
+# stopei
+# name
+# CHECK-INST: csrrs t1, stopei, zero
+# CHECK-ENC: encoding: [0x73,0x23,0xc0,0x15]
+# CHECK-INST-ALIAS: csrr t1, stopei
+# uimm12
+# CHECK-INST: csrrs t2, stopei, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0xc0,0x15]
+# CHECK-INST-ALIAS: csrr t2, stopei
+# name
+csrrs t1, stopei, zero
+# uimm12
+csrrs t2, 0x15C, zero
+
+# stopi
+# name
+# CHECK-INST: csrrs t1, stopi, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x00,0xdb]
+# CHECK-INST-ALIAS: csrr t1, stopi
+# uimm12
+# CHECK-INST: csrrs t2, stopi, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x00,0xdb]
+# CHECK-INST-ALIAS: csrr t2, stopi
+# name
+csrrs t1, stopi, zero
+# uimm12
+csrrs t2, 0xDB0, zero
Index: llvm/test/MC/RISCV/rvi-aliases-valid.s
===
--- llvm/test/MC/RISCV/rvi-aliases-valid.s
+++ llvm/test/MC/RISCV/rvi-aliases-valid.s
@@ -207,8 +207,8 @@
 # CHECK-S-OBJ: rdtime s9
 rdtime x25
 
-# CHECK-S-OBJ-NOALIAS: csrrs  s0, 336, zero
-# CHECK-S-OBJ: csrr s0, 336
+# CHECK-S-OBJ-NOALIAS: csrrs s0, siselect, zero
+# CHECK-S-OBJ: csrr s0, siselect
 csrr x8, 0x150
 # CHECK-S-OBJ-NOALIAS: csrrw zero, sscratch, s1
 # CHECK-S-OBJ: csrw sscratch, s1
@@ -220,8 +220,8 @@
 # CHECK-S-OBJ: csrc 4095, s7
 csrc 0xfff, x23
 
-# CHECK-S-OBJ-NOALIAS: csrrwi zero, 336, 15
-# CHECK-S-OBJ: csrwi 336, 15
+# CHECK-S-OBJ-NOALIAS: csrrwi zero, siselect, 15
+# CHECK-S-OBJ: csrwi siselect, 15
 csrwi 0x150, 0xf
 # CHECK-S-OBJ-NOALIAS: csrrsi zero, 4095, 16
 # CHECK-S-OBJ: csrsi 4095, 16
@@ -230,18 +230,18 @@
 # CHECK-S-OBJ: csrci sscratch, 17
 csrci 0x140, 0x11
 
-# CHECK-S-OBJ-NOALIAS: csrrwi zero, 336, 7
-# CHECK-S-OBJ: csrwi 336, 7
+# CHECK-S-OBJ-NOALIAS: csrrwi zero, siselect, 7
+# CHECK-S-OBJ: csrwi siselect, 7
 csrw 0x150, 7
-# CHECK-S-OBJ-NOALIAS: csrrsi zero, 336, 7
-# CHECK-S-OBJ: csrsi 336, 7
+# CHECK-S-OBJ-NOALIAS: csrrsi zero, siselect, 7
+# CHECK-S-OBJ: csrsi siselect, 7
 csrs 0x150, 7
-# CHECK-S-OBJ-NOALIAS: csrrci zero, 336, 7
-# CHECK-S-OBJ: csrci 336, 7
+# CHECK-S-OBJ-NOALIAS: csrrci zero, siselect, 7
+# CHECK-S-OBJ: csrci siselect, 7
 csrc 0x150, 7
 
-# CHECK-S-OBJ-NOALIAS: csrrwi t0, 336, 15
-# CHECK-S-OBJ: csrrwi t0, 336, 15
+# CHECK-S-OBJ-NOALIAS: csrrwi t0, siselect, 15
+# CHECK-S-OBJ: csrrwi t0, siselect, 15
 csrrw t0, 0x150, 0xf
 # CHECK-S-OBJ-NOALIAS: csrrsi t0, 4095, 16
 # CHECK-S-OBJ: csrrsi t0, 4095, 16
Index: llvm/test/MC/RISCV/rv32-supervisor-csr-names.s
===
--- llvm/test/MC/RISCV/rv32-supervisor-csr-names.s
+++ llvm/test/MC/RISCV/rv32-supervisor-csr-names.s
@@ -21,3 +21,35 @@
 csrrs t1, stimecmph, zero
 # uimm12
 csrrs t2, 0x15D, zero
+
+#
+# Advanced Interrupt Architecture (Smaia and Ssaia)
+#
+
+# sieh
+# name
+# 

[clang] 74c1fa6 - [RISCV] Add Smaia and Ssaia extensions support

2023-05-01 Thread via cfe-commits

Author: 4vtomat
Date: 2023-05-01T22:30:08-07:00
New Revision: 74c1fa60b5f5c1d079e08a2e409a649a26da41d1

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

LOG: [RISCV] Add Smaia and Ssaia extensions support

This patch implements 1.0-RC3:
https://github.com/riscv/riscv-aia/releases/download/1.0-RC3/riscv-interrupts-1.0-RC3.pdf

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

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVSystemOperands.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/hypervisor-csr-names.s
llvm/test/MC/RISCV/machine-csr-names.s
llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
llvm/test/MC/RISCV/rv32-machine-csr-names.s
llvm/test/MC/RISCV/rv32-only-csr-names.s
llvm/test/MC/RISCV/rv32-supervisor-csr-names.s
llvm/test/MC/RISCV/rvi-aliases-valid.s
llvm/test/MC/RISCV/supervisor-csr-names.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index c4135e4d3ddfa..59830012f0eb2 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -63,6 +63,8 @@
 // CHECK-NOT: __riscv_zvksh {{.*$}}
 // CHECK-NOT: __riscv_zvkt {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
+// CHECK-NOT: __riscv_smaia {{.*$}}
+// CHECK-NOT: __riscv_ssaia {{.*$}}
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
 // RUN: -o - | FileCheck %s
@@ -640,3 +642,19 @@
 // RUN: -march=rv64i_zicond1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
 // CHECK-ZICOND-EXT: __riscv_zicond  100{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32ismaia1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-SMAIA-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64ismaia1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-SMAIA-EXT %s
+// CHECK-SMAIA-EXT: __riscv_smaia  100{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32issaia1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64issaia1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
+// CHECK-SSAIA-EXT: __riscv_ssaia  100{{$}}

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index b7f26bddea44d..ae1f91170fc28 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -177,6 +177,12 @@ LLVM supports (to various degrees) a number of 
experimental extensions.  All exp
 
 The primary goal of experimental support is to assist in the process of 
ratification by providing an existence proof of an implementation, and 
simplifying efforts to validate the value of a proposed extension against large 
code bases.  Experimental extensions are expected to either transition to 
ratified status, or be eventually removed.  The decision on whether to accept 
an experimental extension is currently done on an entirely case by case basis; 
if you want to propose one, attending the bi-weekly RISC-V sync-up call is 
strongly advised.
 
+``experimental-smaia``
+  LLVM implements the `Ratification candidate 3 
`_.
+
+``experimental-ssaia``
+  LLVM implements the `Ratification candidate 3 
`_.
+
 ``experimental-zca``
   LLVM implements the `1.0.1 draft specification 
`__.
 

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index da1bd12fb2d56..2014dfdb67ec2 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -135,6 +135,9 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 };
 
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
+{"smaia", RISCVExtensionVersion{1, 0}},
+{"ssaia", RISCVExtensionVersion{1, 0}},
+
 {"zihintntl", RISCVExtensionVersion{0, 2}},
 
 {"zca", RISCVExtensionVersion{1, 0}},

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index d01375ebe8661..258fbdced1e24 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -576,6 +576,19 @@ def HasStdExtZicond : 

[PATCH] D148767: Restore CodeGen/LowLevelType

2023-05-01 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

Adding CodeGen dependency to MCTargetDesc layer does not seem right. Why is it 
necessary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148767

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


[PATCH] D149495: [RISCV] Add sifive-x280 processor and support V extension in SiFive7

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

All CPU name additions should be mentioned in the RISC-V section of 
llvm/docs/ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

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


[PATCH] D149495: [RISCV] Add sifive-x280 processor and support V extension in SiFive7

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVProcessors.td:169
 
+def SIFIVE_X280 : RISCVProcessorModel<"sifive-x280", SiFive7Model,
+  [Feature64Bit,

I would prefer that we add sifive-x280 in a single patch with all of its 
features. Currently zba/zbb are in a different patch. I don't think there's any 
restriction about adding a feature to a CPU without it being present in the 
scheduler model.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

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


[PATCH] D149334: [RISCV] Enable strict fp for RISC-V in clang.

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D149334/new/

https://reviews.llvm.org/D149334

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


[PATCH] D148851: Disable llvm-symbolizer on some of the driver tests that are timing out

2023-05-01 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 518630.
ahatanak added a comment.

Enable llvm-symbolizer when running disable-crash-reports.test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148851

Files:
  llvm/test/tools/llvm-reduce/disable-crash-reports.test
  llvm/utils/lit/lit/TestingConfig.py


Index: llvm/utils/lit/lit/TestingConfig.py
===
--- llvm/utils/lit/lit/TestingConfig.py
+++ llvm/utils/lit/lit/TestingConfig.py
@@ -19,6 +19,7 @@
 'PATH' : os.pathsep.join(litConfig.path +
  [os.environ.get('PATH','')]),
 'LLVM_DISABLE_CRASH_REPORT' : '1',
+'LLVM_DISABLE_SYMBOLIZATION' : '1',
 }
 
 pass_vars = [
Index: llvm/test/tools/llvm-reduce/disable-crash-reports.test
===
--- llvm/test/tools/llvm-reduce/disable-crash-reports.test
+++ llvm/test/tools/llvm-reduce/disable-crash-reports.test
@@ -2,7 +2,7 @@
 
 # RUN: env LLVM_DISABLE_CRASH_REPORT=0 llvm-reduce 
--delta-passes=global-variables -o %t --test %python --test-arg 
%p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck 
-check-prefix=INTERESTING %s
 
-# RUN: not llvm-reduce --preserve-debug-environment 
--delta-passes=global-variables -o %t --test %python --test-arg 
%p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck 
-check-prefix=NOTINTERESTING %s
+# RUN: env LLVM_DISABLE_SYMBOLIZATION=0 not llvm-reduce 
--preserve-debug-environment --delta-passes=global-variables -o %t --test 
%python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 
2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
 
 # RUN: env LLVM_DISABLE_CRASH_REPORT=0 not llvm-reduce 
--preserve-debug-environment --delta-passes=global-variables -o %t --test 
%python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 
2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
 


Index: llvm/utils/lit/lit/TestingConfig.py
===
--- llvm/utils/lit/lit/TestingConfig.py
+++ llvm/utils/lit/lit/TestingConfig.py
@@ -19,6 +19,7 @@
 'PATH' : os.pathsep.join(litConfig.path +
  [os.environ.get('PATH','')]),
 'LLVM_DISABLE_CRASH_REPORT' : '1',
+'LLVM_DISABLE_SYMBOLIZATION' : '1',
 }
 
 pass_vars = [
Index: llvm/test/tools/llvm-reduce/disable-crash-reports.test
===
--- llvm/test/tools/llvm-reduce/disable-crash-reports.test
+++ llvm/test/tools/llvm-reduce/disable-crash-reports.test
@@ -2,7 +2,7 @@
 
 # RUN: env LLVM_DISABLE_CRASH_REPORT=0 llvm-reduce --delta-passes=global-variables -o %t --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=INTERESTING %s
 
-# RUN: not llvm-reduce --preserve-debug-environment --delta-passes=global-variables -o %t --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
+# RUN: env LLVM_DISABLE_SYMBOLIZATION=0 not llvm-reduce --preserve-debug-environment --delta-passes=global-variables -o %t --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
 
 # RUN: env LLVM_DISABLE_CRASH_REPORT=0 not llvm-reduce --preserve-debug-environment --delta-passes=global-variables -o %t --test %python --test-arg %p/Inputs/test-crash-vars.py %p/Inputs/test-output-format.ll 2>&1 | FileCheck -check-prefix=NOTINTERESTING %s
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9ec5423 - [clang][Interp][NFC] Add documentation for SetLocal

2023-05-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-05-02T06:16:49+02:00
New Revision: 9ec5423b90c888d9ec4206c18b728946be5f1368

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

LOG: [clang][Interp][NFC] Add documentation for SetLocal

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d751ba021b11..2baef4293d51 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -744,6 +744,9 @@ bool GetLocal(InterpState , CodePtr OpPC, uint32_t I) {
   return true;
 }
 
+/// 1) Pops the value from the stack.
+/// 2) Writes the value to the local variable with the
+///given offset.
 template ::T>
 bool SetLocal(InterpState , CodePtr OpPC, uint32_t I) {
   S.Current->setLocal(I, S.Stk.pop());



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


[clang] 7d0938b - [clang][Interp][NFC] Make OptionScope final

2023-05-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-05-02T06:16:49+02:00
New Revision: 7d0938bf2c2a35d4eb4b8c4c728aaa85d1dd428e

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

LOG: [clang][Interp][NFC] Make OptionScope final

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9f79a7bcf9d3..ee59fc372a8b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -40,7 +40,7 @@ template  class DeclScope final : public 
VariableScope {
 };
 
 /// Scope used to handle initialization methods.
-template  class OptionScope {
+template  class OptionScope final {
 public:
   /// Root constructor, compiling or discarding primitives.
   OptionScope(ByteCodeExprGen *Ctx, bool NewDiscardResult)



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


[PATCH] D148767: Restore CodeGen/LowLevelType

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> This is rework of;
>
> D30046  (LLT)

Add some information why this is restored? Assume that people may not read the 
depended patches (`Depends on D145937, D146352, and D148768.`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148767

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I have read prior discussions and 
https://discourse.llvm.org/t/rfc-improving-clangs-middle-and-back-end-diagnostics/69261
 .

The current approach seems reasonable.

The summary should incorporate more information. `inlined.from` isn't mentioned 
at all.




Comment at: clang/lib/CodeGen/CodeGenAction.cpp:864
+  for (auto Dec : llvm::enumerate(InliningDecisions))
+Diags.Report(Dec.index() ? diag::note_fe_backend_inlined
+ : diag::note_fe_backend_in)

Shall we use `Diags.Report(LocCookie, ...`?



Comment at: llvm/test/Transforms/Inline/dontcall-attributes.ll:2
+; RUN: opt -S -o - -passes=inline %s \
+; RUN:  | FileCheck %s --check-prefixes=CHECK-BOTH,CHECK
+; RUN: opt -S -o - -passes=always-inline %s \

2-space indentation.

Actually I think the line is short enough, so no indentation is needed. You can 
use `< ` to remove `-o -`



Comment at: llvm/test/Transforms/Inline/dontcall-attributes.ll:80
+; CHECK-NEXT: !2 = !{!"bar", !"baz"}
+; CHECK-NEXT: !3 = !{!"a"}
+; CHECK-NEXT: !4 = !{!"always_callee"}

It's useful to have a Itanium mangled name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D149187: [clang] Canonicalize system headers in dependency file when -canonical-prefixes

2023-05-01 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D149187#4311354 , @chapuni wrote:

> I am afraid this would be incompatible to bazel due to deep symlinks for 
> sandbox.

I assume bazel would use `-no-canonical-prefixes`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149187

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


[PATCH] D149631: [NFC][CLANG] Fix static analyzer codes concerns about large copies by value

2023-05-01 Thread Soumi Manna via Phabricator via cfe-commits
Manna created this revision.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
Herald added a reviewer: aaron.ballman.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
Manna requested review of this revision.

Reported by Static Analyzer Tool:

1. Inside "Format.cpp" file, in 
clang::​format::​internal::​reformat(clang::​format::​FormatStyle const &, 
llvm::​StringRef, llvm::​ArrayRef, unsigned int, 
unsigned int, unsigned int, llvm::​StringRef, 
clang::​format::​FormattingAttemptStatus 
*)::​[lambda(clang::​format::​Environment const &) (instance 4)]::​operator 
()(clang::​format::​Environment const &): A very large function call parameter 
exceeding the high threshold is passed by value.

pass_by_value: Capturing variable S of type clang::format::FormatStyle (size 
800 bytes) by value, which exceeds the high threshold of 512 bytes

This patch removes redundant capturing variable S and uses type 
clang::format::FormatStyle Expanded instead.

2. Inside "ClangAttrEmitter.cpp" file, in 
clang::​GenerateMutualExclusionsChecks(llvm::​Record const &, 
llvm::​RecordKeeper const &, llvm::​raw_ostream &, llvm::​raw_ostream &, 
llvm::​raw_ostream &)::​[lambda(llvm::​Record const *) (instance 1)]::​operator 
()(llvm::​Record const *): A large function call parameter exceeding the low 
threshold is passed by value.

pass_by_value: Capturing variable Attr of type llvm::Record const (size 176 
bytes) by value, which exceeds the low threshold of 128 bytes.

This patch passes const Record by reference in IsCurAttr lambda capture.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149631

Files:
  clang/lib/Format/Format.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3954,7 +3954,7 @@
   for (const Record *Exclusion : ExclusionsList) {
 std::vector MutuallyExclusiveAttrs =
 Exclusion->getValueAsListOfDefs("Exclusions");
-auto IsCurAttr = [Attr](const Record *R) {
+auto IsCurAttr = [](const Record *R) {
   return R->getName() == Attr.getName();
 };
 if (llvm::any_of(MutuallyExclusiveAttrs, IsCurAttr)) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3483,26 +3483,23 @@
 }
 
 if (Style.InsertBraces) {
-  FormatStyle S = Expanded;
-  S.InsertBraces = true;
-  Passes.emplace_back([&, S](const Environment ) {
-return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
+  Expanded.InsertBraces = true;
+  Passes.emplace_back([&](const Environment ) {
+return BracesInserter(Env, Expanded).process(/*SkipAnnotation=*/true);
   });
 }
 
 if (Style.RemoveBracesLLVM) {
-  FormatStyle S = Expanded;
-  S.RemoveBracesLLVM = true;
-  Passes.emplace_back([&, S](const Environment ) {
-return BracesRemover(Env, S).process(/*SkipAnnotation=*/true);
+  Expanded.RemoveBracesLLVM = true;
+  Passes.emplace_back([&](const Environment ) {
+return BracesRemover(Env, Expanded).process(/*SkipAnnotation=*/true);
   });
 }
 
 if (Style.RemoveSemicolon) {
-  FormatStyle S = Expanded;
-  S.RemoveSemicolon = true;
-  Passes.emplace_back([&, S](const Environment ) {
-return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
+  Expanded.RemoveSemicolon = true;
+  Passes.emplace_back([&](const Environment ) {
+return SemiRemover(Env, Expanded).process(/*SkipAnnotation=*/true);
   });
 }
 


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3954,7 +3954,7 @@
   for (const Record *Exclusion : ExclusionsList) {
 std::vector MutuallyExclusiveAttrs =
 Exclusion->getValueAsListOfDefs("Exclusions");
-auto IsCurAttr = [Attr](const Record *R) {
+auto IsCurAttr = [](const Record *R) {
   return R->getName() == Attr.getName();
 };
 if (llvm::any_of(MutuallyExclusiveAttrs, IsCurAttr)) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3483,26 +3483,23 @@
 }
 
 if (Style.InsertBraces) {
-  FormatStyle S = Expanded;
-  S.InsertBraces = true;
-  Passes.emplace_back([&, S](const Environment ) {
-return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
+  Expanded.InsertBraces = true;
+  Passes.emplace_back([&](const Environment ) {
+return 

[PATCH] D146921: [clang-tidy] Implement cppcoreguidelines F.19

2023-05-01 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

bump?


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

https://reviews.llvm.org/D146921

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:863
+  InliningDecisions.push_back(D.getCaller().str());
+  for (size_t i = 0, e = InliningDecisions.size(); i != e; ++i) {
+std::string S = llvm::demangle(InliningDecisions[i]);

aaron.ballman wrote:
> Alternatively:
> ```
> for (auto Dec : llvm::enumerate(InliningDecisions)) {
>   std::string S = llvm::demangle(Dec.value());
>   if (Dec.index() == 0)
> Diags.Report(...);
>   ...
> }
> ```
Nit: use C++17 structured bindings



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:34
+static inline void b() {
+a(10);
+}

The new lines mix 2-space and 4-space indentations. 2 spaces should be more 
common.



Comment at: llvm/test/Transforms/Inline/dontcall-attributes.ll:28
+define void @baz() {
+; CHECK-LABEL: @baz(
+; CHECK-NEXT:call void @foo(), !inlined.from !0

`; CHECK-LABEL: define {{[^@]+}}@baz(` (feel free to use another form, but keep 
`define`)

Otherwise `@baz` is not unique and may match a `call void @baz(...)`.



Comment at: llvm/test/Transforms/Inline/dontcall-attributes.ll:30
+; CHECK-NEXT:call void @foo(), !inlined.from !0
+;
+  call void @bar(i32 10)

Unneeded `^;$` line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D149104: [Demangle] make llvm::demangle take std::string_view rather than const std::string

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!




Comment at: llvm/docs/ReleaseNotes.rst:289
 
+* ``llvm::demangle`` now takes a ``std::string_view`` rather than a
+  ``const std::string&``. Be careful passing temporaries into

The text wrapping appears to use a very small `set textwidth` (neovim)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149104

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


[PATCH] D148944: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows.

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGecad12100927: [clang][Driver] Fix crash with unsupported 
architectures in MinGW and… (authored by k-mana, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D148944?vs=515809=518615#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148944

Files:
  clang/lib/Driver/ToolChains/CrossWindows.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/unsupported-target-arch.c


Index: clang/test/Driver/unsupported-target-arch.c
===
--- clang/test/Driver/unsupported-target-arch.c
+++ clang/test/Driver/unsupported-target-arch.c
@@ -23,3 +23,11 @@
 // RUN: not %clang --target=noarch-unknown-nacl -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NACL %s
 // CHECK-NOARCH-NACL:  error: the target architecture 'noarch' is not 
supported by the target 'Native Client'
+
+// RUN: not %clang --target=noarch-unknown-windows-gnu -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-MINGW %s
+// CHECK-NOARCH-MINGW: error: unknown target triple 
'noarch-unknown-windows-gnu'
+
+// RUN: not %clang --target=noarch-unknown-windows-itanium -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS 
%s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 
'noarch-unknown-windows-itanium'
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -135,7 +135,7 @@
 CmdArgs.push_back("arm64pe");
 break;
   default:
-llvm_unreachable("Unsupported target architecture.");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
   }
 
   Arg *SubsysArg =
Index: clang/lib/Driver/ToolChains/CrossWindows.cpp
===
--- clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,8 @@
   CmdArgs.push_back("-m");
   switch (TC.getArch()) {
   default:
-llvm_unreachable("unsupported architecture");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+break;
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
 // FIXME: this is incorrect for WinCE


Index: clang/test/Driver/unsupported-target-arch.c
===
--- clang/test/Driver/unsupported-target-arch.c
+++ clang/test/Driver/unsupported-target-arch.c
@@ -23,3 +23,11 @@
 // RUN: not %clang --target=noarch-unknown-nacl -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NACL %s
 // CHECK-NOARCH-NACL:  error: the target architecture 'noarch' is not supported by the target 'Native Client'
+
+// RUN: not %clang --target=noarch-unknown-windows-gnu -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-MINGW %s
+// CHECK-NOARCH-MINGW: error: unknown target triple 'noarch-unknown-windows-gnu'
+
+// RUN: not %clang --target=noarch-unknown-windows-itanium -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS %s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 'noarch-unknown-windows-itanium'
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -135,7 +135,7 @@
 CmdArgs.push_back("arm64pe");
 break;
   default:
-llvm_unreachable("Unsupported target architecture.");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
   }
 
   Arg *SubsysArg =
Index: clang/lib/Driver/ToolChains/CrossWindows.cpp
===
--- clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,8 @@
   CmdArgs.push_back("-m");
   switch (TC.getArch()) {
   default:
-llvm_unreachable("unsupported architecture");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+break;
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
 // FIXME: this is incorrect for WinCE
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ecad121 - [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows

2023-05-01 Thread Fangrui Song via cfe-commits

Author: KOMATA Manabu
Date: 2023-05-01T18:34:09-07:00
New Revision: ecad1210092764592ca9ee0670dd15831e54b770

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

LOG: [clang][Driver] Fix crash with unsupported architectures in MinGW and 
CrossWindows

MinGW and CrossWindows crash if the target is an unsupported target 
architecture.
Changed it to emit an error message.

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

Reviewed By: MaskRay, mstorsjo

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CrossWindows.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
clang/test/Driver/unsupported-target-arch.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp 
b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index bc91449326a5..3c5dfba329cf 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,8 @@ void tools::CrossWindows::Linker::ConstructJob(
   CmdArgs.push_back("-m");
   switch (TC.getArch()) {
   default:
-llvm_unreachable("unsupported architecture");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+break;
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
 // FIXME: this is incorrect for WinCE

diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index bac486bab885..947abb9b02b5 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -135,7 +135,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation , 
const JobAction ,
 CmdArgs.push_back("arm64pe");
 break;
   default:
-llvm_unreachable("Unsupported target architecture.");
+D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
   }
 
   Arg *SubsysArg =

diff  --git a/clang/test/Driver/unsupported-target-arch.c 
b/clang/test/Driver/unsupported-target-arch.c
index 11be696546db..b43a77e0486d 100644
--- a/clang/test/Driver/unsupported-target-arch.c
+++ b/clang/test/Driver/unsupported-target-arch.c
@@ -23,3 +23,11 @@
 // RUN: not %clang --target=noarch-unknown-nacl -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NACL %s
 // CHECK-NOARCH-NACL:  error: the target architecture 'noarch' is not 
supported by the target 'Native Client'
+
+// RUN: not %clang --target=noarch-unknown-windows-gnu -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-MINGW %s
+// CHECK-NOARCH-MINGW: error: unknown target triple 
'noarch-unknown-windows-gnu'
+
+// RUN: not %clang --target=noarch-unknown-windows-itanium -o %t.o %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS 
%s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 
'noarch-unknown-windows-itanium'



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


[PATCH] D149187: [clang] Canonicalize system headers in dependency file when -canonical-prefixes

2023-05-01 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

I am afraid this would be incompatible to bazel due to deep symlinks for 
sandbox.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149187

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


[PATCH] D148944: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows.

2023-05-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

Looks great!




Comment at: clang/test/Driver/unsupported-target-arch.c:33
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-CROSSWINDOWS 
%s
+// CHECK-NOARCH-CROSSWINDOWS: error: unknown target triple 
'noarch-unknown-windows-itanium', please use -triple or -arch

mstorsjo wrote:
> Separate side note; the suggested option `-triple` isn't really a clang 
> driver level option, and `-arch` is only relevant for darwin targets (AFAIK) 
> - so maybe the error message text should be revised?
The part ", please use -triple or -arch" is almost always wrong.

For cc1, the error is due to a specified but unknown -triple, we should not 
suggest specifying -triple.
For driver, -triple and -arch are not driver options.

I just removed the hint from the diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148944

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


[clang] ea7e69f - [Driver] Drop incorrect hint from err_target_unknown_triple

2023-05-01 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-01T18:22:49-07:00
New Revision: ea7e69f392b29201502cdcb8cfa83f0f3704da34

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

LOG: [Driver] Drop incorrect hint from err_target_unknown_triple

For an unknown target triple, the ", please use -triple or -arch" hint of the
diagnostic is almost always wrong.
For cc1, the error is due to a specified but unknown -triple.
For driver, -triple and -arch are not driver options.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/test/Driver/unsupported-target-arch.c
clang/test/Misc/serialized-diags-unknown-target.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index bac77299671c5..da4e2b42dc2ea 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -308,7 +308,7 @@ def warn_dup_category_def : Warning<
 // Targets
 
 def err_target_unknown_triple : Error<
-  "unknown target triple '%0', please use -triple or -arch">;
+  "unknown target triple '%0'">;
 def err_target_unknown_cpu : Error<"unknown target CPU '%0'">;
 def note_valid_options : Note<"valid target CPU values are: %0">;
 def err_target_unsupported_cpu_for_micromips : Error<

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1efe7573028ef..4c7d9e80338ec 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -255,6 +255,7 @@ def warn_drv_unknown_argument_clang_cl : Warning<
 def warn_drv_unknown_argument_clang_cl_with_suggestion : Warning<
   "unknown argument ignored in clang-cl '%0'; did you mean '%1'?">,
   InGroup;
+def err_drv_unknown_target_triple : Error<"unknown target triple '%0'">;
 
 def warn_drv_ycyu_
diff erent_arg_clang_cl : Warning<
   "support for '/Yc' and '/Yu' with 
diff erent filenames not implemented yet; flags ignored">,

diff  --git a/clang/test/Driver/unsupported-target-arch.c 
b/clang/test/Driver/unsupported-target-arch.c
index 7c55850f49943..11be696546dbc 100644
--- a/clang/test/Driver/unsupported-target-arch.c
+++ b/clang/test/Driver/unsupported-target-arch.c
@@ -2,23 +2,23 @@
 //
 // RUN: not %clang --target=noarch-unknown-linux -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-LINUX %s
-// CHECK-NOARCH-LINUX: error: unknown target triple 'noarch-unknown-linux', 
please use -triple or -arch
+// CHECK-NOARCH-LINUX: error: unknown target triple 'noarch-unknown-linux'{{$}}
 //
 // RUN: not %clang --target=noarch-unknown-darwin -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-DARWIN %s
-// CHECK-NOARCH-DARWIN: error: unknown target triple 
'unknown-unknown-macosx{{.+}}', please use -triple or -arch
+// CHECK-NOARCH-DARWIN: error: unknown target triple 
'unknown-unknown-macosx{{.+}}'{{$}}
 //
 // RUN: not %clang --target=noarch-unknown-windows -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-WINDOWS %s
-// CHECK-NOARCH-WINDOWS: error: unknown target triple 
'noarch-unknown-windows-{{.+}}', please use -triple or -arch
+// CHECK-NOARCH-WINDOWS: error: unknown target triple 
'noarch-unknown-windows-{{.+}}'{{$}}
 //
 // RUN: not %clang --target=noarch-unknown-freebsd -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-FREEBSD %s
-// CHECK-NOARCH-FREEBSD: error: unknown target triple 
'noarch-unknown-freebsd', please use -triple or -arch
+// CHECK-NOARCH-FREEBSD: error: unknown target triple 
'noarch-unknown-freebsd'{{$}}
 //
 // RUN: not %clang --target=noarch-unknown-netbsd -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NETBSD %s
-// CHECK-NOARCH-NETBSD: error: unknown target triple 'noarch-unknown-netbsd', 
please use -triple or -arch
+// CHECK-NOARCH-NETBSD: error: unknown target triple 
'noarch-unknown-netbsd'{{$}}
 //
 // RUN: not %clang --target=noarch-unknown-nacl -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-NOARCH-NACL %s

diff  --git a/clang/test/Misc/serialized-diags-unknown-target.c 
b/clang/test/Misc/serialized-diags-unknown-target.c
index 040dfa4b2849e..c6d18811333df 100644
--- a/clang/test/Misc/serialized-diags-unknown-target.c
+++ b/clang/test/Misc/serialized-diags-unknown-target.c
@@ -1,4 +1,4 @@
 // RUN: rm -rf %t && mkdir %t
 // RUN: not %clang_cc1 %s -triple blah-unknown-unknown 
-serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
 
-// CHECK: error: unknown target triple 

[PATCH] D148851: Disable llvm-symbolizer on some of the driver tests that are timing out

2023-05-01 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 518610.
ahatanak added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Disable llvm-symbolizer when running lit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148851

Files:
  llvm/utils/lit/lit/TestingConfig.py


Index: llvm/utils/lit/lit/TestingConfig.py
===
--- llvm/utils/lit/lit/TestingConfig.py
+++ llvm/utils/lit/lit/TestingConfig.py
@@ -19,6 +19,7 @@
 'PATH' : os.pathsep.join(litConfig.path +
  [os.environ.get('PATH','')]),
 'LLVM_DISABLE_CRASH_REPORT' : '1',
+'LLVM_DISABLE_SYMBOLIZATION' : '1',
 }
 
 pass_vars = [


Index: llvm/utils/lit/lit/TestingConfig.py
===
--- llvm/utils/lit/lit/TestingConfig.py
+++ llvm/utils/lit/lit/TestingConfig.py
@@ -19,6 +19,7 @@
 'PATH' : os.pathsep.join(litConfig.path +
  [os.environ.get('PATH','')]),
 'LLVM_DISABLE_CRASH_REPORT' : '1',
+'LLVM_DISABLE_SYMBOLIZATION' : '1',
 }
 
 pass_vars = [
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE`

2023-05-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:318
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
+  Builder.defineMacro("__AMDGCN_CUMODE", Twine(CUMode));
 }

arsenm wrote:
> Why do we sometimes use __ on both sides, and sometimes only leading __?
We did not establish a naming convention for pre-defined macros.

The rationale of only prefixing with `__` is that:

1. it is shorter

2. many other targets following that for target feature related macros, e.g.  
https://github.com/llvm/llvm-project/blob/main/clang/test/Preprocessor/arm-target-features.c
 , 
https://github.com/llvm/llvm-project/blob/main/clang/test/Preprocessor/riscv-target-features.c

The rationale of adding `__` on both sides is:

1. most gcc predefined macros follow this convention 
https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

2. some targets follow this convention for target feature related macros, e.g 
https://github.com/llvm/llvm-project/blob/main/clang/test/Preprocessor/x86_target_features.c

I think it is not too late to establish a naming convention for predefined 
macros for amdgpu target. I would prefer to adding `__` on both sides since

1. most of the existing amdgpu predefined macros follow that. We just need to 
add `__AMDGCN_WAVEFRONT_SIZE__` and phasing out `__AMDGCN_WAVEFRONT_SIZE`. This 
will be the least interruptive.

2. we will conform to GCC naming convention for pre-defined macros.

Or maybe we should have an RFC for this topic.


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

https://reviews.llvm.org/D145343

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


[PATCH] D143624: Inlining: Run the legacy AlwaysInliner before the regular inliner.

2023-05-01 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.
Herald added a subscriber: jplehr.

@dmgreen I've been looking at this test again trying to see what's missing. The 
problem now is that only a VF of 4 is chosen. In the good case, 
instcombine/simplifyCFG runs so that it simplifies down to an `smin` intrinsic. 
After this change `__SSAT()` is inlined first. We then have:

  target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
  target triple = "aarch64-linux-gnu"
  
  define void @arm_mult_q15(ptr %pSrcA, ptr %pSrcB, ptr noalias %pDst, i32 
%blockSize) {
  entry:
br label %while.cond
  
  while.cond:   ; preds = %while.body, 
%entry
%pSrcB.addr.0 = phi ptr [ %pSrcB, %entry ], [ %incdec.ptr1, %while.body ]
%pDst.addr.0 = phi ptr [ %pDst, %entry ], [ %incdec.ptr4, %while.body ]
%pSrcA.addr.0 = phi ptr [ %pSrcA, %entry ], [ %incdec.ptr, %while.body ]
%blkCnt.0 = phi i32 [ %blockSize, %entry ], [ %dec, %while.body ]
%cmp.not = icmp eq i32 %blkCnt.0, 0
br i1 %cmp.not, label %while.end, label %while.body
  
  while.body:   ; preds = %while.cond
%incdec.ptr = getelementptr inbounds i16, ptr %pSrcA.addr.0, i32 1
%0 = load i16, ptr %pSrcA.addr.0, align 2
%conv = sext i16 %0 to i32
%incdec.ptr1 = getelementptr inbounds i16, ptr %pSrcB.addr.0, i32 1
%1 = load i16, ptr %pSrcB.addr.0, align 2
%conv2 = sext i16 %1 to i32
%mul = mul nsw i32 %conv, %conv2
%shr = ashr i32 %mul, 15
%cmp4.i = icmp sgt i32 %shr, 32767
%switch.i = icmp ult i1 %cmp4.i, true
%spec.select.i = select i1 %switch.i, i32 %shr, i32 32767
%conv3 = trunc i32 %spec.select.i to i16
%incdec.ptr4 = getelementptr inbounds i16, ptr %pDst.addr.0, i32 1
store i16 %conv3, ptr %pDst.addr.0, align 2
%dec = add i32 %blkCnt.0, -1
br label %while.cond
  
  while.end:; preds = %while.cond
ret void
  }

These instructions are from the callee that should now be combined into `smin`:

  %cmp4.i = icmp sgt i32 %shr, 32767
  %switch.i = icmp ult i1 %cmp4.i, true
  %spec.select.i = select i1 %switch.i, i32 %shr, i32 32767

... except due to the surrounding instructions, the first icmp is optimized 
into 
`icmp sgt i32 %mul, 1073741823` by 
`InstCombinerImpl::foldICmpInstWithConstant()`

This breaks the smin recognition. I'm not sure what the best approach is to fix 
this. InstCombine already has this chunk of code to try to avoid messing with 
compares that might form min/max patterns but it expects further simplification 
to fire:

  // Test if the ICmpInst instruction is used exclusively by a select as
  // part of a minimum or maximum operation. If so, refrain from doing
  // any other folding. This helps out other analyses which understand
  // non-obfuscated minimum and maximum idioms, such as ScalarEvolution
  // and CodeGen. And in this case, at least one of the comparison
  // operands has at least one user besides the compare (the select),
  // which would often largely negate the benefit of folding anyway.
  //
  // Do the same for the other patterns recognized by matchSelectPattern.
  if (I.hasOneUse())
if (SelectInst *SI = dyn_cast(I.user_back())) {
  Value *A, *B;
  SelectPatternResult SPR = matchSelectPattern(SI, A, B);
  if (SPR.Flavor != SPF_UNKNOWN)
return nullptr;
}

Any ideas? I'd really like to get this inliner change in because it's 
fundamentally a good change to have.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143624

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


[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-01 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 518608.

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

https://reviews.llvm.org/D146342

Files:
  clang/include/clang/Sema/AnalysisBasedWarnings.h
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -226,11 +226,11 @@
 void testTemplate(int * p) {
   int *a[10];
   foo(f(p, , a, a)[1]); // expected-warning{{unsafe buffer access}}
-  // expected-note@-1{{in instantiation of function template specialization 'f' requested here}}
+  // FIXME: expected note@-1{{in instantiation of function template specialization 'f' requested here}}
 
   const int **q = const_cast();
 
-  testPointerArithmetic(p, q, p); //expected-note{{in instantiation of}}
+  testPointerArithmetic(p, q, p); //FIXME: expected note{{in instantiation of}}
 }
 
 void testPointerToMember() {
@@ -321,7 +321,7 @@
   foo(ar[5]);   // expected-note{{used in buffer access here}}
 }
 
-template void fArr(int t[]); // expected-note {{in instantiation of}}
+template void fArr(int t[]); // FIXME: expected note {{in instantiation of}}
 
 int testReturn(int t[]) {
   // expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1426,6 +1426,8 @@
 }
   }
 
+  AnalysisWarnings.IssueWarnings(Context.getTranslationUnitDecl());
+
   // Check we've noticed that we're no longer parsing the initializer for every
   // variable. If we miss cases, then at best we have a performance issue and
   // at worst a rejects-valid bug.
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -25,6 +25,8 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/CalledOnceCheck.h"
 #include "clang/Analysis/Analyses/Consumed.h"
@@ -2290,6 +2292,100 @@
 S.Diag(D.Loc, D.PD);
 }
 
+void clang::sema::AnalysisBasedWarnings::IssueWarnings(
+const TranslationUnitDecl *TU) {
+  if (!TU)
+return; // This is unexpected, give up quietly.
+
+  DiagnosticsEngine  = S.getDiagnostics();
+  const bool EmitFixits =
+  Diags.getDiagnosticOptions().ShowFixits && S.getLangOpts().CPlusPlus20;
+
+  if (S.hasUncompilableErrorOccurred() || Diags.getIgnoreAllWarnings())
+// exit if having uncompilable errors or ignoring all warnings:
+return;
+
+  // An AST Visitor that calls analyzers on each callable definition:
+  class CallableVisitor : public RecursiveASTVisitor {
+  private:
+Sema 
+const bool EmitFixits;
+// Will be set to true iff visiting a `LambdaExpr`:
+bool IsVisitingLambda = false;
+
+  public:
+CallableVisitor(Sema , bool EmitFixits) : S(S), EmitFixits(EmitFixits) {}
+
+// The only interface that clients of `CallableVisitor` should call:
+void traverseTU(const TranslationUnitDecl *TU) {
+  for (auto I = TU->decls_begin(); I != TU->decls_end(); ++I)
+TraverseDecl(*I);
+}
+
+bool TraverseDecl(Decl *Node) {
+  DiagnosticsEngine  = S.getDiagnostics();
+
+  if (!Node)
+return true;
+  // Do not do any analysis if we are going to just ignore them.
+  if (Diags.getSuppressSystemWarnings() &&
+  S.SourceMgr.isInSystemHeader(Node->getLocation()))
+return true;
+  // To analyze callables:
+  if (isa(Node)) {
+// For code in dependent contexts, we'll do this at instantiation time:
+if (cast(Node)->isDependentContext())
+  return true;
+
+bool ThisNodeHasBody = false;
+
+if (auto *FD = dyn_cast(Node))
+  // `FunctionDecl->hasBody()` returns true if the function has a body
+  // somewhere defined.  But we want to know if this `Node` has a body
+  // child.  So we use `doesThisDeclarationHaveABody`:
+  ThisNodeHasBody = FD->doesThisDeclarationHaveABody();
+else
+  ThisNodeHasBody = Node->hasBody();
+if (ThisNodeHasBody) {
+  UnsafeBufferUsageReporter R(S);
+
+  checkUnsafeBufferUsage(Node, R, EmitFixits);
+}
+  }
+  // Continue to traverse descendants:
+  return RecursiveASTVisitor::TraverseDecl(Node);
+}
+
+bool TraverseStmt(Stmt *Node, DataRecursionQueue *Queue = nullptr) {
+  if (!Node)
+return 

[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 518604.
jhuber6 added a comment.

Add option to allow overriding the global hash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c
  llvm/lib/Target/NVPTX/CMakeLists.txt
  llvm/lib/Target/NVPTX/NVPTX.h
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll

Index: llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
@@ -0,0 +1,32 @@
+; RUN: opt -S -mtriple=nvptx64-- -nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor \
+; RUN: -nvptx-lower-global-ctor-dtor-id=unique_id < %s | FileCheck %s --check-prefix=GLOBAL
+
+; Make sure we get the same result if we run multiple times
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor,nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: llc -nvptx-lower-global-ctor-dtor -mtriple=nvptx64-amd-amdhsa -mcpu=sm_70 -filetype=asm -o - < %s | FileCheck %s -check-prefix=VISIBILITY
+
+@llvm.global_ctors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @foo, ptr null }]
+@llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @bar, ptr null }]
+
+; CHECK-NOT: @llvm.global_ctors
+; CHECK-NOT: @llvm.global_dtors
+
+; CHECK: @__init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @foo, section ".init_array.1"
+; CHECK: @__fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @bar, section ".fini_array.1"
+; CHECK: @llvm.used = appending global [2 x ptr] [ptr addrspacecast (ptr addrspace(4) @__init_array_object_foo_[[HASH]]_1 to ptr), ptr addrspacecast (ptr addrspace(4) @__fini_array_object_bar_[[HASH]]_1 to ptr)], section "llvm.metadata"
+; GLOBAL: @__init_array_object_foo_unique_id_1 = protected addrspace(4) constant ptr @foo, section ".init_array.1"
+; GLOBAL: @__fini_array_object_bar_unique_id_1 = protected addrspace(4) constant ptr @bar, section ".fini_array.1"
+; GLOBAL: @llvm.used = appending global [2 x ptr] [ptr addrspacecast (ptr addrspace(4) @__init_array_object_foo_unique_id_1 to ptr), ptr addrspacecast (ptr addrspace(4) @__fini_array_object_bar_unique_id_1 to ptr)], section "llvm.metadata"
+
+; VISIBILITY: .visible .const .align 8 .u64 __init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = foo;
+; VISIBILITY: .visible .const .align 8 .u64 __fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = bar;
+
+define internal void @foo() {
+  ret void
+}
+
+define internal void @bar() {
+  ret void
+}
Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -15,6 +15,7 @@
 #include "NVPTXAliasAnalysis.h"
 #include "NVPTXAllocaHoisting.h"
 #include "NVPTXAtomicLower.h"
+#include "NVPTXCtorDtorLowering.h"
 #include "NVPTXLowerAggrCopies.h"
 #include "NVPTXMachineFunctionInfo.h"
 #include "NVPTXTargetObjectFile.h"
@@ -68,8 +69,10 @@
 void initializeNVPTXAllocaHoistingPass(PassRegistry &);
 void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&);
 void initializeNVPTXAtomicLowerPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerAggrCopiesPass(PassRegistry &);
 void initializeNVPTXLowerAllocaPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerArgsPass(PassRegistry &);
 void initializeNVPTXProxyRegErasurePass(PassRegistry &);
 void initializeNVVMIntrRangePass(PassRegistry &);
@@ -95,6 +98,7 @@
   initializeNVPTXAtomicLowerPass(PR);
   initializeNVPTXLowerArgsPass(PR);
   initializeNVPTXLowerAllocaPass(PR);
+  initializeNVPTXCtorDtorLoweringLegacyPass(PR);
   initializeNVPTXLowerAggrCopiesPass(PR);
   initializeNVPTXProxyRegErasurePass(PR);
   initializeNVPTXDAGToDAGISelPass(PR);
@@ -249,6 +253,10 @@
   PB.registerPipelineParsingCallback(
   [](StringRef PassName, ModulePassManager ,
  ArrayRef) {
+if (PassName == "nvptx-lower-ctor-dtor") {
+  PM.addPass(NVPTXCtorDtorLoweringPass());
+  return true;
+}
 if (PassName == "generic-to-nvvm") {
   PM.addPass(GenericToNVVMPass());
   return true;
@@ -369,6 +377,7 @@
   }
 
   addPass(createAtomicExpandPass());
+  addPass(createNVPTXCtorDtorLoweringLegacyPass());
 
   

[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

2023-05-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I guess I should note both the examples in 
https://github.com/llvm/llvm-project/issues/49305 could probably be fixed in 
other ways... we have heuristics to, for example, sink logic ops into loops 
when it's profitable.  But that requires someone to notice the specific issues, 
and take the time to diagnose/fix them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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


[PATCH] D149182: Remove -Wpacked false positive for non-pod types where the layout isn't directly changed

2023-05-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149182

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


[PATCH] D149380: [clang] Add -Wunused-result-always warning

2023-05-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Seems more stylistic/unlikely to meet the diagnostic bar (certtainly couldn't 
be on-by-default for instance) for clang to me (but could go into something 
like clang-tidy), at least.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149380

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-01 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik removed a reviewer: libc++abi.
philnik added a comment.

In D149573#433 , @codemzs wrote:

> In D149573#4310601 , @philnik wrote:
>
>> In D149573#4310009 , @codemzs 
>> wrote:
>>
>>> My change to libcxxabi/test/test_demangle.pass.cpp (last file in the 
>>> change) is only one line i.e 
>>> {"_ZNK5clang4Type16isArithmeticTypeERNS_10ASTContextE", 
>>> "clang::Type::isArithmeticType(clang::ASTContext&) const"}, but running 
>>> clang-format on it changes bunch of lines.
>>
>> Please don't clang-format the test then. There is no need to do it, and the 
>> changes look rather confusing. I don't really understand why you add it at 
>> all TBH. This doesn't look like it tests anything from this patch.
>
> @philnik Thank you for your feedback on the changes to 
> `libcxxabi/test/test_demangle.pass.cpp`. I apologize for any confusion my 
> initial approach may have caused. I intended to keep the test file consistent 
> with the updated function prototype, but I understand your concern about 
> clang-format's impact on readability.
>
> I will revert the changes to the test file as you suggested, ensuring it does 
> not affect the current patch's functionality. I appreciate your guidance and 
> will consider these aspects in future updates.

No worries :D. The clang-format guidelines are a bit confusing, and there is 
nothing wrong with not knowing all the conventions of the different subprojects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149573

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


[PATCH] D148769: Split out `CodeGenTypes` from `CodeGen` for LLT/MVT

2023-05-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

I wouldn't mind a follow-up commit that creates a new/separate directory 
(llvm/{lib,include/llvm}/CodeGenTypes) but that's probably a lot of unnecessary 
churn too, so I can appreciate the argument against it - if folks reckon it's 
better this way, that's OK too. It can just get a bit confusing when the 
directory/naming doesn't match the layering, etc. Might make it more likely 
someone regresses these boundaries by introducing new dependencies that break 
the layering here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148769

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


[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

2023-05-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a reviewer: dmgreen.
efriedma added subscribers: bsmith, paulwalker-arm, lenary.
efriedma added a comment.

The primary tradeoff here is that existing optimizations won't understand the 
intrinsic... for example, we can't constant-fold, or automatically invert the 
mask.  But making the intrinsics more predictably produce efficient sequences 
is probably worthwhile.

(Any other opinions here?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-05-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

> probably too much, but then I wonder "how do we make Fortify work?".

(I'm still sort of on the side of "if the compile-time costs to get more 
verbose diagnostics is high, we could have a low-quality default-on diagnostic 
and it could mention/recommend a different/high quality/compile-time costly 
diagnostic" so for code bases like the Linux kernel that rely on this sort of 
thing a lot, with lots of always_inlining, etc, they can tradeoff toward the 
better diagnostic experience and codebases that don't use these features much 
they can still get the checking for when it does come up, but at some cost of 
quality/awkwardness in needing to rebuild with other flags)

But if folks decided some more invasive tracking was worth implementing 
(alongside the debug info codepath that already exists but is perhaps too slow 
to be always on) I wouldn't get up on a soapbox to strenuously object - I just 
think it's a bit unfortunate to build a duplicate thing, but maybe necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141451

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


[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-05-01 Thread Artem Belevich 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 rGa50e54fbeb48: [CUDA] Temporarily undefine __noinline__ when 
including bits/shared_ptr_base.h (authored by tra).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149364

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h


Index: clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
===
--- /dev/null
+++ clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
@@ -0,0 +1,9 @@
+// CUDA headers define __noinline__ which interferes with libstdc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#include_next "bits/shared_ptr_base.h"
+
+#pragma pop_macro("__noinline__")
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -262,6 +262,7 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/bits/shared_ptr_base.h
 )
 
 set(ppc_wrapper_files


Index: clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
===
--- /dev/null
+++ clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
@@ -0,0 +1,9 @@
+// CUDA headers define __noinline__ which interferes with libstdc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#include_next "bits/shared_ptr_base.h"
+
+#pragma pop_macro("__noinline__")
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -262,6 +262,7 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/bits/shared_ptr_base.h
 )
 
 set(ppc_wrapper_files
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a50e54f - [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-05-01 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2023-05-01T16:27:13-07:00
New Revision: a50e54fbeb48fb8a218a2914d827e1087bae2f8d

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

LOG: [CUDA] Temporarily undefine __noinline__ when including 
bits/shared_ptr_base.h

This avoid CUDA compilation errors caused by CUDA headers defining __noinline__
and conflicting with __noinline__ use in libstdc++.

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

Added: 
clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h

Modified: 
clang/lib/Headers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 7c2f323652bb5..f8d6862bb6584 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -262,6 +262,7 @@ set(cuda_wrapper_files
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/bits/shared_ptr_base.h
 )
 
 set(ppc_wrapper_files

diff  --git a/clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h 
b/clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
new file mode 100644
index 0..10028dd7bd9a0
--- /dev/null
+++ b/clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
@@ -0,0 +1,9 @@
+// CUDA headers define __noinline__ which interferes with libstdc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#include_next "bits/shared_ptr_base.h"
+
+#pragma pop_macro("__noinline__")



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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-01 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a comment.

In D149573#4310601 , @philnik wrote:

> In D149573#4310009 , @codemzs wrote:
>
>> My change to libcxxabi/test/test_demangle.pass.cpp (last file in the change) 
>> is only one line i.e {"_ZNK5clang4Type16isArithmeticTypeERNS_10ASTContextE", 
>> "clang::Type::isArithmeticType(clang::ASTContext&) const"}, but running 
>> clang-format on it changes bunch of lines.
>
> Please don't clang-format the test then. There is no need to do it, and the 
> changes look rather confusing. I don't really understand why you add it at 
> all TBH. This doesn't look like it tests anything from this patch.

@philnik Thank you for your feedback on the changes to 
`libcxxabi/test/test_demangle.pass.cpp`. I apologize for any confusion my 
initial approach may have caused. I intended to keep the test file consistent 
with the updated function prototype, but I understand your concern about 
clang-format's impact on readability.

I will revert the changes to the test file as you suggested, ensuring it does 
not affect the current patch's functionality. I appreciate your guidance and 
will consider these aspects in future updates.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149573

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


[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp:58
+((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + getHash(M.getName()) + "_" +
+ std::to_string(Priority))

tra wrote:
> tra wrote:
> > jhuber6 wrote:
> > > tra wrote:
> > > > Source file name may be a little bit better, though it's still easy to 
> > > > clash if someone does `cd A; clang ./foo.c; cd ../B; clang ./foo.c` and 
> > > > the file name uses relative paths.
> > > > 
> > > > I think we'll need a way to override this unique suffix explicitly as 
> > > > an escape hatch for cases where someone runs into a clash.
> > > I figured it'd be good enough since this is admittedly *very* niche. So 
> > > someone would need to have a file called `foo.c` that also had a 
> > > constructor called `foo` in it. For it to clash. Isn't it too late to 
> > > grab the source filename while we're in the backend lowering stage?
> > > someone would need to have a file called foo.c that also had a 
> > > constructor called foo in it
> > 
> > Unlikely != impossible.  It's a trade-off between the hassle of 
> > implementing the plan B and the hassle of debugging and working around the 
> > clash for someone who runs into this.
> > On one hand that's indeed unlikely to happen, but, given enough exposure, 
> > someone/somewhere will run into it and they will likely be ill-equipped to 
> > even tell what's going on.
> > In general, compiler options are logistically much easier to deal with 
> > compared to having to change the source code.
> > 
> > > Isn't it too late to grab the source filename while we're in the backend 
> > > lowering stage?
> > 
> > The module already has the file name recorded and available via 
> > `llvm::Module::getSourceFileName()`, so it's as easy to get as the module 
> > name.
> On the second thought, do you think we'll ever end up running this pass with 
> a module created purely in memory w/o having a source file name. Or, perhaps 
> even without the module name either?
> 
> Even the hash of the IR itself will not be sufficient. Users are allowed to 
> compile and link completely identical TUs as long as they don't have 
> conflicting names.  I can imagine some sort of "plugin" module with only 
> private symbols, but which has initializers to register stuff on startup. Two 
> identical instances of such a module should be able to work, but they would 
> end up with identical hash in this scheme. I do not see any way to 
> automatically disambiguate them, short of using random numbers, but that 
> would make compilation results unstable.
> 
> I still think we need to be able to provide the uniquifier manually via an 
> option.
> 
> 
Yeah, I'm assuming they would just get a name conflict in that case. We can 
definitely add a special option that just adds some noise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

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


[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp:58
+((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + getHash(M.getName()) + "_" +
+ std::to_string(Priority))

tra wrote:
> jhuber6 wrote:
> > tra wrote:
> > > Source file name may be a little bit better, though it's still easy to 
> > > clash if someone does `cd A; clang ./foo.c; cd ../B; clang ./foo.c` and 
> > > the file name uses relative paths.
> > > 
> > > I think we'll need a way to override this unique suffix explicitly as an 
> > > escape hatch for cases where someone runs into a clash.
> > I figured it'd be good enough since this is admittedly *very* niche. So 
> > someone would need to have a file called `foo.c` that also had a 
> > constructor called `foo` in it. For it to clash. Isn't it too late to grab 
> > the source filename while we're in the backend lowering stage?
> > someone would need to have a file called foo.c that also had a constructor 
> > called foo in it
> 
> Unlikely != impossible.  It's a trade-off between the hassle of implementing 
> the plan B and the hassle of debugging and working around the clash for 
> someone who runs into this.
> On one hand that's indeed unlikely to happen, but, given enough exposure, 
> someone/somewhere will run into it and they will likely be ill-equipped to 
> even tell what's going on.
> In general, compiler options are logistically much easier to deal with 
> compared to having to change the source code.
> 
> > Isn't it too late to grab the source filename while we're in the backend 
> > lowering stage?
> 
> The module already has the file name recorded and available via 
> `llvm::Module::getSourceFileName()`, so it's as easy to get as the module 
> name.
On the second thought, do you think we'll ever end up running this pass with a 
module created purely in memory w/o having a source file name. Or, perhaps even 
without the module name either?

Even the hash of the IR itself will not be sufficient. Users are allowed to 
compile and link completely identical TUs as long as they don't have 
conflicting names.  I can imagine some sort of "plugin" module with only 
private symbols, but which has initializers to register stuff on startup. Two 
identical instances of such a module should be able to work, but they would end 
up with identical hash in this scheme. I do not see any way to automatically 
disambiguate them, short of using random numbers, but that would make 
compilation results unstable.

I still think we need to be able to provide the uniquifier manually via an 
option.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

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


[PATCH] D149492: [clang] makes built-in traits match their stdlib counterparts' names

2023-05-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Looks like I need to special-case `__is_null_pointer` as a function for 
libstdc++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149492

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


[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-05-01 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: llvm/test/Transforms/OpenMP/always_inline_device.ll:11
 
-; Function Attrs: norecurse nounwind
+@kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy 
{ %struct.ConfigurationEnvironmentTy { i8 1, i8 0, i8 1 }, ptr @1, ptr null }
+

@arsenm Does AMDGPU support a global struct with constant initializer? I 
currently encountered an error that, the generated IR has correct initializer, 
but when I read from the global struct from the image (ELF), the corresponding 
memory looks pretty random. I just need one of the first three `i8` values.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

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


[PATCH] D149618: [clang][NFC] documents recent type trait primitives

2023-05-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, erichkeane, shafik.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D149492 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149618

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1398,6 +1398,9 @@
 ``__X(...)`` has the same semantics and constraints as the corresponding
 ``std::X_t<...>`` or ``std::X_v<...>`` type trait.
 
+* ``__add_lvalue_reference(type)`` (C++)
+* ``__add_pointer(type)`` (C++)
+* ``__add_rvalue_reference(type)`` (C++)
 * ``__array_rank(type)`` (Embarcadero):
   Returns the number of levels of array in the type ``type``:
   ``0`` if ``type`` is not an array type, and
@@ -1409,6 +1412,7 @@
   Returns whether a class can be passed in registers under the current
   ABI. This type can only be applied to unqualified class types.
   This is not a portable type trait.
+* ``__decay(type)`` (C++)
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):
@@ -1517,12 +1521,23 @@
   enumeration types if the underlying type was unsigned.
 * ``__is_void`` (C++, Embarcadero)
 * ``__is_volatile`` (C++, Embarcadero)
+* ``__make_signed(type)`` (C++)
+* ``__make_unsigned(type)`` (C++)
 * ``__reference_binds_to_temporary(T, U)`` (Clang):  Determines whether a
   reference of type ``T`` bound to an expression of type ``U`` would bind to a
   materialized temporary object. If ``T`` is not a reference type the result
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
-* ``__underlying_type`` (C++, GNU, Microsoft)
+* ``__remove_all_extents(type)`` (C++)
+* ``__remove_const(type)`` (C++)
+* ``__remove_cv(type)`` (C++)
+* ``__remove_cvref(type)`` (C++)
+* ``__remove_extent(type)`` (C++)
+* ``__remove_pointer(type)``(C++)
+* ``__remove_reference(type)`` (C++)
+* ``__remove_restrict(type)`` (C++)
+* ``__remove_volatile(type)`` (C++)
+* ``__underlying_type(type)`` (C++, GNU, Microsoft)
 
 In addition, the following expression traits are supported:
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -1398,6 +1398,9 @@
 ``__X(...)`` has the same semantics and constraints as the corresponding
 ``std::X_t<...>`` or ``std::X_v<...>`` type trait.
 
+* ``__add_lvalue_reference(type)`` (C++)
+* ``__add_pointer(type)`` (C++)
+* ``__add_rvalue_reference(type)`` (C++)
 * ``__array_rank(type)`` (Embarcadero):
   Returns the number of levels of array in the type ``type``:
   ``0`` if ``type`` is not an array type, and
@@ -1409,6 +1412,7 @@
   Returns whether a class can be passed in registers under the current
   ABI. This type can only be applied to unqualified class types.
   This is not a portable type trait.
+* ``__decay(type)`` (C++)
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):
@@ -1517,12 +1521,23 @@
   enumeration types if the underlying type was unsigned.
 * ``__is_void`` (C++, Embarcadero)
 * ``__is_volatile`` (C++, Embarcadero)
+* ``__make_signed(type)`` (C++)
+* ``__make_unsigned(type)`` (C++)
 * ``__reference_binds_to_temporary(T, U)`` (Clang):  Determines whether a
   reference of type ``T`` bound to an expression of type ``U`` would bind to a
   materialized temporary object. If ``T`` is not a reference type the result
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
-* ``__underlying_type`` (C++, GNU, Microsoft)
+* ``__remove_all_extents(type)`` (C++)
+* ``__remove_const(type)`` (C++)
+* ``__remove_cv(type)`` (C++)
+* ``__remove_cvref(type)`` (C++)
+* ``__remove_extent(type)`` (C++)
+* ``__remove_pointer(type)``(C++)
+* ``__remove_reference(type)`` (C++)
+* ``__remove_restrict(type)`` (C++)
+* ``__remove_volatile(type)`` (C++)
+* ``__underlying_type(type)`` (C++, GNU, Microsoft)
 
 In addition, the following expression traits are supported:
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-01 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added subscribers: iana, ributzka.
dexonsmith added a comment.

In D103930#4310061 , @ivanmurashko 
wrote:

> Friendly ping
>
> @arphaman, @jansvoboda11, I have made the patch buildable on all platforms 
> and have all tests passed. There was also a small fix (temp path for modules 
> artefact) at the test that could fix its run on some platforms. Could you 
> look at it? Does it have any issues on your side?

Alternatively, maybe @vsapsai, @ributzka, or @iana...?

Given that header maps are somewhat Apple-specific and unit test coverage is a 
bit lacking for these sorts of interactions, it'd be nice for someone to check 
this with Apple-internal stuff. But if you're okay with it landing, and then 
you triage internal issues not covered by public tests later, please say that 
as well!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103930

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-05-01 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov added a comment.

@erichkeane - thanks! I'll send a diff for the release notes ~soon (~this 
week).  (P.S.  just in case - I'll be out of office for ~2 weeks)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added 2 blocking reviewer(s): eugenis, MaskRay.
vitalybuka added a comment.

In D143675#4310734 , @rsundahl wrote:

> @kcc @eugenis @MaskRay @vitalybuka Ok to go with this? All new functionality 
> is under the added flag so not expecting any surprises. Rename 
> asabi->asan_abi as suggested.

Thanks, asan_abi LGTM.

I don't have good reasons to object that patch, but I suspect it's sub-optimal. 
But we may get a valuable expirience.

> Rather than adding a lot of conditional code to the LLVM instrumentation phase

We do this for hwasan for Android, and to some extent msan for Chromium. 
@eugenis maybe can share more info.

> Based on previous discussions about this topic, our understanding is that 
> freezing the present ABI would impose an excessive burden on other sanitizer 
> developers and for unrelated platforms.

I guess we just have no way to enforce that. A couple of buildbots with "stable 
clang" + "HEAD runtime" and "HEAD clang" + "stable runtime" which do some 
non-tivial build, e.g. clang bootstrap can enforce that. We can at list to 
enforce default set of flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-01 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

I'm fine with it in general. Is asan_abi.cpp meant as a temporary stub? It's 
not even link anywhere in the current version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-05-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

There's some corresponding code in `lib/CodeGen` that can be deleted too:

 case Builtin::BI__builtin_assume_aligned: {
   const Expr *Ptr = E->getArg(0);
   Value *PtrValue = EmitScalarExpr(Ptr);
  - if (PtrValue->getType() != VoidPtrTy)
  -   PtrValue = EmitCastToVoidPtr(PtrValue);
   Value *OffsetValue =
 (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr;




Comment at: clang/lib/Sema/SemaChecking.cpp:7979-7986
   {
 ExprResult FirstArgResult =
 DefaultFunctionArrayLvalueConversion(FirstArg);
-if (FirstArgResult.isInvalid())
+if (checkBuiltinArgument(*this, TheCall, 0))
   return true;
+/// In-place updation of FirstArg by checkBuiltinArgument is ignored.
 TheCall->setArg(0, FirstArgResult.get());

This still seems to be more complex than necessary. If we can't just do this, 
we should have a comment explaining why. (Eg, does CodeGen really want the 
final conversion from `T*` to `const void*` to not be in the AST?)


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

https://reviews.llvm.org/D149514

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


[PATCH] D142401: [Clang] Fix a crash when recursively callig a default member initializer.

2023-05-01 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG771ad1691ac3: [Clang] Fix a crash when recursively callig a 
default member initializer. (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D142401?vs=518161=518564#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142401

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5926,7 +5926,9 @@
   Param);
   ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
   SkipImmediateInvocations;
-  MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
+  runWithSufficientStackSpace(CallLoc, [&] {
+MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables=*/true);
+  });
   return false;
 }
 
@@ -6036,8 +6038,11 @@
   ExprEvalContexts.back().DelayedDefaultInitializationContext = {
   CallLoc, Param, CurContext};
   EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-  ExprResult Res = Immediate.TransformInitializer(Param->getInit(),
-  /*NotCopy=*/false);
+  ExprResult Res;
+  runWithSufficientStackSpace(CallLoc, [&] {
+Res = Immediate.TransformInitializer(Param->getInit(),
+ /*NotCopy=*/false);
+  });
   if (Res.isInvalid())
 return ExprError();
   Res = ConvertParamDefaultArgument(Param, Res.get(),
@@ -6117,10 +6122,11 @@
 NestedDefaultChecking;
 
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-
-ExprResult Res =
-Immediate.TransformInitializer(Field->getInClassInitializer(),
-   /*CXXDirectInit=*/false);
+ExprResult Res;
+runWithSufficientStackSpace(Loc, [&] {
+  Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
+   /*CXXDirectInit=*/false);
+});
 if (!Res.isInvalid())
   Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
 if (Res.isInvalid()) {
@@ -6133,7 +6139,9 @@
   if (Field->getInClassInitializer()) {
 Expr *E = Init ? Init : Field->getInClassInitializer();
 if (!NestedDefaultChecking)
-  MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  runWithSufficientStackSpace(Loc, [&] {
+MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  });
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.
@@ -18545,7 +18553,9 @@
   if (CXXConstructorDecl *Constructor = dyn_cast(Func)) {
 for (CXXCtorInitializer *Init : Constructor->inits()) {
   if (Init->isInClassMemberInitializer())
-MarkDeclarationsReferencedInExpr(Init->getInit());
+runWithSufficientStackSpace(Init->getSourceLocation(), [&]() {
+  MarkDeclarationsReferencedInExpr(Init->getInit());
+});
 }
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -313,8 +313,8 @@
   not a type concept.
 - Fix crash when a doc comment contains a line splicing.
   (`#62054 `_)
-- Work around with a clang coverage crash which happens when visiting 
-  expressions/statements with invalid source locations in non-assert builds. 
+- Work around with a clang coverage crash which happens when visiting
+  expressions/statements with invalid source locations in non-assert builds.
   Assert builds may still see assertions triggered from this.
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
@@ -335,6 +335,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
+  (`#60082` `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5926,7 +5926,9 @@
   Param);
   ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
   SkipImmediateInvocations;
-  MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
+  

[clang] 771ad16 - [Clang] Fix a crash when recursively callig a default member initializer.

2023-05-01 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-05-01T23:21:14+02:00
New Revision: 771ad1691ac3057df2220dd327d7cdc73ef6c6f5

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

LOG: [Clang] Fix a crash when recursively callig a default member initializer.

This fixes a regression introduced by ca61961380, that would lead
to a segfault due to stack exhaustion when recursively calling
a default member initializer.

Fixes #60082

I'm not able to  get clang to emit a stack exhaustion warning,
which it seems like it should be able to.

Reviewed By: shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a3ee06ba1c22..34636faa36bf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -313,8 +313,8 @@ Bug Fixes in This Version
   not a type concept.
 - Fix crash when a doc comment contains a line splicing.
   (`#62054 `_)
-- Work around with a clang coverage crash which happens when visiting 
-  expressions/statements with invalid source locations in non-assert builds. 
+- Work around with a clang coverage crash which happens when visiting
+  expressions/statements with invalid source locations in non-assert builds.
   Assert builds may still see assertions triggered from this.
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
@@ -335,6 +335,8 @@ Bug Fixes in This Version
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
+  (`#60082` `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5450b4748997..4edaf6970a2d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5926,7 +5926,9 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, 
FunctionDecl *FD,
   Param);
   ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
   SkipImmediateInvocations;
-  MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
+  runWithSufficientStackSpace(CallLoc, [&] {
+MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables=*/true);
+  });
   return false;
 }
 
@@ -6036,8 +6038,11 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation 
CallLoc,
   ExprEvalContexts.back().DelayedDefaultInitializationContext = {
   CallLoc, Param, CurContext};
   EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-  ExprResult Res = Immediate.TransformInitializer(Param->getInit(),
-  /*NotCopy=*/false);
+  ExprResult Res;
+  runWithSufficientStackSpace(CallLoc, [&] {
+Res = Immediate.TransformInitializer(Param->getInit(),
+ /*NotCopy=*/false);
+  });
   if (Res.isInvalid())
 return ExprError();
   Res = ConvertParamDefaultArgument(Param, Res.get(),
@@ -6117,10 +6122,11 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
 NestedDefaultChecking;
 
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-
-ExprResult Res =
-Immediate.TransformInitializer(Field->getInClassInitializer(),
-   /*CXXDirectInit=*/false);
+ExprResult Res;
+runWithSufficientStackSpace(Loc, [&] {
+  Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
+   /*CXXDirectInit=*/false);
+});
 if (!Res.isInvalid())
   Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
 if (Res.isInvalid()) {
@@ -6133,7 +6139,9 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   if (Field->getInClassInitializer()) {
 Expr *E = Init ? Init : Field->getInClassInitializer();
 if (!NestedDefaultChecking)
-  MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  runWithSufficientStackSpace(Loc, [&] {
+MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  });
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.
@@ -18545,7 +18553,9 @@ void 

[PATCH] D149144: [clang][dataflow] Eliminate intermediate `ReferenceValue`s from `Environment::DeclToLoc`.

2023-05-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a subscriber: dcoughlin.
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:616
+  bool erased = DeclToLoc.erase();
+  if (!erased)
+D.dump();

Would we dump this in release builds? Do we want to limit this to debug/assert 
builds?



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:329
+static void
+builtinTransferScopeEnd(const CFGScopeEnd ,
+TypeErasedDataflowAnalysisState ) {

I think one question is whether we are interested in ScopeEnd or LifetimeEnd, 
see the discussions in https://reviews.llvm.org/D15031 and 
https://reviews.llvm.org/D16403, specifically Devin's comment: 

>>! In D16403#799926, @dcoughlin wrote:
>> @dcoughlin As a reviewer of both patches - could you tell us what's the 
>> difference between them? And how are we going to resolve this issue?
> 
> These two patches are emitting markers in the CFG for different things.
> 
> Here is how I would characterize the difference between the two patches.
> 
> - Despite its name, https://reviews.llvm.org/D15031, is really emitting 
> markers for when the lifetime of a C++ object in an automatic variable ends.  
> For C++ objects with non-trivial destructors, this point is when the 
> destructor is called. At this point the storage for the variable still 
> exists, but what you can do with that storage is very restricted by the 
> language because its contents have been destroyed. Note that even with the 
> contents of the object have been destroyed, it is still meaningful to, say, 
> take the address of the variable and construct a new object into it with a 
> placement new. In other words, the same variable can have different objects, 
> with different lifetimes, in it at different program points.
> 
> - In contrast, the purpose of this patch (https://reviews.llvm.org/D16403) is 
> to add markers for when the storage duration for the variable begins and ends 
> (this is, when the storage exists). Once the storage duration has ended, you 
> can't placement new into the variables address, because another variable may 
> already be at that address.
> 
> I don't think there is an "issue" to resolve here.  We should make sure the 
> two patches play nicely with each other, though. In particular, we should 
> make sure that the markers for when lifetime ends and when storage duration 
> ends are ordered correctly.


What I wanted to add, I wonder if we might not get ScopeEnd event for 
temporaries and there might be other differences. The Clang implementation of 
P1179 used LifetimeEnd instead of ScopeEnd, and I believe probably most clients 
are more interested in LifetimeEnd events rather than ScopeEnd.

I think I understand why you went with ScopeEnd for this specific problem, but 
to avoid the confusion from having both in the Cfg (because I anticipate 
someone will need LifetimeEnd at some point), I wonder if we can make this work 
with LifetimeEnd. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149144

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-01 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl marked an inline comment as done.
rsundahl added a comment.

@kcc @eugenis @MaskRay @vitalybuka Ok to go with this? All new functionality is 
under the added flag so not expecting any surprises. Rename asabi->asan_abi as 
suggested.




Comment at: compiler-rt/lib/asabi/CMakeLists.txt:2
+# Build for the ASAN Stable ABI runtime support library.
+set(ASABI_SOURCES
+  asabi_shim.cpp

rsundahl wrote:
> vitalybuka wrote:
> > does it need to be asabi?
> > maybe better asan_abi, files and macro?
> The idea is that "asabi" replaces "asan" (where the "s" stands in for 
> "stable"), but I understand the distraction of sounding like a hot condiment! 
> I wonder what you think of "asan_stable" (over "asan_stable_abi" or 
> "asan_abi" as you suggest). I am more at ease with emphasizing the "stable" 
> over the "abi" since both "asan" and "asan_stable" share ABI-ness without 
> calling it out. This might read and organize a bit more naturally with what 
> we already have. Thanks for the input.
Changed "asabi" namespace to "asan_abi". Applied to files, directories and 
contents.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-05-01 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

You should upload this with full context and add some test cases :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148654

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


[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 518553.
jhuber6 added a comment.

Changing to use source filename.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c
  llvm/lib/Target/NVPTX/CMakeLists.txt
  llvm/lib/Target/NVPTX/NVPTX.h
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll

Index: llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
@@ -0,0 +1,27 @@
+; RUN: opt -S -mtriple=nvptx64-- -nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor < %s | FileCheck %s
+
+; Make sure we get the same result if we run multiple times
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor,nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: llc -nvptx-lower-global-ctor-dtor -mtriple=nvptx64-amd-amdhsa -mcpu=sm_70 -filetype=asm -o - < %s | FileCheck %s -check-prefix=VISIBILITY
+
+@llvm.global_ctors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @foo, ptr null }]
+@llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @bar, ptr null }]
+
+; CHECK-NOT: @llvm.global_ctors
+; CHECK-NOT: @llvm.global_dtors
+
+; CHECK: @__init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @foo, section ".init_array.1"
+; CHECK: @__fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @bar, section ".fini_array.1"
+; CHECK: @llvm.used = appending global [2 x ptr] [ptr addrspacecast (ptr addrspace(4) @__init_array_object_foo_[[HASH]]_1 to ptr), ptr addrspacecast (ptr addrspace(4) @__fini_array_object_bar_[[HASH]]_1 to ptr)], section "llvm.metadata"
+
+; VISIBILITY: .visible .const .align 8 .u64 __init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = foo;
+; VISIBILITY: .visible .const .align 8 .u64 __fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = bar;
+
+define internal void @foo() {
+  ret void
+}
+
+define internal void @bar() {
+  ret void
+}
Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -15,6 +15,7 @@
 #include "NVPTXAliasAnalysis.h"
 #include "NVPTXAllocaHoisting.h"
 #include "NVPTXAtomicLower.h"
+#include "NVPTXCtorDtorLowering.h"
 #include "NVPTXLowerAggrCopies.h"
 #include "NVPTXMachineFunctionInfo.h"
 #include "NVPTXTargetObjectFile.h"
@@ -68,8 +69,10 @@
 void initializeNVPTXAllocaHoistingPass(PassRegistry &);
 void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&);
 void initializeNVPTXAtomicLowerPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerAggrCopiesPass(PassRegistry &);
 void initializeNVPTXLowerAllocaPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerArgsPass(PassRegistry &);
 void initializeNVPTXProxyRegErasurePass(PassRegistry &);
 void initializeNVVMIntrRangePass(PassRegistry &);
@@ -95,6 +98,7 @@
   initializeNVPTXAtomicLowerPass(PR);
   initializeNVPTXLowerArgsPass(PR);
   initializeNVPTXLowerAllocaPass(PR);
+  initializeNVPTXCtorDtorLoweringLegacyPass(PR);
   initializeNVPTXLowerAggrCopiesPass(PR);
   initializeNVPTXProxyRegErasurePass(PR);
   initializeNVPTXDAGToDAGISelPass(PR);
@@ -249,6 +253,10 @@
   PB.registerPipelineParsingCallback(
   [](StringRef PassName, ModulePassManager ,
  ArrayRef) {
+if (PassName == "nvptx-lower-ctor-dtor") {
+  PM.addPass(NVPTXCtorDtorLoweringPass());
+  return true;
+}
 if (PassName == "generic-to-nvvm") {
   PM.addPass(GenericToNVVMPass());
   return true;
@@ -369,6 +377,7 @@
   }
 
   addPass(createAtomicExpandPass());
+  addPass(createNVPTXCtorDtorLoweringLegacyPass());
 
   // === LSR and other generic IR passes ===
   TargetPassConfig::addIRPasses();
Index: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
===
--- /dev/null
+++ llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
@@ -0,0 +1,30 @@
+//===-- NVPTXCtorDtorLowering.h *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-01 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl updated this revision to Diff 518552.
rsundahl added a comment.

Rename asabi->asan_abi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/docs/asan_abi.md
  compiler-rt/lib/asan_abi/CMakeLists.txt
  compiler-rt/lib/asan_abi/asan_abi.cpp
  compiler-rt/lib/asan_abi/asan_abi.h
  compiler-rt/lib/asan_abi/asan_abi_shim.cpp
  compiler-rt/lib/asan_abi/asan_abi_shim.h
  compiler-rt/test/asan_abi/CMakeLists.txt

Index: compiler-rt/test/asan_abi/CMakeLists.txt
===
--- /dev/null
+++ compiler-rt/test/asan_abi/CMakeLists.txt
@@ -0,0 +1 @@
+#TODO: Setup asan_abi test suite.
Index: compiler-rt/lib/asan_abi/asan_abi_shim.h
===
--- /dev/null
+++ compiler-rt/lib/asan_abi/asan_abi_shim.h
@@ -0,0 +1,224 @@
+//===-asan_abi_shim.h - ASan Stable ABI Shim Interfac--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef ASAN_ABI_SHIM_H
+#define ASAN_ABI_SHIM_H
+
+typedef unsigned long uptr;
+typedef unsigned long u64;
+typedef unsigned int u32;
+
+extern void __asan_register_image_globals(uptr *flag);
+extern void __asan_unregister_image_globals(uptr *flag);
+
+extern void __asan_register_elf_globals(uptr *flag, void *start, void *stop);
+extern void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop);
+
+extern void __asan_register_globals(__asan_global *globals, uptr n);
+extern void __asan_unregister_globals(__asan_global *globals, uptr n);
+
+extern void __asan_before_dynamic_init(const char *module_name);
+extern void __asan_after_dynamic_init(void);
+
+// Interceptors
+extern void *__asan_memcpy(void *dst, const void *src, uptr size);
+extern void *__asan_memset(void *s, int c, uptr n);
+extern void *__asan_memmove(void *dest, const void *src, uptr n);
+
+// RTL (Interface)
+extern void __asan_init(void);
+extern void __asan_version_mismatch_check(void);
+extern void __asan_handle_no_return(void);
+
+// RTL (Variables)
+extern uptr __asan_shadow_memory_dynamic_address;
+extern int __asan_option_detect_stack_use_after_return;
+
+// RTL (Report)
+extern void __asan_report_load1(uptr addr);
+extern void __asan_report_load2(uptr addr);
+extern void __asan_report_load4(uptr addr);
+extern void __asan_report_load8(uptr addr);
+extern void __asan_report_load16(uptr addr);
+extern void __asan_report_load_n(uptr addr, uptr size);
+extern void __asan_report_store1(uptr addr);
+extern void __asan_report_store2(uptr addr);
+extern void __asan_report_store4(uptr addr);
+extern void __asan_report_store8(uptr addr);
+extern void __asan_report_store16(uptr addr);
+extern void __asan_report_store_n(uptr addr, uptr size);
+
+// RTL (Report-experimental)
+extern void __asan_report_exp_load1(uptr addr, u32 exp);
+extern void __asan_report_exp_load2(uptr addr, u32 exp);
+extern void __asan_report_exp_load4(uptr addr, u32 exp);
+extern void __asan_report_exp_load8(uptr addr, u32 exp);
+extern void __asan_report_exp_load16(uptr addr, u32 exp);
+extern void __asan_report_exp_load_n(uptr addr, uptr size, u32 exp);
+extern void __asan_report_exp_store1(uptr addr, u32 exp);
+extern void __asan_report_exp_store2(uptr addr, u32 exp);
+extern void __asan_report_exp_store4(uptr addr, u32 exp);
+extern void __asan_report_exp_store8(uptr addr, u32 exp);
+extern void __asan_report_exp_store16(uptr addr, u32 exp);
+extern void __asan_report_exp_store_n(uptr addr, uptr size, u32 exp);
+
+// RTL (Report-noabort)
+extern void __asan_report_load1_noabort(uptr addr);
+extern void __asan_report_load2_noabort(uptr addr);
+extern void __asan_report_load4_noabort(uptr addr);
+extern void __asan_report_load8_noabort(uptr addr);
+extern void __asan_report_load16_noabort(uptr addr);
+extern void __asan_report_load_n_noabort(uptr addr, uptr size);
+extern void __asan_report_store1_noabort(uptr addr);
+extern void __asan_report_store2_noabort(uptr addr);
+extern void __asan_report_store4_noabort(uptr addr);
+extern void __asan_report_store8_noabort(uptr addr);
+extern void __asan_report_store16_noabort(uptr addr);
+extern void __asan_report_store_n_noabort(uptr addr, uptr size);
+
+// RTL (Access)
+extern void __asan_load1(uptr p);
+extern void __asan_load2(uptr p);
+extern void __asan_load4(uptr p);
+extern void __asan_load8(uptr p);
+extern void __asan_load16(uptr p);
+extern void __asan_loadN(uptr p, uptr size);
+extern void __asan_store1(uptr p);

[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp:58
+((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + getHash(M.getName()) + "_" +
+ std::to_string(Priority))

jhuber6 wrote:
> tra wrote:
> > Source file name may be a little bit better, though it's still easy to 
> > clash if someone does `cd A; clang ./foo.c; cd ../B; clang ./foo.c` and the 
> > file name uses relative paths.
> > 
> > I think we'll need a way to override this unique suffix explicitly as an 
> > escape hatch for cases where someone runs into a clash.
> I figured it'd be good enough since this is admittedly *very* niche. So 
> someone would need to have a file called `foo.c` that also had a constructor 
> called `foo` in it. For it to clash. Isn't it too late to grab the source 
> filename while we're in the backend lowering stage?
> someone would need to have a file called foo.c that also had a constructor 
> called foo in it

Unlikely != impossible.  It's a trade-off between the hassle of implementing 
the plan B and the hassle of debugging and working around the clash for someone 
who runs into this.
On one hand that's indeed unlikely to happen, but, given enough exposure, 
someone/somewhere will run into it and they will likely be ill-equipped to even 
tell what's going on.
In general, compiler options are logistically much easier to deal with compared 
to having to change the source code.

> Isn't it too late to grab the source filename while we're in the backend 
> lowering stage?

The module already has the file name recorded and available via 
`llvm::Module::getSourceFileName()`, so it's as easy to get as the module name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

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


[PATCH] D149600: [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Teresa Johnson 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 rG2cc0c0de8021: [MemProf] Recognize hot/cold operator new as 
replaceable allocations (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149600

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp

Index: clang/test/CodeGenCXX/new_hot_cold.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/new_hot_cold.cpp
@@ -0,0 +1,130 @@
+// Test to check that the appropriate attributes are added to the __hot_cold_t
+// versions of operator new.
+
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -faligned-allocation -emit-llvm -o - | FileCheck %s
+
+typedef __typeof__(sizeof(0)) size_t;
+
+namespace std {
+struct nothrow_t {};
+enum class align_val_t : size_t;
+} // namespace std
+std::nothrow_t nothrow;
+
+typedef unsigned char uint8_t;
+
+// See the following link for how this type is declared in tcmalloc:
+// https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53.
+enum class __hot_cold_t : uint8_t;
+
+// Test handling of declaration that uses a type alias, ensuring that it still
+// recognizes the expected __hot_cold_t type name.
+namespace malloc_namespace {
+using hot_cold_t = __hot_cold_t;
+}
+
+void *operator new(size_t size,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new(size_t size, std::align_val_t alignment,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size, std::align_val_t alignment,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, std::align_val_t alignment,
+   const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, std::align_val_t alignment,
+ const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+
+// All explicit operator new calls should not get any builtin attribute, whereas
+// all implicit new expressions should get builtin attributes. All of the
+// declarations should get nobuiltin attributes.
+
+void hot_cold_new() {
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new(1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_array() {
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new[](1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int[1];
+}
+
+// CHECK: declare noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_nothrow() {
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  operator new(1, nothrow, (__hot_cold_t)0);
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 4, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  new (nothrow, (__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1), i8 noundef zeroext) [[ATTR_NOBUILTIN_NOTHROW:#[^ ]*]]
+
+void hot_cold_new_nothrow_array() {
+  // CHECK: call noalias noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  operator new[](1, nothrow, (__hot_cold_t)0);
+  // CHECK: call noalias noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef 4, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  new (nothrow, (__hot_cold_t)0) int[1];
+}
+
+// CHECK: declare noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef, ptr 

[clang] 2cc0c0d - [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Teresa Johnson via cfe-commits

Author: Teresa Johnson
Date: 2023-05-01T13:37:40-07:00
New Revision: 2cc0c0de802178dc7e5408497e2ec53b6c9728fa

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

LOG: [MemProf] Recognize hot/cold operator new as replaceable allocations

Follow up to LLVM-side change to allow conversion to hot/cold hinted
operator new, not yet standard but supported by open source tcmalloc.
The LLVM change in a35206d78280e0ebcf48cd21bc5fff5c3b9c73fa added the
necessary support to recognize these as library functions, and we
subsequently found that a clang-side change is needed to give them
builtin/nobuiltin attributes as appropriate so they have consistent
removeability.

Based on discussion with Richard Smith, converted the parameter type to
a reserved identifier (39f7b48671dae5fbe3afc49f33f50c2b6340bb89) and
added support in this patch to recognize it in clang.

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

Added: 
clang/test/CodeGenCXX/new_hot_cold.cpp

Modified: 
clang/lib/AST/Decl.cpp

Removed: 




diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index b728917fdda6d..d284df29f3b33 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3245,7 +3245,7 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction(
 return false;
 
   const auto *FPT = getType()->castAs();
-  if (FPT->getNumParams() == 0 || FPT->getNumParams() > 3 || FPT->isVariadic())
+  if (FPT->getNumParams() == 0 || FPT->getNumParams() > 4 || FPT->isVariadic())
 return false;
 
   // If this is a single-parameter function, it must be a replaceable global
@@ -3280,8 +3280,8 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction(
   *AlignmentParam = Params;
   }
 
-  // Finally, if this is not a sized delete, the final parameter can
-  // be a 'const std::nothrow_t&'.
+  // If this is not a sized delete, the next parameter can be a
+  // 'const std::nothrow_t&'.
   if (!IsSizedDelete && !Ty.isNull() && Ty->isReferenceType()) {
 Ty = Ty->getPointeeType();
 if (Ty.getCVRQualifiers() != Qualifiers::Const)
@@ -3293,6 +3293,19 @@ bool FunctionDecl::isReplaceableGlobalAllocationFunction(
 }
   }
 
+  // Finally, recognize the not yet standard versions of new that take a
+  // hot/cold allocation hint (__hot_cold_t). These are currently supported by
+  // tcmalloc (see
+  // 
https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53).
+  if (!IsSizedDelete && !Ty.isNull() && Ty->isEnumeralType()) {
+QualType T = Ty;
+while (const auto *TD = T->getAs())
+  T = TD->getDecl()->getUnderlyingType();
+IdentifierInfo *II = T->getAs()->getDecl()->getIdentifier();
+if (II && II->isStr("__hot_cold_t"))
+  Consume();
+  }
+
   return Params == FPT->getNumParams();
 }
 

diff  --git a/clang/test/CodeGenCXX/new_hot_cold.cpp 
b/clang/test/CodeGenCXX/new_hot_cold.cpp
new file mode 100644
index 0..014e815201485
--- /dev/null
+++ b/clang/test/CodeGenCXX/new_hot_cold.cpp
@@ -0,0 +1,130 @@
+// Test to check that the appropriate attributes are added to the __hot_cold_t
+// versions of operator new.
+
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-faligned-allocation -emit-llvm -o - | FileCheck %s
+
+typedef __typeof__(sizeof(0)) size_t;
+
+namespace std {
+struct nothrow_t {};
+enum class align_val_t : size_t;
+} // namespace std
+std::nothrow_t nothrow;
+
+typedef unsigned char uint8_t;
+
+// See the following link for how this type is declared in tcmalloc:
+// 
https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53.
+enum class __hot_cold_t : uint8_t;
+
+// Test handling of declaration that uses a type alias, ensuring that it still
+// recognizes the expected __hot_cold_t type name.
+namespace malloc_namespace {
+using hot_cold_t = __hot_cold_t;
+}
+
+void *operator new(size_t size,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new(size_t size, std::align_val_t alignment,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size, std::align_val_t alignment,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, std::align_val_t alignment,
+   const std::nothrow_t &,
+   

[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp:58
+((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + getHash(M.getName()) + "_" +
+ std::to_string(Priority))

tra wrote:
> Source file name may be a little bit better, though it's still easy to clash 
> if someone does `cd A; clang ./foo.c; cd ../B; clang ./foo.c` and the file 
> name uses relative paths.
> 
> I think we'll need a way to override this unique suffix explicitly as an 
> escape hatch for cases where someone runs into a clash.
I figured it'd be good enough since this is admittedly *very* niche. So someone 
would need to have a file called `foo.c` that also had a constructor called 
`foo` in it. For it to clash. Isn't it too late to grab the source filename 
while we're in the backend lowering stage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

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


[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-05-01 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added a comment.

No, I don't have commit access. You could use just `Bolshakov 
`


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

https://reviews.llvm.org/D146386

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


[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-05-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM overall.




Comment at: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp:58
+((IsCtor ? "__init_array_object_" : "__fini_array_object_") +
+ F->getName() + "_" + getHash(M.getName()) + "_" +
+ std::to_string(Priority))

Source file name may be a little bit better, though it's still easy to clash if 
someone does `cd A; clang ./foo.c; cd ../B; clang ./foo.c` and the file name 
uses relative paths.

I think we'll need a way to override this unique suffix explicitly as an escape 
hatch for cases where someone runs into a clash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

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


[PATCH] D145441: [AMDGPU] Define data layout entries for buffers

2023-05-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

LGTM. It may not be the end step and may be annoying to make further changes 
from this point, but on its own this isn't worse than before




Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:998
 
 // TODO: Should images get their own address space?
+Info.fallbackAddressSpace = AMDGPUAS::BUFFER_RESOURCE;

Should this todo be dropped?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145441

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-01 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks marked an inline comment as done.
aeubanks added a comment.

In D146764#4310398 , @aaron.ballman 
wrote:

> I think you're missing changes in ASTReaderStmt.cpp and ASTWriterStmt.cpp, so 
> serialization through modules or PCH won't work without that.

done. how would this sort of change be tested?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-01 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 518548.
aeubanks added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/IgnoreExpr.h
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/Sema/ms_predefined_expr.cpp

Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- /dev/null
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// expected-no-diagnostics
+
+void f() {
+ const char a[] = __FUNCTION__;
+ const char b[] = __FUNCDNAME__;
+ const char c[] = __FUNCSIG__;
+ const char d[] = __func__;
+ const char e[] = __PRETTY_FUNCTION__;
+}
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -593,6 +593,7 @@
   bool HasFunctionName = E->getFunctionName() != nullptr;
   Record.push_back(HasFunctionName);
   Record.push_back(E->getIdentKind()); // FIXME: stable encoding
+  Record.push_back(E->isTransparent());
   Record.AddSourceLocation(E->getLocation());
   if (HasFunctionName)
 Record.AddStmt(E->getFunctionName());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -582,6 +582,7 @@
   bool HasFunctionName = Record.readInt();
   E->PredefinedExprBits.HasFunctionName = HasFunctionName;
   E->PredefinedExprBits.Kind = Record.readInt();
+  E->PredefinedExprBits.IsTransparent = Record.readInt();
   E->setLocation(readSourceLocation());
   if (HasFunctionName)
 E->setFunctionName(cast(Record.readSubExpr()));
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -173,6 +173,8 @@
   E = GSE->getResultExpr();
 } else if (ChooseExpr *CE = dyn_cast(E)) {
   E = CE->getChosenSubExpr();
+} else if (PredefinedExpr *PE = dyn_cast(E)) {
+  E = PE->getFunctionName();
 } else {
   llvm_unreachable("unexpected expr in string literal init");
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -3580,7 +3580,8 @@
 }
   }
 
-  return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);
+  return PredefinedExpr::Create(Context, Loc, ResTy, IK, LangOpts.MicrosoftExt,
+SL);
 }
 
 ExprResult Sema::BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc,
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -663,13 +663,14 @@
 }
 
 PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
-   StringLiteral *SL)
+   bool IsTransparent, StringLiteral *SL)
 : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary) {
   PredefinedExprBits.Kind = IK;
   assert((getIdentKind() == IK) &&
  "IdentKind do not fit in PredefinedExprBitfields!");
   bool HasFunctionName = SL != nullptr;
   PredefinedExprBits.HasFunctionName = HasFunctionName;
+  PredefinedExprBits.IsTransparent = IsTransparent;
   PredefinedExprBits.Loc = L;
   if (HasFunctionName)
 setFunctionName(SL);
@@ -683,11 +684,11 @@
 
 PredefinedExpr *PredefinedExpr::Create(const ASTContext , SourceLocation L,
QualType FNTy, IdentKind IK,
-   StringLiteral *SL) {
+   bool IsTransparent, StringLiteral *SL) {
   bool HasFunctionName = SL != nullptr;
   void *Mem = Ctx.Allocate(totalSizeToAlloc(HasFunctionName),
alignof(PredefinedExpr));
-  return new (Mem) PredefinedExpr(L, FNTy, IK, SL);
+  return new (Mem) PredefinedExpr(L, FNTy, IK, IsTransparent, SL);
 }
 
 PredefinedExpr *PredefinedExpr::CreateEmpty(const ASTContext ,
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -7068,7 +7068,8 @@
 return std::move(Err);
 
   return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
-E->getIdentKind(), ToFunctionName);
+

[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-05-01 Thread Samira Bazuzi via Phabricator via cfe-commits
bazuzi updated this revision to Diff 518547.
bazuzi added a comment.

Use LLVM_DEPRECATED in place of comments indicating deprecation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -53,9 +53,10 @@
   [UseBuiltinModel = Options.BuiltinOpts.has_value()](ASTContext ,
   Environment ) {
 return NoopAnalysis(
-C, DataflowAnalysisOptions{UseBuiltinModel
-   ? Env.getAnalysisOptions()
-   : std::optional()});
+C,
+DataflowAnalysisOptions{
+UseBuiltinModel ? Env.getDataflowAnalysisContext().getOptions()
+: std::optional()});
   });
   AI.ASTBuildArgs = ASTBuildArgs;
   if (Options.BuiltinOpts)
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -37,14 +37,16 @@
 
   static TestLattice initialElement() { return TestLattice{}; }
   void transfer(const CFGElement &, TestLattice , Environment ) {
-E.logger().log([](llvm::raw_ostream ) { OS << "transfer()"; });
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[](llvm::raw_ostream ) { OS << "transfer()"; });
 ++L.Elements;
   }
   void transferBranch(bool Branch, const Stmt *S, TestLattice ,
   Environment ) {
-E.logger().log([&](llvm::raw_ostream ) {
-  OS << "transferBranch(" << Branch << ")";
-});
+E.getDataflowAnalysisContext().getOptions().Log->log(
+[&](llvm::raw_ostream ) {
+  OS << "transferBranch(" << Branch << ")";
+});
 ++L.Branches;
   }
 };
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -168,7 +168,8 @@
   llvm::ArrayRef>
   BlockStates)
   : CFCtx(CFCtx), Analysis(Analysis), InitEnv(InitEnv),
-Log(InitEnv.logger()), BlockStates(BlockStates) {
+Log(*InitEnv.getDataflowAnalysisContext().getOptions().Log),
+BlockStates(BlockStates) {
 Log.beginAnalysis(CFCtx, Analysis);
   }
   ~AnalysisContext() { Log.endAnalysis(); }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -496,7 +496,7 @@
   }
 
   void VisitReturnStmt(const ReturnStmt *S) {
-if (!Env.getAnalysisOptions().ContextSensitiveOpts)
+if (!Env.getDataflowAnalysisContext().getOptions().ContextSensitiveOpts)
   return;
 
 auto *Ret = S->getRetValue();
@@ -863,12 +863,13 @@
   // `F` of `S`. The type `E` must be either `CallExpr` or `CXXConstructExpr`.
   template 
   void transferInlineCall(const E *S, const FunctionDecl *F) {
-const auto  = Env.getAnalysisOptions();
+const auto  = Env.getDataflowAnalysisContext().getOptions();
 if (!(Options.ContextSensitiveOpts &&
   Env.canDescend(Options.ContextSensitiveOpts->Depth, F)))
   return;
 
-const ControlFlowContext *CFCtx = Env.getControlFlowContext(F);
+const ControlFlowContext *CFCtx =
+Env.getDataflowAnalysisContext().getControlFlowContext(F);
 if (!CFCtx)
   return;
 
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -381,7 +381,7 @@
 
 QualType ParamType = Param->getType();
 if (ParamType->isReferenceType()) {
-  auto  = arena().create(*ArgLoc);
+  auto  = DACtx->arena().create(*ArgLoc);
   setValue(Loc, Val);
 } else if (auto *ArgVal = getValue(*ArgLoc)) {
   setValue(Loc, *ArgVal);
@@ -707,7 +707,7 @@
 // with integers, and so distinguishing them serves no purpose, but could
   

[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE`

2023-05-01 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Basic/Targets/AMDGPU.cpp:318
   Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
+  Builder.defineMacro("__AMDGCN_CUMODE", Twine(CUMode));
 }

Why do we sometimes use __ on both sides, and sometimes only leading __?


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

https://reviews.llvm.org/D145343

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


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-05-01 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 518546.
void added a comment.

Improve error message to use the unknown field's name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9136,6 +9159,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17692,6 +17692,44 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static const IdentifierInfo *
+CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return II;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return nullptr;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17749,6 +17787,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (const IdentifierInfo *II = CheckElementCountAttr(RD, FD, SR))
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+

[PATCH] D149613: [NFC] fix clang-tidy `prefer-isa-or-dyn-cast-in-conditionals` and `namespace-comment`

2023-05-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
HerrCai0907 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/D149613

Files:
  clang/lib/Sema/SemaDeclCXX.cpp

Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -1189,7 +1189,7 @@
 S.popCodeSynthesisContext();
   }
 };
-}
+} // namespace
 
 static bool checkTupleLikeDecomposition(Sema ,
 ArrayRef Bindings,
@@ -4213,7 +4213,7 @@
   CXXRecordDecl *ClassDecl;
 };
 
-}
+} // namespace
 
 ValueDecl *Sema::tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
  CXXScopeSpec ,
@@ -5055,7 +5055,7 @@
 return false;
   }
 };
-}
+} // namespace
 
 /// Determine whether the given type is an incomplete or zero-lenfgth
 /// array type.
@@ -5994,7 +5994,7 @@
   CheckAbstractUsage(*this, D).Visit(TL, Sel);
 }
 
-}
+} // namespace
 
 /// Check for invalid uses of an abstract type in a function declaration.
 static void CheckAbstractClassUsage(AbstractUsageInfo ,
@@ -7386,7 +7386,7 @@
 S.popCodeSynthesisContext();
   }
 };
-}
+} // namespace
 
 static Sema::ImplicitExceptionSpecification
 ComputeDefaultedSpecialMemberExceptionSpec(
@@ -8534,7 +8534,7 @@
SourceRange(Loc, Loc), SourceRange(Loc, Loc));
   }
 };
-}
+} // namespace
 
 /// Perform the unqualified lookups that might be needed to form a defaulted
 /// comparison function for the given operator.
@@ -9079,7 +9079,7 @@
 return false;
   }
 };
-}
+} // namespace
 
 namespace {
 struct SpecialMemberDeletionInfo
@@ -9119,7 +9119,7 @@
 
   bool isAccessible(Subobject Subobj, CXXMethodDecl *D);
 };
-}
+} // namespace
 
 /// Is the given special member inaccessible when used on the given
 /// sub-object.
@@ -11068,7 +11068,7 @@
   Sema::SemaDiagnosticBuilder Diagnostic;
   std::string Specifiers;
 };
-}
+} // namespace
 
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
@@ -11169,7 +11169,7 @@
 // This could still instantiate to the right type, unless we know it
 // names the wrong class template.
 auto *TD = SpecifiedName.getAsTemplateDecl();
-MightInstantiateToSpecialization = !(TD && isa(TD) &&
+MightInstantiateToSpecialization = !(isa_and_nonnull(TD) &&
  !TemplateMatches);
   }
 } else if (!RetTy.hasQualifiers() && RetTy->isDependentType()) {
@@ -11714,7 +11714,7 @@
   }
 };
 
-}
+} // namespace
 
 static bool TryNamespaceTypoCorrection(Sema , LookupResult , Scope *Sc,
CXXScopeSpec ,
@@ -12190,7 +12190,7 @@
 NonTemplateTarget = TargetTD->getTemplatedDecl();
 
   UsingShadowDecl *Shadow;
-  if (NonTemplateTarget && isa(NonTemplateTarget)) {
+  if (isa_and_nonnull(NonTemplateTarget)) {
 UsingDecl *Using = cast(BUD);
 bool IsVirtualBase =
 isVirtualDirectBase(cast(CurContext),
@@ -13313,7 +13313,7 @@
   void visitSubobjectCall(Subobject Subobj,
   Sema::SpecialMemberOverloadResult SMOR);
 };
-}
+} // namespace
 
 bool SpecialMemberExceptionSpecInfo::visitBase(CXXBaseSpecifier *Base) {
   auto *RT = Base->getType()->getAs();
@@ -13477,7 +13477,7 @@
 return WasAlreadyBeingDeclared;
   }
 };
-}
+} // namespace
 
 void Sema::CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD) {
   // Look up any existing declarations, but don't trigger declaration of all
@@ -16821,7 +16821,7 @@
   std::string InnerCondDescription;
   std::tie(InnerCond, InnerCondDescription) =
 findFailedBooleanCondition(Converted.get());
-  if (InnerCond && isa(InnerCond)) {
+  if (isa_and_nonnull(InnerCond)) {
 // Drill down into concept specialization expressions to see why they
 // weren't satisfied.
 Diag(AssertExpr->getBeginLoc(), diag::err_static_assert_failed)
@@ -18275,7 +18275,7 @@
   return false;
 }
   };
-}
+} // namespace
 
 bool Sema::checkThisInStaticMemberFunctionType(CXXMethodDecl *Method) {
   TypeSourceInfo *TSInfo = Method->getTypeSourceInfo();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-05-01 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali updated this revision to Diff 518543.
Ris-Bali added a comment.

Added test for function type


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

https://reviews.llvm.org/D149514

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtin-assume-aligned.c


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,26 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{incompatible 
integer to pointer conversion passing 'int' to parameter of type 'const void *}}
+  return a[0];
+}
+
+int test15(int *b) {
+  int arr[3] = {1, 2, 3};
+  b = (int *)__builtin_assume_aligned(arr, 32); 
+  return b[0];
+}
+
+int val(int x) {
+  return x;
+}
+
+int test16(int *b) {
+  b = (int*)__builtin_assume_aligned(val, 32);
+  return b[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // 
no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7979,8 +7979,9 @@
   {
 ExprResult FirstArgResult =
 DefaultFunctionArrayLvalueConversion(FirstArg);
-if (FirstArgResult.isInvalid())
+if (checkBuiltinArgument(*this, TheCall, 0))
   return true;
+/// In-place updation of FirstArg by checkBuiltinArgument is ignored.
 TheCall->setArg(0, FirstArgResult.get());
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+  ``__builtin_assume_aligned``.
+  (`#62305 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,26 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *}}
+  return a[0];
+}
+
+int test15(int *b) {
+  int arr[3] = {1, 2, 3};
+  b = (int *)__builtin_assume_aligned(arr, 32); 
+  return b[0];
+}
+
+int val(int x) {
+  return x;
+}
+
+int test16(int *b) {
+  b = (int*)__builtin_assume_aligned(val, 32);
+  return b[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7979,8 +7979,9 @@
   {
 ExprResult FirstArgResult =
 DefaultFunctionArrayLvalueConversion(FirstArg);
-if (FirstArgResult.isInvalid())
+if (checkBuiltinArgument(*this, TheCall, 0))
   return true;
+/// In-place updation of FirstArg by checkBuiltinArgument is ignored.
 TheCall->setArg(0, FirstArgResult.get());
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+  ``__builtin_assume_aligned``.
+  (`#62305 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___

[PATCH] D148425: [clang-repl] Correctly disambiguate dtor declarations from statements

2023-05-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:91
 return true;
-  case tok::annot_cxxscope: // Check if this is a dtor.
-if (NextToken().is(tok::tilde))

Are you sure you can remove this? Wouldn't this be used for a case like:
```
struct Foo {
  struct Bar {
struct Baz {
  ~Baz();
};
  };
};

Foo::Bar::Baz::~Baz() {}
```
(I could be reading the code wrong, but I thought we had a reason to check for 
`annot_cxxscope` -- seems we missed test coverage for it!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148425

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D145088#4310464 , @craig.topper 
wrote:

> In D145088#4308840 , @akyrtzi wrote:
>
>> `CodeGen` has the same issue:
>>
>>   $ ninja 
>> tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/TargetInfo.cpp.o
>>   In file included from /llvm-project/clang/lib/CodeGen/TargetInfo.cpp:36:
>>   /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: 
>> fatal error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found
>
> I just posted https://reviews.llvm.org/D149606 to move the constant to a file 
> that doesn't depend on tablegen.

I found an even better fix fa42e7b 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D149606: [RISCV] Move RISCV::RVVBitsPerBlock to be a static member of RISCVISAInfo class.

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper abandoned this revision.
craig.topper added a comment.

fa42e7b  
made this unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149606

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


[clang] fa42e7b - [RISCV] Merge RISCV::parseCPUKind and RISCV::checkCPUKind.

2023-05-01 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-05-01T13:00:05-07:00
New Revision: fa42e7b6bc430941f42cf50b5c4e55b3c19ccc08

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

LOG: [RISCV] Merge RISCV::parseCPUKind and RISCV::checkCPUKind.

Similar for RISCV::parseTuneCPU and RISCV::checkTuneCPUKind.

This makes the CPUKind enum no longer part of the API. It wasn't
providing much value. It was only used to pass between the two
functions.

By removing it, we can remove a dependency on a tablegen generated
file from the RISCVTargetParser.h file. Then we can remove a
dependency from several CMakeLists.txt.

Added: 


Modified: 
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/lib/Sema/CMakeLists.txt
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/TargetParser/RISCVTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index c05036a216c74..caa1b6002e6f1 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -125,7 +125,6 @@ add_clang_library(clangBasic
 
   DEPENDS
   omp_gen
-  RISCVTargetParserTableGen
   )
 
 target_link_libraries(clangBasic

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index dd99d96b5f4d3..6720fcd567ac8 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -325,7 +325,7 @@ bool 
RISCVTargetInfo::handleTargetFeatures(std::vector ,
 
 bool RISCVTargetInfo::isValidCPUName(StringRef Name) const {
   bool Is64Bit = getTriple().isArch64Bit();
-  return llvm::RISCV::checkCPUKind(llvm::RISCV::parseCPUKind(Name), Is64Bit);
+  return llvm::RISCV::parseCPU(Name, Is64Bit);
 }
 
 void RISCVTargetInfo::fillValidCPUList(
@@ -336,8 +336,7 @@ void RISCVTargetInfo::fillValidCPUList(
 
 bool RISCVTargetInfo::isValidTuneCPUName(StringRef Name) const {
   bool Is64Bit = getTriple().isArch64Bit();
-  return llvm::RISCV::checkTuneCPUKind(
-  llvm::RISCV::parseTuneCPUKind(Name, Is64Bit), Is64Bit);
+  return llvm::RISCV::parseTuneCPU(Name, Is64Bit);
 }
 
 void RISCVTargetInfo::fillValidTuneCPUList(

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 3d83c86100bec..a6bd2d41e7975 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -95,7 +95,6 @@ add_clang_library(clangDriver
 
   DEPENDS
   ClangDriverOptions
-  RISCVTargetParserTableGen
 
   LINK_LIBS
   clangBasic

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 7cf01ad8a72b8..a26c9caf64c70 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -54,11 +54,11 @@ static void getRISCFeaturesFromMcpu(const Driver , const 
Arg *A,
 StringRef Mcpu,
 std::vector ) {
   bool Is64Bit = Triple.isRISCV64();
-  llvm::RISCV::CPUKind CPUKind = llvm::RISCV::parseCPUKind(Mcpu);
-  if (!llvm::RISCV::checkCPUKind(CPUKind, Is64Bit)) {
+  if (!llvm::RISCV::parseCPU(Mcpu, Is64Bit)) {
 // Try inverting Is64Bit in case the CPU is valid, but for the wrong 
target.
-if (llvm::RISCV::checkCPUKind(CPUKind, !Is64Bit))
-  D.Diag(clang::diag::err_drv_invalid_riscv_cpu_name_for_target) << Mcpu 
<< Is64Bit;
+if (llvm::RISCV::parseCPU(Mcpu, !Is64Bit))
+  D.Diag(clang::diag::err_drv_invalid_riscv_cpu_name_for_target)
+  << Mcpu << Is64Bit;
 else
   D.Diag(clang::diag::err_drv_unsupported_option_argument)
   << A->getSpelling() << Mcpu;

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 843a269dac720..629fafadcf9f4 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -71,7 +71,6 @@ add_clang_library(clangSema
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
-  RISCVTargetParserTableGen
 
   LINK_LIBS
   clangAST

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 334365fa0a8a4..c764a50f88b22 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -171,6 +171,10 @@ Changes to the RISC-V Backend
 * Updated support experimental vector crypto extensions to version 0.5.1 of
   the specification.
 * Removed N extension (User-Level Interrupts) CSR names in the assembler.
+* ``RISCV::parseCPUKind`` and ``RISCV::checkCPUKind`` were merged into a single
+  ``RISCV::parseCPU``. The ``CPUKind`` enum is no longer part of the
+  RISCVTargetParser.h interface. Similar for ``parseTuneCPUkind`` and
+  ``checkTuneCPUKind``.
 
 Changes to the WebAssembly Backend
 

[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-01 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D149573#4310009 , @codemzs wrote:

> My change to libcxxabi/test/test_demangle.pass.cpp (last file in the change) 
> is only one line i.e {"_ZNK5clang4Type16isArithmeticTypeERNS_10ASTContextE", 
> "clang::Type::isArithmeticType(clang::ASTContext&) const"}, but running 
> clang-format on it changes bunch of lines.

Please don't clang-format the test then. There is no need to do it, and the 
changes look rather confusing. I don't really understand why you add it at all 
TBH. This doesn't look like it tests anything from this patch.


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

https://reviews.llvm.org/D149573

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


[clang] 578a471 - Reland [clang] Canonicalize system headers in dependency file when -canonical-prefixes

2023-05-01 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2023-05-01T12:44:52-07:00
New Revision: 578a4716f549167165a2ec3bac89c86706136d4e

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

LOG: Reland [clang] Canonicalize system headers in dependency file when 
-canonical-prefixes

Clang was writing paths to the dependency file that don't exist when using a 
sysroot with symlinks, causing everything to get rebuilt every time. This is 
reproducible on Linux by creating a symlink to '/', using that as the sysroot, 
and trying to build something with ninja that includes the C++ stdlib (e.g. a 
typical build of LLVM).

This fixes https://github.com/ninja-build/ninja/issues/1330 and somewhat 
matches gcc.

gcc canonicalizes system headers in dependency files under a 
-f[no-]canonical-system-headers, but it makes more sense to look at 
-canonical-prefixes.

D37954 was a previous attempt at this.

Fixed use of %T instead of %t in test, causing bots to fail the test on the 
initial commit.

Reviewed By: hans

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

Added: 
clang/test/Driver/canonical-system-headers.c
clang/test/Preprocessor/Inputs/canonical-system-headers/a.h
clang/test/Preprocessor/canonical-system-headers.c

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/DependencyOutputOptions.h
clang/include/clang/Frontend/Utils.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/DependencyFile.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8c80c7f5ff56a..182f0290736d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5835,6 +5835,9 @@ let Flags = [CC1Option, NoDriverOption] in {
 def sys_header_deps : Flag<["-"], "sys-header-deps">,
   HelpText<"Include system headers in dependency output">,
   MarshallingInfoFlag>;
+def canonical_system_headers : Flag<["-"], "canonical-system-headers">,
+  HelpText<"Canonicalize system headers in dependency output">,
+  MarshallingInfoFlag>;
 def module_file_deps : Flag<["-"], "module-file-deps">,
   HelpText<"Include module files in dependency output">,
   MarshallingInfoFlag>;

diff  --git a/clang/include/clang/Frontend/DependencyOutputOptions.h 
b/clang/include/clang/Frontend/DependencyOutputOptions.h
index e0f445bb5970c..e140ff9baa117 100644
--- a/clang/include/clang/Frontend/DependencyOutputOptions.h
+++ b/clang/include/clang/Frontend/DependencyOutputOptions.h
@@ -34,6 +34,8 @@ enum ExtraDepKind {
 class DependencyOutputOptions {
 public:
   unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies.
+  unsigned
+  CanonicalSystemHeaders : 1; ///< canonicalize system header dependencies.
   unsigned ShowHeaderIncludes : 1;   ///< Show header inclusions (-H).
   unsigned UsePhonyTargets : 1;  ///< Include phony targets for each
  /// dependency, which can avoid some 
'make'
@@ -85,10 +87,11 @@ class DependencyOutputOptions {
 
 public:
   DependencyOutputOptions()
-  : IncludeSystemHeaders(0), ShowHeaderIncludes(0), UsePhonyTargets(0),
-AddMissingHeaderDeps(0), IncludeModuleFiles(0),
-ShowSkippedHeaderIncludes(0), HeaderIncludeFormat(HIFMT_Textual),
-HeaderIncludeFiltering(HIFIL_None) {}
+  : IncludeSystemHeaders(0), CanonicalSystemHeaders(0),
+ShowHeaderIncludes(0), UsePhonyTargets(0), AddMissingHeaderDeps(0),
+IncludeModuleFiles(0), ShowSkippedHeaderIncludes(0),
+HeaderIncludeFormat(HIFMT_Textual), HeaderIncludeFiltering(HIFIL_None) 
{
+  }
 };
 
 }  // end namespace clang

diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b..8300e45d15fe5 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -41,6 +41,7 @@ class ExternalSemaSource;
 class FrontendOptions;
 class PCHContainerReader;
 class Preprocessor;
+class FileManager;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
@@ -79,11 +80,14 @@ class DependencyCollector {
   /// Return true if system files should be passed to sawDependency().
   virtual bool needSystemDependencies() { return false; }
 
+  /// Return true if system files should be canonicalized.
+  virtual bool shouldCanonicalizeSystemDependencies() { return false; }
+
   /// Add a dependency \p Filename if it has not been seen before and
   /// sawDependency() returns true.
   virtual void maybeAddDependency(StringRef Filename, bool FromModule,
   bool IsSystem, bool IsModuleFile,
-  bool IsMissing);
+  FileManager *FileMgr, bool IsMissing);
 
 protected:

[PATCH] D149612: [Sema] avoid merge error type

2023-05-01 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added reviewers: aaron.ballman, rjmccall, shafik.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

fixed: https://github.com/llvm/llvm-project/issues/62447
Ill-formatted type will break `mergeTypes`. So it needs to add more
strict checker for VarDecl in `MergeVarDeclTypes`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149612

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/merge-decls.c


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(); // expected-warning {{incompatible pointer types passing 'int 
(*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 
'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 
'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4392,7 +4392,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || 
New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/merge-decls.c
===
--- clang/test/Sema/merge-decls.c
+++ clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@
   int x[5];
   test7_f(); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char x[sizeof(d.data) == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char x[sizeof(d.data) == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4392,7 +4392,7 @@
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
  bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getType()->containsErrors())
 return;
 
   QualType MergedT;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148944: [clang][Driver] Fix crash with unsupported architectures in MinGW and CrossWindows.

2023-05-01 Thread KOMATA Manabu via Phabricator via cfe-commits
k-mana added a comment.

I don't have commit access.
Please commit at KOMATA Manabu .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148944

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-05-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

nickdesaulniers wrote:
> cjdb wrote:
> > aaron.ballman wrote:
> > > nickdesaulniers wrote:
> > > > cjdb wrote:
> > > > > aaron.ballman wrote:
> > > > > > nickdesaulniers wrote:
> > > > > > > nickdesaulniers wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > Instead of allowing this note to appear anywhere in the file, 
> > > > > > > > > I think it's better to use "bookmark" comments. e.g.,
> > > > > > > > > ```
> > > > > > > > > void baz() { // #baz_defn
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > void foo() {
> > > > > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > > > > }
> > > > > > > > > ```
> > > > > > > > > so that we're testing where the diagnostic is emitted. (This 
> > > > > > > > > is especially important given that the changes are about 
> > > > > > > > > location tracking.)
> > > > > > > > oh, that's new (to me)! will do
> > > > > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > > > > line+col info. They follow the warning/error diagnostic which 
> > > > > > > does, on the bottom most call site.
> > > > > > > 
> > > > > > > The warning is supposed to be emitted on the callsite, not the 
> > > > > > > definition.
> > > > > > I still don't think this is reasonable for test coverage because 
> > > > > > this means we'll accept the note *anywhere* in the file. This makes 
> > > > > > it much too easy to regress the behavior accidentally (e.g., 
> > > > > > accidentally emit all the notes on line 1 of the file). I think we 
> > > > > > need *some* way to nail down where these notes are emitted in the 
> > > > > > test. However, I might be asking you to solve "please track 
> > > > > > location information through the backend" for that, so perhaps this 
> > > > > > isn't a reasonable request?
> > > > > > 
> > > > > > Also, CC @cjdb for awareness of how this kind of diagnostic is 
> > > > > > produced (Chris is working on an idea for how we emit diagnostics 
> > > > > > so we get better structured information from them, so knowing about 
> > > > > > this novel approach might impact that idea).
> > > > > Very interesting, thanks for the heads up! Cross-phase diagnostics 
> > > > > are definitely something I hadn't considered, and it **does** impact 
> > > > > the design (but not in a derailing way).
> > > > I think we're back at "please track location information through the 
> > > > backend".
> > > > 
> > > > That is the tradeoff with this approach; not measurably regressing 
> > > > performance when these attributes aren't used in source in exchange for 
> > > > Note diagnostics that lack precise line+col info, but in practice 
> > > > provide enough info for the user to understand what's going wrong where.
> > > > 
> > > > Your call if the tradeoff is worth it.
> > > Here's my thinking, please correct any misunderstandings I have:
> > > 
> > > * This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
> > > solely for that purpose), and that's an important security feature used 
> > > by glibc and the Linux kernel.
> > > * Security of C and C++ source code is Very Important, especially now 
> > > that various gov't agencies [1][2] are suggesting to not use C or C++ for 
> > > new projects specifically because the security posture of the languages 
> > > and their tools.
> > > * Therefore, the ergonomics of this functionality are quite important for 
> > > the intended use cases and the ecosystem as a whole.
> > > * Emitting only the function name but without location information does 
> > > not give a good user experience, especially in circumstances where the 
> > > function has multiple overloads, because it pushes the burden onto the 
> > > programmer to figure out which functions are actually involved in the 
> > > call chain. This issue is also present in C because of support for 
> > > `__attribute__((overloadable))` and is not just a C++ concern.
> > > * The compile-time performance costs of tracking this location 
> > > information are roughly 1%, and there are no runtime or binary size 
> > > overhead costs unless other functionality is enabled (such as emitting 
> > > debug info).
> > > * We can determine whether we need to enable this location tracking while 
> > > building the AST when we see one of these two attributes being used, so 
> > > we could enable this functionality selectively without burdening the user 
> > > with enabling it manually via a flag. (We could still consider giving the 
> > > user a flag to never track this even in the presence of the attributes if 
> > > a user had a compelling use case for it.)
> > > 
> > > If this is all reasonably accurate, I think it's worth 

[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-05-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM

(Do you have commit access?  If not, please specify the name/email you want for 
the "author" field.)


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

https://reviews.llvm.org/D146386

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


[PATCH] D149600: [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 518526.
tejohnson added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149600

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp

Index: clang/test/CodeGenCXX/new_hot_cold.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/new_hot_cold.cpp
@@ -0,0 +1,130 @@
+// Test to check that the appropriate attributes are added to the __hot_cold_t
+// versions of operator new.
+
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -faligned-allocation -emit-llvm -o - | FileCheck %s
+
+typedef __typeof__(sizeof(0)) size_t;
+
+namespace std {
+struct nothrow_t {};
+enum class align_val_t : size_t;
+} // namespace std
+std::nothrow_t nothrow;
+
+typedef unsigned char uint8_t;
+
+// See the following link for how this type is declared in tcmalloc:
+// https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53.
+enum class __hot_cold_t : uint8_t;
+
+// Test handling of declaration that uses a type alias, ensuring that it still
+// recognizes the expected __hot_cold_t type name.
+namespace malloc_namespace {
+using hot_cold_t = __hot_cold_t;
+}
+
+void *operator new(size_t size,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new(size_t size, std::align_val_t alignment,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size, std::align_val_t alignment,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, std::align_val_t alignment,
+   const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, std::align_val_t alignment,
+ const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+
+// All explicit operator new calls should not get any builtin attribute, whereas
+// all implicit new expressions should get builtin attributes. All of the
+// declarations should get nobuiltin attributes.
+
+void hot_cold_new() {
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new(1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_array() {
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new[](1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int[1];
+}
+
+// CHECK: declare noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_nothrow() {
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  operator new(1, nothrow, (__hot_cold_t)0);
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 4, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  new (nothrow, (__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1), i8 noundef zeroext) [[ATTR_NOBUILTIN_NOTHROW:#[^ ]*]]
+
+void hot_cold_new_nothrow_array() {
+  // CHECK: call noalias noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  operator new[](1, nothrow, (__hot_cold_t)0);
+  // CHECK: call noalias noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef 4, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  new (nothrow, (__hot_cold_t)0) int[1];
+}
+
+// CHECK: declare noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1), i8 noundef zeroext) [[ATTR_NOBUILTIN_NOTHROW:#[^ ]*]]
+
+class alignas(32) alignedstruct {
+  int x;
+};
+
+void 

[PATCH] D149553: [clang] Use -std=c++23 instead of -std=c++2b

2023-05-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! The Clang changes are mostly all good, but I 
think we should hold off on changing the value of `__cplusplus` for the moment 
as it's not set in stone in the standard yet (I thought it was though, so I'm 
checking with the editor).




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6638
  .Case("c++20", "-std=c++20")
- .Case("c++latest", "-std=c++2b")
+ // TODO add c++23 when MSVC supports it.
+ .Case("c++latest", "-std=c++23")

Good catch!



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:455
+if (LangOpts.CPlusPlus23)
+  Builder.defineMacro("__cplusplus", "202302L");
 //  [C++20] The integer literal 202002L.

I think this might still be premature. I noticed that the draft C++ standard 
does not have this value set yet: 
https://github.com/cplusplus/draft/blob/main/source/config.tex#L6

I've emailed the editor to find out if that's a mistake (I am pretty sure we're 
sending this off to PDTS at some point shortly).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149553

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


[PATCH] D149464: [clang][dataflow] Expose DataflowAnalysisContext from DataflowEnvironment.

2023-05-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:189
 
+  /// Deprecated. Use *getDataflowAnalysisContext().getOptions().Log instead.
   Logger () const { return *DACtx->getOptions().Log; }

bazuzi wrote:
> xazax.hun wrote:
> > Any reason for a comment as opposed to the deprecated attribute? 
> I couldn't tell exactly what the conventions were or whether all of the 
> chained replacements could be used as the FIX very well.
> 
> If you can confirm that `LLVM_DEPRECATED("DataflowAnalysisContext is now 
> directly exposed.", "*getDataflowAnalysisContext().getOptions().Log")`, 
> `LLVM_DEPRECATED(..., "getDataflowAnalysisContext().arena")`, etc. will 
> provide useful fixes, happy to replace with those. Or with replacements just 
> in the MSG and "" for FIX otherwise.
Unfortunately, I am also not 100% sure what is the convention. But I am OK with 
not providing a FIXIT here. I do not expect too many clients yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149464

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D145088#4308840 , @akyrtzi wrote:

> `CodeGen` has the same issue:
>
>   $ ninja 
> tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/TargetInfo.cpp.o
>   In file included from /llvm-project/clang/lib/CodeGen/TargetInfo.cpp:36:
>   /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: 
> fatal error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found

I just posted https://reviews.llvm.org/D149606 to move the constant to a file 
that doesn't depend on tablegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-05-01 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This looks like a nice improvement to me.




Comment at: clang/lib/Interpreter/IncrementalParser.cpp:162
+  if (P->getCurToken().is(tok::annot_repl_input_end)) {
+P->ConsumeAnyToken();
 // FIXME: Clang does not call ExitScope on finalizing the regular TU, we





Comment at: clang/lib/Interpreter/IncrementalParser.cpp:254-268
   if (PP.getLangOpts().DelayedTemplateParsing) {
 // Microsoft-specific:
 // Late parsed templates can leave unswallowed "macro"-like tokens.
 // They will seriously confuse the Parser when entering the next
 // source file. So lex until we are EOF.
 Token Tok;
 do {

Not really related to this patch, but in `DelayedTemplateParsing` mode this 
code appears to expect two `annot_repl_input_end` tokens in a row.



Comment at: clang/lib/Parse/ParseStmt.cpp:546-556
+  Token *CurTok = nullptr;
+  // If we're parsing an ExprStmt and the last semicolon is missing and the
+  // incremental externsion is enabled and we're reaching the end, consider we
+  // want to do value printing. Note this is only enable in C++ mode
+  // since part of the implementation requires C++ language features.
+  //
+  // Note we shouldn't eat the token since the callback need it.

I don't think we need to check whether incremental processing is enabled here 
-- if not, we shouldn't see the "end of REPL input" token at all.



Comment at: clang/lib/Parse/Parser.cpp:620-621
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::annot_repl_input_end))
+ConsumeAnnotationToken();
 

Do we need to do this here? `IncrementalParser` already seems to take care of 
this, and the logic here would be easier to reason about if `Parser` never 
steps past an `annot_repl_input_end` token, and such tokens instead are only 
ever consumed by the REPL.

Are there other users of incremental processing mode, other than the REPL / 
`IncrementalParser`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D109210: [clang-tidy] Attach fixit to warning, not note, in add_new_check.py example

2023-05-01 Thread Matt Beardsley via Phabricator via cfe-commits
mattbeardsley added a comment.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.

Someone else ultimately fixed this (slightly differently) last month:
https://reviews.llvm.org/D146875


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109210

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


[PATCH] D149600: [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/test/CodeGenCXX/new_hot_cold.cpp:16
+
+enum class __hot_cold_t : uint8_t;
+namespace malloc_namespace {

snehasish wrote:
> Can we skip the typedef and just say `enum class __hot_cold_t : unsigned 
> char;`?
> 
> Also it might be useful to link to the tcmalloc documentation for hot_cold_t 
> to document the expected underlying type?
> https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53
> 
> 
> Can we skip the typedef and just say enum class __hot_cold_t : unsigned char;?

I did that specifically to test the way it is declared in tcmalloc. In 
particular, this tests the TypedefType while loop at lines 3301-2 in Decl.cpp 
which was required to "see through" that and handle that case properly. I can 
add a comment here to the test. Will also add the link to tcmalloc here and in 
Decl.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149600

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


[PATCH] D149606: [RISCV] Move RISCV::RVVBitsPerBlock to be a static member of RISCVISAInfo class.

2023-05-01 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: reames, asb, luismarques, frasercrmck, 
kito-cheng, rogfer01, pcwang-thead.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, evandro, apazos, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, niosHD, 
sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, eopXD, MaskRay.
Herald added projects: clang, LLVM.

This constant is used by clang and llvm so needs to be shared.

It can't be in RISCVTargetParser.h where it is today because that
file depends on a tablegen output.

I don't want to create a new header file so I figured RISCVISAInfo.h
could be a new home for it.

lld imports RISCVISAInfo.h and lld has a class named llvm::RISCV.
So we can't expose the llvm::RISCV namespace to lld.

Thus this patch to put it inside the RISCVISAInfo class.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149606

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaType.cpp
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Index: llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
===
--- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -210,15 +210,15 @@
 
 std::optional RISCVTTIImpl::getMaxVScale() const {
   if (ST->hasVInstructions())
-return ST->getRealMaxVLen() / RISCV::RVVBitsPerBlock;
+return ST->getRealMaxVLen() / RISCVISAInfo::RVVBitsPerBlock;
   return BaseT::getMaxVScale();
 }
 
 std::optional RISCVTTIImpl::getVScaleForTuning() const {
   if (ST->hasVInstructions())
 if (unsigned MinVLen = ST->getRealMinVLen();
-MinVLen >= RISCV::RVVBitsPerBlock)
-  return MinVLen / RISCV::RVVBitsPerBlock;
+MinVLen >= RISCVISAInfo::RVVBitsPerBlock)
+  return MinVLen / RISCVISAInfo::RVVBitsPerBlock;
   return BaseT::getVScaleForTuning();
 }
 
@@ -235,8 +235,8 @@
   case TargetTransformInfo::RGK_ScalableVector:
 return TypeSize::getScalable(
 (ST->hasVInstructions() &&
- ST->getRealMinVLen() >= RISCV::RVVBitsPerBlock)
-? LMUL * RISCV::RVVBitsPerBlock
+ ST->getRealMinVLen() >= RISCVISAInfo::RVVBitsPerBlock)
+? LMUL * RISCVISAInfo::RVVBitsPerBlock
 : 0);
   }
 
@@ -1193,7 +1193,8 @@
   if (isa(Ty)) {
 const unsigned EltSize = DL.getTypeSizeInBits(Ty->getElementType());
 const unsigned MinSize = DL.getTypeSizeInBits(Ty).getKnownMinValue();
-const unsigned VectorBits = *getVScaleForTuning() * RISCV::RVVBitsPerBlock;
+const unsigned VectorBits =
+*getVScaleForTuning() * RISCVISAInfo::RVVBitsPerBlock;
 return RISCVTargetLowering::computeVLMAX(VectorBits, EltSize, MinSize);
   }
   return cast(Ty)->getNumElements();
@@ -1673,7 +1674,7 @@
   TypeSize Size = DL.getTypeSizeInBits(Ty);
   if (Ty->isVectorTy()) {
 if (Size.isScalable() && ST->hasVInstructions())
-  return divideCeil(Size.getKnownMinValue(), RISCV::RVVBitsPerBlock);
+  return divideCeil(Size.getKnownMinValue(), RISCVISAInfo::RVVBitsPerBlock);
 
 if (ST->useRVVForFixedLengthVectors())
   return divideCeil(Size, ST->getRealMinVLen());
Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -140,10 +140,11 @@
   Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange);
   if (VScaleRangeAttr.isValid()) {
 if (!RVVVectorBitsMinOpt.getNumOccurrences())
-  RVVBitsMin = VScaleRangeAttr.getVScaleRangeMin() * RISCV::RVVBitsPerBlock;
+  RVVBitsMin =
+  VScaleRangeAttr.getVScaleRangeMin() * RISCVISAInfo::RVVBitsPerBlock;
 std::optional VScaleMax = VScaleRangeAttr.getVScaleRangeMax();
 if (VScaleMax.has_value() && !RVVVectorBitsMaxOpt.getNumOccurrences())
-  RVVBitsMax = *VScaleMax * RISCV::RVVBitsPerBlock;
+  RVVBitsMax = *VScaleMax * RISCVISAInfo::RVVBitsPerBlock;
   }
 
   if (RVVBitsMin != -1U) {
Index: llvm/lib/Target/RISCV/RISCVISelLowering.h
===
--- llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -18,7 +18,6 @@
 #include "llvm/CodeGen/CallingConvLower.h"
 #include "llvm/CodeGen/SelectionDAG.h"
 

[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think you're missing changes in ASTReaderStmt.cpp and ASTWriterStmt.cpp, so 
serialization through modules or PCH won't work without that.




Comment at: clang/include/clang/AST/Expr.h:1996
   PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
- StringLiteral *SL);
+ bool TreatAsStringLiteral, StringLiteral *SL);
 

I think we should keep `PredefinedExpr` general, so how about `IsTransparent` 
instead? Then we can add a comment above `Create()` that explains what 
`IsTransparent` does.

(This makes it easier for us to add predefined expressions that aren't string 
literals but are still transparently handled.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D149562: [clang-format] Stop comment disrupting indentation of Verilog ports

2023-05-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

I don't see the problem, could you elaborate a bit more? (Keep in mind, I have 
no idea about Verilog.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149562

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


[PATCH] D149600: [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Snehasish Kumar via Phabricator via cfe-commits
snehasish accepted this revision.
snehasish added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clang/test/CodeGenCXX/new_hot_cold.cpp:16
+
+enum class __hot_cold_t : uint8_t;
+namespace malloc_namespace {

Can we skip the typedef and just say `enum class __hot_cold_t : unsigned char;`?

Also it might be useful to link to the tcmalloc documentation for hot_cold_t to 
document the expected underlying type?
https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149600

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


[PATCH] D149600: [MemProf] Recognize hot/cold operator new as replaceable allocations

2023-05-01 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: rsmith, snehasish.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Follow up to LLVM-side change to allow conversion to hot/cold hinted
operator new, not yet standard but supported by open source tcmalloc.
The LLVM change in a35206d78280e0ebcf48cd21bc5fff5c3b9c73fa 
 added the
necessary support to recognize these as library functions, and we
subsequently found that a clang-side change is needed to give them
builtin/nobuiltin attributes as appropriate so they have consistent
removeability.

Based on discussion with Richard Smith, converted the parameter type to
a reserved identifier (39f7b48671dae5fbe3afc49f33f50c2b6340bb89 
) and
added support in this patch to recognize it in clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149600

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp

Index: clang/test/CodeGenCXX/new_hot_cold.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/new_hot_cold.cpp
@@ -0,0 +1,125 @@
+// Test to check that the appropriate attributes are added to the __hot_cold_t
+// versions of operator new.
+
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -faligned-allocation -emit-llvm -o - | FileCheck %s
+
+typedef __typeof__(sizeof(0)) size_t;
+
+namespace std {
+struct nothrow_t {};
+enum class align_val_t : size_t;
+} // namespace std
+std::nothrow_t nothrow;
+
+typedef unsigned char uint8_t;
+
+enum class __hot_cold_t : uint8_t;
+namespace malloc_namespace {
+using hot_cold_t = __hot_cold_t;
+}
+
+void *operator new(size_t size,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new(size_t size, std::align_val_t alignment,
+   malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new[](size_t size, std::align_val_t alignment,
+ malloc_namespace::hot_cold_t hot_cold) noexcept(false);
+void *operator new(size_t size, std::align_val_t alignment,
+   const std::nothrow_t &,
+   malloc_namespace::hot_cold_t hot_cold) noexcept;
+void *operator new[](size_t size, std::align_val_t alignment,
+ const std::nothrow_t &,
+ malloc_namespace::hot_cold_t hot_cold) noexcept;
+
+// All explicit operator new calls should not get any builtin attribute, whereas
+// all implicit new expressions should get builtin attributes. All of the
+// declarations should get nobuiltin attributes.
+
+void hot_cold_new() {
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new(1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef nonnull ptr @_Znwm12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_array() {
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 1, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_CALL:#[^ ]*]]
+  operator new[](1, (__hot_cold_t)0);
+  // CHECK: call noalias noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef 4, i8 noundef zeroext 0) [[ATTR_BUILTIN_CALL:#[^ ]*]]
+  new ((__hot_cold_t)0) int[1];
+}
+
+// CHECK: declare noundef nonnull ptr @_Znam12__hot_cold_t(i64 noundef, i8 noundef zeroext) [[ATTR_NOBUILTIN:#[^ ]*]]
+
+void hot_cold_new_nothrow() {
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  operator new(1, nothrow, (__hot_cold_t)0);
+  // CHECK: call noalias noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef 4, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_BUILTIN_NOTHROW_CALL:#[^ ]*]]
+  new (nothrow, (__hot_cold_t)0) int;
+}
+
+// CHECK: declare noundef ptr @_ZnwmRKSt9nothrow_t12__hot_cold_t(i64 noundef, ptr noundef nonnull align 1 dereferenceable(1), i8 noundef zeroext) [[ATTR_NOBUILTIN_NOTHROW:#[^ ]*]]
+
+void hot_cold_new_nothrow_array() {
+  // CHECK: call noalias noundef ptr @_ZnamRKSt9nothrow_t12__hot_cold_t(i64 noundef 1, {{.*}} @nothrow, i8 noundef zeroext 0) [[ATTR_NO_BUILTIN_NOTHROW_CALL:#[^ ]*]]

[PATCH] D149104: [Demangle] make llvm::demangle take std::string_view rather than const std::string

2023-05-01 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

bumping for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149104

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


[clang] f9fbda7 - Revert "[clang] Canonicalize system headers in dependency file when -canonical-prefixes"

2023-05-01 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2023-05-01T10:55:53-07:00
New Revision: f9fbda7102fb6da79dedf9b15694d7a61e8c49b7

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

LOG: Revert "[clang] Canonicalize system headers in dependency file when 
-canonical-prefixes"

This reverts commit 8f0dd4ef3ed2137d1e2554204127434fc46ee190.

Causes bot failures: https://lab.llvm.org/buildbot/#builders/139/builds/39964

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/DependencyOutputOptions.h
clang/include/clang/Frontend/Utils.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/DependencyFile.cpp

Removed: 
clang/test/Driver/canonical-system-headers.c
clang/test/Preprocessor/Inputs/canonical-system-headers/a.h
clang/test/Preprocessor/canonical-system-headers.c



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 182f0290736d8..8c80c7f5ff56a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5835,9 +5835,6 @@ let Flags = [CC1Option, NoDriverOption] in {
 def sys_header_deps : Flag<["-"], "sys-header-deps">,
   HelpText<"Include system headers in dependency output">,
   MarshallingInfoFlag>;
-def canonical_system_headers : Flag<["-"], "canonical-system-headers">,
-  HelpText<"Canonicalize system headers in dependency output">,
-  MarshallingInfoFlag>;
 def module_file_deps : Flag<["-"], "module-file-deps">,
   HelpText<"Include module files in dependency output">,
   MarshallingInfoFlag>;

diff  --git a/clang/include/clang/Frontend/DependencyOutputOptions.h 
b/clang/include/clang/Frontend/DependencyOutputOptions.h
index e140ff9baa117..e0f445bb5970c 100644
--- a/clang/include/clang/Frontend/DependencyOutputOptions.h
+++ b/clang/include/clang/Frontend/DependencyOutputOptions.h
@@ -34,8 +34,6 @@ enum ExtraDepKind {
 class DependencyOutputOptions {
 public:
   unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies.
-  unsigned
-  CanonicalSystemHeaders : 1; ///< canonicalize system header dependencies.
   unsigned ShowHeaderIncludes : 1;   ///< Show header inclusions (-H).
   unsigned UsePhonyTargets : 1;  ///< Include phony targets for each
  /// dependency, which can avoid some 
'make'
@@ -87,11 +85,10 @@ class DependencyOutputOptions {
 
 public:
   DependencyOutputOptions()
-  : IncludeSystemHeaders(0), CanonicalSystemHeaders(0),
-ShowHeaderIncludes(0), UsePhonyTargets(0), AddMissingHeaderDeps(0),
-IncludeModuleFiles(0), ShowSkippedHeaderIncludes(0),
-HeaderIncludeFormat(HIFMT_Textual), HeaderIncludeFiltering(HIFIL_None) 
{
-  }
+  : IncludeSystemHeaders(0), ShowHeaderIncludes(0), UsePhonyTargets(0),
+AddMissingHeaderDeps(0), IncludeModuleFiles(0),
+ShowSkippedHeaderIncludes(0), HeaderIncludeFormat(HIFMT_Textual),
+HeaderIncludeFiltering(HIFIL_None) {}
 };
 
 }  // end namespace clang

diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 8300e45d15fe5..143cf4359f00b 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -41,7 +41,6 @@ class ExternalSemaSource;
 class FrontendOptions;
 class PCHContainerReader;
 class Preprocessor;
-class FileManager;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
@@ -80,14 +79,11 @@ class DependencyCollector {
   /// Return true if system files should be passed to sawDependency().
   virtual bool needSystemDependencies() { return false; }
 
-  /// Return true if system files should be canonicalized.
-  virtual bool shouldCanonicalizeSystemDependencies() { return false; }
-
   /// Add a dependency \p Filename if it has not been seen before and
   /// sawDependency() returns true.
   virtual void maybeAddDependency(StringRef Filename, bool FromModule,
   bool IsSystem, bool IsModuleFile,
-  FileManager *FileMgr, bool IsMissing);
+  bool IsMissing);
 
 protected:
   /// Return true if the filename was added to the list of dependencies, false
@@ -116,10 +112,6 @@ class DependencyFileGenerator : public DependencyCollector 
{
   bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem,
  bool IsModuleFile, bool IsMissing) final;
 
-  bool shouldCanonicalizeSystemDependencies() override {
-return CanonicalSystemHeaders;
-  }
-
 protected:
   void outputDependencyFile(llvm::raw_ostream );
 
@@ -129,7 +121,6 @@ class DependencyFileGenerator : public DependencyCollector {
   std::string OutputFile;
   std::vector Targets;
   bool IncludeSystemHeaders;
-  bool 

[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-05-01 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

cjdb wrote:
> aaron.ballman wrote:
> > nickdesaulniers wrote:
> > > cjdb wrote:
> > > > aaron.ballman wrote:
> > > > > nickdesaulniers wrote:
> > > > > > nickdesaulniers wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > Instead of allowing this note to appear anywhere in the file, I 
> > > > > > > > think it's better to use "bookmark" comments. e.g.,
> > > > > > > > ```
> > > > > > > > void baz() { // #baz_defn
> > > > > > > > }
> > > > > > > > 
> > > > > > > > void foo() {
> > > > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > > > }
> > > > > > > > ```
> > > > > > > > so that we're testing where the diagnostic is emitted. (This is 
> > > > > > > > especially important given that the changes are about location 
> > > > > > > > tracking.)
> > > > > > > oh, that's new (to me)! will do
> > > > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > > > line+col info. They follow the warning/error diagnostic which does, 
> > > > > > on the bottom most call site.
> > > > > > 
> > > > > > The warning is supposed to be emitted on the callsite, not the 
> > > > > > definition.
> > > > > I still don't think this is reasonable for test coverage because this 
> > > > > means we'll accept the note *anywhere* in the file. This makes it 
> > > > > much too easy to regress the behavior accidentally (e.g., 
> > > > > accidentally emit all the notes on line 1 of the file). I think we 
> > > > > need *some* way to nail down where these notes are emitted in the 
> > > > > test. However, I might be asking you to solve "please track location 
> > > > > information through the backend" for that, so perhaps this isn't a 
> > > > > reasonable request?
> > > > > 
> > > > > Also, CC @cjdb for awareness of how this kind of diagnostic is 
> > > > > produced (Chris is working on an idea for how we emit diagnostics so 
> > > > > we get better structured information from them, so knowing about this 
> > > > > novel approach might impact that idea).
> > > > Very interesting, thanks for the heads up! Cross-phase diagnostics are 
> > > > definitely something I hadn't considered, and it **does** impact the 
> > > > design (but not in a derailing way).
> > > I think we're back at "please track location information through the 
> > > backend".
> > > 
> > > That is the tradeoff with this approach; not measurably regressing 
> > > performance when these attributes aren't used in source in exchange for 
> > > Note diagnostics that lack precise line+col info, but in practice provide 
> > > enough info for the user to understand what's going wrong where.
> > > 
> > > Your call if the tradeoff is worth it.
> > Here's my thinking, please correct any misunderstandings I have:
> > 
> > * This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
> > solely for that purpose), and that's an important security feature used by 
> > glibc and the Linux kernel.
> > * Security of C and C++ source code is Very Important, especially now that 
> > various gov't agencies [1][2] are suggesting to not use C or C++ for new 
> > projects specifically because the security posture of the languages and 
> > their tools.
> > * Therefore, the ergonomics of this functionality are quite important for 
> > the intended use cases and the ecosystem as a whole.
> > * Emitting only the function name but without location information does not 
> > give a good user experience, especially in circumstances where the function 
> > has multiple overloads, because it pushes the burden onto the programmer to 
> > figure out which functions are actually involved in the call chain. This 
> > issue is also present in C because of support for 
> > `__attribute__((overloadable))` and is not just a C++ concern.
> > * The compile-time performance costs of tracking this location information 
> > are roughly 1%, and there are no runtime or binary size overhead costs 
> > unless other functionality is enabled (such as emitting debug info).
> > * We can determine whether we need to enable this location tracking while 
> > building the AST when we see one of these two attributes being used, so we 
> > could enable this functionality selectively without burdening the user with 
> > enabling it manually via a flag. (We could still consider giving the user a 
> > flag to never track this even in the presence of the attributes if a user 
> > had a compelling use case for it.)
> > 
> > If this is all reasonably accurate, I think it's worth seriously 
> > considering accepting the costs. I don't want to increase our compile time 
> > overhead, but at the same time, if ~1% is a "make or break" amount of 
> > compile-time 

[PATCH] D149187: [clang] Canonicalize system headers in dependency file when -canonical-prefixes

2023-05-01 Thread Arthur Eubanks 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 rG8f0dd4ef3ed2: [clang] Canonicalize system headers in 
dependency file when -canonical-prefixes (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149187

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/DependencyOutputOptions.h
  clang/include/clang/Frontend/Utils.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/test/Driver/canonical-system-headers.c
  clang/test/Preprocessor/Inputs/canonical-system-headers/a.h
  clang/test/Preprocessor/canonical-system-headers.c

Index: clang/test/Preprocessor/canonical-system-headers.c
===
--- /dev/null
+++ clang/test/Preprocessor/canonical-system-headers.c
@@ -0,0 +1,16 @@
+// don't create symlinks on windows
+// UNSUPPORTED: system-windows
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/foo/
+// RUN: ln -f -s %S/Inputs/canonical-system-headers %t/foo/include
+// RUN: %clang_cc1 -isystem %T/foo/include -sys-header-deps -MT foo.o -dependency-file %t2 %s -fsyntax-only
+// RUN: FileCheck %s --check-prefix=NOCANON --implicit-check-not=a.h < %t2
+// RUN: %clang_cc1 -isystem %T/foo/include -sys-header-deps -MT foo.o -dependency-file %t2 %s -fsyntax-only -canonical-system-headers
+// RUN: FileCheck %s --check-prefix=CANON --implicit-check-not=a.h < %t2
+
+// NOCANON: foo/include/a.h
+// CANON: Inputs/canonical-system-headers/a.h
+
+#include 
Index: clang/test/Driver/canonical-system-headers.c
===
--- /dev/null
+++ clang/test/Driver/canonical-system-headers.c
@@ -0,0 +1,6 @@
+// RUN: %clang -MD -no-canonical-prefixes -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-NO
+// RUN: %clang -MD -canonical-prefixes -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-YES
+// RUN: %clang -MD -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-YES
+
+// CHECK-YES: "-canonical-system-headers"
+// CHECK-NO-NOT: "-canonical-system-headers"
Index: clang/lib/Frontend/DependencyFile.cpp
===
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -49,6 +49,7 @@
   DepCollector.maybeAddDependency(
   llvm::sys::path::remove_leading_dotslash(*Filename),
   /*FromModule*/ false, isSystem(FileType), /*IsModuleFile*/ false,
+  (),
   /*IsMissing*/ false);
   }
 
@@ -56,9 +57,11 @@
SrcMgr::CharacteristicKind FileType) override {
 StringRef Filename =
 llvm::sys::path::remove_leading_dotslash(SkippedFile.getName());
-DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
+DepCollector.maybeAddDependency(Filename,
+/*FromModule=*/false,
 /*IsSystem=*/isSystem(FileType),
 /*IsModuleFile=*/false,
+(),
 /*IsMissing=*/false);
   }
 
@@ -69,9 +72,12 @@
   StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 if (!File)
-  DepCollector.maybeAddDependency(FileName, /*FromModule*/false,
- /*IsSystem*/false, /*IsModuleFile*/false,
- /*IsMissing*/true);
+  DepCollector.maybeAddDependency(FileName,
+  /*FromModule*/ false,
+  /*IsSystem*/ false,
+  /*IsModuleFile*/ false,
+  (),
+  /*IsMissing*/ true);
 // Files that actually exist are handled by FileChanged.
   }
 
@@ -82,9 +88,11 @@
   return;
 StringRef Filename =
 llvm::sys::path::remove_leading_dotslash(File->getName());
-DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
+DepCollector.maybeAddDependency(Filename,
+/*FromModule=*/false,
 /*IsSystem=*/isSystem(FileType),
 /*IsModuleFile=*/false,
+(),
 /*IsMissing=*/false);
   }
 
@@ -100,10 +108,12 @@
   void moduleMapFileRead(SourceLocation Loc, const FileEntry ,
  bool IsSystem) override {
 StringRef Filename = Entry.getName();
-DepCollector.maybeAddDependency(Filename, /*FromModule*/false,
-/*IsSystem*/IsSystem,
-

[clang] 8f0dd4e - [clang] Canonicalize system headers in dependency file when -canonical-prefixes

2023-05-01 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2023-05-01T10:40:18-07:00
New Revision: 8f0dd4ef3ed2137d1e2554204127434fc46ee190

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

LOG: [clang] Canonicalize system headers in dependency file when 
-canonical-prefixes

Clang was writing paths to the dependency file that don't exist when using a 
sysroot with symlinks, causing everything to get rebuilt every time. This is 
reproducible on Linux by creating a symlink to '/', using that as the sysroot, 
and trying to build something with ninja that includes the C++ stdlib (e.g. a 
typical build of LLVM).

This fixes https://github.com/ninja-build/ninja/issues/1330 and somewhat 
matches gcc.

gcc canonicalizes system headers in dependency files under a 
-f[no-]canonical-system-headers, but it makes more sense to look at 
-canonical-prefixes.

D37954 was a previous attempt at this.

Reviewed By: hans

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

Added: 
clang/test/Driver/canonical-system-headers.c
clang/test/Preprocessor/Inputs/canonical-system-headers/a.h
clang/test/Preprocessor/canonical-system-headers.c

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/DependencyOutputOptions.h
clang/include/clang/Frontend/Utils.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/DependencyFile.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8c80c7f5ff56a..182f0290736d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5835,6 +5835,9 @@ let Flags = [CC1Option, NoDriverOption] in {
 def sys_header_deps : Flag<["-"], "sys-header-deps">,
   HelpText<"Include system headers in dependency output">,
   MarshallingInfoFlag>;
+def canonical_system_headers : Flag<["-"], "canonical-system-headers">,
+  HelpText<"Canonicalize system headers in dependency output">,
+  MarshallingInfoFlag>;
 def module_file_deps : Flag<["-"], "module-file-deps">,
   HelpText<"Include module files in dependency output">,
   MarshallingInfoFlag>;

diff  --git a/clang/include/clang/Frontend/DependencyOutputOptions.h 
b/clang/include/clang/Frontend/DependencyOutputOptions.h
index e0f445bb5970c..e140ff9baa117 100644
--- a/clang/include/clang/Frontend/DependencyOutputOptions.h
+++ b/clang/include/clang/Frontend/DependencyOutputOptions.h
@@ -34,6 +34,8 @@ enum ExtraDepKind {
 class DependencyOutputOptions {
 public:
   unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies.
+  unsigned
+  CanonicalSystemHeaders : 1; ///< canonicalize system header dependencies.
   unsigned ShowHeaderIncludes : 1;   ///< Show header inclusions (-H).
   unsigned UsePhonyTargets : 1;  ///< Include phony targets for each
  /// dependency, which can avoid some 
'make'
@@ -85,10 +87,11 @@ class DependencyOutputOptions {
 
 public:
   DependencyOutputOptions()
-  : IncludeSystemHeaders(0), ShowHeaderIncludes(0), UsePhonyTargets(0),
-AddMissingHeaderDeps(0), IncludeModuleFiles(0),
-ShowSkippedHeaderIncludes(0), HeaderIncludeFormat(HIFMT_Textual),
-HeaderIncludeFiltering(HIFIL_None) {}
+  : IncludeSystemHeaders(0), CanonicalSystemHeaders(0),
+ShowHeaderIncludes(0), UsePhonyTargets(0), AddMissingHeaderDeps(0),
+IncludeModuleFiles(0), ShowSkippedHeaderIncludes(0),
+HeaderIncludeFormat(HIFMT_Textual), HeaderIncludeFiltering(HIFIL_None) 
{
+  }
 };
 
 }  // end namespace clang

diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b..8300e45d15fe5 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -41,6 +41,7 @@ class ExternalSemaSource;
 class FrontendOptions;
 class PCHContainerReader;
 class Preprocessor;
+class FileManager;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
 
@@ -79,11 +80,14 @@ class DependencyCollector {
   /// Return true if system files should be passed to sawDependency().
   virtual bool needSystemDependencies() { return false; }
 
+  /// Return true if system files should be canonicalized.
+  virtual bool shouldCanonicalizeSystemDependencies() { return false; }
+
   /// Add a dependency \p Filename if it has not been seen before and
   /// sawDependency() returns true.
   virtual void maybeAddDependency(StringRef Filename, bool FromModule,
   bool IsSystem, bool IsModuleFile,
-  bool IsMissing);
+  FileManager *FileMgr, bool IsMissing);
 
 protected:
   /// Return true if the filename was added to the list of dependencies, false
@@ -112,6 +116,10 @@ 

[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-01 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[clang] f762798 - Fix ReleaseNotes.rst unresolved merge conflict

2023-05-01 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-01T10:26:15-07:00
New Revision: f762798599171efca03964f4371cc8104d2392f9

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

LOG: Fix ReleaseNotes.rst unresolved merge conflict

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ec0dc0adc58b..a3ee06ba1c22 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,15 +373,12 @@ Bug Fixes to C++ Support
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
-<<< HEAD
 - Fix default member initializers sometimes being ignored when performing
   parenthesized aggregate initialization of templated types.
   (`#62266 `_)
-===
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
->>> c7422b289522 ([clang] Fix overly aggressive lifetime checks for 
parenthesized aggregate initialization)
 
 Bug Fixes to AST Handling
 ^



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


[PATCH] D149596: [AIX][TLS] Relax front end diagnostics to accept the local-exec TLS model

2023-05-01 Thread Amy Kwan via Phabricator via cfe-commits
amyk created this revision.
amyk added reviewers: PowerPC, stefanp, kamaub, nemanjai.
amyk added projects: LLVM, PowerPC, clang.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
amyk requested review of this revision.
Herald added a subscriber: cfe-commits.

This patch relaxes the front end AIX diagnostics added in D102070 
 to accept the
local-exec TLS model, as we plan to support this model in a series of future 
patches.

The diagnostics are relaxed when `local-exec` is used as a compiler option to 
`-ftls-model=*`
and in the `__attribute__((tls_model("local-exec")))` attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149596

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/PowerPC/aix-tls-model.cpp
  clang/test/Sema/aix-attr-tls_model.c


Index: clang/test/Sema/aix-attr-tls_model.c
===
--- clang/test/Sema/aix-attr-tls_model.c
+++ clang/test/Sema/aix-attr-tls_model.c
@@ -8,4 +8,4 @@
 static __thread int y __attribute((tls_model("global-dynamic"))); // no-warning
 static __thread int y __attribute((tls_model("local-dynamic"))); // 
expected-error {{TLS model 'local-dynamic' is not yet supported on AIX}}
 static __thread int y __attribute((tls_model("initial-exec"))); // 
expected-error {{TLS model 'initial-exec' is not yet supported on AIX}}
-static __thread int y __attribute((tls_model("local-exec"))); // 
expected-error {{TLS model 'local-exec' is not yet supported on AIX}}
+static __thread int y __attribute((tls_model("local-exec"))); // no-warning
Index: clang/test/CodeGen/PowerPC/aix-tls-model.cpp
===
--- clang/test/CodeGen/PowerPC/aix-tls-model.cpp
+++ clang/test/CodeGen/PowerPC/aix-tls-model.cpp
@@ -2,12 +2,12 @@
 // RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LD-ERROR
 // RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s 
-check-prefix=CHECK-IE-ERROR
-// RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LE-ERROR
+// RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LE
 // RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LD-ERROR
 // RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s 
-check-prefix=CHECK-IE-ERROR
-// RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LE-ERROR
+// RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LE
 
 int z1 = 0;
 int z2;
@@ -23,4 +23,7 @@
 // CHECK-GD: @_ZZ1fvE1y = internal thread_local global i32 0
 // CHECK-LD-ERROR:  error: TLS model 'local-dynamic' is not yet supported on 
AIX
 // CHECK-IE-ERROR:  error: TLS model 'initial-exec' is not yet supported on AIX
-// CHECK-LE-ERROR:  error: TLS model 'local-exec' is not yet supported on AIX
+// CHECK-LE: @z1 ={{.*}} global i32 0
+// CHECK-LE: @z2 ={{.*}} global i32 0
+// CHECK-LE: @x ={{.*}} thread_local(localexec) global i32 0
+// CHECK-LE: @_ZZ1fvE1y = internal thread_local(localexec) global i32 0
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2033,7 +2033,7 @@
   }
 
   if (S.Context.getTargetInfo().getTriple().isOSAIX() &&
-  Model != "global-dynamic") {
+  Model != "global-dynamic" && Model != "local-exec") {
 S.Diag(LiteralLoc, diag::err_aix_attr_unsupported_tls_model) << Model;
 return;
   }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1891,7 +1891,7 @@
   if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
 if (T.isOSAIX()) {
   StringRef Name = A->getValue();
-  if (Name != "global-dynamic")

[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-05-01 Thread Alan Zhao 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 rG9b4faa11c68b: [clang] Fix overly aggressive lifetime checks 
for parenthesized aggregate… (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148274

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp

Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -9,7 +9,7 @@
 struct B {
   A a;
   int b[20];
-  int & // expected-note {{reference member declared here}}
+  int &
 };
 
 struct C { // expected-note 5{{candidate constructor}}
@@ -21,9 +21,9 @@
   int a;
 };
 
-struct E { // expected-note 3{{candidate constructor}}
-  struct F {
-F(int, int);
+struct E {
+  struct F { // expected-note 2{{candidate constructor}}
+F(int, int); // expected-note {{candidate constructor}}
   };
   int a;
   F f;
@@ -56,6 +56,22 @@
   int b[]; // expected-note {{initialized flexible array member 'b' is here}}
 };
 
+enum K { K0, K1, K2 };
+
+struct L {
+  K k : 1;
+};
+
+struct M {
+  struct N {
+private:
+N(int);
+// expected-note@-1 {{declared private here}}
+  };
+  int i;
+  N n;
+};
+
 union U {
   int a;
   char* b;
@@ -74,7 +90,7 @@
   // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
 
-void foo() {
+void foo(int n) {
   A a1(1954, 9, 21);
   // expected-error@-1 {{excess elements in struct initializer}}
   A a2(2.1);
@@ -96,9 +112,8 @@
   B b1(2022, {7, 8});
   // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
   B b2(A(1), {}, 1);
-  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
-  // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
-  // beforecxx20-warning@-3 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
 
   C c(A(1), 1, 2, 3, 4);
   // expected-error@-1 {{array initializer must be an initializer list}}
@@ -130,7 +145,7 @@
   // expected-error@-1 {{excess elements in union initializer}}
 
   E e1(1);
-  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+  // expected-error@-1 {{no matching constructor for initialization of 'F'}}
 
   constexpr F f1(1);
   // expected-error@-1 {{constexpr variable 'f1' must be initialized by a constant expression}}
@@ -148,18 +163,29 @@
   A a7 = Construct('i', 2.2);
   // beforecxx20-note@-1 {{in instantiation of function template specialization 'Construct' requested here}}
 
+  L l(K::K2);
+  // expected-warning@-1 {{implicit truncation}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'L' from a parenthesized list of values is a C++20 extension}}
+
   int arr4[](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
   int arr5[2](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
+  int arr6[n](1, 2, 3);
+  // expected-error@-1 {{variable-sized object may not be initialized}}
+
   I i(1, 2);
   // expected-error@-1 {{no matching constructor for initialization of 'I'}}
 
   J j(1, {2, 3});
   // expected-error@-1 {{initialization of flexible array member is not allowed}}
 
+  M m(1, 1);
+  // expected-error@-1 {{field of type 'N' has private constructor}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
   static_assert(__is_trivially_constructible(A, char, double));
   static_assert(__is_trivially_constructible(A, char, int));
   static_assert(__is_trivially_constructible(A, char));
@@ -221,5 +247,22 @@
 N n(43);
 // expected-error@-1 {{field of type 'L' has protected constructor}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+}
+
+namespace gh61567 {
+struct O {
+  int i;
+  int &
+  // expected-note@-1 {{uninitialized reference member is here}}
+  int & = 1;
+};
+
+O o1(0, 0, 0); // 

[clang] 9b4faa1 - [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-05-01 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-01T10:02:15-07:00
New Revision: 9b4faa11c68be4b45ddf29acd575bb52a3c2fad7

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

LOG: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate 
initialization

Before this patch, initialized class members would have the LifetimeKind
LK_MemInitializer, which does not allow for binding a temporary to a
reference. Binding to a temporary however is allowed in parenthesized
aggregate initialization, even if it leads to a dangling reference. To
fix this, we create a new EntityKind, EK_ParenAggInitMember, which has
LifetimeKind LK_FullExpression.

This patch does *not* attempt to diagnose dangling references as a
result of using this feature.

This patch also refactors TryOrBuildParenListInitialization(...) to
accomodate creating different InitializedEntity objects.

Fixes #61567

[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html

Reviewed By: shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Initialization.h
clang/lib/Sema/SemaAccess.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index eaabe08599520..ec0dc0adc58b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,9 +373,15 @@ Bug Fixes to C++ Support
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
+<<< HEAD
 - Fix default member initializers sometimes being ignored when performing
   parenthesized aggregate initialization of templated types.
   (`#62266 `_)
+===
+- Fix overly aggressive lifetime checks for parenthesized aggregate
+  initialization.
+  (`#61567 `_)
+>>> c7422b289522 ([clang] Fix overly aggressive lifetime checks for 
parenthesized aggregate initialization)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7d0ee502eabfc..17585752edf8e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2126,7 +2126,8 @@ def err_init_conversion_failed : Error<
   "exception object|a member subobject|an array element|a new value|a value|a "
   "base class|a constructor delegation|a vector element|a block element|a "
   "block element|a complex element|a lambda capture|a compound literal "
-  "initializer|a related result|a parameter of CF audited function}0 "
+  "initializer|a related result|a parameter of CF audited function|a "
+  "structured binding|a member subobject}0 "
   "%
diff {of type $ with an %select{rvalue|lvalue}2 of type $|"
   "with an %select{rvalue|lvalue}2 of incompatible type}1,3"
   "%select{|: 
diff erent classes%
diff { ($ vs $)|}5,6"

diff  --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index fcfb56f9731ef..2072cd8d1c3ef 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -123,6 +123,10 @@ class alignas(8) InitializedEntity {
 /// decomposition declaration.
 EK_Binding,
 
+/// The entity being initialized is a non-static data member subobject of 
an
+/// object initialized via parenthesized aggregate initialization.
+EK_ParenAggInitMember,
+
 // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
 // enum as an index for its first %select.  When modifying this list,
 // that diagnostic text needs to be updated as well.
@@ -227,8 +231,10 @@ class alignas(8) InitializedEntity {
 
   /// Create the initialization entity for a member subobject.
   InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
-bool Implicit, bool DefaultMemberInit)
-  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
+bool Implicit, bool DefaultMemberInit,
+bool IsParenAggInit = false)
+  : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
+Parent(Parent), Type(Member->getType()),
 Variable{Member, Implicit, DefaultMemberInit} {}
 
   /// Create the initialization entity for an array element.
@@ -388,6 +394,14 @@ class alignas(8) InitializedEntity {
 return 

  1   2   >