[clang] [clang][analyzer] Fix crash in loop unrolling (PR #82089)

2024-03-14 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/82089

>From 2802ef4b9ed88da3cacb16ab7738907ee806 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Sat, 17 Feb 2024 10:43:48 +0800
Subject: [PATCH 01/10] Fix crash on StaticAnalyzer loop unrolling

---
 clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index a80352816be613..4001268bde6677 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -226,6 +226,17 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
   return false;
   }
 }
+
+if (const SwitchStmt *SS = dyn_cast(S)) {
+  for (const Stmt *CB : dyn_cast(SS->getBody())->body()) {
+for (const Decl *D : dyn_cast(CB)->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return false;
+}
+  }
+}
+
 // Check the usage of the pass-by-ref function calls and adress-of operator
 // on VD and reference initialized by VD.
 ASTContext &ASTCtx =

>From e9e195e4462da7f3ca2317096ddace6ce3e88d13 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Mon, 19 Feb 2024 18:17:27 +0800
Subject: [PATCH 02/10] Check if dynamic cast get pointer to valid elements

---
 clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index 4001268bde6677..093e9bbf4ce5e0 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -228,11 +228,15 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
 }
 
 if (const SwitchStmt *SS = dyn_cast(S)) {
-  for (const Stmt *CB : dyn_cast(SS->getBody())->body()) {
-for (const Decl *D : dyn_cast(CB)->decls()) {
-  // Once we reach the declaration of the VD we can return.
-  if (D->getCanonicalDecl() == VD)
-return false;
+  if (const CompoundStmt *CST = dyn_cast(SS->getBody())) {
+for (const Stmt *CB : CST->body()) {
+  if (const DeclStmt *DST = dyn_cast(CB)) {
+for (const Decl *D : DST->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return false;
+}
+  }
 }
   }
 }

>From 6ed9ea88865e91f1727077b1a3a24d7b110060fd Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Tue, 20 Feb 2024 11:31:23 +0800
Subject: [PATCH 03/10] Add testcase for finding declaration within SwitchStmt

---
 .../test-escaping-on-var-before-switch-case.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
clang/test/Analysis/test-escaping-on-var-before-switch-case.c

diff --git a/clang/test/Analysis/test-escaping-on-var-before-switch-case.c 
b/clang/test/Analysis/test-escaping-on-var-before-switch-case.c
new file mode 100644
index 00..95aed8cab06b55
--- /dev/null
+++ b/clang/test/Analysis/test-escaping-on-var-before-switch-case.c
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config 
unroll-loops=true -verify %s
+
+void test_escaping_on_var_before_switch_case_no_crash(int c) {
+  switch (c) {
+int i; // expected error{{Reached root without finding the declaration of 
VD}}
+case 0: {
+  for (i = 0; i < 16; i++) {}
+  break;
+}
+  }
+}

>From 294b7c960233cbef8ee0d8721c60792fd1e6a064 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Thu, 22 Feb 2024 21:04:06 +0800
Subject: [PATCH 04/10] Hoist duplicated code into function

---
 .../lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 29 ++-
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index 093e9bbf4ce5e0..697e811470e708 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -190,6 +190,17 @@ static bool isCapturedByReference(ExplodedNode *N, const 
DeclRefExpr *DR) {
   return FD->getType()->isReferenceType();
 }
 
+static bool isFoundInStmt(const Stmt *S, const VarDecl *VD) {
+  if (const DeclStmt *DS = dyn_cast(S)) {
+for (const Decl *D : DS->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return true;
+}
+  }
+  return false;
+}
+
 // A loop counter is considered escaped if:
 // case 1: It is a global variable.
 // case 2: It is a reference parameter or a reference capture.
@@ -219,24 +230,16 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRef

[clang] [llvm] [RISC-V] Add CSR read/write builtins (PR #85091)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits

nemanjai wrote:

> > Individual implementations will provide different sets of CSR's and need a 
> > way to read/write them. Of course, this can be done with inline asm, but 
> > doing such things with inline asm has its limitations (no error checking,
> 
> Wouldn't the assembler error check the constant? Diagnostic is probably a bit 
> uglier, but its not nothing.
Perhaps it would, but I really don't think it is particularly friendly to the 
user to rely on the assembler for this.

> 
> > if a user attempts to wrap the asm in a function, they won't be able to 
> > build code that calls those functions with -O0 as inlining/constant 
> > propagation is required, etc.).
> 
> You mean if they write a generic write_csr or read_csr function? If they use 
> a `write_frm` or `read_fcsr` function then there is no constant propagation 
> issue and they get to refer to the CSR by name in the assembly string instead 
> of maintaining a constant in their code.

Yes, I mean the general, unnamed CSR's.

https://github.com/llvm/llvm-project/pull/85091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-14 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 8dc42f5c90ba369a145868f8c1a9a8cb3e988cb0 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH 1/2] [RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/docs/ReleaseNotes.rst|   1 +
 clang/test/Driver/riscv-profiles.c | 312 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  65 ++
 3 files changed, 378 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bce27dc8c4a996..a072bf4a5ff4b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option is now supported.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature" "+ziccrse"
+// RVA22S64: "-target-feature" "+zicntr"

[clang] 2582965 - [C++20] [Modules] [Reduced BMI] Generate the function body from implicitly instantiated class and constant variables

2024-03-14 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-03-14T15:07:08+08:00
New Revision: 2582965c160486f9e3b0680f1cebc5ffdef9620c

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

LOG: [C++20] [Modules] [Reduced BMI] Generate the function body from implicitly 
instantiated class and constant variables

After this patch, we will generate the function body from implicitly
instantiated class. This is important for consumers with same
template arguments. Otherwise the consumers won't see the function body.
Since the consumers won't instantiate the templates again if they find an
instantiation.

Also we will generate the variable definition if the variable is
non-inline but known as constant. Such variables may not affect the
ABI, but they may get involved into the compile time constant computation
in the consumer's code. So we have to generate such definitions.

Added: 
clang/test/Modules/reduced-bmi-generating-codes.cppm

Modified: 
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index d04e1c781b4e28..86f64bf2a24250 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -281,11 +281,18 @@ bool clang::CanElideDeclDef(const Decl *D) {
 
 if (FD->isDependentContext())
   return false;
+
+if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
+  return false;
   }
 
   if (auto *VD = dyn_cast(D)) {
 if (!VD->getDeclContext()->getRedeclContext()->isFileContext() ||
-VD->isInline() || VD->isConstexpr() || isa(VD))
+VD->isInline() || VD->isConstexpr() || isa(VD) ||
+// Constant initialized variable may not affect the ABI, but they
+// may be used in constant evaluation in the frontend, so we have
+// to remain them.
+VD->hasConstantInitialization())
   return false;
 
 if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)

diff  --git a/clang/test/Modules/reduced-bmi-generating-codes.cppm 
b/clang/test/Modules/reduced-bmi-generating-codes.cppm
new file mode 100644
index 00..13dcda06437b29
--- /dev/null
+++ b/clang/test/Modules/reduced-bmi-generating-codes.cppm
@@ -0,0 +1,40 @@
+// Although the reduced BMI are not designed to be generated,
+// it is helpful for testing whether we've reduced the definitions.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \
+// RUN: -emit-reduced-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cpp \
+// RUN: -fmodule-file=a=%t/a.pcm -S -emit-llvm -o - \
+// RUN: | FileCheck %t/b.cpp
+
+//--- a.cppm
+export module a;
+
+export template 
+class A {
+public:
+int member() {
+return 43;
+}
+};
+
+// Instantiate `A::member()`.
+export int a_member = A().member();
+
+export const int a = 43;
+
+//--- b.cpp
+import a;
+
+static_assert(a == 43);
+
+int b() {
+A a;
+return a.member();
+}
+
+// CHECK: define{{.*}}@_ZNW1a1AIiE6memberEv



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


[clang] [Headers][X86] Add rounding and exception notes to conversions (PR #83447)

2024-03-14 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang approved this pull request.

Looks great, thanks!

https://github.com/llvm/llvm-project/pull/83447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-03-14 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm requested changes to this pull request.

Outstanding comments 

https://github.com/llvm/llvm-project/pull/79236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-14 Thread Wang Pengcheng via cfe-commits


@@ -854,6 +895,30 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
  "string must be lowercase");
   }
 
+  bool IsProfile = Arch.starts_with("rvi") || Arch.starts_with("rva") ||
+   Arch.starts_with("rvb") || Arch.starts_with("rvm");
+  std::string NewArch;

wangpc-pp wrote:

What should I do?

https://github.com/llvm/llvm-project/pull/76357
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-14 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 8dc42f5c90ba369a145868f8c1a9a8cb3e988cb0 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH 1/3] [RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.
---
 clang/docs/ReleaseNotes.rst|   1 +
 clang/test/Driver/riscv-profiles.c | 312 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  65 ++
 3 files changed, 378 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bce27dc8c4a996..a072bf4a5ff4b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,6 +408,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option is now supported.
 
 CUDA/HIP Language Changes
 ^
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature" "+ziccrse"
+// RVA22S64: "-target-feature" "+zicntr"

[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-14 Thread via cfe-commits

T-Gruber wrote:

Thanks again @steakhal! This is helpful and interesting background information. 
I really appreciate your help!

https://github.com/llvm/llvm-project/pull/85104
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Add a test for result object location on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

martinboehme wrote:

The newly added test is failing, but apparently only on Windows. Will need to 
take a closer look at why this is, and will update this PR when I have 
something new.

https://github.com/llvm/llvm-project/pull/85072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8f68022 - [clang][analyzer] Fix crash in loop unrolling (#82089)

2024-03-14 Thread via cfe-commits

Author: huang-me
Date: 2024-03-14T09:16:40+01:00
New Revision: 8f68022f8e6e54d1aeae4ed301f5a015963089b7

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

LOG: [clang][analyzer] Fix crash in loop unrolling (#82089)

StaticAnalyzer didn't check if the variable is declared in
`CompoundStmt` under `SwitchStmt`, which make static analyzer reach root
without finding the declaration.

Fixes #68819

-

Co-authored-by: Balazs Benics 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/Analysis/loop-unrolling.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index abeb5a8b77bf1f..71c1edc8f67b17 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -492,6 +492,10 @@ libclang
 Static Analyzer
 ---
 
+- Fixed crashing on loops if the loop variable was declared in switch blocks
+  but not under any case blocks if ``unroll-loops=true`` analyzer config is
+  set. (#GH68819)
+
 New features
 
 

diff  --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index a80352816be613..7042f1aeb803fc 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -190,6 +190,17 @@ static bool isCapturedByReference(ExplodedNode *N, const 
DeclRefExpr *DR) {
   return FD->getType()->isReferenceType();
 }
 
+static bool isFoundInStmt(const Stmt *S, const VarDecl *VD) {
+  if (const DeclStmt *DS = dyn_cast(S)) {
+for (const Decl *D : DS->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return true;
+}
+  }
+  return false;
+}
+
 // A loop counter is considered escaped if:
 // case 1: It is a global variable.
 // case 2: It is a reference parameter or a reference capture.
@@ -219,13 +230,19 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
   continue;
 }
 
-if (const DeclStmt *DS = dyn_cast(S)) {
-  for (const Decl *D : DS->decls()) {
-// Once we reach the declaration of the VD we can return.
-if (D->getCanonicalDecl() == VD)
-  return false;
+if (isFoundInStmt(S, VD)) {
+  return false;
+}
+
+if (const auto *SS = dyn_cast(S)) {
+  if (const auto *CST = dyn_cast(SS->getBody())) {
+for (const Stmt *CB : CST->body()) {
+  if (isFoundInStmt(CB, VD))
+return false;
+}
   }
 }
+
 // Check the usage of the pass-by-ref function calls and adress-of operator
 // on VD and reference initialized by VD.
 ASTContext &ASTCtx =

diff  --git a/clang/test/Analysis/loop-unrolling.cpp 
b/clang/test/Analysis/loop-unrolling.cpp
index fc1fb06cdc014e..66a828abfb5133 100644
--- a/clang/test/Analysis/loop-unrolling.cpp
+++ b/clang/test/Analysis/loop-unrolling.cpp
@@ -547,3 +547,15 @@ void capture_implicitly_by_ref_as_loop_counter() {
 }
   };
 }
+
+
+void test_escaping_on_var_before_switch_case_no_crash(int c) {
+  // https://github.com/llvm/llvm-project/issues/68819
+  switch (c) {
+int i; // no-crash: The declaration of `i` is found here.
+case 0: {
+  for (i = 0; i < 16; i++) {}
+  break;
+}
+  }
+}



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


[clang] [clang][analyzer] Fix crash in loop unrolling (PR #82089)

2024-03-14 Thread Balazs Benics via cfe-commits

https://github.com/steakhal closed 
https://github.com/llvm/llvm-project/pull/82089
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Fix crash in loop unrolling (PR #82089)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:



@huang-me Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/82089
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AArch64] Enable fp128 for aarch64 linux target (PR #85070)

2024-03-14 Thread David Green via cfe-commits

https://github.com/davemgreen commented:

Hi - I think this looks sensible, considering that long double == fp128. Should 
we be doing the same for other OS's in this file too? 

https://github.com/llvm/llvm-project/pull/85070
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (PR #67999)

2024-03-14 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

This is broken by the patch 
https://lab.llvm.org/buildbot/#/builders/5/builds/41773/steps/9/logs/stdio

https://github.com/llvm/llvm-project/pull/67999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-14 Thread via cfe-commits

https://github.com/eddyz87 updated 
https://github.com/llvm/llvm-project/pull/85161

>From ab31efc46153f7065b186b37e406d72188c4f780 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman 
Date: Thu, 14 Mar 2024 01:56:18 +0200
Subject: [PATCH 1/2] [BPF] rename 'arena' to 'address_space'

There are a few places where 'arena' name is used for pointers in
non-zero address space in BPF backend, rename these to use a more
generic 'address_space':
- macro __BPF_FEATURE_ARENA_CAST -> __BPF_FEATURE_ADDRESS_SPACE_CAST
- name for arena global variables section .arena.N -> .address_space.N
---
 clang/lib/Basic/Targets/BPF.cpp |  2 +-
 clang/test/Preprocessor/bpf-predefined-macros.c |  2 +-
 llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp | 10 +-
 llvm/test/CodeGen/BPF/addr-space-globals.ll |  2 +-
 llvm/test/CodeGen/BPF/addr-space-globals2.ll|  4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index 26a54f631fcfc4..9a1188acab944c 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -36,7 +36,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
 return;
   }
 
-  Builder.defineMacro("__BPF_FEATURE_ARENA_CAST");
+  Builder.defineMacro("__BPF_FEATURE_ADDRESS_SPACE_CAST");
 
   if (CPU.empty() || CPU == "generic" || CPU == "v1") {
 Builder.defineMacro("__BPF_CPU_VERSION__", "1");
diff --git a/clang/test/Preprocessor/bpf-predefined-macros.c 
b/clang/test/Preprocessor/bpf-predefined-macros.c
index fea24d1ea0ff7b..b6928c5c6ff4b4 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -61,7 +61,7 @@ int r;
 #ifdef __BPF_FEATURE_ST
 int s;
 #endif
-#ifdef __BPF_FEATURE_ARENA_CAST
+#ifdef __BPF_FEATURE_ADDRESS_SPACE_CAST
 int t;
 #endif
 
diff --git a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp 
b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
index edd59aaa6d01d2..070dd1ff4c5784 100644
--- a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
+++ b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
@@ -15,7 +15,7 @@
 //   - remove llvm.bpf.getelementptr.and.load builtins.
 //   - remove llvm.bpf.getelementptr.and.store builtins.
 //   - for loads and stores with base addresses from non-zero address space
-// cast base address to zero address space (support for BPF arenas).
+// cast base address to zero address space (support for BPF address 
spaces).
 //
 
//===--===//
 
@@ -482,7 +482,7 @@ static void aspaceWrapOperand(DenseMap 
&Cache, Instruction *I,
   }
 }
 
-// Support for BPF arenas:
+// Support for BPF address spaces:
 // - for each function in the module M, update pointer operand of
 //   each memory access instruction (load/store/cmpxchg/atomicrmw)
 //   by casting it from non-zero address space to zero address space, e.g:
@@ -490,7 +490,7 @@ static void aspaceWrapOperand(DenseMap 
&Cache, Instruction *I,
 //   (load (ptr addrspace (N) %p) ...)
 // -> (load (addrspacecast ptr addrspace (N) %p to ptr))
 //
-// - assign section with name .arena.N for globals defined in
+// - assign section with name .address_space.N for globals defined in
 //   non-zero address space N
 bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
   bool Changed = false;
@@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
 Changed |= !CastsCache.empty();
   }
   // Merge all globals within same address space into single
-  // .arena. section
+  // .address_space. section
   for (GlobalVariable &G : M.globals()) {
 if (G.getAddressSpace() == 0 || G.hasSection())
   continue;
 SmallString<16> SecName;
 raw_svector_ostream OS(SecName);
-OS << ".arena." << G.getAddressSpace();
+OS << ".address_space." << G.getAddressSpace();
 G.setSection(SecName);
 // Prevent having separate section for constants
 G.setConstant(false);
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals.ll
index 878ba0dfce6cd1..9848b1bbcd4f35 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals.ll
+++ b/llvm/test/CodeGen/BPF/addr-space-globals.ll
@@ -18,7 +18,7 @@
 
 ; Verify that a,b,c reside in the same section
 
-; CHECK: .section .arena.272,"aw",@progbits
+; CHECK: .section .address_space.272,"aw",@progbits
 ; CHECK-NOT: .section
 ; CHECK: .globl  a
 ; CHECK: .ascii  "\001\002"
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals2.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals2.ll
index d1e2318948751e..816741e2e834eb 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals2.ll
+++ b/llvm/test/CodeGen/BPF/addr-space-globals2.ll
@@ -14,12 +14,12 @@
 
 ; Verify that a,b reside in separate sections
 
-; CHECK: .section .arena.1,"aw",@progbits
+; CHECK: .section .address_space.1,"aw",@progbits
 ; CHECK-NOT: .section
 ; CHECK: .globl  a
 ; CHECK:   

[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-14 Thread via cfe-commits


@@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module &M) {
 Changed |= !CastsCache.empty();
   }
   // Merge all globals within same address space into single
-  // .arena. section
+  // .address_space. section
   for (GlobalVariable &G : M.globals()) {
 if (G.getAddressSpace() == 0 || G.hasSection())
   continue;
 SmallString<16> SecName;
 raw_svector_ostream OS(SecName);
-OS << ".arena." << G.getAddressSpace();
+OS << ".address_space." << G.getAddressSpace();

eddyz87 wrote:

Renamed all "address_space" to "addr_space".

https://github.com/llvm/llvm-project/pull/85161
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Add a test for result object location on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

martinboehme wrote:

The new test now does actually also fail for me locally. Not sure why I didn't 
notice this before. Will add a fix.

https://github.com/llvm/llvm-project/pull/85072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-03-14 Thread Axel Lundberg via cfe-commits


@@ -0,0 +1,61 @@
+// RUN: %clang -fsanitize=implicit-bitfield-conversion -target x86_64-linux -S 
-emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION

Zonotora wrote:

I will add some testcases later today!

https://github.com/llvm/llvm-project/pull/75481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

2024-03-14 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/85198

None

>From 8925332a806b171bf2e12a7beb257ea85bd0a668 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 14 Mar 2024 16:32:36 +0800
Subject: [PATCH] [Clang][Sema] Fix issue on requires expression with templated
 base class member function

---
 clang/lib/Sema/SemaExpr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8725b09f8546cf..31df62d06f1c05 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7729,7 +7729,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))
-if (Method->isImplicitObjectMemberFunction())
+if (!isa(CurContext) &&
+Method->isImplicitObjectMemberFunction())
   return ExprError(Diag(LParenLoc, diag::err_member_call_without_object)
<< Fn->getSourceRange() << 0);
 

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-03-14 Thread Axel Lundberg via cfe-commits


@@ -147,6 +147,7 @@ struct ImplicitConversionData {
   const TypeDescriptor &FromType;
   const TypeDescriptor &ToType;
   /* ImplicitConversionCheckKind */ unsigned char Kind;
+  unsigned int BitfieldBits;

Zonotora wrote:

@zygoloid 

https://github.com/llvm/llvm-project/pull/75481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

2024-03-14 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/85198

>From 23a344395180cbdcd47618e3170e72260139d4b7 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 14 Mar 2024 16:32:36 +0800
Subject: [PATCH] [Clang][Sema] Fix issue on requires expression with templated
 base class member function

---
 clang/lib/Sema/SemaExpr.cpp|  3 ++-
 clang/test/SemaCXX/PR84020.cpp | 23 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR84020.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8725b09f8546cf..31df62d06f1c05 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7729,7 +7729,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))
-if (Method->isImplicitObjectMemberFunction())
+if (!isa(CurContext) &&
+Method->isImplicitObjectMemberFunction())
   return ExprError(Diag(LParenLoc, diag::err_member_call_without_object)
<< Fn->getSourceRange() << 0);
 
diff --git a/clang/test/SemaCXX/PR84020.cpp b/clang/test/SemaCXX/PR84020.cpp
new file mode 100644
index 00..8ea5dcc4527ae7
--- /dev/null
+++ b/clang/test/SemaCXX/PR84020.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+struct B {
+template 
+void foo();
+
+void bar();
+};
+
+template 
+struct A : T {
+auto foo() {
+static_assert(requires { T::template foo(); });
+static_assert(requires { T::bar(); });
+}
+};
+
+int main() {
+A a;
+a.foo();
+}

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


[clang] [clang][dataflow] Add a test for result object location on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/85072

>From 7c61dc4872a1ffba8c241aa92bd87863f585e301 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 14 Mar 2024 08:46:06 +
Subject: [PATCH] [clang][dataflow] Fix `getResultObjectLocation()` on
 `CXXDefaultArgExpr`.

This patch includes a test that causes an assertion failure without the other
changes in this patch.
---
 .../FlowSensitive/DataflowEnvironment.cpp |  1 +
 clang/lib/Analysis/FlowSensitive/Transfer.cpp |  6 
 .../Analysis/FlowSensitive/TransferTest.cpp   | 30 +++
 3 files changed, 37 insertions(+)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 1d2bd9a9b08af3..cc1ebd511191a9 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -771,6 +771,7 @@ static bool isOriginalRecordConstructor(const Expr 
&RecordPRValue) {
 return !Init->isSemanticForm() || !Init->isTransparent();
   return isa(RecordPRValue) || isa(RecordPRValue) 
||
  isa(RecordPRValue) ||
+ isa(RecordPRValue) ||
  isa(RecordPRValue) ||
  // The framework currently does not propagate the objects created in
  // the two branches of a `ConditionalOperator` because there is no way
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 04aa2831df0558..ea166fcdb89e20 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -450,6 +450,12 @@ class TransferVisitor : public 
ConstStmtVisitor {
 Env.setStorageLocation(*S, *MemberLoc);
   }
 
+  void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
+const Expr *ArgExpr = S->getExpr();
+assert(ArgExpr != nullptr);
+propagateValueOrStorageLocation(*ArgExpr, *S, Env);
+  }
+
   void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
 const Expr *InitExpr = S->getExpr();
 assert(InitExpr != nullptr);
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index a8c282f140b4cd..86c7f32f0104be 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2924,6 +2924,36 @@ TEST(TransferTest, ResultObjectLocation) {
   });
 }
 
+TEST(TransferTest, ResultObjectLocationForDefaultArgExpr) {
+  std::string Code = R"(
+struct S {};
+void funcWithDefaultArg(S s = S());
+void target() {
+  funcWithDefaultArg();
+  // [[p]]
+}
+  )";
+
+  using ast_matchers::cxxDefaultArgExpr;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *DefaultArg = selectFirst(
+"default_arg",
+match(cxxDefaultArgExpr().bind("default_arg"), ASTCtx));
+ASSERT_NE(DefaultArg, nullptr);
+
+// The values for default arguments aren't modeled; we merely verify
+// that we can get a result object location for a default arg.
+Env.getResultObjectLocation(*DefaultArg);
+  });
+}
+
 TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) {
   std::string Code = R"(
 struct S {};

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


[clang] [clang][dataflow] Fix `getResultObjectLocation()` on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/85072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Fix `getResultObjectLocation()` on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/85072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Fix `getResultObjectLocation()` on `CXXDefaultArgExpr`. (PR #85072)

2024-03-14 Thread via cfe-commits

martinboehme wrote:

New commit pushed with fix. I have changed the title and description of the PR 
accordingly.

https://github.com/llvm/llvm-project/pull/85072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #81545)

2024-03-14 Thread William Junda Huang via cfe-commits

https://github.com/huangjd updated 
https://github.com/llvm/llvm-project/pull/81545

>From f2c82758e1cba7773e41d941d2812c829c339675 Mon Sep 17 00:00:00 2001
From: William Huang 
Date: Mon, 12 Feb 2024 02:27:13 -0500
Subject: [PATCH 1/4] Add option to generate additional info for expression
 containing pointer of pointers.

Such expression does correspond to a variable in the source code thus
does not have a debug location. However the user may want to collect
sampling counter for memory accesses to analyze usage frequency of class
members. By enabling -fdebug_info_for_pointer_type a psuedo variable and
its debug info is generated in place whenever there's an intermediate
expression with pointer access.
---
 clang/include/clang/Basic/DebugOptions.def |  4 ++
 clang/include/clang/Driver/Options.td  |  4 ++
 clang/lib/CodeGen/CGDebugInfo.cpp  | 16 +
 clang/lib/CodeGen/CGDebugInfo.h|  6 ++
 clang/lib/CodeGen/CGDecl.cpp   |  4 ++
 clang/lib/CodeGen/CGExpr.cpp   | 79 ++
 clang/lib/CodeGen/CodeGenFunction.h|  5 ++
 clang/lib/Driver/ToolChains/Clang.cpp  |  3 +
 8 files changed, 121 insertions(+)

diff --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index 7cd3edf08a17ea..6dd09f46842077 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -129,6 +129,10 @@ DEBUGOPT(CodeViewCommandLine, 1, 0)
 /// Whether emit extra debug info for sample pgo profile collection.
 DEBUGOPT(DebugInfoForProfiling, 1, 0)
 
+/// Whether to generate pseudo variables and their debug info for intermediate
+/// pointer accesses.
+DEBUGOPT(DebugInfoForPointerType, 1, 0)
+
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 DEBUGOPT(DebugNameTable, 2, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748faca..96b22d3f7640dd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1675,6 +1675,10 @@ defm debug_info_for_profiling : 
BoolFOption<"debug-info-for-profiling",
   PosFlag,
   NegFlag>;
+def fdebug_info_for_pointer_type : Flag<["-"], "fdebug-info-for-pointer-type">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Generate pseudo variables and their debug info for intermediate 
pointer accesses">,
+  MarshallingInfoFlag>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0f3f684d61dc94..6ce40da22dc97d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5636,6 +5636,22 @@ void 
CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+ SourceLocation Loc) {
+  llvm::DIFile *Unit = getOrCreateFile(Loc);
+  unsigned Line = getLineNumber(Loc);
+  unsigned Column = getColumnNumber(Loc);
+  llvm::DILocalVariable *D = DBuilder.createAutoVariable(
+  LexicalBlockStack.back(), Alloca->getName(), getOrCreateFile(Loc), Line,
+  getOrCreateType(Ty, Unit));
+  llvm::DILocation *DIL =
+  llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
+LexicalBlockStack.back(), CurInlinedAt);
+  SmallVector Expr;
+  DBuilder.insertDeclare(Alloca, D, DBuilder.createExpression(Expr), DIL,
+ Alloca->getParent());
+}
+
 void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
   const GlobalDecl GD) {
 
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 7b60e94555d060..a2c484f50b2bc5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -529,6 +529,12 @@ class CGDebugInfo {
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit debug information for a pseudo variable assigned to the value of an
+  /// intermediate expression, so that a performance counter can track the 
usage
+  /// of a specific expression of interest.
+  void EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+  SourceLocation Loc);
+
   /// Emit information about global variable alias.
   void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index bbe14ef4c17244..5f7b2529179003 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -793,6 +793,10 @@ void CodeGenFunct

[clang] [llvm] [RISC-V] Add CSR read/write builtins (PR #85091)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits

nemanjai wrote:

> I have always been unconvinced that these are a good idea to have / add 
> significant value over using inline assembly. IIRC Arm has them but nobody 
> uses them?

Is this a comment about the general concept of builtins to produce specific 
instructions or about these specific ones?
For these ones, the patch isn't something I materialized out of thin air just 
because I think it's nice to have - it was in response to the very use case I 
described (from a library writer). They had something like:
```
void __attribute__((always_inline)) set_csr(unsigned CSRNum, unsigned Val) {
__asm__ volatile ...
```
Which works great if you're optimizing, but doesn't with -O0. Of course they 
could write it as a macro, but that has all the pitfalls of function-style 
macros.

Of course, if the consensus is to not provide these because of some reason, I'm 
fine with that - I would just like to understand the reason for the opposition 
to this.

https://github.com/llvm/llvm-project/pull/85091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISC-V] Add CSR read/write builtins (PR #85091)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits


@@ -20,6 +20,12 @@ class RISCVBuiltin : 
TargetBuiltin {
 
 let Attributes = [NoThrow, Const] in {
 
//===--===//
+// Zicsr extension.
+//===--===//
+def csrr : RISCVBuiltin<"unsigned long int(unsigned long int)", "zicsr">;

nemanjai wrote:

I can certainly change it to `size_t`. And I'll move them out of the section 
marked with `Const`.

https://github.com/llvm/llvm-project/pull/85091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I looked at this a bit and the change that increases the constexpr 
> restrictions is that ext_defaulted_comparison_constexpr_mismatch (which was 
> added in https://reviews.llvm.org/D146090) became 
> err_incorrect_defaulted_comparison_constexpr?

Yes, it was intentional change. And the diagnostic you're seeing is valid for 
C++20. Prior C++23 defaulted function that invokes non-constexpr function under 
the hood cannot be marked constexpr. Since relaxing that was made in 
https://reviews.llvm.org/D146090 is a part of P2448R2, but other parts 
implemented by this patch are C++23-only due to the problems I described in 
https://github.com/llvm/llvm-project/pull/77753#issuecomment-1979028701 , I've 
made all parts of P2448R2 consistent.
I would suggest opening an issue here on GitHub to discuss whether we would 
like to make the feature inconsistent.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISC-V] Add CSR read/write builtins (PR #85091)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits


@@ -74,6 +74,21 @@ let TargetPrefix = "riscv" in {
 
 } // TargetPrefix = "riscv"
 
+let TargetPrefix = "riscv" in {
+  // Zicsr
+  def int_riscv_csrr :
+DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, 
ImmArg>]>;
+  def int_riscv_csrr64 :
+DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty],
+  [IntrNoMem, IntrHasSideEffects, 
ImmArg>]>;
+  def int_riscv_csrw :
+DefaultAttrsIntrinsic<[], [llvm_i32_ty, llvm_i32_ty],
+  [IntrNoMem, IntrHasSideEffects, 
ImmArg>]>;
+  def int_riscv_csrw64 :
+DefaultAttrsIntrinsic<[], [llvm_i64_ty, llvm_i64_ty],
+  [IntrNoMem, IntrHasSideEffects, 
ImmArg>]>;
+} // TargetPrefix = "riscv"

nemanjai wrote:

TBH, I only implemented these two initially for 2 reasons
1. The user that requested them only needs these for now
2. To validate the approach with the community

I think ultimately, we could provide read, write, set, clear and swap (and 
handle producing the immediate forms if the operand allows it).

https://github.com/llvm/llvm-project/pull/85091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Don't use crtbegin/crtend when building for musl. (PR #85089)

2024-03-14 Thread Alastair Houghton via cfe-commits

https://github.com/al45tair closed 
https://github.com/llvm/llvm-project/pull/85089
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Don't use crtbegin/crtend when building for musl. (PR #85089)

2024-03-14 Thread Alastair Houghton via cfe-commits

al45tair wrote:

Regardless of who provides them, if someone is relying on this then this is the 
wrong change. Closing.

https://github.com/llvm/llvm-project/pull/85089
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DRAFT][RISCV] Emit arch string macro to facilitate ASM programming (PR #85063)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits

https://github.com/nemanjai closed 
https://github.com/llvm/llvm-project/pull/85063
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [DRAFT][RISCV] Emit arch string macro to facilitate ASM programming (PR #85063)

2024-03-14 Thread Nemanja Ivanovic via cfe-commits

nemanjai wrote:

Ah, I missed the fact that there is an option `-riscv-add-build-attributes` 
that the clang driver passes when invoking `cc1as`.  Perhaps that option should 
default to `true`? Thanks and sorry for the noise.

https://github.com/llvm/llvm-project/pull/85063
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

2024-03-14 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Please add a more useful PR description, since that's useful for reviewers and 
ends up in the git log.

https://github.com/llvm/llvm-project/pull/85198
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

2024-03-14 Thread via cfe-commits

alexfh wrote:

I guess the reduction could have dropped some important parts of this. Let me 
try the original code with assertions-enabled clang build...

https://github.com/llvm/llvm-project/pull/83997
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [X86] Fast AVX-512-VNNI vpdpwssd tuning (PR #85033)

2024-03-14 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon requested changes to this pull request.

This patch needs to be cleanly rebased on trunk (force push is OK in PR branchs)

https://github.com/llvm/llvm-project/pull/85033
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add restriction for rldimi builtin (PR #85040)

2024-03-14 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/85040

>From 4977659b16a7f220e1a738a0b9841102fe9f1d07 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 13 Mar 2024 15:46:51 +0800
Subject: [PATCH] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins

rldimi is 64-bit instruction, so the corresponding builtin should not
be available in 32-bit mode. Rotate amount should be in range and
cases when mask is zero needs special handling.

This change also swaps the first and second operands of rldimi/rlwimi
to match previous behavior. For masks not ending at bit 63-SH,
rotation will be inserted before rldimi.
---
 clang/lib/Sema/SemaChecking.cpp   |  5 ++-
 .../PowerPC/builtins-ppc-xlcompat-error.c |  7 
 .../PowerPC/builtins-ppc-xlcompat-rotate.c| 22 +++-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   | 35 +++
 llvm/test/CodeGen/PowerPC/rlwimi.ll   |  3 +-
 5 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a5f42b630c3fa2..b032ea1db344a8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4992,6 +4992,7 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
   case PPC::BI__builtin_ppc_fetch_and_andlp:
   case PPC::BI__builtin_ppc_fetch_and_orlp:
   case PPC::BI__builtin_ppc_fetch_and_swaplp:
+  case PPC::BI__builtin_ppc_rldimi:
 return true;
   }
   return false;
@@ -5093,8 +5094,10 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI, unsigned BuiltinID,
   case PPC::BI__builtin_ppc_rlwnm:
 return SemaValueIsRunOfOnes(TheCall, 2);
   case PPC::BI__builtin_ppc_rlwimi:
+return SemaBuiltinConstantArgRange(TheCall, 2, 0, 31) ||
+   SemaValueIsRunOfOnes(TheCall, 3);
   case PPC::BI__builtin_ppc_rldimi:
-return SemaBuiltinConstantArg(TheCall, 2, Result) ||
+return SemaBuiltinConstantArgRange(TheCall, 2, 0, 63) ||
SemaValueIsRunOfOnes(TheCall, 3);
   case PPC::BI__builtin_ppc_addex: {
 if (SemaBuiltinConstantArgRange(TheCall, 2, 0, 3))
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
index 5f57d7575c859a..272e0222dc9e41 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c
@@ -24,13 +24,16 @@ void test_trap(void) {
   __tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid 
range [1, 31]}}
 }
 
+#ifdef __PPC64__
 void test_builtin_ppc_rldimi() {
   unsigned int shift;
   unsigned long long mask;
   unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, mask);// 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}
+  res = __builtin_ppc_rldimi(ull, ull, 64, 0x);  // 
expected-error {{argument value 64 is outside the valid range [0, 63]}}
 }
+#endif
 
 void test_builtin_ppc_rlwimi() {
   unsigned int shift;
@@ -83,6 +86,10 @@ void testalignx(const void *pointer, unsigned int alignment) 
{
 }
 
 #ifndef __PPC64__
+unsigned long long testrldimi32() {
+  return __rldimi(ull, ui, 3, 0x78ULL); //expected-error {{this builtin is 
only available on 64-bit targets}}
+}
+
 long long testbpermd(long long bit_selector, long long source) {
   return __bpermd(bit_selector, source); //expected-error {{this builtin is 
only available on 64-bit targets}}
 }
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
index b218547c00d931..4773d6cb1a0cfd 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
@@ -1,8 +1,10 @@
 // REQUIRES: powerpc-registered-target
 // RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
-// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s \
+// RUN:   -check-prefixes=PPC64,CHECK
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \
-// RUN:   -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s
+// RUN:   -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s \
+// RUN:   -check-prefixes=PPC64,CHECK
 // RUN: %clang_cc1 -triple powerpc-unknown-aix \
 // RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64-unknown-aix \
@@ -11,18 +13,20 @@
 extern unsigned int ui;
 extern unsigned long long ull;
 
+#ifdef __PPC64__
 void test_builtin_ppc_rldimi() {
-  // CHECK-LABEL: test_builtin_ppc_rldimi
-  // CHECK:   %res = alloca i64, align 8
-  // CHECK-

[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)

2024-03-14 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/85040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (PR #85040)

2024-03-14 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/85040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Prioritise built-in headers, even on musl. (PR #85092)

2024-03-14 Thread Alastair Houghton via cfe-commits

https://github.com/al45tair updated 
https://github.com/llvm/llvm-project/pull/85092

>From 527aa4616dc53f8f7ca212472fa40c23f40b6dc1 Mon Sep 17 00:00:00 2001
From: Alastair Houghton 
Date: Thu, 22 Feb 2024 11:33:32 +
Subject: [PATCH 1/2] [Clang] Prioritise built-in headers, even on musl.

Clang was putting its built-in headers at the end of the search path
if running on musl; this was a mistake, because it breaks libc++, as
the latter tries to include the built-in header and then the
`#include_next` in the built-in header fails.

The right solution here is to have the built-in headers remain in
their usual location in the search path, and then if it's desirable
to override them for musl, have them explicitly include the musl
header with `#include_next`.  This is the solution that is already
in use for other platforms.

rdar://118881637
---
 clang/lib/Basic/Targets/OSTargets.h   |  2 ++
 clang/lib/Driver/ToolChains/Linux.cpp | 22 +-
 clang/lib/Headers/float.h | 10 +++---
 clang/lib/Headers/stddef.h| 10 ++
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 4366c1149e4053..7c5ef420757ef3 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -331,6 +331,8 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 } else {
 Builder.defineMacro("__gnu_linux__");
 }
+if (Triple.isMusl())
+  Builder.defineMacro("__musl__", "1");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
 if (Opts.CPlusPlus)
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 6c2f23e57bce05..857cbb73240cf6 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -629,13 +629,20 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
 
   // Add 'include' in the resource directory, which is similar to
   // GCC_INCLUDE_DIR (private headers) in GCC. Note: the include directory
-  // contains some files conflicting with system /usr/include. musl systems
-  // prefer the /usr/include copies which are more relevant.
-  SmallString<128> ResourceDirInclude(D.ResourceDir);
-  llvm::sys::path::append(ResourceDirInclude, "include");
-  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
-  (!getTriple().isMusl() || DriverArgs.hasArg(options::OPT_nostdlibinc)))
+  // contains some files conflicting with system /usr/include.
+  //
+  // Note: the include order used to be different on musl systems because
+  // of the expectation that that users of that C library would use the
+  // C library's copies of the "built-in" headers.  This was a mistake;
+  // it's better to adapt the built-in headers to fall through in that case
+  // (using #include_next), since otherwise if they get pulled in through
+  // some other mechanism, __has_include_next() will fail and then
+  // they'll try to redefine things, which causes errors.
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> ResourceDirInclude(D.ResourceDir);
+llvm::sys::path::append(ResourceDirInclude, "include");
 addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+  }
 
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
@@ -676,9 +683,6 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
   addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
 
   addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, 
"/usr/include"));
-
-  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl())
-addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
 }
 
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
diff --git a/clang/lib/Headers/float.h b/clang/lib/Headers/float.h
index 0e73bca0a2d6e4..715a4eb54b54a4 100644
--- a/clang/lib/Headers/float.h
+++ b/clang/lib/Headers/float.h
@@ -10,15 +10,11 @@
 #ifndef __CLANG_FLOAT_H
 #define __CLANG_FLOAT_H
 
-/* If we're on MinGW, fall back to the system's float.h, which might have
- * additional definitions provided for Windows.
- * For more details see http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx
- *
- * Also fall back on Darwin and AIX to allow additional definitions and
- * implementation-defined values.
+/* On various platforms, fall back to the system's float.h, which might have
+ * additional definitions and/or implementation-defined values.
  */
 #if (defined(__APPLE__) || defined(__MINGW32__) || defined(_MSC_VER) ||
\
- defined(_AIX)) && 
\
+ defined(_AIX) || defined(__musl__)) &&
\
 __STDC_HOSTED__ && __has_include_next()
 
 /* Prior to Apple's 10.7 SDK, float.h SDK header used to apply an extra level
diff --git a/clang/lib/Headers/stddef.h 

[clang] [llvm] [AArch64] Remove Automatic Enablement of FEAT_F32MM (PR #85203)

2024-03-14 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 created 
https://github.com/llvm/llvm-project/pull/85203

When `+sve` is passed in the command line, if the Architecture being targeted 
is V8.6A/V9.1A or later, `+f32mm` is also added. This enables FEAT_32MM, 
however at the time of writing no CPU's support this. This leads to the 
FEAT_32MM instructions being compiled for CPU's that do not support them.

This commit removes the automatic enablement, however the option is still able 
to be used by passing `+f32mm`.

>From b5a0ad5d4b7ab3510cd00d178da245761e34d32d Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Thu, 14 Mar 2024 10:06:05 +
Subject: [PATCH] [AArch64] Remove Automatic Enablement of FEAT_F32MM

When `+sve` is passed in the command line, if the Architecture being targeted 
is V8.6A/V9.1A or later, `+f32mm` is also added. This enables FEAT_32MM, 
however at the time of writing no CPU's support this. This leads to the 
FEAT_32MM instructions being compiled for CPU's that do not support them.

This commit removes the automatic enablement, however the option is still able 
to be used by passing `+f32mm`.
---
 clang/test/Driver/aarch64-sve.c   | 9 -
 clang/test/Preprocessor/aarch64-target-features.c | 2 +-
 llvm/docs/ReleaseNotes.rst| 1 +
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 5 -
 llvm/unittests/TargetParser/TargetParserTest.cpp  | 9 +
 5 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/clang/test/Driver/aarch64-sve.c b/clang/test/Driver/aarch64-sve.c
index f34b2700deb91c..4a33c2e3c8d367 100644
--- a/clang/test/Driver/aarch64-sve.c
+++ b/clang/test/Driver/aarch64-sve.c
@@ -6,12 +6,11 @@
 // RUN: %clang --target=aarch64 -march=armv8.6a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV8A-NOSVE %s
 // GENERICV8A-NOSVE-NOT: "-target-feature" "+sve"
 
-// The 32-bit floating point matrix multiply extension is enabled by default
-// for armv8.6-a targets (or later) with SVE, and can optionally be enabled for
-// any target from armv8.2a onwards (we don't enforce not using it with earlier
-// targets).
+// The 32-bit floating point matrix multiply extension is an optional feature
+// that can be used for any target from armv8.2a and onwards. This can be
+// enabled using the `+f32mm` option.`.
 // RUN: %clang --target=aarch64 -march=armv8.6a   -### -c %s 2>&1 | 
FileCheck -check-prefix=NO-F32MM %s
-// RUN: %clang --target=aarch64 -march=armv8.6a+sve   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
+// RUN: %clang --target=aarch64 -march=armv8.6a+sve+f32mm   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // RUN: %clang --target=aarch64 -march=armv8.5a+f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // NO-F32MM-NOT: "-target-feature" "+f32mm"
 // F32MM: "-target-feature" "+f32mm"
diff --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 6ec4dcd60cf601..ab06cc7983ae85 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -196,7 +196,7 @@
 // CHECK-8_6-NOT: __ARM_FEATURE_SHA3 1
 // CHECK-8_6-NOT: __ARM_FEATURE_SM4 1
 
-// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+f32mm -x c 
-E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_BF16 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_MATMUL_FP32 1
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7be51730663bd1..b65a108a9b6a36 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -74,6 +74,7 @@ Changes to the AMDGPU Backend
 
 Changes to the ARM Backend
 --
+* FEAT_F32MM is no longer activated by default when using `+sve` on v8.6-A or 
greater. The feature is still availble and can be using by adding `+f32mm` to 
the command line options.
 
 Changes to the AVR Backend
 --
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp 
b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index e36832f563eed8..71099462d5ecff 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -186,11 +186,6 @@ void AArch64::ExtensionSet::enable(ArchExtKind E) {
   // Special cases for dependencies which vary depending on the base
   // architecture version.
   if (BaseArch) {
-// +sve implies +f32mm if the base architecture is v8.6A+ or v9.1A+
-// It isn't the case in general that sve implies both f64mm and f32mm
-if (E == AEK_SVE && BaseArch->is_superset(ARMV8_6A))
-  enable(AEK_F32MM);
-
 // +fp16 implies +fp16fml for v8.4A+, but not v9.0-A+
 if (E == AEK_FP16 && BaseArch->is_superset(ARMV8_4A) &&
 !BaseArch->is_superset(ARMV9A))
diff --git a/llvm/unitte

[clang] [llvm] [AArch64] Remove Automatic Enablement of FEAT_F32MM (PR #85203)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Jack Styles (Stylie777)


Changes

When `+sve` is passed in the command line, if the Architecture being targeted 
is V8.6A/V9.1A or later, `+f32mm` is also added. This enables FEAT_32MM, 
however at the time of writing no CPU's support this. This leads to the 
FEAT_32MM instructions being compiled for CPU's that do not support them.

This commit removes the automatic enablement, however the option is still able 
to be used by passing `+f32mm`.

---
Full diff: https://github.com/llvm/llvm-project/pull/85203.diff


5 Files Affected:

- (modified) clang/test/Driver/aarch64-sve.c (+4-5) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (+1-1) 
- (modified) llvm/docs/ReleaseNotes.rst (+1) 
- (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (-5) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+1-8) 


``diff
diff --git a/clang/test/Driver/aarch64-sve.c b/clang/test/Driver/aarch64-sve.c
index f34b2700deb91c..4a33c2e3c8d367 100644
--- a/clang/test/Driver/aarch64-sve.c
+++ b/clang/test/Driver/aarch64-sve.c
@@ -6,12 +6,11 @@
 // RUN: %clang --target=aarch64 -march=armv8.6a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV8A-NOSVE %s
 // GENERICV8A-NOSVE-NOT: "-target-feature" "+sve"
 
-// The 32-bit floating point matrix multiply extension is enabled by default
-// for armv8.6-a targets (or later) with SVE, and can optionally be enabled for
-// any target from armv8.2a onwards (we don't enforce not using it with earlier
-// targets).
+// The 32-bit floating point matrix multiply extension is an optional feature
+// that can be used for any target from armv8.2a and onwards. This can be
+// enabled using the `+f32mm` option.`.
 // RUN: %clang --target=aarch64 -march=armv8.6a   -### -c %s 2>&1 | 
FileCheck -check-prefix=NO-F32MM %s
-// RUN: %clang --target=aarch64 -march=armv8.6a+sve   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
+// RUN: %clang --target=aarch64 -march=armv8.6a+sve+f32mm   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // RUN: %clang --target=aarch64 -march=armv8.5a+f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // NO-F32MM-NOT: "-target-feature" "+f32mm"
 // F32MM: "-target-feature" "+f32mm"
diff --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 6ec4dcd60cf601..ab06cc7983ae85 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -196,7 +196,7 @@
 // CHECK-8_6-NOT: __ARM_FEATURE_SHA3 1
 // CHECK-8_6-NOT: __ARM_FEATURE_SM4 1
 
-// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+f32mm -x c 
-E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_BF16 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_MATMUL_FP32 1
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7be51730663bd1..b65a108a9b6a36 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -74,6 +74,7 @@ Changes to the AMDGPU Backend
 
 Changes to the ARM Backend
 --
+* FEAT_F32MM is no longer activated by default when using `+sve` on v8.6-A or 
greater. The feature is still availble and can be using by adding `+f32mm` to 
the command line options.
 
 Changes to the AVR Backend
 --
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp 
b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index e36832f563eed8..71099462d5ecff 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -186,11 +186,6 @@ void AArch64::ExtensionSet::enable(ArchExtKind E) {
   // Special cases for dependencies which vary depending on the base
   // architecture version.
   if (BaseArch) {
-// +sve implies +f32mm if the base architecture is v8.6A+ or v9.1A+
-// It isn't the case in general that sve implies both f64mm and f32mm
-if (E == AEK_SVE && BaseArch->is_superset(ARMV8_6A))
-  enable(AEK_F32MM);
-
 // +fp16 implies +fp16fml for v8.4A+, but not v9.0-A+
 if (E == AEK_FP16 && BaseArch->is_superset(ARMV8_4A) &&
 !BaseArch->is_superset(ARMV9A))
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 3773f59a3c5af9..a21846f5b4940b 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2314,13 +2314,6 @@ AArch64ExtensionDependenciesBaseArchTestParams
  {},
  {"aes", "sha2", "sha3", "sm4"}},
 
-// +sve implies +f32mm if the base architecture is v8.6A+ or v9.1A+, 
but
-// not earlier architectures.
-{AArch64::ARMV8_5A, {"sve"}, {"sve"}, {"f32mm"}},

[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 5614f89c90cf865c88fbcf95d707e34dfeb18a19 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 77 +--
 2 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..afdb589536c969 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == '--clspv':
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -250,14 +257,19 @@ def generate_default_conversion(src, dst, mode):
 if close_conditional:
 print("#endif")
 
-
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +319,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC

[clang] [llvm] [AArch64] Remove Automatic Enablement of FEAT_F32MM (PR #85203)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff afec257d369a13893b39d02bc630f9f3cec80162 
b5a0ad5d4b7ab3510cd00d178da245761e34d32d -- clang/test/Driver/aarch64-sve.c 
clang/test/Preprocessor/aarch64-target-features.c 
llvm/lib/TargetParser/AArch64TargetParser.cpp 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index a21846f5b4..4bd52d3782 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2480,10 +2480,10 @@ AArch64ExtensionDependenciesBaseCPUTestParams
  {}},
 {"cortex-a520",
  {},
- {"v9.2a","bf16", "crc", "dotprod","flagm",
-  "fp-armv8", "fullfp16", "fp16fml", "i8mm","lse",  "mte",
-  "pauth","perfmon",  "predres", "ras", "rcpc", "rdm",
-  "sb",   "neon", "ssbs","sve", "sve2-bitperm", 
"sve2"},
+ {"v9.2a","bf16","crc",  "dotprod",  "flagm", "fp-armv8",
+  "fullfp16", "fp16fml", "i8mm", "lse",  "mte",   "pauth",
+  "perfmon",  "predres", "ras",  "rcpc", "rdm",   "sb",
+  "neon", "ssbs","sve",  "sve2-bitperm", "sve2"},
  {}},
 
 // Negative modifiers

``




https://github.com/llvm/llvm-project/pull/85203
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr edited 
https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr edited 
https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-14 Thread Kishan Parmar via cfe-commits


@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+ArgGPRsLeft -= TypeSize / RegLen;
+return handleComplex(TypeSize);
+  }
+
+  if (ArgGPRsLeft) {
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (isAggregateTypeForABI(Ty))
+  ArgGPRsLeft -= 1;
+else if (!Ty->isFloatingType()) {
+  // For other premitive types.
+  if (TypeSize > RegLen && TypeSize <= 2 * RegLen)
+ArgGPRsLeft -= TypeSize / RegLen;

Long5hot wrote:

llvm powerpc backend takes care of that. 
refer CC_PPC32_SVR4_Custom_AlignArgRegs method from PPCCallingconvention.cpp 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCCallingConv.cpp#L80

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-14 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot edited 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
0f1847cb2c5462a09d65a9b5ac24904ac3c15a0f...5614f89c90cf865c88fbcf95d707e34dfeb18a19
 libclc/generic/lib/gen_convert.py
``





View the diff from darker here.


``diff
--- gen_convert.py  2024-03-14 10:17:28.00 +
+++ gen_convert.py  2024-03-14 10:29:40.440233 +
@@ -28,11 +28,11 @@
 # convert_<_sat><_roundingMode>()
 
 import sys
 
 clspv = False
-if len(sys.argv) == 2 and sys.argv[1] == '--clspv':
+if len(sys.argv) == 2 and sys.argv[1] == "--clspv":
 clspv = True
 
 types = [
 "char",
 "uchar",
@@ -255,10 +255,11 @@
 )
 
 if close_conditional:
 print("#endif")
 
+
 # Do not generate default conversion for clspv as they are handle natively
 if not clspv:
 for src in types:
 for dst in types:
 generate_default_conversion(src, dst, "")
@@ -462,11 +463,15 @@
 )
 else:
 print("  {SRC}{N} abs_x = fabs(x);".format(SRC=src, N=size))
 print("  {SRC}{N} abs_y = fabs(y);".format(SRC=src, N=size))
 if clspv:
-print("  {BOOL}{N} c = convert_{BOOL}{N}(abs_y > 
abs_x);".format(BOOL=bool_type[dst], N=size))
+print(
+"  {BOOL}{N} c = convert_{BOOL}{N}(abs_y > abs_x);".format(
+BOOL=bool_type[dst], N=size
+)
+)
 if sizeof_type[src] >= 4 and src in int_types:
 print(
 "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
x);".format(
 BOOL=bool_type[dst], N=size, SRC=src, 
SRC_MAX=limit_max[src]
 )
@@ -488,11 +493,15 @@
 DST=dst, N=size, BOOL=bool_type[dst]
 )
 )
 if mode == "_rtn":
 if clspv:
-print("  {BOOL}{N} c = convert_{BOOL}{N}(y > 
x);".format(BOOL=bool_type[dst], N=size))
+print(
+"  {BOOL}{N} c = convert_{BOOL}{N}(y > x);".format(
+BOOL=bool_type[dst], N=size
+)
+)
 if sizeof_type[src] >= 4 and src in int_types:
 print(
 "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
x);".format(
 BOOL=bool_type[dst], N=size, SRC=src, 
SRC_MAX=limit_max[src]
 )

``




https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From a6146bbc90d198d62d516bf09a41034f36f7866c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 77 +--
 2 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..afdb589536c969 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == '--clspv':
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -250,14 +257,19 @@ def generate_default_conversion(src, dst, mode):
 if close_conditional:
 print("#endif")
 
-
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +319,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC

[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 8d2b49e198feb8ec3d836b871178b14c161c4d5d Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 84 +--
 2 files changed, 83 insertions(+), 16 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..768f0200999b79 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == "--clspv":
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -251,13 +258,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +320,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
   re

[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

2024-03-14 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> Please add a more useful PR description, since that's useful for reviewers 
> and ends up in the git log.

Thanks for your remind! I am waiting for CI to finish and after that I will add 
the description. Maybe mark it with draft would be better.

https://github.com/llvm/llvm-project/pull/85198
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

2024-03-14 Thread via cfe-commits

alexfh wrote:

It turns out debug build of clang before this patch generated an assertion on 
the original code as well:
```
assert.h assertion failed at llvm-project/clang/lib/AST/ExprConstant.cpp:15739 
in bool clang::Expr::EvaluateAsConstantExpr(EvalResult &, const ASTContext &, 
ConstantExprKind) const: !isValueDependent() && "Expression evaluator can't be 
called on a dependent expression."
...
@ 0x5643bcdac9e4  __assert_fail
@ 0x5643b9734df7  clang::Expr::EvaluateAsConstantExpr()
@ 0x5643b89f7fea  calculateConstraintSatisfaction<>()
@ 0x5643b89f1bcf  CheckConstraintSatisfaction()
@ 0x5643b89f193e  clang::Sema::CheckConstraintSatisfaction()
@ 0x5643b90d9f23  clang::Sema::CheckConceptTemplateId()
@ 0x5643b9259656  
clang::TreeTransform<>::TransformConceptSpecializationExpr()
@ 0x5643b925ce00  clang::TreeTransform<>::TransformCXXFoldExpr()
@ 0x5643b924b6e0  clang::Sema::SubstConstraintExpr()
@ 0x5643b89f9097  calculateConstraintSatisfaction()::$_0::operator()()
@ 0x5643b89f7f50  calculateConstraintSatisfaction<>()
@ 0x5643b89f1bcf  CheckConstraintSatisfaction()
@ 0x5643b89f193e  clang::Sema::CheckConstraintSatisfaction()
@ 0x5643b9237c6d  FinishTemplateArgumentDeduction<>()
@ 0x5643b9236cd2  llvm::function_ref<>::callback_fn<>()
@ 0x5643b888fa2f  clang::Sema::runWithSufficientStackSpace()
@ 0x5643b91c2e17  clang::Sema::DeduceTemplateArguments()
@ 0x5643b9248e19  clang::Sema::InstantiateClassTemplateSpecialization()
@ 0x5643b9334e73  llvm::function_ref<>::callback_fn<>()
@ 0x5643b888fa2f  clang::Sema::runWithSufficientStackSpace()
@ 0x5643b931fdc4  clang::Sema::RequireCompleteTypeImpl()
@ 0x5643b931f535  clang::Sema::RequireCompleteType()
@ 0x5643b891bad7  clang::Sema::RequireCompleteDeclContext()
@ 0x5643b90eda4d  clang::Sema::CheckTypenameType()
@ 0x5643b926edd2  clang::TreeTransform<>::TransformDependentNameType()
@ 0x5643b9243d1c  clang::TreeTransform<>::TransformType()
@ 0x5643b92436ff  clang::TreeTransform<>::TransformType()
@ 0x5643b9244293  clang::Sema::SubstType()
@ 0x5643b90d0e8a  clang::Sema::CheckTemplateIdType()
@ 0x5643b90d5015  clang::Sema::ActOnTemplateIdType()
@ 0x5643b8674084  clang::Parser::AnnotateTemplateIdTokenAsType()
@ 0x5643b86536cf  clang::Parser::ParseDeclarationSpecifiers()
@ 0x5643b864fffa  clang::Parser::ParseSpecifierQualifierList()
@ 0x5643b863da31  clang::Parser::ParseTypeName()
@ 0x5643b86262bd  clang::Parser::ParseAliasDeclarationAfterDeclarator()
@ 0x5643b8624ea0  clang::Parser::ParseUsingDeclaration()
@ 0x5643b8623e70  clang::Parser::ParseUsingDirectiveOrDeclaration()
@ 0x5643b864b6ef  clang::Parser::ParseDeclaration()
@ 0x5643b868a9a4  
clang::Parser::ParseStatementOrDeclarationAfterAttributes()
@ 0x5643b8689d78  clang::Parser::ParseStatementOrDeclaration()
@ 0x5643b8693bc0  clang::Parser::ParseCompoundStatementBody()
@ 0x5643b8694bce  clang::Parser::ParseFunctionStatementBody()
@ 0x5643b85da8ad  clang::Parser::ParseFunctionDefinition()
@ 0x5643b864df89  clang::Parser::ParseDeclGroup()
@ 0x5643b85d8ec9  clang::Parser::ParseDeclOrFunctionDefInternal()
@ 0x5643b85d868e  clang::Parser::ParseDeclarationOrFunctionDefinition()
@ 0x5643b85d7434  clang::Parser::ParseExternalDeclaration()
@ 0x5643b8622693  clang::Parser::ParseInnerNamespace()
@ 0x5643b8621893  clang::Parser::ParseNamespace()
@ 0x5643b864b7de  clang::Parser::ParseDeclaration()
@ 0x5643b85d6fb6  clang::Parser::ParseExternalDeclaration()
@ 0x5643b85d516b  clang::Parser::ParseTopLevelDecl()
@ 0x5643b85ceebe  clang::ParseAST()
@ 0x5643b831a4c3  clang::FrontendAction::Execute()
@ 0x5643b8294efd  clang::CompilerInstance::ExecuteAction()
@ 0x5643b717f84e  clang::ExecuteCompilerInvocation()
@ 0x5643b71737c6  cc1_main()
@ 0x5643b7171066  ExecuteCC1Tool()
@ 0x5643b843fe3e  llvm::function_ref<>::callback_fn<>()
@ 0x5643bcc44415  llvm::CrashRecoveryContext::RunSafely()
@ 0x5643b843f5bb  clang::driver::CC1Command::Execute()
@ 0x5643b8400494  clang::driver::Compilation::ExecuteCommand()
@ 0x5643b84007af  clang::driver::Compilation::ExecuteJobs()
@ 0x5643b841ea80  clang::driver::Driver::ExecuteCompilation()
@ 0x5643b717061b  clang_main()
@ 0x5643b716d834  main
```

I'll try to figure out what's wrong with the original code.

https://github.com/llvm/llvm-project/pull/83997
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Remove Automatic Enablement of FEAT_F32MM (PR #85203)

2024-03-14 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 updated 
https://github.com/llvm/llvm-project/pull/85203

>From 276e3421de7ebe2e2a9a2feb02d585bf3d4e8915 Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Thu, 14 Mar 2024 10:43:22 +
Subject: [PATCH] [AArch64] Remove Automatic Enablement of FEAT_F32MM

When `+sve` is passed in the command line, if the Architecture being targeted 
is V8.6A/V9.1A or later, `+f32mm` is also added. This enables FEAT_32MM, 
however at the time of writing no CPU's support this. This leads to the 
FEAT_32MM instructions being compiled for CPU's that do not support them.

This commit removes the automatic enablement, however the option is still able 
to be used by passing `+f32mm`.
---
 clang/test/Driver/aarch64-sve.c   |  9 -
 clang/test/Preprocessor/aarch64-target-features.c |  2 +-
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  5 -
 llvm/unittests/TargetParser/TargetParserTest.cpp  | 15 ---
 5 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/test/Driver/aarch64-sve.c b/clang/test/Driver/aarch64-sve.c
index f34b2700deb91c..4a33c2e3c8d367 100644
--- a/clang/test/Driver/aarch64-sve.c
+++ b/clang/test/Driver/aarch64-sve.c
@@ -6,12 +6,11 @@
 // RUN: %clang --target=aarch64 -march=armv8.6a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV8A-NOSVE %s
 // GENERICV8A-NOSVE-NOT: "-target-feature" "+sve"
 
-// The 32-bit floating point matrix multiply extension is enabled by default
-// for armv8.6-a targets (or later) with SVE, and can optionally be enabled for
-// any target from armv8.2a onwards (we don't enforce not using it with earlier
-// targets).
+// The 32-bit floating point matrix multiply extension is an optional feature
+// that can be used for any target from armv8.2a and onwards. This can be
+// enabled using the `+f32mm` option.`.
 // RUN: %clang --target=aarch64 -march=armv8.6a   -### -c %s 2>&1 | 
FileCheck -check-prefix=NO-F32MM %s
-// RUN: %clang --target=aarch64 -march=armv8.6a+sve   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
+// RUN: %clang --target=aarch64 -march=armv8.6a+sve+f32mm   -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // RUN: %clang --target=aarch64 -march=armv8.5a+f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=F32MM %s
 // NO-F32MM-NOT: "-target-feature" "+f32mm"
 // F32MM: "-target-feature" "+f32mm"
diff --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 6ec4dcd60cf601..ab06cc7983ae85 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -196,7 +196,7 @@
 // CHECK-8_6-NOT: __ARM_FEATURE_SHA3 1
 // CHECK-8_6-NOT: __ARM_FEATURE_SM4 1
 
-// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve -x c -E -dM 
%s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.6-a+sve+f32mm -x c 
-E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE-8_6 %s
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_BF16 1
 // CHECK-SVE-8_6: __ARM_FEATURE_SVE_MATMUL_FP32 1
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7be51730663bd1..b65a108a9b6a36 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -74,6 +74,7 @@ Changes to the AMDGPU Backend
 
 Changes to the ARM Backend
 --
+* FEAT_F32MM is no longer activated by default when using `+sve` on v8.6-A or 
greater. The feature is still availble and can be using by adding `+f32mm` to 
the command line options.
 
 Changes to the AVR Backend
 --
diff --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp 
b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index e36832f563eed8..71099462d5ecff 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -186,11 +186,6 @@ void AArch64::ExtensionSet::enable(ArchExtKind E) {
   // Special cases for dependencies which vary depending on the base
   // architecture version.
   if (BaseArch) {
-// +sve implies +f32mm if the base architecture is v8.6A+ or v9.1A+
-// It isn't the case in general that sve implies both f64mm and f32mm
-if (E == AEK_SVE && BaseArch->is_superset(ARMV8_6A))
-  enable(AEK_F32MM);
-
 // +fp16 implies +fp16fml for v8.4A+, but not v9.0-A+
 if (E == AEK_FP16 && BaseArch->is_superset(ARMV8_4A) &&
 !BaseArch->is_superset(ARMV9A))
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 3773f59a3c5af9..4bd52d37826fbd 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -2314,13 +2314,6 @@ AArch64ExtensionDependenciesBaseArchTestParams
  {},
  {"aes", "sha2", "sha3", "sm4"}},
 
-// +sve implies +f32

[clang] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [X86] Fast AVX-512-VNNI vpdpwssd tuning (PR #85033)

2024-03-14 Thread via cfe-commits

ganeshgit wrote:

> This patch needs to be cleanly rebased on trunk (force push is OK in PR 
> branchs)
I think my overnight rebase scripts screwed the fixups. I will close this and I 
will raise a new pull request. 

https://github.com/llvm/llvm-project/pull/85033
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Kévin Petit via cfe-commits


@@ -251,13 +258,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle

kpet wrote:

```suggestion
# Do not generate "_rte" conversion for clspv as they are handled
```

https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Kévin Petit via cfe-commits


@@ -484,4 +536,8 @@ def generate_float_conversion(src, dst, size, mode, sat):
 for dst in float_types:
 for size in vector_sizes:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are
+# handle natively

kpet wrote:

```suggestion
# handled natively
```

https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Kévin Petit via cfe-commits


@@ -251,13 +258,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively

kpet wrote:

```suggestion
# Do not generate default conversion for clspv as they are handled natively
```

https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Kévin Petit via cfe-commits


@@ -307,8 +320,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});

kpet wrote:

Did you intend to change these lines? If yes and the change applies 
independently of the clspv mode, this looks like a standalone bugfix.

https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Kévin Petit via cfe-commits


@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == "--clspv":
+clspv = True
+

kpet wrote:

```suggestion
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--clspv', help="Generate the clspv variant of the code")
args = parser.parse_args()
clspv = args.clspv
```
It's not that much more code and will be easier to maintain, use, and extend. 

https://github.com/llvm/llvm-project/pull/66902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4299c72 - AArch64: add __builtin_arm_trap

2024-03-14 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2024-03-14T11:32:44Z
New Revision: 4299c727e4806aa55398ad23da48a401554cd432

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

LOG: AArch64: add __builtin_arm_trap

It's useful to provide an indicator code with the trap, which the generic
__builtin_trap can't do. asm("brk #N") is an option, but following that with a
__builtin_unreachable() leads to two traps when the compiler doesn't know the
block can't return. So compiler support like this is useful.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-arm64.c
clang/test/Sema/builtins-arm64.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca..9347703e96e21a 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3443,6 +3443,21 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_arm_trap``
+--
+
+``__builtin_arm_trap`` is an AArch64 extension to ``__builtin_trap`` which 
also accepts a compile-time constant value, encoded directly into the trap 
instruction for later inspection.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_arm_trap(const unsigned short payload)
+
+**Description**
+
+``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
+
 ``__builtin_nondeterministic_value``
 
 

diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index b5cbe90c8fd6a3..cf8711c6eaee37 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -50,6 +50,9 @@ BUILTIN(__builtin_arm_wfi, "v", "")
 BUILTIN(__builtin_arm_sev, "v", "")
 BUILTIN(__builtin_arm_sevl, "v", "")
 
+// Like __builtin_trap but provide an 16-bit immediate reason code (which goes 
into `brk #N`).
+BUILTIN(__builtin_arm_trap, "vUIs", "nr")
+
 // CRC32
 TARGET_BUILTIN(__builtin_arm_crc32b, "UiUiUc", "nc", "crc")
 TARGET_BUILTIN(__builtin_arm_crc32cb, "UiUiUc", "nc", "crc")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 93ab465079777b..528a13fb275124 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10686,6 +10686,12 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID));
   }
 
+  if (BuiltinID == clang::AArch64::BI__builtin_arm_trap) {
+Function *F = CGM.getIntrinsic(Intrinsic::aarch64_break);
+llvm::Value *Arg = EmitScalarExpr(E->getArg(0));
+return Builder.CreateCall(F, Builder.CreateZExt(Arg, CGM.Int32Ty));
+  }
+
   if (BuiltinID == clang::AArch64::BI__builtin_arm_get_sme_state) {
 // Create call to __arm_sme_state and store the results to the two 
pointers.
 CallInst *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(

diff  --git a/clang/test/CodeGen/builtins-arm64.c 
b/clang/test/CodeGen/builtins-arm64.c
index 05ea1c719edff3..8bd68d9ceb48ec 100644
--- a/clang/test/CodeGen/builtins-arm64.c
+++ b/clang/test/CodeGen/builtins-arm64.c
@@ -156,4 +156,10 @@ int rndrrs(uint64_t *__addr) {
   return __builtin_arm_rndrrs(__addr);
 }
 
+// CHECK-LABEL: @trap(
+// CHECK: call void @llvm.aarch64.break(i32 42)
+void trap() {
+  __builtin_arm_trap(42);
+}
+
 // CHECK: ![[M0]] = !{!"1:2:3:4:5"}

diff  --git a/clang/test/Sema/builtins-arm64.c 
b/clang/test/Sema/builtins-arm64.c
index e711121f7260ff..f094162b3aadc9 100644
--- a/clang/test/Sema/builtins-arm64.c
+++ b/clang/test/Sema/builtins-arm64.c
@@ -29,3 +29,12 @@ void test_prefetch(void) {
   __builtin_arm_prefetch(0, 0, 0, 2, 0); // expected-error-re {{argument value 
{{.*}} is outside the valid range}}
   __builtin_arm_prefetch(0, 0, 0, 0, 2); // expected-error-re {{argument value 
{{.*}} is outside the valid range}}
 }
+
+void test_trap(short s, unsigned short us) {
+  __builtin_arm_trap(42);
+  __builtin_arm_trap(65535);
+  __builtin_arm_trap(-1);
+  __builtin_arm_trap(65536); // expected-warning {{implicit conversion from 
'int' to 'unsigned short' changes value from 65536 to 0}}
+  __builtin_arm_trap(s); // expected-error {{argument to '__builtin_arm_trap' 
must be a constant integer}}
+  __builtin_arm_trap(us); // expected-error {{argument to '__builtin_arm_trap' 
must be a constant integer}}
+}
\ No newline at end of file



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

[clang] AArch64: add __builtin_arm_trap (PR #85054)

2024-03-14 Thread Tim Northover via cfe-commits

https://github.com/TNorthover closed 
https://github.com/llvm/llvm-project/pull/85054
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] AArch64: add __builtin_arm_trap (PR #85054)

2024-03-14 Thread Tim Northover via cfe-commits

TNorthover wrote:

Thanks. Good idea on the docs, I've added some wording and pushed the change 
(4299c727e480)

https://github.com/llvm/llvm-project/pull/85054
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)

2024-03-14 Thread Roberto Bampi via cfe-commits

https://github.com/gigaroby updated 
https://github.com/llvm/llvm-project/pull/84346

>From f65709e2a353fa19919df291d6c3a60f5e1d1bd4 Mon Sep 17 00:00:00 2001
From: Roberto Bampi 
Date: Thu, 7 Mar 2024 18:10:56 +0100
Subject: [PATCH 1/2] [clang-format] Add --fail-on-incomplete-format.

At the moment clang-format will return exit code 0 on incomplete
results. In scripts it would sometimes be useful if clang-format would
instead fail in those cases, signalling that there was something wrong
with the code being formatted.
---
 clang/docs/ClangFormat.rst   |  1 +
 clang/tools/clang-format/ClangFormat.cpp | 14 +++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 819d9ee9f9cde1..80dc38a075c8fc 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -61,6 +61,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
 --dry-run  - If set, do not actually make the 
formatting changes
 --dump-config  - Dump configuration options to stdout and 
exit.
  Can be used with -style option.
+--fail-on-incomplete-format- If set, fail with exit code 1 on 
incomplete format.
 --fallback-style=  - The name of the predefined style used as a
  fallback in case clang-format is invoked 
with
  -style=file, but can not find the 
.clang-format
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index e122cea50f7268..58027af5d9e091 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -205,6 +205,11 @@ static cl::list FileNames(cl::Positional,
cl::desc("[@] [ ...]"),
cl::cat(ClangFormatCategory));
 
+static cl::opt FailOnIncompleteFormat(
+"fail-on-incomplete-format",
+cl::desc("If set, fail with exit code 1 on incomplete format."),
+cl::init(false), cl::cat(ClangFormatCategory));
+
 namespace clang {
 namespace format {
 
@@ -399,7 +404,7 @@ class ClangFormatDiagConsumer : public DiagnosticConsumer {
 };
 
 // Returns true on error.
-static bool format(StringRef FileName) {
+static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
   const bool IsSTDIN = FileName == "-";
   if (!OutputXML && Inplace && IsSTDIN) {
 errs() << "error: cannot use -i when reading from stdin.\n";
@@ -535,6 +540,9 @@ static bool format(StringRef FileName) {
   Rewrite.getEditBuffer(ID).write(outs());
 }
   }
+  if (ErrorOnIncompleteFormat && !Status.FormatComplete)
+return true;
+
   return false;
 }
 
@@ -699,7 +707,7 @@ int main(int argc, const char **argv) {
   }
 
   if (FileNames.empty())
-return clang::format::format("-");
+return clang::format::format("-", FailOnIncompleteFormat);
 
   if (FileNames.size() > 1 &&
   (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
@@ -717,7 +725,7 @@ int main(int argc, const char **argv) {
   errs() << "Formatting [" << FileNo++ << "/" << FileNames.size() << "] "
  << FileName << "\n";
 }
-Error |= clang::format::format(FileName);
+Error |= clang::format::format(FileName, FailOnIncompleteFormat);
   }
   return Error ? 1 : 0;
 }

>From 51523aae1d42b916d70ca8a2fe7ead82323f38bd Mon Sep 17 00:00:00 2001
From: Roberto Bampi 
Date: Fri, 8 Mar 2024 14:51:49 +0100
Subject: [PATCH 2/2] Update clang/tools/clang-format/ClangFormat.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/tools/clang-format/ClangFormat.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 58027af5d9e091..ed401135ad8433 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -540,10 +540,7 @@ static bool format(StringRef FileName, bool 
ErrorOnIncompleteFormat = false) {
   Rewrite.getEditBuffer(ID).write(outs());
 }
   }
-  if (ErrorOnIncompleteFormat && !Status.FormatComplete)
-return true;
-
-  return false;
+  return ErrorOnIncompleteFormat && !Status.FormatComplete;
 }
 
 } // namespace format

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


[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)

2024-03-14 Thread Roberto Bampi via cfe-commits

gigaroby wrote:

> > I think you need to run `clang/docs/tools/dump_format_help.py`.

Done.

https://github.com/llvm/llvm-project/pull/84346
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Wrap SymbolicRegions by ElementRegions before getting a FieldRegion (PR #85211)

2024-03-14 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/85211

Inside the ExprEngine when we process the initializers, we create a 
PostInitializer program-point, which will refer to the field being initialized, 
see `FieldLoc` inside `ExprEngine::ProcessInitializer`.

When a constructor (of which we evaluate the initializer-list) is analyzed in 
top-level context, then the `this` pointer will be represented by a 
`SymbolicRegion`, (as it should be).

This means that we will form a `FieldRegion{SymbolicRegion{.}}` as the 
initialized region.

```c++
class Bear {
public:
  void brum() const;
};
class Door {
public:
  // PostInitializer would refer to "FieldRegion{SymRegion{this}}"
  // whereas in the store and everywhere else it would be:
  // "FieldRegion{ELementRegion{SymRegion{Ty*, this}, 0, Ty}".
  Door() : ptr(nullptr) {
ptr->brum(); // Bug
  }
private:
  Bear* ptr;
};
```

We (as CSA folks) decided to avoid the creation of FieldRegions directly of 
symbolic regions in the past:
https://github.com/llvm/llvm-project/commit/f8643a9b31c4029942f67d4534c9139b45173504

---

In this patch, I propose to also canonicalize it as in the mentioned patch, 
into this: `FieldRegion{ElementRegion{SymbolicRegion{Ty*, .}, 0, Ty}`

This would mean that FieldRegions will/should never simply wrap a 
SymbolicRegion directly, but rather an ElementRegion that is sitting in between.

This patch should have practically no observable effects, as the store (due to 
the mentioned patch) was made resilient to this issue, but we use 
`PostInitializer::getLocationValue()` for an alternative reporting, where we 
faced this issue.

Note that in really rare cases it suppresses now dereference bugs, as 
demonstrated in the test. It is because in the past we failed to follow the 
region of the PostInitializer inside the StoreSiteFinder visitor - because it 
was using this code:
```c++
// If this is a post initializer expression, initializing the region, we
// should track the initializer expression.
if (std::optional PIP =
Pred->getLocationAs()) {
  const MemRegion *FieldReg = (const MemRegion *)PIP->getLocationValue();
  if (FieldReg == R) {
StoreSite = Pred;
InitE = PIP->getInitializer()->getInit();
  }
}
```
Notice that the equality check didn't pass for the regions I'm canonicalizing 
in this patch.

Given the nature of this change, we would rather upstream this patch.

CPP-4954

>From bde85e0d145049a6661afba6f4585865c5630792 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 14 Mar 2024 12:38:12 +0100
Subject: [PATCH] [analyzer] Wrap SymbolicRegions by ElementRegions before
 getting a FieldRegion

Inside the ExprEngine when we process the initializers, we create a
PostInitializer program-point, which will refer to the field being
initialized, see `FieldLoc` inside `ExprEngine::ProcessInitializer`.

When a constructor (of which we evaluate the initializer-list) is analyzed
in top-level context, then the `this` pointer will be represented by a
`SymbolicRegion`, (as it should be).

This means that we will form a `FieldRegion{SymbolicRegion{.}}` as the
initialized region.

```c++
class Bear {
public:
  void brum() const;
};
class Door {
public:
  // PostInitializer would refer to "FieldRegion{SymRegion{this}}"
  // whereas in the store and everywhere else it would be:
  // "FieldRegion{ELementRegion{SymRegion{Ty*, this}, 0, Ty}".
  Door() : ptr(nullptr) {
ptr->brum(); // Bug
  }
private:
  Bear* ptr;
};
```

We (as CSA folks) decided to avoid the creation of FieldRegions directly of
symbolic regions in the past:
https://github.com/llvm/llvm-project/commit/f8643a9b31c4029942f67d4534c9139b45173504

---

In this patch, I propose to also canonicalize it as in the mentioned patch,
into this: `FieldRegion{ElementRegion{SymbolicRegion{Ty*, .}, 0, Ty}`

This would mean that FieldRegions will/should never simply wrap a
SymbolicRegion directly, but rather an ElementRegion that is sitting
in between.

This patch should have practically no observable effects, as the store
(due to the mentioned patch) was made resilient to this issue, but we use
`PostInitializer::getLocationValue()` for an alternative reporting,
where we faced this issue.

Note that in really rare cases it suppresses now dereference bugs, as
demonstrated in the test. It is because in the past we failed to
follow the region of the PostInitializer inside
the StoreSiteFinder visitor - because it was using this code:
```c++
// If this is a post initializer expression, initializing the region, we
// should track the initializer expression.
if (std::optional PIP =
Pred->getLocationAs()) {
  const MemRegion *FieldReg = (const MemRegion *)PIP->getLocationValue();
  if (FieldReg == R) {
StoreSite = Pred;
InitE = PIP->getInitializer()->getInit();
  }
}
```
And the equality check didn't pass for the regions I'm canonicalizing in this 
patch.

Given the nature of this change, we would rather upstream this patch.

CPP-4954
---

[clang] [analyzer] Wrap SymbolicRegions by ElementRegions before getting a FieldRegion (PR #85211)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

Inside the ExprEngine when we process the initializers, we create a 
PostInitializer program-point, which will refer to the field being initialized, 
see `FieldLoc` inside `ExprEngine::ProcessInitializer`.

When a constructor (of which we evaluate the initializer-list) is analyzed in 
top-level context, then the `this` pointer will be represented by a 
`SymbolicRegion`, (as it should be).

This means that we will form a `FieldRegion{SymbolicRegion{.}}` as the 
initialized region.

```c++
class Bear {
public:
  void brum() const;
};
class Door {
public:
  // PostInitializer would refer to "FieldRegion{SymRegion{this}}"
  // whereas in the store and everywhere else it would be:
  // "FieldRegion{ELementRegion{SymRegion{Ty*, this}, 0, Ty}".
  Door() : ptr(nullptr) {
ptr->brum(); // Bug
  }
private:
  Bear* ptr;
};
```

We (as CSA folks) decided to avoid the creation of FieldRegions directly of 
symbolic regions in the past:
https://github.com/llvm/llvm-project/commit/f8643a9b31c4029942f67d4534c9139b45173504

---

In this patch, I propose to also canonicalize it as in the mentioned patch, 
into this: `FieldRegion{ElementRegion{SymbolicRegion{Ty*, .}, 0, Ty}`

This would mean that FieldRegions will/should never simply wrap a 
SymbolicRegion directly, but rather an ElementRegion that is sitting in between.

This patch should have practically no observable effects, as the store (due to 
the mentioned patch) was made resilient to this issue, but we use 
`PostInitializer::getLocationValue()` for an alternative reporting, where we 
faced this issue.

Note that in really rare cases it suppresses now dereference bugs, as 
demonstrated in the test. It is because in the past we failed to follow the 
region of the PostInitializer inside the StoreSiteFinder visitor - because it 
was using this code:
```c++
// If this is a post initializer expression, initializing the region, we
// should track the initializer expression.
if (std::optional PIP =
Pred->getLocationAs()) {
  const MemRegion *FieldReg = (const MemRegion *)PIP->getLocationValue();
  if (FieldReg == R) {
StoreSite = Pred;
InitE = PIP->getInitializer()->getInit();
  }
}
```
Notice that the equality check didn't pass for the regions I'm canonicalizing 
in this patch.

Given the nature of this change, we would rather upstream this patch.

CPP-4954

---
Full diff: https://github.com/llvm/llvm-project/pull/85211.diff


3 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (-14) 
- (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+32) 
- (modified) clang/test/Analysis/inlining/false-positive-suppression.cpp (+17) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
index ca75c2a756a4a5..47fc4ad88d3161 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -782,20 +782,6 @@ inline SVal ProgramState::getLValue(const ObjCIvarDecl *D, 
SVal Base) const {
   return getStateManager().StoreMgr->getLValueIvar(D, Base);
 }
 
-inline SVal ProgramState::getLValue(const FieldDecl *D, SVal Base) const {
-  return getStateManager().StoreMgr->getLValueField(D, Base);
-}
-
-inline SVal ProgramState::getLValue(const IndirectFieldDecl *D,
-SVal Base) const {
-  StoreManager &SM = *getStateManager().StoreMgr;
-  for (const auto *I : D->chain()) {
-Base = SM.getLValueField(cast(I), Base);
-  }
-
-  return Base;
-}
-
 inline SVal ProgramState::getLValue(QualType ElementType, SVal Idx, SVal Base) 
const{
   if (std::optional N = Idx.getAs())
 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp 
b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index f12f1a5ac970dd..604728cdf1 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -451,6 +451,38 @@ void ProgramState::setStore(const StoreRef &newStore) {
   store = newStoreStore;
 }
 
+/// FieldRegions are expected to be wrapped by an ElementRegion as a canonical
+/// representation. See f8643a9b31c4029942f67d4534c9139b45173504 why.
+static SVal wrapSymbolicRegion(const ProgramState &State, SVal Base) {
+  const auto *SymbolicBase =
+  dyn_cast_or_null(Base.getAsRegion());
+
+  if (!SymbolicBase)
+return Base;
+
+  StoreManager &SM = State.getStateManager().getStoreManager();
+  QualType ElemTy = SymbolicBase->getPointeeStaticType();
+  return loc::MemRegionVal{SM.GetElementZeroRegion(SymbolicBase, ElemTy)};
+}
+
+SVal ProgramState::getLValue(const FieldDecl *D, SVal Base) const {
+  Base = wrapSymbolicRegi

[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-14 Thread Kishan Parmar via cfe-commits


@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");

Long5hot wrote:

I apologize because, There's a bug here. for if not IsComplexInRegABI we need 
to --ArgGPRsLeft;
Will test and update the review accordingly.
Thank you.

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-14 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot deleted 
https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix directive in ActOnOpenMPTargetParallelForSimdDire… (PR #85217)

2024-03-14 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/85217

…ctive

The function `ActOnOpenMPTargetParallelForSimdDirective` gets the number of 
capture levels for OMPD_target_parallel_for, whereas the intended directive is 
OMPD_target_parallel_for_simd.

>From 717561a9d9bdc5cf85f695d3745cb91df622e82c Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 14 Mar 2024 07:39:24 -0500
Subject: [PATCH] [clang][OpenMP] Fix directive in
 ActOnOpenMPTargetParallelForSimdDirective

The function `ActOnOpenMPTargetParallelForSimdDirective` gets the number
of capture levels for OMPD_target_parallel_for, whereas the intended
directive is OMPD_target_parallel_for_simd.
---
 clang/lib/Sema/SemaOpenMP.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0cc0cbacb37548..e9ad7bbde0f9b5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14366,7 +14366,8 @@ StmtResult 
Sema::ActOnOpenMPTargetParallelForSimdDirective(
   // The point of exit cannot be a branch out of the structured block.
   // longjmp() and throw() must not violate the entry/exit criteria.
   CS->getCapturedDecl()->setNothrow();
-  for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for);
+  for (int ThisCaptureLevel =
+   getOpenMPCaptureLevels(OMPD_target_parallel_for_simd);
ThisCaptureLevel > 1; --ThisCaptureLevel) {
 CS = cast(CS->getCapturedStmt());
 // 1.2.2 OpenMP Language Terminology

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


[clang] [clang][OpenMP] Fix directive in ActOnOpenMPTargetParallelForSimdDire… (PR #85217)

2024-03-14 Thread Krzysztof Parzyszek via cfe-commits

kparzysz wrote:

I suspect this was a mistake, let me know if you intended to use the existing 
directive here.

https://github.com/llvm/llvm-project/pull/85217
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix directive in ActOnOpenMPTargetParallelForSimdDire… (PR #85217)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krzysztof Parzyszek (kparzysz)


Changes

…ctive

The function `ActOnOpenMPTargetParallelForSimdDirective` gets the number of 
capture levels for OMPD_target_parallel_for, whereas the intended directive is 
OMPD_target_parallel_for_simd.

---
Full diff: https://github.com/llvm/llvm-project/pull/85217.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaOpenMP.cpp (+2-1) 


``diff
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0cc0cbacb37548..e9ad7bbde0f9b5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14366,7 +14366,8 @@ StmtResult 
Sema::ActOnOpenMPTargetParallelForSimdDirective(
   // The point of exit cannot be a branch out of the structured block.
   // longjmp() and throw() must not violate the entry/exit criteria.
   CS->getCapturedDecl()->setNothrow();
-  for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for);
+  for (int ThisCaptureLevel =
+   getOpenMPCaptureLevels(OMPD_target_parallel_for_simd);
ThisCaptureLevel > 1; --ThisCaptureLevel) {
 CS = cast(CS->getCapturedStmt());
 // 1.2.2 OpenMP Language Terminology

``




https://github.com/llvm/llvm-project/pull/85217
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][OpenMP] Fix directive in ActOnOpenMPTargetParallelForSimdDire… (PR #85217)

2024-03-14 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG.
In the current implementation there is just no difference, they have same 
number of capture levels

https://github.com/llvm/llvm-project/pull/85217
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 72d300a - [clang][Interp][NFC] Move a varible declaration in the closest scope

2024-03-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-14T13:50:05+01:00
New Revision: 72d300adad4022b150c24e4a44488d3b9334e999

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

LOG: [clang][Interp][NFC] Move a varible declaration in the closest scope

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 3f85635f43674d..af60ced0e10e9e 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -320,10 +320,10 @@ std::optional Pointer::toRValue(const Context 
&Ctx) const {
 // Complex types.
 if (const auto *CT = Ty->getAs()) {
   QualType ElemTy = CT->getElementType();
-  std::optional ElemT = Ctx.classify(ElemTy);
-  assert(ElemT);
 
   if (ElemTy->isIntegerType()) {
+std::optional ElemT = Ctx.classify(ElemTy);
+assert(ElemT);
 INT_TYPE_SWITCH(*ElemT, {
   auto V1 = Ptr.atIndex(0).deref();
   auto V2 = Ptr.atIndex(1).deref();



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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-14 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts updated 
https://github.com/llvm/llvm-project/pull/80680

From 818ccfd0258602fdd0630823bb2b8af0507749d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Fri, 2 Feb 2024 16:38:46 +0100
Subject: [PATCH 1/6] [clang][HLSL][SPRI-V] Add convergence intrinsics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

HLSL has wave operations and other kind of function which required the
control flow to either be converged, or respect certain constraints as
where and how to re-converge.

At the HLSL level, the convergence are mostly obvious: the control flow
is expected to re-converge at the end of a scope.
Once translated to IR, HLSL scopes disapear. This means we need a way to
communicate convergence restrictions down to the backend.

For this, the SPIR-V backend uses convergence intrinsics. So this commit
adds some code to generate convergence intrinsics when required.

This commit is not to be submitted as-is (lacks testing), but
should serve as a basis for an upcoming RFC.

Signed-off-by: Nathan Gauër 
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 102 +++
 clang/lib/CodeGen/CGCall.cpp |   4 ++
 clang/lib/CodeGen/CGLoopInfo.h   |   8 ++-
 clang/lib/CodeGen/CodeGenFunction.h  |  19 +
 llvm/include/llvm/IR/IntrinsicInst.h |  13 
 5 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 20c35757939152..ba5e27a5d4668c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1130,8 +1130,97 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullopt otherwise.
+std::optional getConvergenceToken(llvm::BasicBlock *BB) 
{
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return std::nullopt;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,
+   llvm::Value *ParentToken) {
+  llvm::Value *bundleArgs[] = {ParentToken};
+  llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
+  auto Output = llvm::CallBase::addOperandBundle(
+  Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
+  Input->replaceAllUsesWith(Output);
+  Input->eraseFromParent();
+  return Output;
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,
+ llvm::Value *ParentToken) {
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto CB = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_loop, {}, {});
+  Builder.restoreIP(IP);
+
+  auto I = AddConvergenceControlAttr(CB, ParentToken);
+  // Controlled convergence is incompatible with uncontrolled convergence.
+  // Removing any old attributes.
+  I->setNotConvergent();
+
+  assert(isa(I));
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
+  auto *BB = &F->getEntryBlock();
+  auto token = getConvergenceToken(BB);
+  if (token.has_value())
+return token.value();
+
+  // Adding a convergence token requires the function to be marked as
+  // convergent.
+  F->setConvergent();
+
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto I = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_entry, {}, {});
+  assert(isa(I));
+  Builder.restoreIP(IP);
+
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceLoopToken(const LoopInfo *LI) {
+  assert(LI != nullptr);
+
+  auto token = getConvergenceToken(LI->getHeader());
+  if (token.has_value())
+return *token;
+
+  llvm::IntrinsicInst *PII =
+  LI->getParent()
+  ? EmitConvergenceLoop(LI->getHeader(),
+getOrEmitConvergenceLoopToken(LI->getParent()))
+  : getOrEmitConvergenceEntryToken(LI->getHeader()->getParent());
+
+  return EmitConvergenceLoop(LI->getHeader(), PII);
+}
+
+llvm::CallBase *
+CodeGenFunction::AddControlledConvergenceAttr(llvm::CallBase *Input) {
+  llvm::Value *ParentToken =
+  LoopStack.hasInfo()
+  ? getOrEmitConvergenceLoopToken(&LoopStack.getInfo())
+  : getOrEmitConvergenceEntryToken(Input->getFunction());
+  return AddConvergenceControlAttr(Input, ParentToken);
+}
+
 BitTest BitTest::decodeBitTestBuiltin(unsigned BuiltinID) {
   switch (BuiltinID) {
 // Main portable variants.
@@ -5698,6 +5787,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 {NDRange, Kernel, Block}));
   }
 
+  case Builtin::BI__builtin_hlsl_wave_active_count_bits: {
+llvm::Typ

[clang] b97c129 - [clang][Interp] Fix non-primitive ltor casts

2024-03-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-14T13:55:55+01:00
New Revision: b97c12936dd8d520a5565ace3d51a460939a5c61

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

LOG: [clang][Interp] Fix non-primitive ltor casts

This doesn't happen in C++ since it will instead call the
struct's copy constructor. However, in C, this needs to work.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 86304a54473cea..ae5e2dadac951b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -82,15 +82,27 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 if (DiscardResult)
   return this->discard(SubExpr);
 
-if (SubExpr->getType()->isAnyComplexType())
-  return this->delegate(SubExpr);
+std::optional SubExprT = classify(SubExpr->getType());
+// Prepare storage for the result.
+if (!Initializing && !SubExprT) {
+  std::optional LocalIndex =
+  allocateLocal(SubExpr, /*IsExtended=*/false);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
+return false;
+}
 
 if (!this->visit(SubExpr))
   return false;
 
-if (std::optional SubExprT = classify(SubExpr->getType()))
+if (SubExprT)
   return this->emitLoadPop(*SubExprT, CE);
-return false;
+
+// If the subexpr type is not primitive, we need to perform a copy here.
+// This happens for example in C when dereferencing a pointer of struct
+// type.
+return this->emitMemcpy(CE);
   }
 
   case CK_UncheckedDerivedToBase:
@@ -3247,53 +3259,20 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // pointer to the actual value) instead of a pointer to the pointer to the
   // value.
   bool IsReference = D->getType()->isReferenceType();
-  // Complex values are copied in the AST via a simply assignment or
-  // ltor cast. But we represent them as two-element arrays, which means
-  // we pass them around as pointers. So, to assignm from them, we will
-  // have to copy both (primitive) elements instead.
-  bool IsComplex = D->getType()->isAnyComplexType();
 
   // Check for local/global variables and parameters.
   if (auto It = Locals.find(D); It != Locals.end()) {
 const unsigned Offset = It->second.Offset;
-// FIXME: Fix the code duplication here with the code in the global case.
-if (Initializing && IsComplex) {
-  PrimType ElemT = classifyComplexElementType(D->getType());
-  for (unsigned I = 0; I != 2; ++I) {
-if (!this->emitGetPtrLocal(Offset, E))
-  return false;
-if (!this->emitArrayElemPop(ElemT, I, E))
-  return false;
-if (!this->emitInitElem(ElemT, I, E))
-  return false;
-  }
-  return true;
-}
-
 if (IsReference)
   return this->emitGetLocal(PT_Ptr, Offset, E);
 return this->emitGetPtrLocal(Offset, E);
   } else if (auto GlobalIndex = P.getGlobal(D)) {
-if (Initializing && IsComplex) {
-  PrimType ElemT = classifyComplexElementType(D->getType());
-  for (unsigned I = 0; I != 2; ++I) {
-if (!this->emitGetPtrGlobal(*GlobalIndex, E))
-  return false;
-if (!this->emitArrayElemPop(ElemT, I, E))
-  return false;
-if (!this->emitInitElem(ElemT, I, E))
-  return false;
-  }
-  return true;
-}
-
 if (IsReference)
   return this->emitGetGlobalPtr(*GlobalIndex, E);
 
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
-  // FIXME: _Complex initializing case?
   if (IsReference || !It->second.IsPtr)
 return this->emitGetParamPtr(It->second.Offset, E);
 

diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index ce7ed9cec3db3f..dff8eed12428ec 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -233,9 +233,10 @@ static BlockMoveFn getMoveArrayPrim(PrimType Type) {
 Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
bool IsConst, bool IsTemporary, bool IsMutable)
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize),
-  MDSize(MD.value_or(0)), AllocSize(align(Size + MDSize)), 
IsConst(IsConst),
-  IsMutable(IsMutable), IsTemporary(IsTemporary), 
CtorFn(getCtorPrim(Type)),
-   

[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-14 Thread via cfe-commits

https://github.com/NagyDonat edited 
https://github.com/llvm/llvm-project/pull/85104
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-14 Thread via cfe-commits

https://github.com/NagyDonat requested changes to this pull request.

I strongly suspect that there are some situations where this commit would 
behave incorrectly (assert on legal code or print incorrect output). See inline 
comment for explanation and a suggested solution (that I did not test).

https://github.com/llvm/llvm-project/pull/85104
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-14 Thread via cfe-commits


@@ -720,14 +720,20 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) 
const {
   CI->getValue().toString(Idx);
   ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str();
 }
-// If not a ConcreteInt, try to obtain the variable
-// name by calling 'getDescriptiveName' recursively.
-else {
-  std::string Idx = ER->getDescriptiveName(false);
-  if (!Idx.empty()) {
-ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
+// Index is a SymbolVal.
+else if (auto SI = ER->getIndex().getAs()) {
+  if (SymbolRef SR = SI->getAsSymbol()) {
+if (const MemRegion *OR = SR->getOriginRegion()) {
+  std::string Idx = OR->getDescriptiveName(false);
+  ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
+}
   }
 }
+// Index is neither a ConcreteInt nor SymbolVal, give up and return.
+else {
+  assert(false && "we should have a descriptive name");
+  return "";
+}

NagyDonat wrote:

```suggestion
// Index is symbolic, but may have a descriptive name
else {
  auto SI = ER->getIndex().getAs();
  if (!SI)
return "";

  const MemRegion *OR = SI->getAsSymbol()->getOriginRegion();
  if (!OR)
return "";

  std::string Idx = OR->getDescriptiveName(false);
  if (Idx.empty())
return "";
  
  ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
}
```

I realize it just now, but there are several failure cases that are not 
handled/handled incorrectly within this code:
(1) `ER->getIndex().getAs()` may return `nullptr` in the 
unusual but perfectly legal case when the index is a symbolic value that is 
e.g. a `nonloc::LocAsInteger` (a pointer converted to an integer type).

(2) `SymbolVal::getAsSymbol()` returns nonnull, but 
`SI->getAsSymbol()->getOriginRegion();` may return `nullptr` when we have a 
symbolic value that doesn't originate as the value of a memory region (e.g. 
it's a conjured symbol, the integer returned by an opaque function).

(3) Finally `OR->getDescriptiveName(false)` may return an empty string when the 
origin region doesn't have a descriptive name (e.g. it's a symbolic region 
behind an opaque pointer, a nameless heap area returned by `malloc` etc.).

In each of these three situations the right thing to do is returning an empty 
string, because `getDescriptiveName` already signals failure by returning `""` 
when it cannot find a natural descriptive name. (And code that uses this 
function checks for an empty return value.)

Disclaimer: I did not test the code that I'm suggesting here; there may be 
typos in it. Also, it would be good to have testcases that cover the situations 
(1)-(3) and verify that this method doesn't produce incorrect output under them.

https://github.com/llvm/llvm-project/pull/85104
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-14 Thread via cfe-commits

https://github.com/NagyDonat edited 
https://github.com/llvm/llvm-project/pull/85104
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a551cce - [clang][Interp][NFC] Print primitive global values in dump()

2024-03-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-14T14:05:33+01:00
New Revision: a551ccee66fc70b5ecd03a2c8b9db5a7330820f0

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

LOG: [clang][Interp][NFC] Print primitive global values in dump()

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 315ddb293044b7..160701f4d4a760 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -10,8 +10,11 @@
 //
 
//===--===//
 
+#include "Boolean.h"
 #include "Floating.h"
 #include "Function.h"
+#include "FunctionPointer.h"
+#include "Integral.h"
 #include "IntegralAP.h"
 #include "Opcode.h"
 #include "PrimType.h"
@@ -86,6 +89,40 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
 
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
 
+static const char *primTypeToString(PrimType T) {
+  switch (T) {
+  case PT_Sint8:
+return "Sint8";
+  case PT_Uint8:
+return "Uint8";
+  case PT_Sint16:
+return "Sint16";
+  case PT_Uint16:
+return "Uint16";
+  case PT_Sint32:
+return "Sint32";
+  case PT_Uint32:
+return "Uint32";
+  case PT_Sint64:
+return "Sint64";
+  case PT_Uint64:
+return "Uint64";
+  case PT_IntAP:
+return "IntAP";
+  case PT_IntAPS:
+return "IntAPS";
+  case PT_Bool:
+return "Bool";
+  case PT_Float:
+return "Float";
+  case PT_Ptr:
+return "Ptr";
+  case PT_FnPtr:
+return "FnPtr";
+  }
+  llvm_unreachable("Unhandled PrimType");
+}
+
 LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
   {
 ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_RED, true});
@@ -100,9 +137,10 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) 
const {
   unsigned GI = 0;
   for (const Global *G : Globals) {
 const Descriptor *Desc = G->block()->getDescriptor();
+Pointer GP = getPtrGlobal(GI);
+
 OS << GI << ": " << (void *)G->block() << " ";
 {
-  Pointer GP = getPtrGlobal(GI);
   ColorScope SC(OS, true,
 GP.isInitialized()
 ? TerminalColor{llvm::raw_ostream::GREEN, false}
@@ -111,6 +149,15 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) 
const {
 }
 Desc->dump(OS);
 OS << "\n";
+if (Desc->isPrimitive() && !Desc->isDummy()) {
+  OS << "   ";
+  {
+ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_CYAN, false});
+OS << primTypeToString(Desc->getPrimType()) << " ";
+  }
+  TYPE_SWITCH(Desc->getPrimType(), { GP.deref().print(OS); });
+  OS << "\n";
+}
 ++GI;
   }
 



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


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben created 
https://github.com/llvm/llvm-project/pull/85222

This PR adds `-march=generic` support for the NVPTX backend. This fulfills a 
TODO introduced in #79873.

With this PR, users can explicitly request the default CUDA architecture. This 
default is regularly updated, and the most recent configuration as of commit 
ab202aa sets it to `sm_52`. This value is also assumed when no `-march` option 
is provided.

This PR does not address any compatibility issues between different CUDA 
versions.


>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

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


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yichen Yan (oraluben)


Changes

This PR adds `-march=generic` support for the NVPTX backend. This fulfills a 
TODO introduced in #79873.

With this PR, users can explicitly request the default CUDA architecture. This 
default is regularly updated, and the most recent configuration as of commit 
ab202aa sets it to `sm_52`. This value is also assumed when no `-march` option 
is provided.

This PR does not address any compatibility issues between different CUDA 
versions.


---
Full diff: https://github.com/llvm/llvm-project/pull/85222.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+2-2) 
- (modified) clang/test/Driver/cuda-cross-compiling.c (+7-2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

``




https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 34ba90745fa55777436a2429a51a3799c83c6d4c 
9d6fe5f8522ddedde66525e93f4b66e547ddadc6 -- 
clang/lib/Driver/ToolChains/Cuda.cpp clang/test/Driver/cuda-cross-compiling.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28..6114e4f015 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

``




https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

oraluben wrote:

@jhuber6 @Artem-B You might want to check if this LGTY :)

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits

https://github.com/oraluben updated 
https://github.com/llvm/llvm-project/pull/85222

>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/2] [NVPTX] Add `-march=general` option to mirror default
 configuration

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
 clang/test/Driver/cuda-cross-compiling.c | 9 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  // TODO: We should accept 'generic' as a valid architecture.
-  if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
+  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));
   } else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c 
b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
 //
 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=GENERIC %s
 
 //  ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" 
"sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
 // ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+//  GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} 
"-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" 
"[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" 
"[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} 
"[[CUBIN]].cubin"
 
 //
 // Test the generated arguments to the CUDA binary utils when targeting NVPTX. 
@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan 
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/2] fmt

---
 clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const 
llvm::opt::DerivedArgList &Args,
 if (!llvm::is_contained(*DAL, A))
   DAL->append(A);
 
-  if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) 
||
+  if ((!DAL->hasArg(options::OPT_march_EQ) &&
+   OffloadKind != Action::OFK_None) ||
   (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
   CudaArchToString(CudaArch::CudaDefault));

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


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-14 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/84014

>From bdefe754c14c5e050ebf2b9c82eca458041564a4 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Tue, 5 Mar 2024 05:35:16 -0800
Subject: [PATCH 1/6] [clang-cl] Fix value of __FUNCTION__ in MSVC mode.

---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/AST/Expr.h|  3 +-
 clang/lib/AST/Expr.cpp| 26 ++--
 clang/lib/AST/TypePrinter.cpp | 24 +--
 clang/lib/Sema/SemaExpr.cpp   |  5 +-
 clang/test/AST/Interp/literals.cpp|  8 +--
 clang/test/Analysis/eval-predefined-exprs.cpp | 22 +--
 clang/test/SemaCXX/source_location.cpp| 64 +++
 clang/unittests/AST/DeclPrinterTest.cpp   | 15 +
 9 files changed, 149 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 612b4329727455..20c14fae1dd31b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Bug Fixes in This Version
   for variables created through copy initialization having side-effects in 
C++17 and later.
   Fixes (#GH64356) (#GH79518).
 
+- Fix value of predefined macro ``__FUNCTION__`` to match MSVC's value. Fixes
+  (`#66114 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index bf0622bdeca30e..ce8e64a4bed04b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2034,7 +2034,8 @@ class PredefinedExpr final
   }
 
   static std::string ComputeName(PredefinedIdentKind IK,
- const Decl *CurrentDecl);
+ const Decl *CurrentDecl,
+ bool ForceElaboratedPrinting = false);
 
   SourceLocation getBeginLoc() const { return getLocation(); }
   SourceLocation getEndLoc() const { return getLocation(); }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..796e50817ee319 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -673,7 +673,8 @@ StringRef 
PredefinedExpr::getIdentKindName(PredefinedIdentKind IK) {
 // FIXME: Maybe this should use DeclPrinter with a special "print predefined
 // expr" policy instead.
 std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
-const Decl *CurrentDecl) {
+const Decl *CurrentDecl,
+bool ForceElaboratedPrinting) {
   ASTContext &Context = CurrentDecl->getASTContext();
 
   if (IK == PredefinedIdentKind::FuncDName) {
@@ -721,10 +722,17 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 return std::string(Out.str());
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
-if (IK != PredefinedIdentKind::PrettyFunction &&
-IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
-IK != PredefinedIdentKind::FuncSig &&
-IK != PredefinedIdentKind::LFuncSig)
+const auto &LO = Context.getLangOpts();
+if ((ForceElaboratedPrinting &&
+ (((IK == PredefinedIdentKind::Func ||
+IK == PredefinedIdentKind ::Function) &&
+   !LO.MicrosoftExt) ||
+  (IK == PredefinedIdentKind::LFunction && LO.MicrosoftExt))) ||
+(!ForceElaboratedPrinting &&
+ (IK != PredefinedIdentKind::PrettyFunction &&
+  IK != PredefinedIdentKind::PrettyFunctionNoVirtual &&
+  IK != PredefinedIdentKind::FuncSig &&
+  IK != PredefinedIdentKind::LFuncSig)))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -752,6 +760,8 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind 
IK,
 PrintingPolicy Policy(Context.getLangOpts());
 PrettyCallbacks PrettyCB(Context.getLangOpts());
 Policy.Callbacks = &PrettyCB;
+if (IK == PredefinedIdentKind::Function && ForceElaboratedPrinting)
+  Policy.SuppressTagKeyword = !LO.MicrosoftExt;
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
@@ -779,6 +789,12 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 
 FD->printQualifiedName(POut, Policy);
 
+if (IK == PredefinedIdentKind::Function) {
+  POut.flush();
+  Out << Proto;
+  return std::string(Name);
+}
+
 POut << "(";
 if (FT) {
   for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7dcc4348f8e036..21605e1f53e3d9 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1635,6 +1635,17 @@ void TypePrinter::printElaboratedBefore(const 
ElaboratedType *T,
 if (T->getKeyword() != ElaboratedTypeKeyword::None)
   OS << " ";
 NestedNameSpecifier *Q

[clang] [analyzer] Fix false double free when including 3rd-party headers with overloaded delete operator as system headers (PR #85224)

2024-03-14 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 created 
https://github.com/llvm/llvm-project/pull/85224

Fixes #62985 

When 3rd-party header files are included as system headers, their overloaded 
`new` and `delete` operators are also considered as the std ones. However, 
those overloaded operator functions will also be inlined. This makes the same
symbolic memory marked as released twice: during `checkPreCall` of the 
overloaded `delete` operator and when calling `::operator delete` after 
inlining the overloaded operator function (if it has).

This patch attempts to fix this bug by adjusting the strategy of verifying 
whether the callee is a standard `new` or `delete` operator in the 
`isStandardNewDelete` function.

>From b3e6a2273e9c35ac4cc3ac16aebcf4ea0d89ef74 Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Thu, 14 Mar 2024 20:41:20 +0800
Subject: [PATCH] wip: the first workaround

---
 .../StaticAnalyzer/Checkers/MallocChecker.cpp |  3 ++-
 .../Inputs/overloaded-delete-in-header.h  | 17 +
 .../overloaded-delete-in-system-header.cpp| 25 +++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Analysis/Inputs/overloaded-delete-in-header.h
 create mode 100644 clang/test/Analysis/overloaded-delete-in-system-header.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 03cb7696707fe2..c7ec2b7cc43b30 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1090,7 +1090,8 @@ static bool isStandardNewDelete(const FunctionDecl *FD) {
   // If the header for operator delete is not included, it's still defined
   // in an invalid source location. Check to make sure we don't crash.
   return !L.isValid() ||
- FD->getASTContext().getSourceManager().isInSystemHeader(L);
+ (!FD->hasBody() && // FIXME: Still a false alarm after CTU inlining.
+  FD->getASTContext().getSourceManager().isInSystemHeader(L));
 }
 
 
//===--===//
diff --git a/clang/test/Analysis/Inputs/overloaded-delete-in-header.h 
b/clang/test/Analysis/Inputs/overloaded-delete-in-header.h
new file mode 100644
index 00..5090de0d9bbd6b
--- /dev/null
+++ b/clang/test/Analysis/Inputs/overloaded-delete-in-header.h
@@ -0,0 +1,17 @@
+#ifndef OVERLOADED_DELETE_IN_HEADER
+#define OVERLOADED_DELETE_IN_HEADER
+
+void clang_analyzer_printState();
+
+struct DeleteInHeader {
+  inline void operator delete(void *ptr) {
+// No matter whether this header file is included as a system header file
+// with -isystem or a user header file with -I, ptr should not be marked as
+// released.
+clang_analyzer_printState();
+
+::operator delete(ptr); // The first place where ptr is marked as released.
+  }
+};
+
+#endif // OVERLOADED_DELETE_IN_SYSTEM_HEADER
diff --git a/clang/test/Analysis/overloaded-delete-in-system-header.cpp 
b/clang/test/Analysis/overloaded-delete-in-system-header.cpp
new file mode 100644
index 00..f7780b67e93b99
--- /dev/null
+++ b/clang/test/Analysis/overloaded-delete-in-system-header.cpp
@@ -0,0 +1,25 @@
+// issue 62985
+// When 3rd-party header files are included as system headers, their overloaded
+// new and delete operators are also considered as the std ones. However, those
+// overloaded operator functions will also be inlined. This makes the same
+// symbolic memory marked as released twice, which leads to a false uaf alarm.
+//
+// The first run, include as system header. False uaf report before fix.
+//
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
+// RUN:   -isystem %S/Inputs/ 2>&1 | \
+// RUN:   FileCheck %s
+//
+// The second run, include as user header. Should always silent.
+//
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
+// RUN:   -I %S/Inputs/ 2>&1 | \
+// RUN:   FileCheck %s
+
+#include "overloaded-delete-in-header.h"
+
+void deleteInHeader(DeleteInHeader *p) { delete p; }
+
+// CHECK-NOT: Released

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


[clang] 2421e76 - [clang][Interp][NFC] Add more _Complex tests

2024-03-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-14T14:05:33+01:00
New Revision: 2421e76159536ec4d2224e17fd10dfc4df6a2bc5

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

LOG: [clang][Interp][NFC] Add more _Complex tests

Added: 


Modified: 
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 6a42afc68d26c7..d4e3d5a46a64fb 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -313,3 +313,53 @@ namespace Cmp {
   static_assert((0.0 + 0.0j) > (0.0 + 0.0j)); // both-error {{invalid operands 
to binary expression}}
   static_assert((0.0 + 0.0j) ^ (0.0 + 0.0j)); // both-error {{invalid operands 
to binary expression}}
 }
+
+/// From test/SemaCXX/constant-expression-cxx11.cpp
+///
+/// Some of the diagnostics we emit are 
diff erent than the one of the
+/// current interpreter.
+///
+/// FIXME: For the '&test3 + 1' test, we are _not_ creating an explicit 
pointer variable
+/// anywhere and so the &test3+1 is the same as __imag(test3) for us.
+namespace ComplexConstexpr {
+  constexpr _Complex float test1 = {};
+  constexpr _Complex float test2 = {1};
+  constexpr _Complex double test3 = {1,2};
+  constexpr _Complex int test4 = {4};
+  constexpr _Complex int test5 = 4;
+  constexpr _Complex int test6 = {5,6};
+  typedef _Complex float fcomplex;
+  constexpr fcomplex test7 = fcomplex();
+
+  constexpr const double &t2r = __real test3;
+  constexpr const double &t2i = __imag test3;
+  static_assert(&t2r + 1 == &t2i, "");
+  static_assert(t2r == 1.0, "");
+  static_assert(t2i == 2.0, "");
+  constexpr const double *t2p = &t2r;
+  static_assert(t2p[-1] == 0.0, ""); // both-error {{constant expr}} \
+ // both-note {{cannot refer to element -1 
of array of 2 elements}}
+  static_assert(t2p[0] == 1.0, "");
+  static_assert(t2p[1] == 2.0, "");
+  static_assert(t2p[2] == 0.0, ""); // both-error {{constant expr}} \
+// both-note {{one-past-the-end pointer}}
+  static_assert(t2p[3] == 0.0, ""); // both-error {{constant expr}} \
+// both-note {{cannot refer to element 3 
of array of 2 elements}}
+  constexpr _Complex float *p = 0;
+  constexpr float pr = __real *p; // both-error {{constant expr}} \
+  // ref-note {{cannot access real component 
of null}} \
+  // expected-note {{read of dereferenced null 
pointer}}
+  constexpr float pi = __imag *p; // both-error {{constant expr}} \
+  // ref-note {{cannot access imaginary 
component of null}} \
+  // expected-note {{cannot perform pointer 
arithmetic on null pointer}}
+  constexpr const _Complex double *q = &test3 + 1;
+  constexpr double qr = __real *q; // ref-error {{constant expr}} \
+   // ref-note {{cannot access real component 
of pointer past the end}}
+  constexpr double qi = __imag *q; // both-error {{constant expr}} \
+   // ref-note {{cannot access imaginary 
component of pointer past the end}} \
+   // expected-note {{read of dereferenced 
one-past-the-end pointer}}
+
+  static_assert(__real test6 == 5, "");
+  static_assert(__imag test6 == 6, "");
+  static_assert(&__imag test6 == &__real test6 + 1, "");
+}



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


[clang] [analyzer] Fix false double free when including 3rd-party headers with overloaded delete operator as system headers (PR #85224)

2024-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ella Ma (Snape3058)


Changes

Fixes #62985 

When 3rd-party header files are included as system headers, their overloaded 
`new` and `delete` operators are also considered as the std ones. However, 
those overloaded operator functions will also be inlined. This makes the same
symbolic memory marked as released twice: during `checkPreCall` of the 
overloaded `delete` operator and when calling `::operator delete` after 
inlining the overloaded operator function (if it has).

This patch attempts to fix this bug by adjusting the strategy of verifying 
whether the callee is a standard `new` or `delete` operator in the 
`isStandardNewDelete` function.

---
Full diff: https://github.com/llvm/llvm-project/pull/85224.diff


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+2-1) 
- (added) clang/test/Analysis/Inputs/overloaded-delete-in-header.h (+17) 
- (added) clang/test/Analysis/overloaded-delete-in-system-header.cpp (+25) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 03cb7696707fe2..c7ec2b7cc43b30 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1090,7 +1090,8 @@ static bool isStandardNewDelete(const FunctionDecl *FD) {
   // If the header for operator delete is not included, it's still defined
   // in an invalid source location. Check to make sure we don't crash.
   return !L.isValid() ||
- FD->getASTContext().getSourceManager().isInSystemHeader(L);
+ (!FD->hasBody() && // FIXME: Still a false alarm after CTU inlining.
+  FD->getASTContext().getSourceManager().isInSystemHeader(L));
 }
 
 
//===--===//
diff --git a/clang/test/Analysis/Inputs/overloaded-delete-in-header.h 
b/clang/test/Analysis/Inputs/overloaded-delete-in-header.h
new file mode 100644
index 00..5090de0d9bbd6b
--- /dev/null
+++ b/clang/test/Analysis/Inputs/overloaded-delete-in-header.h
@@ -0,0 +1,17 @@
+#ifndef OVERLOADED_DELETE_IN_HEADER
+#define OVERLOADED_DELETE_IN_HEADER
+
+void clang_analyzer_printState();
+
+struct DeleteInHeader {
+  inline void operator delete(void *ptr) {
+// No matter whether this header file is included as a system header file
+// with -isystem or a user header file with -I, ptr should not be marked as
+// released.
+clang_analyzer_printState();
+
+::operator delete(ptr); // The first place where ptr is marked as released.
+  }
+};
+
+#endif // OVERLOADED_DELETE_IN_SYSTEM_HEADER
diff --git a/clang/test/Analysis/overloaded-delete-in-system-header.cpp 
b/clang/test/Analysis/overloaded-delete-in-system-header.cpp
new file mode 100644
index 00..f7780b67e93b99
--- /dev/null
+++ b/clang/test/Analysis/overloaded-delete-in-system-header.cpp
@@ -0,0 +1,25 @@
+// issue 62985
+// When 3rd-party header files are included as system headers, their overloaded
+// new and delete operators are also considered as the std ones. However, those
+// overloaded operator functions will also be inlined. This makes the same
+// symbolic memory marked as released twice, which leads to a false uaf alarm.
+//
+// The first run, include as system header. False uaf report before fix.
+//
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
+// RUN:   -isystem %S/Inputs/ 2>&1 | \
+// RUN:   FileCheck %s
+//
+// The second run, include as user header. Should always silent.
+//
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=core,cplusplus.NewDelete,debug.ExprInspection \
+// RUN:   -I %S/Inputs/ 2>&1 | \
+// RUN:   FileCheck %s
+
+#include "overloaded-delete-in-header.h"
+
+void deleteInHeader(DeleteInHeader *p) { delete p; }
+
+// CHECK-NOT: Released

``




https://github.com/llvm/llvm-project/pull/85224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #84014)

2024-03-14 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 93e423f19fc5317ee208f77d8f36e677db124cc8 
4b42f76d5c1e5439311cc8153ef9530be2625840 -- clang/include/clang/AST/Expr.h 
clang/lib/AST/DeclPrinter.cpp clang/lib/AST/Expr.cpp 
clang/lib/AST/TypePrinter.cpp clang/lib/Sema/SemaExpr.cpp 
clang/test/Analysis/eval-predefined-exprs.cpp 
clang/test/SemaCXX/source_location.cpp clang/unittests/AST/DeclPrinterTest.cpp 
clang/unittests/AST/TypePrinterTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index 06829313b5..e024c41e03 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -359,18 +359,18 @@ TEST(DeclPrinter, TestCXXRecordDecl11) {
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl12) {
-  ASSERT_TRUE(PrintedDeclCXX98Matches(
-  "struct S { int x; };"
-  "namespace NS { class C {};}"
-  "void foo() {using namespace NS; C c;}",
-  "foo",
-  "void foo() {\nusing namespace NS;\nclass "
-  "NS::C c;\n}\n",
-  [](PrintingPolicy &Policy) {
-Policy.SuppressTagKeyword = false;
-Policy.SuppressScope = true;
-Policy.TerseOutput = false;
-  }));
+  ASSERT_TRUE(
+  PrintedDeclCXX98Matches("struct S { int x; };"
+  "namespace NS { class C {};}"
+  "void foo() {using namespace NS; C c;}",
+  "foo",
+  "void foo() {\nusing namespace NS;\nclass "
+  "NS::C c;\n}\n",
+  [](PrintingPolicy &Policy) {
+Policy.SuppressTagKeyword = false;
+Policy.SuppressScope = true;
+Policy.TerseOutput = false;
+  }));
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl13) {
@@ -378,9 +378,7 @@ TEST(DeclPrinter, TestCXXRecordDecl13) {
   "struct S { int x; };"
   "S s1;"
   "S foo() {return s1;}",
-  "foo",
-  "struct S foo() {\nreturn s1;\n}\n",
-  [](PrintingPolicy &Policy) {
+  "foo", "struct S foo() {\nreturn s1;\n}\n", [](PrintingPolicy &Policy) {
 Policy.SuppressTagKeyword = false;
 Policy.SuppressScope = true;
 Policy.TerseOutput = false;
@@ -391,8 +389,7 @@ TEST(DeclPrinter, TestCXXRecordDecl14) {
   ASSERT_TRUE(PrintedDeclCXX98Matches(
   "struct S { int x; };"
   "S foo(S s1) {return s1;}",
-  "foo",
-  "struct S foo(struct S s1) {\nreturn s1;\n}\n",
+  "foo", "struct S foo(struct S s1) {\nreturn s1;\n}\n",
   [](PrintingPolicy &Policy) {
 Policy.SuppressTagKeyword = false;
 Policy.SuppressScope = true;
diff --git a/clang/unittests/AST/TypePrinterTest.cpp 
b/clang/unittests/AST/TypePrinterTest.cpp
index 2cdab5d1d3..494085a2eb 100644
--- a/clang/unittests/AST/TypePrinterTest.cpp
+++ b/clang/unittests/AST/TypePrinterTest.cpp
@@ -156,21 +156,19 @@ TEST(TypePrinter, TemplateIdWithNTTP) {
 }
 
 TEST(TypePrinter, TemplateArgumentsSubstitution) {
- constexpr char Code[] = R"cpp(
+  constexpr char Code[] = R"cpp(
template  class X {};
typedef X A;
int foo() {
   return sizeof(A);
}
   )cpp";
-  auto Matcher = typedefNameDecl(hasName("A"),
- hasType(qualType().bind("id")));
-  ASSERT_TRUE(PrintedTypeMatches(
-  Code, {}, Matcher, "X",
- [](PrintingPolicy &Policy) {
-   Policy.SuppressTagKeyword = false;
-   Policy.SuppressScope = true;
- }));
+  auto Matcher = typedefNameDecl(hasName("A"), hasType(qualType().bind("id")));
+  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher, "X",
+ [](PrintingPolicy &Policy) {
+   Policy.SuppressTagKeyword = false;
+   Policy.SuppressScope = true;
+ }));
 }
 
 TEST(TypePrinter, TemplateArgumentsSubstitution_Expressions) {

``




https://github.com/llvm/llvm-project/pull/84014
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix false double free when including 3rd-party headers with overloaded delete operator as system headers (PR #85224)

2024-03-14 Thread Ella Ma via cfe-commits

Snape3058 wrote:

This version is just a trivial workaround for this issue. Refer to the FIXME 
comment in the checker. Feel free to provide suggestions on fixing this bug.

https://github.com/llvm/llvm-project/pull/85224
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 edited 
https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 requested changes to this pull request.

Thanks for looking at this. When the user compiles with `-march=xyz` it 
introduces a lot of subtarget specific metadata intro the output IR. The 
purpose of the original patch was to keep `-target-cpu` unset in cases where 
`-march=xyz` was not passed in. The expected semantics here is that 
`-march=sm_52 -march=generic` will override `-march=sm_52` and result in no 
`-target-cpu` being set just like if you didn't pass `-march` at all.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Joseph Huber via cfe-commits


@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 

jhuber6 wrote:

```suggestion
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c 
%s -### 2>&1 \
// RUN:   | FileCheck -check-prefix=GENERIC %s
```
The test should look like this, using `-march=generic` overrides the previous 
`-march` and results in the same output as if `-march` was not passed at all.

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 21d8085 - [clang][Interp][NFC] Rename DummyParams to DummyVariables

2024-03-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-14T14:05:33+01:00
New Revision: 21d80859df3fb416efac13ce8178fdf6d6489292

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

LOG: [clang][Interp][NFC] Rename DummyParams to DummyVariables

We create dummy descriptors for variables other than parameters
these days.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 86e18ede638114..58bddb991fd6de 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -145,7 +145,7 @@ std::optional Program::getOrCreateGlobal(const 
ValueDecl *VD,
 
 std::optional Program::getOrCreateDummy(const ValueDecl *VD) {
   // Dedup blocks since they are immutable and pointers cannot be compared.
-  if (auto It = DummyParams.find(VD); It != DummyParams.end())
+  if (auto It = DummyVariables.find(VD); It != DummyVariables.end())
 return It->second;
 
   // Create dummy descriptor.
@@ -158,7 +158,7 @@ std::optional Program::getOrCreateDummy(const 
ValueDecl *VD) {
   G->block()->invokeCtor();
 
   Globals.push_back(G);
-  DummyParams[VD] = I;
+  DummyVariables[VD] = I;
   return I;
 }
 

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 50bdb575e805cf..36b5a1faa513a9 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -208,7 +208,7 @@ class Program final {
   llvm::DenseMap Records;
 
   /// Dummy parameter to generate pointers from.
-  llvm::DenseMap DummyParams;
+  llvm::DenseMap DummyVariables;
 
   /// Creates a new descriptor.
   template 



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


[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)

2024-03-14 Thread Yichen Yan via cfe-commits


@@ -85,6 +90,6 @@
 // MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 
'nvlink'
 
 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=GENERIC %s
+// RUN:   | FileCheck -check-prefix=COMPILE %s
 

oraluben wrote:

I see, thanks for clarifying!

https://github.com/llvm/llvm-project/pull/85222
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >