[clang] [llvm] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-02-07 Thread Connor Sughrue via cfe-commits

https://github.com/cpsughrue updated 
https://github.com/llvm/llvm-project/pull/67562

>From 03d3310ca300630a94517fa300858d1f2645e843 Mon Sep 17 00:00:00 2001
From: cpsughrue 
Date: Sun, 9 Jul 2023 23:19:58 -0400
Subject: [PATCH 1/8] [clang][MBD] set up module build daemon infrastructure

The module build daemon (mbd) will serve as a cc1 tool that helps convert
implicit module command lines to explicit module command lines. A clang
invocation will check to see if a mbd exists, if not the invocation will spawn
one. After the mbd is up and running and a handshake has successfully been
carried out between the mbd and clang invocation the clang invocation will
share it's command line with the mbd. The mbd will then scan the translation
unit and build all modular dependencies before returning a modified cc1 command
line such that all arguments related to modules are converted from the
implicit option to their explicit option.

This commit sets up the basic mbd infrastructure. Including the ability to
spawn a mbd and carry out a handshake between the clang invocation and mbd.

RFC: 
https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  20 ++
 clang/include/clang/Basic/DiagnosticGroups.td |   1 +
 clang/include/clang/Driver/Options.td |  13 +
 .../include/clang/Frontend/FrontendOptions.h  |   8 +
 .../Tooling/ModuleBuildDaemon/Frontend.h  |  36 +++
 .../Tooling/ModuleBuildDaemon/SocketSupport.h | 126 +
 .../clang/Tooling/ModuleBuildDaemon/Utils.h   |  58 
 clang/lib/Driver/ToolChains/Clang.cpp |  14 +-
 clang/lib/Tooling/CMakeLists.txt  |   1 +
 .../Tooling/ModuleBuildDaemon/CMakeLists.txt  |   9 +
 .../Tooling/ModuleBuildDaemon/Frontend.cpp| 166 
 .../ModuleBuildDaemon/SocketSupport.cpp   |  66 +
 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp |  49 
 clang/test/Driver/unknown-arg.c   |   2 +-
 clang/test/Frontend/warning-options.cpp   |   2 +-
 clang/test/ModuleBuildDaemon/daemon-launch.c  |  18 ++
 clang/test/ModuleBuildDaemon/handshake.c  |  22 ++
 clang/test/lit.cfg.py |  11 +
 clang/tools/driver/CMakeLists.txt |   3 +
 clang/tools/driver/cc1_main.cpp   |  17 +-
 clang/tools/driver/cc1modbuildd_main.cpp  | 255 ++
 clang/tools/driver/driver.cpp |  10 +-
 clang/utils/kill_process.py   |  86 ++
 llvm/include/llvm/Support/Program.h   |   3 +-
 llvm/include/llvm/Support/raw_socket_stream.h |   8 +-
 llvm/lib/Support/Program.cpp  |   9 +-
 llvm/lib/Support/Unix/Program.inc |  18 +-
 llvm/lib/Support/Windows/Program.inc  |   7 +-
 llvm/lib/Support/raw_socket_stream.cpp|  46 +++-
 29 files changed, 1055 insertions(+), 29 deletions(-)
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Frontend.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Utils.h
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Frontend.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp
 create mode 100644 clang/test/ModuleBuildDaemon/daemon-launch.c
 create mode 100644 clang/test/ModuleBuildDaemon/handshake.c
 create mode 100644 clang/tools/driver/cc1modbuildd_main.cpp
 create mode 100644 clang/utils/kill_process.py

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 85ecfdf9de62d4..a858bc163de0c3 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -262,6 +262,26 @@ def err_test_module_file_extension_version : Error<
   "test module file extension '%0' has different version (%1.%2) than expected 
"
   "(%3.%4)">;
 
+// Module Build Daemon
+def err_basepath_length :
+  Error<"BasePath '%0' is longer then the max length of %1">,
+  DefaultFatal;
+def err_mbd_handshake :
+  Error<"Attempt to handshake with module build daemon has failed: %0">,
+  DefaultFatal;
+def err_mbd_connect :
+  Error<"Attempt to connect to module build daemon has failed: %0">,
+  DefaultFatal;
+def remark_mbd_spawn :
+  Remark<"Successfully spawned module build daemon">,
+  InGroup;
+def remark_mbd_connection :
+  Remark<"Successfully connected to module build daemon at %0">,
+  InGroup;
+def remark_mbd_handshake :
+  Remark<"Successfully completed handshake with module build daemon">,
+  InGroup;
+
 def warn_eagerly_load_for_standard_cplusplus_modules : Warning<
   "the form '-fmodule-file=' is deprecated for standard C++ named 
modules;"
   "consider to use '-fmodule-file==' inste

[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-07 Thread Pierre van Houtryve via cfe-commits

Pierre-vh wrote:

For the MD changes, it's just to describe the version increment, nothing else. 
I think describing is important as the V6 diff already updated the 
amdhsa.version.
If amdhsa.version didn't need to change then i need to fix that first, and then 
we can remove the V6 MD section

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-07 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have fixed the merge conflict , will be adding more tests as I am able to 
test them locally.
Thank you

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


[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-07 Thread Qizhi Hu via cfe-commits

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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-07 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/76955

>From 616dda8bc9e000e4243ddb8f6b7f4b04f956a620 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:48:05 +0100
Subject: [PATCH 1/5] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets

These generic targets include multiple GPUs and will, in the future, provide a 
way to build once and run on multiple GPU, at the cost of less optimization 
opportunities.
Note that this is just doing the compiler side of things, device libs an 
runtimes/loader/etc. don't know about these targets yet, so none of them 
actually work in practice right now. This is just the initial commit to make 
LLVM aware of them.

No docs in this patch either as I plan to do it all in a follow-up patch.
---
 clang/lib/Basic/Targets/AMDGPU.cpp|  20 +-
 clang/test/Driver/amdgpu-macros.cl|   5 +
 clang/test/Driver/amdgpu-mcpu.cl  |  10 +
 llvm/docs/AMDGPUUsage.rst | 325 +-
 llvm/include/llvm/BinaryFormat/ELF.h  |   6 +-
 llvm/include/llvm/TargetParser/TargetParser.h |  10 +
 llvm/lib/Object/ELFObjectFile.cpp |  10 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   4 +
 llvm/lib/Target/AMDGPU/AMDGPU.td  |  87 +++--
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   6 +
 .../AMDGPURemoveIncompatibleFunctions.cpp |   6 +-
 llvm/lib/Target/AMDGPU/GCNProcessors.td   |  22 ++
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   4 +
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  26 ++
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |  11 +
 llvm/lib/TargetParser/TargetParser.cpp|  46 +++
 .../GlobalISel/llvm.amdgcn.workitem.id.ll |   1 +
 .../CodeGen/AMDGPU/directive-amdgcn-target.ll |  14 +
 .../CodeGen/AMDGPU/elf-header-flags-mach.ll   |  10 +
 llvm/test/CodeGen/AMDGPU/gds-allocation.ll|   1 +
 llvm/test/CodeGen/AMDGPU/gds-atomic.ll|   1 +
 .../AMDGPU/generic-targets-require-v6.ll  |  18 +
 .../AMDGPU/hsa-generic-target-features.ll |  31 ++
 .../llvm.amdgcn.image.gather4.d16.dim.ll  |   3 +
 .../AMDGPU/llvm.amdgcn.image.sample.dim.ll|   3 +
 .../AMDGPU/unsupported-image-sample.ll|  12 +-
 .../Object/AMDGPU/elf-header-flags-mach.yaml  |  29 ++
 .../llvm-objdump/ELF/AMDGPU/subtarget.ll  |  20 ++
 .../llvm-readobj/ELF/AMDGPU/elf-headers.test  |  12 +
 llvm/tools/llvm-readobj/ELFDumper.cpp | 128 +++
 30 files changed, 689 insertions(+), 192 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/generic-targets-require-v6.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/hsa-generic-target-features.ll

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 141501e8a4d9a..799634ccec7ba 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -279,13 +279,25 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (GPUKind == llvm::AMDGPU::GK_NONE && !IsHIPHost)
 return;
 
-  StringRef CanonName = isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
-  : getArchNameR600(GPUKind);
+  std::string CanonName = (isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
+ : getArchNameR600(GPUKind))
+  .str();
+
+  // Sanitize the name of generic targets.
+  // e.g. gfx10.1-generic -> gfx10_1_generic
+  if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
+  GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
+std::replace(CanonName.begin(), CanonName.end(), '.', '_');
+std::replace(CanonName.begin(), CanonName.end(), '-', '_');
+  }
+
   Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
   // Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
   if (isAMDGCN(getTriple()) && !IsHIPHost) {
-assert(CanonName.starts_with("gfx") && "Invalid amdgcn canonical name");
-Builder.defineMacro(Twine("__") + Twine(CanonName.drop_back(2).upper()) +
+assert(StringRef(CanonName).starts_with("gfx") &&
+   "Invalid amdgcn canonical name");
+StringRef CanonFamilyName = getArchFamilyNameAMDGCN(GPUKind);
+Builder.defineMacro(Twine("__") + Twine(CanonFamilyName.upper()) +
 Twine("__"));
 Builder.defineMacro("__amdgcn_processor__",
 Twine("\"") + Twine(CanonName) + Twine("\""));
diff --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 81c22af460d12..3b10444ef71d3 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -131,6 +131,11 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1200 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1200 
-DFAMILY=GFX12
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s 

[clang] [Clang][Sema] fix crash in codegen stage when an lambda expression declared in an unevaluated context (PR #80802)

2024-02-07 Thread Qizhi Hu via cfe-commits

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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-07 Thread Pierre van Houtryve via cfe-commits


@@ -520,6 +520,102 @@ Every processor supports every OS ABI (see 
:ref:`amdgpu-os`) with the following
 
  === ===  = = 
=== === ==
 
+Generic processors allow execution of a single code objects on any of the 
processors that
+it supports. Such code objects may not perform as well as those for the 
non-generic processors.
+
+Generic processors are only available on code object V6 and above (see 
:ref:`amdgpu-elf-code-object`).
+
+Generic processor code objects are versioned (see 
:ref:`amdgpu-elf-header-e_flags-table-v6-onwards`).
+The version number is used by runtimes to determine if a code object can be 
run on a specific agent.

Pierre-vh wrote:

I rephrased it a bit (e.g. member -> supported processor) but I mostly followed 
your suggestion

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-07 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Perhaps `[Driver] Allow -fbasic-block-sections for ELF AArch64'

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


[clang] Allow default arguments to be evaluated like other arguments. (PR #80956)

2024-02-07 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/80956

This PR aligns the evaluation of default arguments with other kinds of 
arguments by extracting the expressions within them as argument values to be 
evaluated.

>From 9d3f7377901539abeef949c1b33a99b1278900d8 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Wed, 7 Feb 2024 00:57:00 -0800
Subject: [PATCH] Allow default arguments to be evaluated like other arguments.

This PR aligns the evaluation of default arguments with other kinds of arguments
by extracting the expressions within them as argument values to be evaluated.
---
 .../WebKit/UncountedCallArgsChecker.cpp   |  3 ++
 .../ref-countable-default-arg-nullptr.cpp | 45 +++
 2 files changed, 48 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..7cb0e4680d9e9e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -91,6 +91,9 @@ class UncountedCallArgsChecker
 
 const auto *Arg = CE->getArg(ArgIdx);
 
+if (auto *defaultArg = dyn_cast(Arg))
+  Arg = defaultArg->getExpr();
+
 std::pair ArgOrigin =
 tryToFindPtrOrigin(Arg, true);
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
new file mode 100644
index 00..cd38b335dcf85e
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+template 
+class RefPtr {
+public:
+  RefPtr(T* ptr)
+: m_ptr(ptr)
+  {
+if (m_ptr)
+  m_ptr->ref();
+  }
+
+  ~RefPtr()
+  {
+if (m_ptr)
+  m_ptr->deref();
+  }
+
+  T* get() { return m_ptr; }
+
+private:
+  T* m_ptr;
+};
+
+class Obj {
+public:
+  static Obj* get();
+  static RefPtr create();
+  void ref() const;
+  void deref() const;
+};
+
+void someFunction(Obj*, Obj* = nullptr);
+void otherFunction(Obj*, Obj* = Obj::get());
+// expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+void anotherFunction(Obj*, Obj* = Obj::create().get());
+
+void otherFunction() {
+  someFunction(nullptr);
+  someFunction(Obj::get());
+  // expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+  someFunction(Obj::create().get());
+  otherFunction(nullptr);
+  anotherFunction(nullptr);
+}

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


[clang] Allow default arguments to be evaluated like other arguments. (PR #80956)

2024-02-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

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

Author: Ryosuke Niwa (rniwa)


Changes

This PR aligns the evaluation of default arguments with other kinds of 
arguments by extracting the expressions within them as argument values to be 
evaluated.

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


2 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+3) 
- (added) 
clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp (+45) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..7cb0e4680d9e9e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -91,6 +91,9 @@ class UncountedCallArgsChecker
 
 const auto *Arg = CE->getArg(ArgIdx);
 
+if (auto *defaultArg = dyn_cast(Arg))
+  Arg = defaultArg->getExpr();
+
 std::pair ArgOrigin =
 tryToFindPtrOrigin(Arg, true);
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
new file mode 100644
index 00..cd38b335dcf85e
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+template 
+class RefPtr {
+public:
+  RefPtr(T* ptr)
+: m_ptr(ptr)
+  {
+if (m_ptr)
+  m_ptr->ref();
+  }
+
+  ~RefPtr()
+  {
+if (m_ptr)
+  m_ptr->deref();
+  }
+
+  T* get() { return m_ptr; }
+
+private:
+  T* m_ptr;
+};
+
+class Obj {
+public:
+  static Obj* get();
+  static RefPtr create();
+  void ref() const;
+  void deref() const;
+};
+
+void someFunction(Obj*, Obj* = nullptr);
+void otherFunction(Obj*, Obj* = Obj::get());
+// expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+void anotherFunction(Obj*, Obj* = Obj::create().get());
+
+void otherFunction() {
+  someFunction(nullptr);
+  someFunction(Obj::get());
+  // expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+  someFunction(Obj::create().get());
+  otherFunction(nullptr);
+  anotherFunction(nullptr);
+}

``




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


[clang] Allow default arguments to be evaluated like other arguments. (PR #80956)

2024-02-07 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/80956

>From bc390afd3a2e9de6e2a883205ce3862e45d26e06 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Wed, 7 Feb 2024 00:57:00 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Allow default
 arguments to be evaluated like other arguments.

This PR aligns the evaluation of default arguments with other kinds of arguments
by extracting the expressions within them as argument values to be evaluated.
---
 .../WebKit/UncountedCallArgsChecker.cpp   |  3 ++
 .../ref-countable-default-arg-nullptr.cpp | 45 +++
 2 files changed, 48 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..7cb0e4680d9e9e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -91,6 +91,9 @@ class UncountedCallArgsChecker
 
 const auto *Arg = CE->getArg(ArgIdx);
 
+if (auto *defaultArg = dyn_cast(Arg))
+  Arg = defaultArg->getExpr();
+
 std::pair ArgOrigin =
 tryToFindPtrOrigin(Arg, true);
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
new file mode 100644
index 00..cd38b335dcf85e
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+template 
+class RefPtr {
+public:
+  RefPtr(T* ptr)
+: m_ptr(ptr)
+  {
+if (m_ptr)
+  m_ptr->ref();
+  }
+
+  ~RefPtr()
+  {
+if (m_ptr)
+  m_ptr->deref();
+  }
+
+  T* get() { return m_ptr; }
+
+private:
+  T* m_ptr;
+};
+
+class Obj {
+public:
+  static Obj* get();
+  static RefPtr create();
+  void ref() const;
+  void deref() const;
+};
+
+void someFunction(Obj*, Obj* = nullptr);
+void otherFunction(Obj*, Obj* = Obj::get());
+// expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+void anotherFunction(Obj*, Obj* = Obj::create().get());
+
+void otherFunction() {
+  someFunction(nullptr);
+  someFunction(Obj::get());
+  // expected-warning@-1{{Call argument is uncounted and unsafe 
[alpha.webkit.UncountedCallArgsChecker]}}
+  someFunction(Obj::create().get());
+  otherFunction(nullptr);
+  anotherFunction(nullptr);
+}

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


[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/80959

Sema would incorrectly skip diagnosing a malformed use of `= default` on an 
implcitly deleted move constructor while performing template instantiation, 
even if we were about to then generate a definition of said move constructor, 
which caused a crash.

This fixes that by always erroring in that case. However, there are some things 
to note here
1. This problem did not exist in earlier versions of Clang (e.g. the release 
branch of Clang 17 diagnoses this correctly with an overload resolution error). 
2. There are some other code paths that seem very similar to this one that that 
should probably also be investigated (specifically, other special member 
functions and potentially also defaulted comparison operators; I’ll take a look 
at adding some tests for those too if need be, but I wanted to document the 
current state of this here before that).
3. There may be a better place to put this check seeing as the functions that 
are changed by this do not seem to have been modified compared to the release 
branch of Clang 17, which also begs the question as to what change actually 
caused this to break.

This fixes #80869.

>From 9224a09244d48b630358ef8659c4c28436d6d28a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 10:07:32 +0100
Subject: [PATCH] [Clang][Sema] Do not attempt to instantiate a deleted move
 constructor

---
 clang/include/clang/Sema/Sema.h   |  3 ++-
 clang/lib/Sema/SemaDeclCXX.cpp| 18 +++--
 .../SemaCXX/cxx0x-defaulted-functions.cpp | 20 +++
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3c26003b5bda7f..7e36b3f1771a71 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7999,7 +7999,8 @@ class Sema final {
 
   bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
  CXXSpecialMember CSM,
- SourceLocation DefaultLoc);
+ SourceLocation DefaultLoc,
+ bool ForDefinition = false);
   void CheckDelayedMemberExceptionSpecs();
 
   bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ab8a967b06a456..8f355e1e86519d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7676,7 +7676,8 @@ void Sema::CheckExplicitlyDefaultedFunction(Scope *S, 
FunctionDecl *FD) {
 
 bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
  CXXSpecialMember CSM,
- SourceLocation DefaultLoc) {
+ SourceLocation DefaultLoc,
+ bool ForDefinition) {
   CXXRecordDecl *RD = MD->getParent();
 
   assert(MD->isExplicitlyDefaulted() && CSM != CXXInvalid &&
@@ -7894,13 +7895,18 @@ bool 
Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
   if (ShouldDeleteForTypeMismatch || ShouldDeleteSpecialMember(MD, CSM)) {
 if (First) {
   SetDeclDeleted(MD, MD->getLocation());
-  if (!inTemplateInstantiation() && !HadError) {
-Diag(MD->getLocation(), diag::warn_defaulted_method_deleted) << CSM;
+  if ((ForDefinition || !inTemplateInstantiation()) && !HadError) {
+// Always error if we're about to generate a definition.
+HadError = ForDefinition;
+Diag(MD->getLocation(), ForDefinition
+? diag::err_out_of_line_default_deletes
+: diag::warn_defaulted_method_deleted)
+<< CSM;
 if (ShouldDeleteForTypeMismatch) {
   Diag(MD->getLocation(), diag::note_deleted_type_mismatch) << CSM;
 } else if (ShouldDeleteSpecialMember(MD, CSM, nullptr,
  /*Diagnose*/ true) &&
-   DefaultLoc.isValid()) {
+   DefaultLoc.isValid() && !ForDefinition) {
   Diag(DefaultLoc, diag::note_replace_equals_default_to_delete)
   << FixItHint::CreateReplacement(DefaultLoc, "delete");
 }
@@ -18285,8 +18291,8 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation 
DefaultLoc) {
   } else {
 auto *MD = cast(FD);
 
-if (CheckExplicitlyDefaultedSpecialMember(MD, DefKind.asSpecialMember(),
-  DefaultLoc))
+if (CheckExplicitlyDefaultedSpecialMember(
+MD, DefKind.asSpecialMember(), DefaultLoc, /*ForDefinition=*/true))
   MD->setInvalidDecl();
 else
   DefineDefaultedFunction(*this, MD, DefaultLoc);
diff --git a/clang/test/SemaCXX/cxx0x-defaulted-functi

[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Sema would incorrectly skip diagnosing a malformed use of `= default` on an 
implcitly deleted move constructor while performing template instantiation, 
even if we were about to then generate a definition of said move constructor, 
which caused a crash.

This fixes that by always erroring in that case. However, there are some things 
to note here
1. This problem did not exist in earlier versions of Clang (e.g. the release 
branch of Clang 17 diagnoses this correctly with an overload resolution error). 
2. There are some other code paths that seem very similar to this one that that 
should probably also be investigated (specifically, other special member 
functions and potentially also defaulted comparison operators; I’ll take a look 
at adding some tests for those too if need be, but I wanted to document the 
current state of this here before that).
3. There may be a better place to put this check seeing as the functions that 
are changed by this do not seem to have been modified compared to the release 
branch of Clang 17, which also begs the question as to what change actually 
caused this to break.

This fixes #80869.

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


3 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+12-6) 
- (modified) clang/test/SemaCXX/cxx0x-defaulted-functions.cpp (+20) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3c26003b5bda7f..7e36b3f1771a71 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7999,7 +7999,8 @@ class Sema final {
 
   bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
  CXXSpecialMember CSM,
- SourceLocation DefaultLoc);
+ SourceLocation DefaultLoc,
+ bool ForDefinition = false);
   void CheckDelayedMemberExceptionSpecs();
 
   bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ab8a967b06a456..8f355e1e86519d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7676,7 +7676,8 @@ void Sema::CheckExplicitlyDefaultedFunction(Scope *S, 
FunctionDecl *FD) {
 
 bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
  CXXSpecialMember CSM,
- SourceLocation DefaultLoc) {
+ SourceLocation DefaultLoc,
+ bool ForDefinition) {
   CXXRecordDecl *RD = MD->getParent();
 
   assert(MD->isExplicitlyDefaulted() && CSM != CXXInvalid &&
@@ -7894,13 +7895,18 @@ bool 
Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
   if (ShouldDeleteForTypeMismatch || ShouldDeleteSpecialMember(MD, CSM)) {
 if (First) {
   SetDeclDeleted(MD, MD->getLocation());
-  if (!inTemplateInstantiation() && !HadError) {
-Diag(MD->getLocation(), diag::warn_defaulted_method_deleted) << CSM;
+  if ((ForDefinition || !inTemplateInstantiation()) && !HadError) {
+// Always error if we're about to generate a definition.
+HadError = ForDefinition;
+Diag(MD->getLocation(), ForDefinition
+? diag::err_out_of_line_default_deletes
+: diag::warn_defaulted_method_deleted)
+<< CSM;
 if (ShouldDeleteForTypeMismatch) {
   Diag(MD->getLocation(), diag::note_deleted_type_mismatch) << CSM;
 } else if (ShouldDeleteSpecialMember(MD, CSM, nullptr,
  /*Diagnose*/ true) &&
-   DefaultLoc.isValid()) {
+   DefaultLoc.isValid() && !ForDefinition) {
   Diag(DefaultLoc, diag::note_replace_equals_default_to_delete)
   << FixItHint::CreateReplacement(DefaultLoc, "delete");
 }
@@ -18285,8 +18291,8 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation 
DefaultLoc) {
   } else {
 auto *MD = cast(FD);
 
-if (CheckExplicitlyDefaultedSpecialMember(MD, DefKind.asSpecialMember(),
-  DefaultLoc))
+if (CheckExplicitlyDefaultedSpecialMember(
+MD, DefKind.asSpecialMember(), DefaultLoc, /*ForDefinition=*/true))
   MD->setInvalidDecl();
 else
   DefineDefaultedFunction(*this, MD, DefaultLoc);
diff --git a/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp 
b/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
index 0c3dd1ea7aa274..112bb4488de063 100644
--- a/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ b/clang/test/SemaCXX/cxx0x-de

[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

CC @shafik, @erichkeane, @AaronBallman 

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


[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> which also begs the question as to what change actually caused this to break

Since I’m not sure how that is usually done here, is bisecting a reasonable 
approach? I’m asking because rebuilding a project the size of Clang 
unfortunately ends up taking a rather substantial amount of time...

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


[clang] [dataflow] Fix crash when InitListExpr is not a prvalue (PR #80970)

2024-02-07 Thread Paul Semel via cfe-commits

https://github.com/paulsemel created 
https://github.com/llvm/llvm-project/pull/80970

None

>From e56ced76e19d57a020030ab41a125012460d08d7 Mon Sep 17 00:00:00 2001
From: Paul Semel 
Date: Wed, 7 Feb 2024 10:26:23 +
Subject: [PATCH] [dataflow] Fix crash when InitListExpr is not a prvalue

---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp  |  6 ++
 .../Analysis/FlowSensitive/TransferTest.cpp| 14 ++
 2 files changed, 20 insertions(+)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb3aec763c29c..dc0f1bd6dcc29 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -648,6 +648,12 @@ class TransferVisitor : public 
ConstStmtVisitor {
 QualType Type = S->getType();
 
 if (!Type->isStructureOrClassType()) {
+  // It is possible that InitListExpr is not a prvalue, in which case
+  // `setValue` will fail. In this case, we can just let the next
+  // transfer function handle the value creation.
+  if (!S->isPRValue())
+return;
+
   if (auto *Val = Env.createValue(Type))
 Env.setValue(*S, *Val);
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 8bbb04024dcce..74e6f1abfa4ba 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2313,6 +2313,20 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, InitListExprAsXValue) {
+  // This is a crash repro.
+  std::string Code = R"(
+void target() {
+  auto&& test{false};
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
 TEST(TransferTest, CopyConstructor) {
   std::string Code = R"(
 struct A {

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


[clang] [dataflow] Fix crash when InitListExpr is not a prvalue (PR #80970)

2024-02-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: Paul Semel (paulsemel)


Changes



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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+6) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+14) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb3aec763c29ca..dc0f1bd6dcc291 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -648,6 +648,12 @@ class TransferVisitor : public 
ConstStmtVisitor {
 QualType Type = S->getType();
 
 if (!Type->isStructureOrClassType()) {
+  // It is possible that InitListExpr is not a prvalue, in which case
+  // `setValue` will fail. In this case, we can just let the next
+  // transfer function handle the value creation.
+  if (!S->isPRValue())
+return;
+
   if (auto *Val = Env.createValue(Type))
 Env.setValue(*S, *Val);
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 8bbb04024dcce6..74e6f1abfa4ba3 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2313,6 +2313,20 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, InitListExprAsXValue) {
+  // This is a crash repro.
+  std::string Code = R"(
+void target() {
+  auto&& test{false};
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
 TEST(TransferTest, CopyConstructor) {
   std::string Code = R"(
 struct A {

``




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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-07 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@ldionne if downstream is catching upstream, I would love to discuss rationale 
behind ignoring command line option. I asked this question several times and 
haven't got answer. Original [diff](https://reviews.llvm.org/D89001) that 
introduced this behavior also didn't explain why new behavior is "intended" and 
better than old one. Instead of resolving case of two headers it actually 
prevents finding header that exists and path is specified in command line.

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/80916

>From ccd5fd925a3629d99c0e12ba4757758f740c1407 Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [Driver] Allow -fbasic-block-sections for AArch64 ELF

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 9 +
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf2421154372..4a3fe7c5148b31 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
+}
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d5..5e701072bfc74a 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/80916

>From 36f9de4ab82f4f27131f561417749481eada0f3e Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [Driver] Allow -fbasic-block-sections for AArch64 ELF

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 9 +
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf242115437..b970533ddc253 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64() && Triple.isOSBinFormatELF) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
+}
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d..5e701072bfc74 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/80916

>From 18f602b2cc0c603564c17737241bb9f188b965e7 Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [Driver] Allow -fbasic-block-sections for AArch64 ELF

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 9 +
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf2421154372..b970533ddc2536 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64() && Triple.isOSBinFormatELF) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
+}
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d5..5e701072bfc74a 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] [clang] Add fbasic-block-sections support for AArch64 (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits


@@ -5972,6 +5972,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new

dhoekwater wrote:

Yep, added! I got so caught up writing a comment that I forgot to actually do 
what I created this PR to do...

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


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-07 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

Sorry, the discussion went too specific for me :-(

But after taking a quick look, my impression is that this change reverses the 
bug fixed in https://github.com/llvm/llvm-project/pull/70817.

To recap, that PR preferred the C++ headers available in the toolchain 
distribution over the SDK headers, when the compiler was launched via a 
symbolic link to the executable (a behaviour common to the npm/xpm ecosystem).

If I understand this proposal right (please correct me if I'm wrong), it will 
move the SDK headers to the top of the list. 

If this will happen only when an explicit `-isysroot` is passed on the compiler 
command line, it might be ok, but if it will happen for all cases, this will 
simply bring us back to the pre 70817 case, when builds on old macOS-es (like 
10.13) with a new clang (like 17.x) will fail, due to the out of sync old 
headers from the SDK with the new library from the toolchain. I wasted quite a 
lot of time to diagnose this subtle issue by that time.



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


[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)

2024-02-07 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/80975

As it was pointed out in https://github.com/llvm/llvm-project/pull/80724, we 
should not be checking `getLangOpts().Bool` when determining something related 
to logical operators, since it only indicates that bool keyword is present, not 
which semantic logical operators have. As a side effect a missing 
`-Wpointer-bool-conversion` in OpenCL C was restored since like C23, OpenCL C 
has bool keyword but logical operators still return int.

>From 32b1b114cdf9c77af7a400b8f7705d50de2ef9de Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 7 Feb 2024 03:07:47 -0800
Subject: [PATCH] [clang] Use CPlusPlus language option instead of Bool

As it was pointed out in https://github.com/llvm/llvm-project/pull/80724,
we should not be checking `getLangOpts().Bool` when determining something
related to logical operators, since it only indicates that bool keyword
is present, not which semantic logical operators have.
As a side effect a missing `-Wpointer-bool-conversion` in OpenCL C was
restored since like C23, OpenCL C has bool keyword but logical operators
still return int.
---
 clang/lib/Sema/SemaChecking.cpp| 8 
 clang/test/SemaOpenCL/operators.cl | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b071a02ca3713..6588aa23e1116 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16129,10 +16129,10 @@ static void CheckConditionalOperator(Sema &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  // While C23 does have bool as a keyword, we still need to run the bool-like
-  // conversion checks as bools are still not used as the return type from
-  // "boolean" operators or as the input type for conditional operators.
-  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
+  // Run the bool-like conversion checks only for C since there bools are
+  // still not used as the return type from "boolean" operators or as the input
+  // type for conditional operators.
+  if (S.getLangOpts().CPlusPlus)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/SemaOpenCL/operators.cl 
b/clang/test/SemaOpenCL/operators.cl
index cf359acd5acb9..76a7692a7105c 100644
--- a/clang/test/SemaOpenCL/operators.cl
+++ b/clang/test/SemaOpenCL/operators.cl
@@ -118,6 +118,6 @@ kernel void pointer_ops(){
   bool b = !p;
   b = p==0;
   int i;
-  b = !&i;
+  b = !&i; // expected-warning {{address of 'i' will always evaluate to 
'true'}}
   b = &i==(int *)1;
 }

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


[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

As it was pointed out in https://github.com/llvm/llvm-project/pull/80724, we 
should not be checking `getLangOpts().Bool` when determining something related 
to logical operators, since it only indicates that bool keyword is present, not 
which semantic logical operators have. As a side effect a missing 
`-Wpointer-bool-conversion` in OpenCL C was restored since like C23, OpenCL C 
has bool keyword but logical operators still return int.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+4-4) 
- (modified) clang/test/SemaOpenCL/operators.cl (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b071a02ca3713f..6588aa23e1116f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16129,10 +16129,10 @@ static void CheckConditionalOperator(Sema &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  // While C23 does have bool as a keyword, we still need to run the bool-like
-  // conversion checks as bools are still not used as the return type from
-  // "boolean" operators or as the input type for conditional operators.
-  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
+  // Run the bool-like conversion checks only for C since there bools are
+  // still not used as the return type from "boolean" operators or as the input
+  // type for conditional operators.
+  if (S.getLangOpts().CPlusPlus)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/SemaOpenCL/operators.cl 
b/clang/test/SemaOpenCL/operators.cl
index cf359acd5acb97..76a7692a7105c8 100644
--- a/clang/test/SemaOpenCL/operators.cl
+++ b/clang/test/SemaOpenCL/operators.cl
@@ -118,6 +118,6 @@ kernel void pointer_ops(){
   bool b = !p;
   b = p==0;
   int i;
-  b = !&i;
+  b = !&i; // expected-warning {{address of 'i' will always evaluate to 
'true'}}
   b = &i==(int *)1;
 }

``




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


[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)

2024-02-07 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Not sure about what to put in a release note, and whether it is necessary at 
all.

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


[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-02-07 Thread Shahid Iqbal via cfe-commits

https://github.com/shahidiqbal13 created 
https://github.com/llvm/llvm-project/pull/80976

- Raising for preliminary review (forget about formating)
- Fixed the '...' catch all ellipsis in catch stmt
- Will fix the failed testcases once we get agree on this
- I don't think we need to support for the variadic function support ellipsis 
token this usecase [void bar(int, ...); ]
- See the issue here:  https://github.com/llvm/llvm-project/issues/63106

Output of the fixed 1st issue (catch(...))
```
`-FunctionDecl 0x55bdaf78d9a0  line:1:6 foo 'void ()'
  `-CompoundStmt 0x55bdaf78dbb8 
`-CXXTryStmt 0x55bdaf78db98 
  |-CompoundStmt 0x55bdaf78da90 
  `-CXXCatchStmt 0x55bdaf78db78 
|-VarDecl 0x55bdaf78db00 <, col:12> col:12 catch_all  
''
`-CompoundStmt 0x55bdaf78db68 
```


>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Thu, 16 Nov 2023 11:26:43 -0500
Subject: [PATCH 1/2] TESTING infra

---
 clang/NOTES.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index f06ea8c70cd340..c83dda52a1fc21 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,6 +4,8 @@
 
 //===-===//
 
+//TESTING git infra//
+
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 79c592853c77fb0a96746d860be63d4605ea87e7 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Wed, 7 Feb 2024 06:08:10 -0500
Subject: [PATCH 2/2] =?UTF-8?q?Issue=20#63106:=20[=D1=81lang]=20Representa?=
 =?UTF-8?q?tion=20of=20ellipsis=20in=20AST?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 clang/include/clang/AST/DeclBase.h | 11 +--
 clang/include/clang/Sema/Sema.h|  2 +-
 clang/lib/AST/TextNodeDumper.cpp   |  3 +++
 clang/lib/Parse/ParseStmt.cpp  | 14 +++---
 clang/lib/Sema/SemaDeclCXX.cpp |  7 +--
 clang/test/AST/ast-dump-stmt.cpp   |  2 +-
 6 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc674..67f5c7dd1b7f98 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -301,6 +301,9 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(bool)
   unsigned Implicit : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasCatchEllipsis : 1;
+
   /// Whether this declaration was "used", meaning that a definition is
   /// required.
   LLVM_PREFERRED_TYPE(bool)
@@ -394,7 +397,7 @@ class alignas(8) Decl {
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+Implicit(false), HasCatchEllipsis(false), Used(false), 
Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
@@ -402,7 +405,7 @@ class alignas(8) Decl {
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), 
HasCatchEllipsis(false),
 Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
 Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
@@ -597,6 +600,10 @@ class alignas(8) Decl {
   bool isImplicit() const { return Implicit; }
   void setImplicit(bool I = true) { Implicit = I; }
 
+  /// isCatchEllipsisTok - Indicates whether '...' is present in the catch decl
+  bool isCatchEllipsisTok() const { return HasCatchEllipsis; }
+  void setCatchEllipsisTok(bool I = true) { HasCatchEllipsis = I; }
+
   /// Whether *any* (re-)declaration of the entity was used, meaning that
   /// a definition is required.
   ///
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 501dc01200a1c3..ffc6d2926f85f2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5322,7 +5322,7 @@ class Sema final {
  SourceLocation IdLoc,
  IdentifierInfo *Id);
 
-  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
+  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D, bool isCatchAll = 
false);
 
   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
 Decl *ExDecl, Stmt *HandlerBlock);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9c..1da20cdfa36a66 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -272,6 +272,9 @@ void TextNode

[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shahid Iqbal (shahidiqbal13)


Changes

- Raising for preliminary review (forget about formating)
- Fixed the '...' catch all ellipsis in catch stmt
- Will fix the failed testcases once we get agree on this
- I don't think we need to support for the variadic function support ellipsis 
token this usecase [void bar(int, ...); ]
- See the issue here:  https://github.com/llvm/llvm-project/issues/63106

Output of the fixed 1st issue (catch(...))
```
`-FunctionDecl 0x55bdaf78d9a0  line:1:6 foo 
'void ()'
  `-CompoundStmt 0x55bdaf78dbb8 
`-CXXTryStmt 0x55bdaf78db98 
  |-CompoundStmt 0x55bdaf78da90 
  `-CXXCatchStmt 0x55bdaf78db78 
|-VarDecl 0x55bdaf78db00 <, col:12> col:12 
catch_all  ''
`-CompoundStmt 0x55bdaf78db68 
```


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


7 Files Affected:

- (modified) clang/NOTES.txt (+2) 
- (modified) clang/include/clang/AST/DeclBase.h (+9-2) 
- (modified) clang/include/clang/Sema/Sema.h (+1-1) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+3) 
- (modified) clang/lib/Parse/ParseStmt.cpp (+11-3) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+5-2) 
- (modified) clang/test/AST/ast-dump-stmt.cpp (+1-1) 


``diff
diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index f06ea8c70cd34..c83dda52a1fc2 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,6 +4,8 @@
 
 //===-===//
 
+//TESTING git infra//
+
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc67..67f5c7dd1b7f9 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -301,6 +301,9 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(bool)
   unsigned Implicit : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasCatchEllipsis : 1;
+
   /// Whether this declaration was "used", meaning that a definition is
   /// required.
   LLVM_PREFERRED_TYPE(bool)
@@ -394,7 +397,7 @@ class alignas(8) Decl {
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+Implicit(false), HasCatchEllipsis(false), Used(false), 
Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
@@ -402,7 +405,7 @@ class alignas(8) Decl {
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), 
HasCatchEllipsis(false),
 Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
 Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
@@ -597,6 +600,10 @@ class alignas(8) Decl {
   bool isImplicit() const { return Implicit; }
   void setImplicit(bool I = true) { Implicit = I; }
 
+  /// isCatchEllipsisTok - Indicates whether '...' is present in the catch decl
+  bool isCatchEllipsisTok() const { return HasCatchEllipsis; }
+  void setCatchEllipsisTok(bool I = true) { HasCatchEllipsis = I; }
+
   /// Whether *any* (re-)declaration of the entity was used, meaning that
   /// a definition is required.
   ///
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 501dc01200a1c..ffc6d2926f85f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5322,7 +5322,7 @@ class Sema final {
  SourceLocation IdLoc,
  IdentifierInfo *Id);
 
-  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
+  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D, bool isCatchAll = 
false);
 
   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
 Decl *ExDecl, Stmt *HandlerBlock);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9..1da20cdfa36a6 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -272,6 +272,9 @@ void TextNodeDumper::Visit(const Decl *D) {
   if (D->isImplicit())
 OS << " implicit";
 
+  if (D->isCatchEllipsisTok())
+OS << " catch_all ";
+
   if (D->isUsed())
 OS << " used";
   else if (D->isThisDeclarationReferenced())
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 2531147c23

[clang] [scan-build] Use python3 instead of python in scripts. (PR #80977)

2024-02-07 Thread Collin Funk via cfe-commits

https://github.com/collinfunk created 
https://github.com/llvm/llvm-project/pull/80977

This was done in some other python files in the following commit:
4c1e487c413810655757ea19d0cf3d4f5c40898e

Without this change these scripts do not run on Debian or Ubuntu systems. See 
the referenced patch for more information.

>From 13a23576ec703553b70e0bad9e189fc922bb46cd Mon Sep 17 00:00:00 2001
From: Collin Funk 
Date: Wed, 7 Feb 2024 03:22:59 -0800
Subject: [PATCH] [scan-build] Use python3 instead of python in scripts.

This was done in some other python files in the following
commit:
4c1e487c413810655757ea19d0cf3d4f5c40898e

Without this change these scripts do not run on Debian or
Ubuntu systems. See the refrenced patch for more information.

Signed-off-by: Collin Funk 
---
 clang/tools/include-mapping/test.py  | 2 +-
 clang/tools/scan-view/bin/scan-view  | 2 +-
 clang/tools/scan-view/share/Reporter.py  | 2 +-
 clang/tools/scan-view/share/startfile.py | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
 mode change 100644 => 100755 clang/tools/scan-view/share/Reporter.py
 mode change 100644 => 100755 clang/tools/scan-view/share/startfile.py

diff --git a/clang/tools/include-mapping/test.py 
b/clang/tools/include-mapping/test.py
index eef328381f2bb..c0f1f3a79f922 100755
--- a/clang/tools/include-mapping/test.py
+++ b/clang/tools/include-mapping/test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # ===- test.py -  -*- python 
-*--===#
 #
 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
diff --git a/clang/tools/scan-view/bin/scan-view 
b/clang/tools/scan-view/bin/scan-view
index d01aebb4029a7..f3375804654d2 100755
--- a/clang/tools/scan-view/bin/scan-view
+++ b/clang/tools/scan-view/bin/scan-view
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import print_function
 
diff --git a/clang/tools/scan-view/share/Reporter.py 
b/clang/tools/scan-view/share/Reporter.py
old mode 100644
new mode 100755
index 21874b378687e..aa16a47524c8b
--- a/clang/tools/scan-view/share/Reporter.py
+++ b/clang/tools/scan-view/share/Reporter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """Methods for reporting bugs."""
diff --git a/clang/tools/scan-view/share/startfile.py 
b/clang/tools/scan-view/share/startfile.py
old mode 100644
new mode 100755
index d63e69280e90d..05e88ce642171
--- a/clang/tools/scan-view/share/startfile.py
+++ b/clang/tools/scan-view/share/startfile.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """Utility for opening a file using the default application in a cross-platform

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


[clang] [scan-build] Use python3 instead of python in scripts. (PR #80977)

2024-02-07 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/80977
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [scan-build] Use python3 instead of python in scripts. (PR #80977)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Collin Funk (collinfunk)


Changes

This was done in some other python files in the following commit:
4c1e487c413810655757ea19d0cf3d4f5c40898e

Without this change these scripts do not run on Debian or Ubuntu systems. See 
the referenced patch for more information.

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


4 Files Affected:

- (modified) clang/tools/include-mapping/test.py (+1-1) 
- (modified) clang/tools/scan-view/bin/scan-view (+1-1) 
- (modified) clang/tools/scan-view/share/Reporter.py (+1-1) 
- (modified) clang/tools/scan-view/share/startfile.py (+1-1) 


``diff
diff --git a/clang/tools/include-mapping/test.py 
b/clang/tools/include-mapping/test.py
index eef328381f2bb..c0f1f3a79f922 100755
--- a/clang/tools/include-mapping/test.py
+++ b/clang/tools/include-mapping/test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # ===- test.py -  -*- python 
-*--===#
 #
 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
diff --git a/clang/tools/scan-view/bin/scan-view 
b/clang/tools/scan-view/bin/scan-view
index d01aebb4029a7..f3375804654d2 100755
--- a/clang/tools/scan-view/bin/scan-view
+++ b/clang/tools/scan-view/bin/scan-view
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 from __future__ import print_function
 
diff --git a/clang/tools/scan-view/share/Reporter.py 
b/clang/tools/scan-view/share/Reporter.py
old mode 100644
new mode 100755
index 21874b378687e..aa16a47524c8b
--- a/clang/tools/scan-view/share/Reporter.py
+++ b/clang/tools/scan-view/share/Reporter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """Methods for reporting bugs."""
diff --git a/clang/tools/scan-view/share/startfile.py 
b/clang/tools/scan-view/share/startfile.py
old mode 100644
new mode 100755
index d63e69280e90d..05e88ce642171
--- a/clang/tools/scan-view/share/startfile.py
+++ b/clang/tools/scan-view/share/startfile.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 """Utility for opening a file using the default application in a cross-platform

``




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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-07 Thread via cfe-commits

https://github.com/mmoadeli updated 
https://github.com/llvm/llvm-project/pull/78759

>From 286ac8f3ea6aec711827ccab9608b010e78b18cf Mon Sep 17 00:00:00 2001
From: m moadeli 
Date: Fri, 19 Jan 2024 18:42:24 +
Subject: [PATCH 1/2] - Address space cast of a `local_space` specialized
 `nullptr` into a generic space for the CUDA backend. - In the context of AMD
 GPU, assigns a NULL value of `~0` for the address spaces of `sycl_local` and
 `sycl_private`

---
 clang/lib/Basic/Targets/AMDGPU.h  |   6 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   |  18 +++
 .../CodeGenSYCL/address-space-conversions.cpp |   4 +
 .../amd-address-space-conversions.cpp | 128 ++
 .../cuda-address-space-conversions.cpp| 122 +
 5 files changed, 276 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
 create mode 100644 clang/test/CodeGenSYCL/cuda-address-space-conversions.cpp

diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 90a1516ecdd20d..94d6ee7f5f72df 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -418,8 +418,10 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   // value ~0.
   uint64_t getNullPointerValue(LangAS AS) const override {
 // FIXME: Also should handle region.
-return (AS == LangAS::opencl_local || AS == LangAS::opencl_private)
-  ? ~0 : 0;
+return (AS == LangAS::opencl_local || AS == LangAS::opencl_private ||
+AS == LangAS::sycl_local || AS == LangAS::sycl_private)
+   ? ~0
+   : 0;
   }
 
   void setAuxTarget(const TargetInfo *Aux) override;
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index d0dc7c258a03a6..8718f1ecf3a7e0 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -47,6 +47,10 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
CodeGen::CodeGenModule &M) const override;
   bool shouldEmitStaticExternCAliases() const override;
 
+  llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
+ llvm::PointerType *T,
+ QualType QT) const override;
+
   llvm::Type *getCUDADeviceBuiltinSurfaceDeviceType() const override {
 // On the device side, surface reference is represented as an object handle
 // in 64-bit integer.
@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto &Ctx = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}
 }
 
 void CodeGenModule::handleCUDALaunchBoundsAttr(llvm::Function *F,
diff --git a/clang/test/CodeGenSYCL/address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/address-space-conversions.cpp
index 3933ad375412da..10a181318a174b 100644
--- a/clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ b/clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -25,6 +25,10 @@ void usages() {
   __attribute__((opencl_local)) int *LOC;
   // CHECK-DAG: [[NoAS:%[a-zA-Z0-9]+]] = alloca ptr addrspace(4)
   // CHECK-DAG: [[NoAS]].ascast = addrspacecast ptr [[NoAS]] to ptr 
addrspace(4)
+  LOC = nullptr;
+  // CHECK-DAG: store ptr addrspace(3) null, ptr addrspace(4) [[LOC]].ascast, 
align 8
+  GLOB = nullptr;
+  // CHECK-DAG: store ptr addrspace(1) null, ptr addrspace(4) [[GLOB]].ascast, 
align 8
   int *NoAS;
   // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca ptr
   // CHECK-DAG: [[PRIV]].ascast = addrspacecast ptr [[PRIV]] to ptr 
addrspace(4)
diff --git a/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp 
b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
new file mode 100644
index 00..35da61cd8cbbe3
--- /dev/null
+++ b/clang/test/CodeGenSYCL/amd-address-space-conversions.cpp
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsycl-is-device 
-disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+void bar(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar2(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF2:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar(__attribute__((opencl_local)) int &Data) {}
+// CHEC

[clang] [Driver] Allow -fbasic-block-sections for AArch64 ELF (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-07 Thread via cfe-commits


@@ -0,0 +1,122 @@
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsycl-is-device 
-disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+void bar(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar2(int &Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_REF2:[a-zA-Z0-9_]+]](ptr noundef 
nonnull align 4 dereferenceable(4) %
+void bar(__attribute__((opencl_local)) int &Data) {}
+// CHECK-DAG: define dso_local void @[[LOCAL_REF:[a-zA-Z0-9_]+]](ptr 
addrspace(3) noundef align 4 dereferenceable(4) %
+void foo(int *Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_PTR:[a-zA-Z0-9_]+]](ptr noundef %
+void foo2(int *Data) {}
+// CHECK-DAG: define dso_local void @[[RAW_PTR2:[a-zA-Z0-9_]+]](ptr noundef %
+void foo(__attribute__((opencl_local)) int *Data) {}
+// CHECK-DAG: define dso_local void @[[LOC_PTR:[a-zA-Z0-9_]+]](ptr 
addrspace(3) noundef %
+
+template 
+void tmpl(T t);
+// See Check Lines below.
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  // CHECK-DAG: [[GLOB:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 8
+  __attribute__((opencl_local)) int *LOC;
+  // CHECK-DAG: [[LOC:%[a-zA-Z0-9]+]] = alloca ptr addrspace(3), align 8
+  LOC = nullptr;
+  // CHECK-DAG: store ptr addrspace(3) addrspacecast (ptr null to ptr 
addrspace(3)), ptr [[LOC]], align 8
+  GLOB = nullptr;
+  // CHECK-DAG: store ptr addrspace(1) null, ptr [[GLOB]], align 8
+  int *NoAS;
+  // CHECK-DAG: [[NoAS:%[a-zA-Z0-9]+]] = alloca ptr, align 8
+  __attribute__((opencl_private)) int *PRIV;
+  // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca ptr, align 8
+  __attribute__((opencl_global_device)) int *GLOBDEVICE;
+  // CHECK-DAG: [[GLOB_DEVICE:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 
8
+  __attribute__((opencl_global_host)) int *GLOBHOST;
+  // CHECK-DAG: [[GLOB_HOST:%[a-zA-Z0-9]+]] = alloca ptr addrspace(1), align 8
+  NoAS = (int *)GLOB;
+  // CHECK-DAG: [[GLOB_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB]], align 8
+  // CHECK-DAG: [[GLOB_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr addrspace(1) 
[[GLOB_LOAD]] to ptr
+  // CHECK-DAG: store ptr [[GLOB_CAST]], ptr [[NoAS]], align 8
+  NoAS = (int *)LOC;
+  // CHECK-DAG: [[LOC_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(3), ptr 
[[LOC]], align 8
+  // CHECK-DAG: [[LOC_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr addrspace(3) 
[[LOC_LOAD]] to ptr
+  // CHECK-DAG: store ptr [[LOC_CAST]], ptr [[NoAS]], align 8
+  NoAS = (int *)PRIV;
+  // CHECK-DAG: [[LOC_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[PRIV]], align 8
+  // CHECK-DAG: store ptr [[LOC_LOAD]], ptr [[NoAS]], align 8
+  GLOB = (__attribute__((opencl_global)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr [[NoAS_LOAD]] 
to ptr addrspace(1)
+  // CHECK-DAG: store ptr addrspace(1) [[NoAS_CAST]], ptr [[GLOB]], align 8
+  LOC = (__attribute__((opencl_local)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: [[NoAS_CAST:%[a-zA-Z0-9]+]] = addrspacecast ptr [[NoAS_LOAD]] 
to ptr addrspace(3)
+  // CHECK-DAG: store ptr addrspace(3) [[NoAS_CAST]], ptr [[LOC]], align 8
+  PRIV = (__attribute__((opencl_private)) int *)NoAS;
+  // CHECK-DAG: [[NoAS_LOAD:%[a-zA-Z0-9]+]] = load ptr, ptr [[NoAS]], align 8
+  // CHECK-DAG: store ptr [[NoAS_LOAD]], ptr [[PRIV]], align 8
+  GLOB = (__attribute__((opencl_global)) int *)GLOBDEVICE;
+  // CHECK-DAG: [[GLOBDEVICE_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB_DEVICE]], align 8
+  // CHECK-DAG: store ptr addrspace(1) [[GLOBDEVICE_LOAD]], ptr %GLOB, align 8
+  GLOB = (__attribute__((opencl_global)) int *)GLOBHOST;
+  // CHECK-DAG: [[GLOB_HOST_LOAD:%[a-zA-Z0-9]+]] = load ptr addrspace(1), ptr 
[[GLOB_HOST]], align 8
+  // CHECK-DAG: store ptr addrspace(1) [[GLOB_HOST_LOAD]], ptr [[GLOB]], align 
8
+  bar(*GLOB);

mmoadeli wrote:

Thanks @arichardson in added AMD and CUDA tests `CHECK-DAG`s are replaced with 
`CHECK`. 

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


[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-02-07 Thread Shahid Iqbal via cfe-commits

https://github.com/shahidiqbal13 updated 
https://github.com/llvm/llvm-project/pull/80976

>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Thu, 16 Nov 2023 11:26:43 -0500
Subject: [PATCH 1/3] TESTING infra

---
 clang/NOTES.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index f06ea8c70cd340..c83dda52a1fc21 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,6 +4,8 @@
 
 //===-===//
 
+//TESTING git infra//
+
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 79c592853c77fb0a96746d860be63d4605ea87e7 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Wed, 7 Feb 2024 06:08:10 -0500
Subject: [PATCH 2/3] =?UTF-8?q?Issue=20#63106:=20[=D1=81lang]=20Representa?=
 =?UTF-8?q?tion=20of=20ellipsis=20in=20AST?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 clang/include/clang/AST/DeclBase.h | 11 +--
 clang/include/clang/Sema/Sema.h|  2 +-
 clang/lib/AST/TextNodeDumper.cpp   |  3 +++
 clang/lib/Parse/ParseStmt.cpp  | 14 +++---
 clang/lib/Sema/SemaDeclCXX.cpp |  7 +--
 clang/test/AST/ast-dump-stmt.cpp   |  2 +-
 6 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 5b1038582bc674..67f5c7dd1b7f98 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -301,6 +301,9 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(bool)
   unsigned Implicit : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasCatchEllipsis : 1;
+
   /// Whether this declaration was "used", meaning that a definition is
   /// required.
   LLVM_PREFERRED_TYPE(bool)
@@ -394,7 +397,7 @@ class alignas(8) Decl {
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+Implicit(false), HasCatchEllipsis(false), Used(false), 
Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
@@ -402,7 +405,7 @@ class alignas(8) Decl {
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), 
HasCatchEllipsis(false),
 Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
 Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
@@ -597,6 +600,10 @@ class alignas(8) Decl {
   bool isImplicit() const { return Implicit; }
   void setImplicit(bool I = true) { Implicit = I; }
 
+  /// isCatchEllipsisTok - Indicates whether '...' is present in the catch decl
+  bool isCatchEllipsisTok() const { return HasCatchEllipsis; }
+  void setCatchEllipsisTok(bool I = true) { HasCatchEllipsis = I; }
+
   /// Whether *any* (re-)declaration of the entity was used, meaning that
   /// a definition is required.
   ///
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 501dc01200a1c3..ffc6d2926f85f2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5322,7 +5322,7 @@ class Sema final {
  SourceLocation IdLoc,
  IdentifierInfo *Id);
 
-  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
+  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D, bool isCatchAll = 
false);
 
   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
 Decl *ExDecl, Stmt *HandlerBlock);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9c..1da20cdfa36a66 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -272,6 +272,9 @@ void TextNodeDumper::Visit(const Decl *D) {
   if (D->isImplicit())
 OS << " implicit";
 
+  if (D->isCatchEllipsisTok())
+OS << " catch_all ";
+
   if (D->isUsed())
 OS << " used";
   else if (D->isThisDeclarationReferenced())
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 2531147c23196a..56c1e86afd4811 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2698,9 +2698,17 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
 Declarator ExDecl(DS, Attributes, DeclaratorContext::CXXCatch);
 ParseDeclarator(ExDecl);
 ExceptionDecl = Actions.ActOnExceptionDeclarator(getCurScope(), ExDecl);
-  } else
-ConsumeToken();
-
+  }
+  e

[clang] [Driver] Allow -fbasic-block-sections for AArch64 ELF (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/80916

>From 3eb66efd6d5a0f027191e2cdd65921f5058220d2 Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [Driver] Allow -fbasic-block-sections for AArch64 ELF

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf2421154372..942ebbc4106078 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d5..5e701072bfc74a 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-02-07 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 ec42d547eba5c0ad0bddbecc8902d35383968e78 
79c592853c77fb0a96746d860be63d4605ea87e7 -- clang/include/clang/AST/DeclBase.h 
clang/include/clang/Sema/Sema.h clang/lib/AST/TextNodeDumper.cpp 
clang/lib/Parse/ParseStmt.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/test/AST/ast-dump-stmt.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 67f5c7dd1b7..06f236db328 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -397,17 +397,17 @@ protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), HasCatchEllipsis(false), Used(false), 
Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
-IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
+Implicit(false), HasCatchEllipsis(false), Used(false),
+Referenced(false), TopLevelDeclInObjCContainer(false), Access(AS_none),
+FromASTFile(0), IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
 if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), 
HasCatchEllipsis(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+HasCatchEllipsis(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
 if (StatisticsEnabled) add(DK);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ffc6d2926f8..0f9418e329e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5322,7 +5322,8 @@ public:
  SourceLocation IdLoc,
  IdentifierInfo *Id);
 
-  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D, bool isCatchAll = 
false);
+  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D,
+ bool isCatchAll = false);
 
   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
 Decl *ExDecl, Stmt *HandlerBlock);
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 56c1e86afd4..df109c7fc48 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2698,16 +2698,17 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
 Declarator ExDecl(DS, Attributes, DeclaratorContext::CXXCatch);
 ParseDeclarator(ExDecl);
 ExceptionDecl = Actions.ActOnExceptionDeclarator(getCurScope(), ExDecl);
-  }
-  else {
-  ConsumeToken();
-  // explicitly creating a var of type no-type for '...' and marking it as 
catch_all
-  ParsedAttributes Attributes(AttrFactory);
-  DeclSpec DS(AttrFactory);
-  Declarator ExDecl(DS, Attributes, DeclaratorContext::BlockLiteral);
-  ParseDeclarator(ExDecl);
-  ExceptionDecl = Actions.ActOnExceptionDeclarator(getCurScope(), ExDecl, 
true);
-  ExceptionDecl->setCatchEllipsisTok();
+  } else {
+ConsumeToken();
+// explicitly creating a var of type no-type for '...' and marking it as
+// catch_all
+ParsedAttributes Attributes(AttrFactory);
+DeclSpec DS(AttrFactory);
+Declarator ExDecl(DS, Attributes, DeclaratorContext::BlockLiteral);
+ParseDeclarator(ExDecl);
+ExceptionDecl =
+Actions.ActOnExceptionDeclarator(getCurScope(), ExDecl, true);
+ExceptionDecl->setCatchEllipsisTok();
   }
   T.consumeClose();
   if (T.getCloseLocation().isInvalid())
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1916d3c3d8e..3a69b632426 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16994,7 +16994,7 @@ Decl *Sema::ActOnExceptionDeclarator(Scope *S, 
Declarator &D, bool isCatchAll) {
  D.getIdentifierLoc());
 Invalid = true;
   }
-if (isCatchAll)
+  if (isCatchAll)
 TInfo = Context.getTrivialTypeSourceInfo(Context.UnknownAnyTy,
  D.getIdentifierLoc());
 

``




https://github.com/llvm/llvm-project/pull/80976
___
cfe-commits mailing list
cfe-commi

[clang] [Driver] Allow -fbasic-block-sections for AArch64 ELF (PR #80916)

2024-02-07 Thread Daniel Hoekwater via cfe-commits

https://github.com/dhoekwater updated 
https://github.com/llvm/llvm-project/pull/80916

>From 7eaf94fefa1250fc8a46982cea8ce99abacae11f Mon Sep 17 00:00:00 2001
From: Daniel Hoekwater 
Date: Wed, 7 Feb 2024 01:03:17 +
Subject: [PATCH] [Driver] Allow -fbasic-block-sections for AArch64 ELF

Basic block sections "all" doesn't work on AArch64 since branch
relaxation may create new basic blocks. However, the other basic
block section modes should work out of the box since machine function
splitting already uses the basic block sections pass.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/fbasic-block-sections.c | 4 
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 13bf2421154372..942ebbc4106078 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5972,6 +5972,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 << A->getAsString(Args) << A->getValue();
   else
 A->render(Args, CmdArgs);
+} else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
+  // "all" is not supported on AArch64 since branch relaxation creates new
+  // basic blocks for some cross-section branches.
+  if (Val != "labels" && Val != "none" && !Val.starts_with("list="))
+D.Diag(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  else
+A->render(Args, CmdArgs);
 } else if (Triple.isNVPTX()) {
   // Do not pass the option to the GPU compilation. We still want it 
enabled
   // for the host-side compilation, so seeing it here is not an error.
diff --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 24262209d1e4d5..e13cc81e910be3 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -2,6 +2,10 @@
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
 // RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=aarch64 -fbasic-block-sections=labels %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -### --target=aarch64 -fbasic-block-sections=all %s -S 2>&1 
| FileCheck -check-prefix=CHECK-INVALID-VALUE %s
 // RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
 // RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/80978

Trying to compile a C-style variadic member function with an explicit object 
parameter was crashing in Sema because of an out-of-bounds access.

This fixes #80971.

>From 9c32a0ad9b85328b34545c8ec3a47611ecb4cd72 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 12:49:18 +0100
Subject: [PATCH] [Clang][Sema] Fix out-of-bounds access

---
 clang/lib/Sema/SemaOverload.cpp|  2 +-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f0414..fc3d7d8dcf16e8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,7 +7719,7 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size()); 
I != N;
++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..670e72944ee82d 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}
\ No newline at end of file

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

Trying to compile a C-style variadic member function with an explicit object 
parameter was crashing in Sema because of an out-of-bounds access.

This fixes #80971.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+10) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f0414..fc3d7d8dcf16e8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,7 +7719,7 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size()); 
I != N;
++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..670e72944ee82d 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}
\ No newline at end of file

``




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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

CC @AaronBallman 

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/80978

>From 673ecd846857075fd9c9f2a7cf5cb326e23abb06 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 12:49:18 +0100
Subject: [PATCH] [Clang][Sema] Fix out-of-bounds access

---
 clang/lib/Sema/SemaOverload.cpp|  4 ++--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f0414..ebbbdac631ed23 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,8 +7719,8 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
-   ++I) {
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
+   I != N; ++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..670e72944ee82d 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}
\ No newline at end of file

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 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 390b99743bdd60649414fe470d7a9bacc9992231 
9c32a0ad9b85328b34545c8ec3a47611ecb4cd72 -- clang/lib/Sema/SemaOverload.cpp 
clang/test/SemaCXX/cxx2b-deducing-this.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index fc3d7d8dcf..ebbbdac631 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,8 +7719,8 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size()); 
I != N;
-   ++I) {
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
+   I != N; ++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx;

``




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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/80978

>From 366651f687eb58ab1775e88da55b1489c118e874 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 12:49:18 +0100
Subject: [PATCH] [Clang][Sema] Fix out-of-bounds access

---
 clang/lib/Sema/SemaOverload.cpp|  4 ++--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f041..ebbbdac631ed2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,8 +7719,8 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
-   ++I) {
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
+   I != N; ++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8..30131d6adc4db 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

If you’re wondering what the force-pushes are about, first I forgot to run `git 
clang-format`, then I was also missing a newline at the end of the test file...

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


[clang] [flang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

2024-02-07 Thread Nikita Popov via cfe-commits

nikic wrote:

@Artem-B I've put up https://github.com/llvm/llvm-project/pull/80983 to address 
this issue.

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/80978

>From 366651f687eb58ab1775e88da55b1489c118e874 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 12:49:18 +0100
Subject: [PATCH 1/2] [Clang][Sema] Fix out-of-bounds access

---
 clang/lib/Sema/SemaOverload.cpp|  4 ++--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f041..ebbbdac631ed2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,8 +7719,8 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
-   ++I) {
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
+   I != N; ++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx;
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8..30131d6adc4db 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}

>From 9545bf33c4d0cd3448f31e07935f84f46c055f97 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 13:08:59 +0100
Subject: [PATCH 2/2] [Clang] Update release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3596109bf044f..55497cc7883bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -201,6 +201,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
+  Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [clang][analyzer] Add note tags to alpha.unix.BlockInCriticalSection (PR #80029)

2024-02-07 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/80029

From f7875a7f1ff20f3cf850ce1c23bec6d6c3d88d57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Tue, 30 Jan 2024 11:33:30 +0100
Subject: [PATCH 1/2] [clang][analyzer] Add note tags to
 alpha.unix.BlockInCriticalSection checker

On entering a critical section, a note tag is now placed along the
bugpath.
---
 .../BlockInCriticalSectionChecker.cpp | 18 -
 .../Analysis/block-in-critical-section.cpp| 77 ++-
 2 files changed, 75 insertions(+), 20 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index 66e080adb1382b..1297ae96c8b644 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -57,6 +57,8 @@ class BlockInCriticalSectionChecker : public 
Checker {
 const CallEvent &call,
 CheckerContext &C) const;
 
+  const NoteTag *createCriticalSectionNote(CheckerContext &C) const;
+
 public:
   bool isBlockingFunction(const CallEvent &Call) const;
   bool isLockFunction(const CallEvent &Call) const;
@@ -126,8 +128,9 @@ void BlockInCriticalSectionChecker::checkPostCall(const 
CallEvent &Call,
 State = State->set(--mutexCount);
 C.addTransition(State);
   } else if (isLockFunction(Call)) {
+const NoteTag *Note = createCriticalSectionNote(C);
 State = State->set(++mutexCount);
-C.addTransition(State);
+C.addTransition(State, Note);
   } else if (mutexCount > 0) {
 SymbolRef BlockDesc = Call.getReturnValue().getAsSymbol();
 reportBlockInCritSection(BlockDesc, Call, C);
@@ -151,10 +154,21 @@ void 
BlockInCriticalSectionChecker::reportBlockInCritSection(
   C.emitReport(std::move(R));
 }
 
+const NoteTag *BlockInCriticalSectionChecker::createCriticalSectionNote(
+CheckerContext &C) const {
+  const BugType *BT = &this->BlockInCritSectionBugType;
+  return C.getNoteTag([BT](PathSensitiveBugReport &BR, llvm::raw_ostream &OS) {
+if (&BR.getBugType() != BT)
+  return;
+OS << "Entering critical section here";
+  });
+}
+
 void ento::registerBlockInCriticalSectionChecker(CheckerManager &mgr) {
   mgr.registerChecker();
 }
 
-bool ento::shouldRegisterBlockInCriticalSectionChecker(const CheckerManager 
&mgr) {
+bool ento::shouldRegisterBlockInCriticalSectionChecker(
+const CheckerManager &mgr) {
   return true;
 }
diff --git a/clang/test/Analysis/block-in-critical-section.cpp 
b/clang/test/Analysis/block-in-critical-section.cpp
index fcf6188fc033ec..93d46c741e16ff 100644
--- a/clang/test/Analysis/block-in-critical-section.cpp
+++ b/clang/test/Analysis/block-in-critical-section.cpp
@@ -1,4 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.unix.BlockInCriticalSection 
-std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN:   -analyzer-checker=alpha.unix.BlockInCriticalSection \
+// RUN:   -std=c++11 \
+// RUN:   -analyzer-output text \
+// RUN:   -verify %s
 
 void sleep(int x) {}
 
@@ -21,7 +25,7 @@ template
 struct not_real_lock {
   not_real_lock(std::mutex) {}
 };
-}
+} // namespace std
 
 void getc() {}
 void fgets() {}
@@ -39,81 +43,115 @@ void mtx_unlock() {}
 
 void testBlockInCriticalSectionWithStdMutex() {
   std::mutex m;
-  m.lock();
+  m.lock(); // expected-note 5{{Entering critical section here}}
   sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of 
critical section}}
+// expected-note@-1 {{Call to blocking function 'sleep' inside of 
critical section}}
   getc(); // expected-warning {{Call to blocking function 'getc' inside of 
critical section}}
+  // expected-note@-1 {{Call to blocking function 'getc' inside of 
critical section}}
   fgets(); // expected-warning {{Call to blocking function 'fgets' inside of 
critical section}}
+   // expected-note@-1 {{Call to blocking function 'fgets' inside of 
critical section}}
   read(); // expected-warning {{Call to blocking function 'read' inside of 
critical section}}
+  // expected-note@-1 {{Call to blocking function 'read' inside of 
critical section}}
   recv(); // expected-warning {{Call to blocking function 'recv' inside of 
critical section}}
+  // expected-note@-1 {{Call to blocking function 'recv' inside of 
critical section}}
   m.unlock();
 }
 
 void testBlockInCriticalSectionWithPthreadMutex() {
-  pthread_mutex_lock();
+  pthread_mutex_lock(); // expected-note 10{{Entering critical section here}}
   sleep(3); // expected-warning {{Call to blocking function 'sleep' inside of 
critical section}}
+// expected-note@-1 {{Call to blocking function 'sleep' inside of 
critical section}}
   getc(); // expected-warning {{Call to blocking function 'getc' inside of 
critical section}}
+  // expected-n

[clang] af6656c - [clang][Interp][NFC] Fix moveArrayTy byte offset

2024-02-07 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T13:07:42+01:00
New Revision: af6656c375b8aa9c9156575f7c0ac678a57070d5

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

LOG: [clang][Interp][NFC] Fix moveArrayTy byte offset

We need to account for the InitMapPtr here. This is NFC right now since
no test is affected by it.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 5701cf0acf915d..f75a9fc4b46650 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -63,6 +63,9 @@ static void dtorArrayTy(Block *, std::byte *Ptr, const 
Descriptor *D) {
 template 
 static void moveArrayTy(Block *, const std::byte *Src, std::byte *Dst,
 const Descriptor *D) {
+  // FIXME: Need to copy the InitMap?
+  Src += sizeof(InitMapPtr);
+  Dst += sizeof(InitMapPtr);
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
 const auto *SrcPtr = &reinterpret_cast(Src)[I];
 auto *DstPtr = &reinterpret_cast(Dst)[I];



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


[clang] 61c7a69 - [clang][Interp] Fix sizeof of reference types

2024-02-07 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T13:32:07+01:00
New Revision: 61c7a69fa0c020e92b1b10882d5d2957f3b8da21

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

LOG: [clang][Interp] Fix sizeof of reference types

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 38b2d6fad043c..b95126ee20fe2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1085,6 +1085,12 @@ bool 
ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
 
   if (Kind == UETT_SizeOf) {
 QualType ArgType = E->getTypeOfArgument();
+
+// C++ [expr.sizeof]p2: "When applied to a reference or a reference type,
+//   the result is the size of the referenced type."
+if (const auto *Ref = ArgType->getAs())
+  ArgType = Ref->getPointeeType();
+
 CharUnits Size;
 if (ArgType->isVoidType() || ArgType->isFunctionType())
   Size = CharUnits::One();

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c2bc5338ea925..000d2bc8a4f6c 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -216,6 +216,8 @@ namespace PointerComparison {
 }
 
 namespace SizeOf {
+  static_assert(alignof(char&) == 1);
+
   constexpr int soint = sizeof(int);
   constexpr int souint = sizeof(unsigned int);
   static_assert(soint == souint, "");



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


[clang] a97ff2d - [clang][Interp] Add missing static_assert message

2024-02-07 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T13:41:27+01:00
New Revision: a97ff2d35af0a5c640c20abf4215c08e0e69aa41

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

LOG: [clang][Interp] Add missing static_assert message

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/139/builds/58960

Added: 


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

Removed: 




diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 000d2bc8a4f6c5..f5b5f77ffc624b 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -216,7 +216,7 @@ namespace PointerComparison {
 }
 
 namespace SizeOf {
-  static_assert(alignof(char&) == 1);
+  static_assert(alignof(char&) == 1, "");
 
   constexpr int soint = sizeof(int);
   constexpr int souint = sizeof(unsigned int);



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


[clang] [clang] Fix OMPT ident flag in combined distribute parallel for pragma (PR #80987)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (mikaoP)


Changes



---

Patch is 1.89 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/80987.diff


88 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+9-6) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2) 
- (modified) clang/test/OpenMP/bug60602.cpp (+1-1) 
- (modified) clang/test/OpenMP/distribute_parallel_for_codegen.cpp (+32-32) 
- (modified) clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp (+8-8) 
- (modified) clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp 
(+280-280) 
- (modified) clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp 
(+3-3) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp (+17-17) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp 
(+30-30) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp 
(+24-24) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp 
(+34-34) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp (+32-32) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp 
(+336-336) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp (+3-3) 
- (modified) clang/test/OpenMP/distribute_simd_codegen.cpp (+18-18) 
- (modified) clang/test/OpenMP/nvptx_SPMD_codegen.cpp (+48-48) 
- (modified) 
clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp (+2-2) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp 
(+18-18) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
 (+2-2) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp 
(+8-8) 
- (modified) clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp 
(+18-18) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp 
(+4-4) 
- (modified) clang/test/OpenMP/reduction_implicit_map.cpp (+16-16) 
- (modified) clang/test/OpenMP/target_ompx_dyn_cgroup_mem_codegen.cpp (+58-58) 
- (modified) clang/test/OpenMP/target_teams_distribute_codegen.cpp (+64-64) 
- (modified) clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
 (+18-18) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp (+8-8) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp 
(+10-10) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_proc_bind_codegen.cpp 
(+3-3) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_codegen.cpp 
(+25-25) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
 (+19-19) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp 
(+36-36) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp 
(+12-12) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
 (+6-6) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
 (+18-18) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
 (+17-17) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp 
(+40-40) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_codegen.cpp
 (+32-32) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp 
(+10-10) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_proc_bind_codegen.cpp
 (+3-3) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_reduction_codegen.cpp
 (+25-25) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
 (+36-36) 
- (modified) clang/test/OpenMP/target_teams_generic_loop_codegen-1.cpp (+15-15) 
- (modified) clang/test/OpenMP/target

[clang] [clang] Fix OMPT ident flag in combined distribute parallel for pragma (PR #80987)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (mikaoP)


Changes



---

Patch is 1.89 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/80987.diff


88 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+9-6) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2) 
- (modified) clang/test/OpenMP/bug60602.cpp (+1-1) 
- (modified) clang/test/OpenMP/distribute_parallel_for_codegen.cpp (+32-32) 
- (modified) clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp (+8-8) 
- (modified) clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp 
(+280-280) 
- (modified) clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp 
(+10-10) 
- (modified) clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp 
(+3-3) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp (+17-17) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp 
(+30-30) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp 
(+24-24) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp 
(+34-34) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp (+32-32) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp 
(+336-336) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp (+3-3) 
- (modified) clang/test/OpenMP/distribute_simd_codegen.cpp (+18-18) 
- (modified) clang/test/OpenMP/nvptx_SPMD_codegen.cpp (+48-48) 
- (modified) 
clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp (+2-2) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp 
(+18-18) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
 (+2-2) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp 
(+8-8) 
- (modified) clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp 
(+18-18) 
- (modified) 
clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp 
(+4-4) 
- (modified) clang/test/OpenMP/reduction_implicit_map.cpp (+16-16) 
- (modified) clang/test/OpenMP/target_ompx_dyn_cgroup_mem_codegen.cpp (+58-58) 
- (modified) clang/test/OpenMP/target_teams_distribute_codegen.cpp (+64-64) 
- (modified) clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp 
(+6-6) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
 (+18-18) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp (+8-8) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp 
(+10-10) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp 
(+15-15) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_proc_bind_codegen.cpp 
(+3-3) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_codegen.cpp 
(+25-25) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
 (+19-19) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp 
(+36-36) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp 
(+12-12) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
 (+6-6) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
 (+18-18) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
 (+17-17) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp 
(+40-40) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_codegen.cpp
 (+32-32) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp 
(+10-10) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_proc_bind_codegen.cpp
 (+3-3) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_reduction_codegen.cpp
 (+25-25) 
- (modified) 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
 (+36-36) 
- (modified) clang/test/OpenMP/target_teams_generic_loop_codegen-1.cpp (+15-15) 
- (modified) clang/test/OpenM

[clang] [clang] Fix OMPT ident flag in combined distribute parallel for pragma (PR #80987)

2024-02-07 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 95403b42da0de500f4f86add7a60b0daf8ec98d0 
62a2704a725d8fcf81392c42d292d3bb1b27e56c -- 
clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp 
clang/lib/CodeGen/CodeGenFunction.h clang/test/OpenMP/bug60602.cpp 
clang/test/OpenMP/distribute_parallel_for_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp 
clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp 
clang/test/OpenMP/distribute_simd_codegen.cpp 
clang/test/OpenMP/nvptx_SPMD_codegen.cpp 
clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp 
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
 clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp 
clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp 
clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp 
clang/test/OpenMP/reduction_implicit_map.cpp 
clang/test/OpenMP/target_ompx_dyn_cgroup_mem_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_proc_bind_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
 clang/test/OpenMP/target_teams_distribute_parallel_for_schedule_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp
 clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_proc_bind_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_reduction_codegen.cpp
 
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_schedule_codegen.cpp
 clang/test/OpenMP/target_teams_generic_loop_codegen-1.cpp 
clang/test/OpenMP/target_teams_generic_loop_collapse_codegen.cpp 
clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp 
clang/test/OpenMP/target_teams_generic_loop_private_codegen.cpp 
clang/test/OpenMP/target_teams_generic_loop_reduction_codegen.cpp 
clang/test/OpenMP/target_teams_generic_loop_uses_allocators_codegen.cpp 
clang/test/OpenMP/teams_distribute_dist_schedule_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_collapse_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_copyin_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_dist_schedule_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_firstprivate_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_if_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_lastprivate_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_private_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_for_proc_bind_codegen.cpp 
clang/test/OpenMP/teams_distribute_parallel_

[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2024-02-07 Thread Felix via cfe-commits

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


[clang] [llvm] [LinkerWrapper] Support relocatable linking for offloading (PR #80066)

2024-02-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

ping

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


[clang] b0c6fc8 - [clang][Interp] Ignore UsingEnumDecls

2024-02-07 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T14:24:37+01:00
New Revision: b0c6fc81fe132f20eed38bd836620dfcb5ac17e9

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

LOG: [clang][Interp] Ignore UsingEnumDecls

We previously aborted compilation when seeing one of them. Ignore
them instead, they have no effect on the generated bytecode.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/SemaCXX/cxx20-using-enum.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index a2d8c4e13010c6..b0ec90a1f2851c 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -317,7 +317,7 @@ bool ByteCodeStmtGen::visitCompoundStmt(
 template 
 bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) {
   for (auto *D : DS->decls()) {
-if (isa(D))
+if (isa(D))
   continue;
 
 const auto *VD = dyn_cast(D);

diff  --git a/clang/test/SemaCXX/cxx20-using-enum.cpp 
b/clang/test/SemaCXX/cxx20-using-enum.cpp
index 872353aad8a0d4..d16df4e1b9d3cd 100644
--- a/clang/test/SemaCXX/cxx20-using-enum.cpp
+++ b/clang/test/SemaCXX/cxx20-using-enum.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s 
-fexperimental-new-constant-interpreter
 
 // p1099 'using enum ELABORATED-ENUM-SPECIFIER ;'
 



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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2024-02-07 Thread Felix via cfe-commits


@@ -145,9 +164,89 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the

orcguru wrote:

This is correct. I will elaborate in the comment.

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


[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)

2024-02-07 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

The change in OpenCL behavior looks reasonable to me, but let's wait for 
@AnastasiaStulova to have a chance to weigh in.

I think we can skip a release note as this is *almost* an NFC change except for 
the OpenCL bits. We could put a release note under OpenCL for this if we wanted 
though.

The changes themselves LGTM barring feedback on OpenCL.

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2024-02-07 Thread Felix via cfe-commits


@@ -145,9 +164,89 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// .__tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the .__tls_get_mod node.
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use the OutReg.
+  for (MachineOperand &MO : RegInfo.use_operands(OutReg))
+Uses.insert(MO.getParent());
+  // Find the first user (e.g.: lwax/stfdx) within the current BB.

orcguru wrote:

Thank you! I will apply the change.

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-02-07 Thread Paul Semel via cfe-commits

https://github.com/paulsemel created 
https://github.com/llvm/llvm-project/pull/80989

This is needed in order to correctly assume implicit iterator validity in the 
iterator checker.

>From b227aa82732cdc087ead5df62077055042d22696 Mon Sep 17 00:00:00 2001
From: Paul Semel 
Date: Wed, 7 Feb 2024 13:06:40 +
Subject: [PATCH] [dataflow] CXXForRangeStmt should extend flow condition

This is needed in order to correctly assume implicit iterator validity
in the iterator checker.
---
 .../FlowSensitive/TypeErasedDataflowAnalysis.cpp | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 4c88c46142d64d..f02c65094113ec 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -103,9 +103,12 @@ class TerminatorVisitor
 return {nullptr, false};
   }
 
-  TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *) {
-// Don't do anything special for CXXForRangeStmt, because the condition
-// (being implicitly generated) isn't visible from the loop body.
+  TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
+// Even though the condition isn't visible from the loop body, analysis
+// might depend on the implicit implicit statements implied by the loop.
+auto *Cond = S->getCond();
+if (Cond != nullptr)
+  return extendFlowCondition(*Cond);
 return {nullptr, false};
   }
 

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


[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Semel (paulsemel)


Changes

This is needed in order to correctly assume implicit iterator validity in the 
iterator checker.

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


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+6-3) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 4c88c46142d64d..f02c65094113ec 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -103,9 +103,12 @@ class TerminatorVisitor
 return {nullptr, false};
   }
 
-  TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *) {
-// Don't do anything special for CXXForRangeStmt, because the condition
-// (being implicitly generated) isn't visible from the loop body.
+  TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
+// Even though the condition isn't visible from the loop body, analysis
+// might depend on the implicit implicit statements implied by the loop.
+auto *Cond = S->getCond();
+if (Cond != nullptr)
+  return extendFlowCondition(*Cond);
 return {nullptr, false};
   }
 

``




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


[clang] [Clang][TableGen] Add Features to TargetBuiltin (PR #80279)

2024-02-07 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

The changes seem reasonable to me but I'd feel more comfortable if the 
functionality was also being used (so that we'd get test coverage verifying its 
correctness). Do you think it would be reasonable to include the RISCV changes 
as well?

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


[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2024-02-07 Thread Felix via cfe-commits


@@ -145,9 +164,89 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (IsTLSLDAIXMI) {
+// The relative order between the LoadOffset@toc node, and the
+// .__tls_get_mod node is being tuned here. It is better to put the
+// LoadOffset@toc node after the call, since the LoadOffset@toc 
node
+// can use clobbers r4/r5. Search for the pattern of two Load@toc
+// nodes, and then move the LoadOffset@toc node right before the
+// node that uses the OutReg of the .__tls_get_mod node.
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use the OutReg.
+  for (MachineOperand &MO : RegInfo.use_operands(OutReg))
+Uses.insert(MO.getParent());
+  // Find the first user (e.g.: lwax/stfdx) within the current BB.
+  MachineBasicBlock::iterator UseIter = MBB.begin();
+  for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
+   ++UseIter)
+if (Uses.count(&*UseIter))
+  break;
+
+  // Got some work to do when UseIter pointing to valid node. Check
+  // the pattern and do the movement if match.

orcguru wrote:

Yep. Much better! Thank you!

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [llvm] [LinkerWrapper] Support relocatable linking for offloading (PR #80066)

2024-02-07 Thread Yaxun Liu via cfe-commits

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

LGTM. Thanks

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


[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-02-07 Thread via cfe-commits

cor3ntin wrote:

Using an extra bit for that in `Decl` (that is the base class of all 
declaration), seems a bit heavy handed as bits in that part of the astnode are 
precious.
Did you consider storing the EllipsisLoc in CXXCatchStmt ? 

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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> LGTM, thanks!

I don’t have commit access, so you or someone else would have to merge it

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread Paul Semel via cfe-commits

https://github.com/paulsemel created 
https://github.com/llvm/llvm-project/pull/80991

Although in a normal implementation the assumption is reasonable, it seems that 
some esoteric implementation are not returning a T&. This should be handled 
correctly and the values be propagated.

>From 4aad70021b0cda8613f8944a6900fb71e55838e3 Mon Sep 17 00:00:00 2001
From: Paul Semel 
Date: Wed, 7 Feb 2024 13:59:40 +
Subject: [PATCH] [dataflow] CXXOperatorCallExpr equal operator might not be a
 glvalue

Although in a normal implementation the assumption is reasonable, it
seems that some esoteric implementation are not returning a T&. This
should be handled correctly and the values be propagated.
---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 14 +++-
 .../Analysis/FlowSensitive/TransferTest.cpp   | 36 +++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb3aec763c29ca..fb1c6848197339 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -535,7 +535,19 @@ class TransferVisitor : public 
ConstStmtVisitor {
 return;
 
   copyRecord(*LocSrc, *LocDst, Env);
-  Env.setStorageLocation(*S, *LocDst);
+
+  // If the expr is a glvalue, we can reasonably assume the operator is
+  // returning T& and thus we can assign it `LocDst`.
+  if (S->isGLValue()) {
+Env.setStorageLocation(*S, *LocDst);
+  } else if (S->getType()->isRecordType() && S->isPRValue()) {
+// If the expr is a prvalue, we cannot really assume anything regarding
+// the new value being created. We should just propagate it to ensure a
+// `RecordValue` exist for it.
+if (Env.getValue(*S) == nullptr)
+  refreshRecordValue(*S, Env);
+  }
+
   return;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 8bbb04024dcce6..86f4081c798d55 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  void operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsPRValue) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  B operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
 TEST(TransferTest, CopyConstructor) {
   std::string Code = R"(
 struct A {

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Semel (paulsemel)


Changes

Although in a normal implementation the assumption is reasonable, it seems that 
some esoteric implementation are not returning a T&. This should be handled 
correctly and the values be propagated.

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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+13-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+36) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bb3aec763c29ca..fb1c6848197339 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -535,7 +535,19 @@ class TransferVisitor : public 
ConstStmtVisitor {
 return;
 
   copyRecord(*LocSrc, *LocDst, Env);
-  Env.setStorageLocation(*S, *LocDst);
+
+  // If the expr is a glvalue, we can reasonably assume the operator is
+  // returning T& and thus we can assign it `LocDst`.
+  if (S->isGLValue()) {
+Env.setStorageLocation(*S, *LocDst);
+  } else if (S->getType()->isRecordType() && S->isPRValue()) {
+// If the expr is a prvalue, we cannot really assume anything regarding
+// the new value being created. We should just propagate it to ensure a
+// `RecordValue` exist for it.
+if (Env.getValue(*S) == nullptr)
+  refreshRecordValue(*S, Env);
+  }
+
   return;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 8bbb04024dcce6..86f4081c798d55 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  void operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsPRValue) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  B operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
 TEST(TransferTest, CopyConstructor) {
   std::string Code = R"(
 struct A {

``




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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-07 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > One possibility would be to use a type qualifier? It has basically the kind 
> > of properties you want... the underlying type is
> > still there, and places that strip qualifiers will automatically do the 
> > right thing in a lot of cases. It might require a bit more
> > work to handle it in various places in semantic analysis, though.
> 
> Thanks @efriedma-quic! We also thought about using qualifiers before but it's 
> tricky because we would like the bounds annotations to be able to apply to 
> function return types. WDYT?

To clarify the problem, qualifiers are stripped from the return type in C when 
forming the function type itself (see C23 6.7.6.3p4).

> We haven't experimented these alternative designs so I'm curious about 
> @AaronBallman's thoughts.

I think that encoding this into `Qualifiers` would be difficult because that's 
a 32-bit opaque value and I think counted_by needs to store more information 
than we have room for: 
https://github.com/llvm/llvm-project/blob/b0c6fc81fe132f20eed38bd836620dfcb5ac17e9/clang/include/clang/AST/Type.h#L147

I think `AttributedType` might be a reasonable way forward. That's how we model 
nullability qualifiers, for example: 
https://github.com/llvm/llvm-project/blob/0aacd44a4698da012ee0704815123b28f2a06d0f/clang/lib/AST/Type.cpp#L4514
 and 
https://github.com/llvm/llvm-project/blob/b0c6fc81fe132f20eed38bd836620dfcb5ac17e9/clang/include/clang/AST/Type.h#L5189
 and counted_by feels roughly similar in terms of behavior (not able to 
overload based on presence/absence of the attribute, etc).

CC @erichkeane as attributes code owner.

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


[clang] 4e58f03 - [Clang] Fix : More Detailed "No expected directives found" (#78338)

2024-02-07 Thread via cfe-commits

Author: Shourya Goel
Date: 2024-02-07T09:10:17-05:00
New Revision: 4e58f03f298eb5c74877942c1c68911341c678bd

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

LOG: [Clang] Fix : More Detailed "No expected directives found" (#78338)

Updated the error message to use the proper prefix when
no expected directives are found by changing the hard coded expected in
the message to a dynamic value in two error messages.

Fixes #58290

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/test/Frontend/verify.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 85ecfdf9de62d4..b1a282f5164a2a 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -176,10 +176,10 @@ def err_verify_inconsistent_diags : Error<
 "'%0' diagnostics %select{expected|seen}1 but not %select{seen|expected}1: 
"
 "%2">;
 def err_verify_invalid_no_diags : Error<
-"%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
-"%select{'expected-no-diagnostics' directive|other expected directives}0">;
+"%select{expected|'%0-no-diagnostics'}1 directive cannot follow "
+"%select{'%0-no-diagnostics' directive|other expected directives}1">;
 def err_verify_no_directives : Error<
-"no expected directives found: consider use of 'expected-no-diagnostics'">;
+"no expected directives found: consider use of '%0-no-diagnostics'">;
 def err_verify_nonconst_addrspace : Error<
   "qualifier 'const' is needed for variables in address space '%0'">;
 

diff  --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 304935a0a90b8e..48330e93617181 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -396,6 +396,12 @@ class VerifyDiagnosticConsumer::MarkerTracker {
   }
 };
 
+static std::string DetailedErrorString(const DiagnosticsEngine &Diags) {
+  if (Diags.getDiagnosticOptions().VerifyPrefixes.empty())
+return "expected";
+  return *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+}
+
 /// ParseDirective - Go through the comment and see if it indicates expected
 /// diagnostics. If so, then put them in the appropriate directive list.
 ///
@@ -478,14 +484,14 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, 
SourceManager &SM,
 if (NoDiag) {
   if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives)
 Diags.Report(Pos, diag::err_verify_invalid_no_diags)
-  << /*IsExpectedNoDiagnostics=*/true;
+<< DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/true;
   else
 Status = VerifyDiagnosticConsumer::HasExpectedNoDiagnostics;
   continue;
 }
 if (Status == VerifyDiagnosticConsumer::HasExpectedNoDiagnostics) {
   Diags.Report(Pos, diag::err_verify_invalid_no_diags)
-<< /*IsExpectedNoDiagnostics=*/false;
+  << DetailedErrorString(Diags) << /*IsExpectedNoDiagnostics=*/false;
   continue;
 }
 Status = VerifyDiagnosticConsumer::HasOtherExpectedDirectives;
@@ -1104,7 +1110,8 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  Diags.Report(diag::err_verify_no_directives).setForceEmit()
+  << DetailedErrorString(Diags);
   ++NumErrors;
   Status = HasNoDirectivesReported;
 }

diff  --git a/clang/test/Frontend/verify.c b/clang/test/Frontend/verify.c
index c549011d7b7a9a..afd1c7d6907e20 100644
--- a/clang/test/Frontend/verify.c
+++ b/clang/test/Frontend/verify.c
@@ -187,3 +187,32 @@ unexpected b; // expected-error@33 1-1 {{unknown type}}
 #endif
 
 #endif
+
+#ifdef TEST10
+// RUN: not %clang_cc1 -DTEST10 -verify=foo %s 2>&1 | FileCheck 
-check-prefix=CHECK10 %s
+
+// CHECK10: error: no expected directives found: consider use of 
'foo-no-diagnostics'
+#endif
+
+#ifdef TEST11
+// RUN: not %clang_cc1 -DTEST11 -verify=foo %s 2>&1 | FileCheck 
-check-prefix=CHECK11 %s
+
+// foo-no-diagnostics
+// foo-note {{}}
+
+//  CHECK11: error: 'foo-error' diagnostics seen but not expected:
+// CHECK11-NEXT:   Line 201: expected directive cannot follow 
'foo-no-diagnostics' directive
+// CHECK11-NEXT: 1 error generated.
+#endif
+
+#ifdef TEST12
+// RUN: not %clang_cc1 -DTEST12 -verify=foo %s 2>&1 | FileCheck 
-check-prefix=CHECK12 %s
+
+#warning X
+// foo-warning@-1 {{X}}
+// foo-no-diagnostic

[clang] [clang-tools-extra] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-02-07 Thread Aaron Ballman via cfe-commits

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


[clang] 52bf531 - [Clang][Sema] Fix out-of-bounds access (#80978)

2024-02-07 Thread via cfe-commits

Author: Sirraide
Date: 2024-02-07T15:12:15+01:00
New Revision: 52bf531630d19e115d30b4ca46f1ef03b9a724c6

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

LOG: [Clang][Sema] Fix out-of-bounds access (#80978)

Trying to compile a C-style variadic member function with an explicit
object parameter was crashing in Sema because of an out-of-bounds
access.

This fixes #80971.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..52a48c750fe55b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,8 @@ Bug Fixes to C++ Support
   parameter where we did an incorrect specialization of the initialization of
   the default parameter.
   Fixes (`#68490 `_)
+- Fix a crash when trying to call a varargs function that also has an explicit 
object parameter.
+  Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c46f6338a5a125..42960c229077c3 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7722,8 +7722,8 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
   Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
-   ++I) {
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
+   I != N; ++I) {
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx;

diff  --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..30131d6adc4db0 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
 }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}



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


[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

2024-02-07 Thread via cfe-commits

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


[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > which also begs the question as to what change actually caused this to break
> 
> Since I’m not sure how that is usually done here, is bisecting a reasonable 
> approach? I’m asking because rebuilding a project the size of Clang 
> unfortunately ends up taking a rather substantial amount of time...

Bisecting is one useful approach (with the drawback of how resource-intensive 
it is), but you can also sometimes do well with `git blame` on the surrounding 
code to see how the code evolved and what comments there were on the reviews. 

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


[clang] [Clang][Sema] Do not attempt to instantiate a deleted move constructor (PR #80959)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -7894,13 +7895,18 @@ bool 
Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
   if (ShouldDeleteForTypeMismatch || ShouldDeleteSpecialMember(MD, CSM)) {
 if (First) {
   SetDeclDeleted(MD, MD->getLocation());
-  if (!inTemplateInstantiation() && !HadError) {
-Diag(MD->getLocation(), diag::warn_defaulted_method_deleted) << CSM;
+  if ((ForDefinition || !inTemplateInstantiation()) && !HadError) {
+// Always error if we're about to generate a definition.
+HadError = ForDefinition;

erichkeane wrote:

This does not seem right here... I would expect us to still want to instantiate 
the function, just skip doing that earlier.  I think the bisect as suggested by 
others to see if we can figure out what the difference is for the cause is a 
better way forward than this.

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


[clang] 5c84054 - [LinkerWrapper] Support relocatable linking for offloading (#80066)

2024-02-07 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-02-07T08:20:07-06:00
New Revision: 5c84054223102b00cc0dd343a4023e3c6cba42b2

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

LOG: [LinkerWrapper] Support relocatable linking for offloading (#80066)

Summary:
The standard GPU compilation process embeds each intermediate object
file into the host file at the `.llvm.offloading` section so it can be
linked later. We also use a special section called something like
`omp_offloading_entries` to store all the globals that need to be
registered by the runtime. The linker-wrapper's job is to link the
embedded device code stored at this section and then emit code to
register the linked image and the kernels and globals in the offloading
entry section.

One downside to RDC linking is that it can become quite big for very
large projects that wish to make use of static linking. This patch
changes the support for relocatable linking via `-r` to support a kind
of "partial" RDC compilation for offloading languages.

This primarily requires manually editing the embedded data in the
output object file for the relocatable link. We need to rename the
output section to make it distinct from the input sections that will be
merged. We then delete the old embedded object code so it won't be
linked further. We then need to rename the old offloading section so
that it is private to the module. A runtime solution could also be done
to defer entries that don't belong to the given GPU executable, but this
is easier. Note that this does not work with COFF linking, only the ELF
method for handling offloading entries, that could be made to work
similarly.

Given this support, the following compilation path should produce two
distinct images for OpenMP offloading.
```
$ clang foo.c -fopenmp --offload-arch=native -c
$ clang foo.c -lomptarget.devicertl --offload-link -r -o merged.o
$ clang main.c merged.o -fopenmp --offload-arch=native
$ ./a.out
```

Or similarly for HIP to effectively perform non-RDC mode compilation for
a subset of files.

```
$ clang -x hip foo.c --offload-arch=native --offload-new-driver -fgpu-rdc -c
$ clang -x hip foo.c -lomptarget.devicertl --offload-link -r -o merged.o
$ clang -x hip main.c merged.o --offload-arch=native --offload-new-driver 
-fgpu-rdc
$ ./a.out
```

One question is whether or not this should be the default behavior of
`-r` when run through the linker-wrapper or a special option. Standard
`-r` behavior is still possible if used without invoking the
linker-wrapper and it guaranteed to be correct.

Added: 


Modified: 
clang/docs/ClangLinkerWrapper.rst
clang/docs/OffloadingDesign.rst
clang/test/Driver/linker-wrapper-image.c
clang/test/Driver/linker-wrapper.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
llvm/include/llvm/Frontend/Offloading/OffloadWrapper.h
llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
llvm/lib/Object/OffloadBinary.cpp

Removed: 




diff  --git a/clang/docs/ClangLinkerWrapper.rst 
b/clang/docs/ClangLinkerWrapper.rst
index fbabb4f8613b3a..1e851b0aa06192 100644
--- a/clang/docs/ClangLinkerWrapper.rst
+++ b/clang/docs/ClangLinkerWrapper.rst
@@ -54,12 +54,30 @@ only for the linker wrapper will be forwarded to the 
wrapped linker job.
 --pass-remarks= Pass remarks for LTO
 --print-wrapped-module Print the wrapped module's IR for testing
 --ptxas-arg=Argument to pass to the 'ptxas' invocation
+--relocatable   Link device code to create a relocatable 
offloading application
 --save-temps   Save intermediate results
 --sysroot   Set the system root
 --verbose  Verbose output from tools
 --vDisplay the version number and exit
 -- The separator for the wrapped linker arguments
 
+Relocatable Linking
+===
+
+The ``clang-linker-wrapper`` handles linking embedded device code and then 
+registering it with the appropriate runtime. Normally, this is only done when 
+the executable is created so other files containing device code can be linked 
+together. This can be somewhat problematic for users who wish to ship static 
+libraries that contain offloading code to users without a compatible 
offloading 
+toolchain.
+
+When using a relocatable link with ``-r``, the ``clang-linker-wrapper`` will 
+perform the device linking and registration eagerly. This will remove the 
+embedded device code and register it correctly with the runtime. Semantically, 
+this is similar to creating a shared library object. If standard relocatable 
+linking is desired, simply do not run the binaries through the 
+``clang-linker-wrapper``. This will simply append the embedded device code so 

[clang] [llvm] [LinkerWrapper] Support relocatable linking for offloading (PR #80066)

2024-02-07 Thread Joseph Huber via cfe-commits

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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-07 Thread Matt Arsenault via cfe-commits


@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto &Ctx = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}

arsenm wrote:

"The semantics of non-zero address spaces are target-specific. Memory access 
through a non-dereferenceable pointer is undefined behavior in any address 
space. Pointers with the bit-value 0 are only assumed to be non-dereferenceable 
in address space 0, unless the function is marked with the 
null_pointer_is_valid attribute."

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


[clang] [NVPTX][AMDGPU][CodeGen] Fix `local_space nullptr` handling for NVPTX and local/private `nullptr` value for AMDGPU. (PR #78759)

2024-02-07 Thread Matt Arsenault via cfe-commits


@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
+   llvm::PointerType *PT,
+   QualType QT) const {
+  auto &Ctx = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+  PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+  llvm::ConstantPointerNull::get(NPT), PT);
+}

arsenm wrote:

I think this really needs to be a property of the datalayout. the addrspacecast 
is a roundabout way of using -1 

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


[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-02-07 Thread Akash Banerjee via cfe-commits

TIFitis wrote:

> There is some code that is related to Flang/MLIR that shouldn't be in the 
> patch. e.g. ReductionInfoManager is not used anywhere. I am currently working 
> on a patch that refactors this code a bit and how it is used in the MLIR 
> lowering.

Thanks for pointing this out, I've removed it from this PR.



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


[clang] [Clang][TableGen] Add Features to TargetBuiltin (PR #80279)

2024-02-07 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

> The changes seem reasonable to me but I'd feel more comfortable if the 
> functionality was also being used (so that we'd get test coverage verifying 
> its correctness). Do you think it would be reasonable to include the RISCV 
> changes as well?

Yeah, I separated RISCV changes into another 
PR(https://github.com/llvm/llvm-project/pull/80280).

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


[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-02-07 Thread Akash Banerjee via cfe-commits


@@ -2719,10 +4051,24 @@ getKmpcForStaticLoopForType(Type *Ty, OpenMPIRBuilder 
*OMPBuilder,
 static void createTargetLoopWorkshareCall(
 OpenMPIRBuilder *OMPBuilder, WorksharingLoopType LoopType,
 BasicBlock *InsertBlock, Value *Ident, Value *LoopBodyArg,
-Type *ParallelTaskPtr, Value *TripCount, Function &LoopBodyFn) {
-  Type *TripCountTy = TripCount->getType();
+Type *ParallelTaskPtr, Value *TripCountOrig, Function &LoopBodyFn) {
   Module &M = OMPBuilder->M;
   IRBuilder<> &Builder = OMPBuilder->Builder;
+  Value *TripCount = TripCountOrig;
+  // FIXME(JAN): The trip count is 1 larger than it should be for GPU, this may
+  // not be the right way to fix it, but this works for now.

TIFitis wrote:

This section of the code is never executed from Clang, so I'm not sure.

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


[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-02-07 Thread Akash Banerjee via cfe-commits


@@ -2042,35 +2057,1378 @@ OpenMPIRBuilder::createSection(const 
LocationDescription &Loc,
   /*IsCancellable*/ true);
 }
 
-/// Create a function with a unique name and a "void (i8*, i8*)" signature in
-/// the given module and return it.
-Function *getFreshReductionFunc(Module &M) {
-  Type *VoidTy = Type::getVoidTy(M.getContext());
-  Type *Int8PtrTy = PointerType::getUnqual(M.getContext());
-  auto *FuncTy =
-  FunctionType::get(VoidTy, {Int8PtrTy, Int8PtrTy}, /* IsVarArg */ false);
-  return Function::Create(FuncTy, GlobalVariable::InternalLinkage,
-  M.getDataLayout().getDefaultGlobalsAddressSpace(),
-  ".omp.reduction.func", &M);
+static OpenMPIRBuilder::InsertPointTy getInsertPointAfterInstr(Instruction *I) 
{
+  BasicBlock::iterator IT(I);
+  IT++;
+  return OpenMPIRBuilder::InsertPointTy(I->getParent(), IT);
 }
 
-OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
-const LocationDescription &Loc, InsertPointTy AllocaIP,
-ArrayRef ReductionInfos, bool IsNoWait) {
-  for (const ReductionInfo &RI : ReductionInfos) {
+void OpenMPIRBuilder::emitUsed(StringRef Name,
+   std::vector &List) {
+  if (List.empty())
+return;
+
+  // Convert List to what ConstantArray needs.
+  SmallVector UsedArray;
+  UsedArray.resize(List.size());
+  for (unsigned I = 0, E = List.size(); I != E; ++I)
+UsedArray[I] = ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+cast(&*List[I]), Builder.getPtrTy());
+
+  if (UsedArray.empty())
+return;
+  ArrayType *ATy = ArrayType::get(Builder.getPtrTy(), UsedArray.size());
+
+  auto *GV = new GlobalVariable(M, ATy, false, GlobalValue::AppendingLinkage,
+ConstantArray::get(ATy, UsedArray), Name);
+
+  GV->setSection("llvm.metadata");
+}
+
+Value *OpenMPIRBuilder::getGPUThreadID() {
+  return Builder.CreateCall(
+  getOrCreateRuntimeFunction(M,
+ 
OMPRTL___kmpc_get_hardware_thread_id_in_block),
+  {});
+}
+
+Value *OpenMPIRBuilder::getGPUWarpSize() {
+  return Builder.CreateCall(
+  getOrCreateRuntimeFunction(M, OMPRTL___kmpc_get_warp_size), {});
+}
+
+Value *OpenMPIRBuilder::getNVPTXWarpID() {
+  unsigned LaneIDBits = Log2_32(Config.getGridValue().GV_Warp_Size);
+  return Builder.CreateAShr(getGPUThreadID(), LaneIDBits, "nvptx_warp_id");
+}
+
+Value *OpenMPIRBuilder::getNVPTXLaneID() {
+  unsigned LaneIDBits = Log2_32(Config.getGridValue().GV_Warp_Size);
+  assert(LaneIDBits < 32 && "Invalid LaneIDBits size in NVPTX device.");
+  unsigned LaneIDMask = ~0u >> (32u - LaneIDBits);
+  return Builder.CreateAnd(getGPUThreadID(), Builder.getInt32(LaneIDMask),
+   "nvptx_lane_id");
+}
+
+Value *OpenMPIRBuilder::castValueToType(InsertPointTy AllocaIP, Value *From,
+Type *ToType) {
+  Type *FromType = From->getType();
+  uint64_t FromSize = M.getDataLayout().getTypeStoreSize(FromType);
+  uint64_t ToSize = M.getDataLayout().getTypeStoreSize(ToType);
+  assert(FromSize > 0 && "From size must be greater than zero");
+  assert(ToSize > 0 && "To size must be greater than zero");
+  if (FromType == ToType)
+return From;
+  if (FromSize == ToSize)
+return Builder.CreateBitCast(From, ToType);
+  if (ToType->isIntegerTy() && FromType->isIntegerTy())
+return Builder.CreateIntCast(From, ToType, /*isSigned*/ true);
+  InsertPointTy SaveIP = Builder.saveIP();
+  Builder.restoreIP(AllocaIP);
+  Value *CastItem = Builder.CreateAlloca(ToType);
+  Builder.restoreIP(SaveIP);
+
+  Value *ValCastItem = Builder.CreatePointerBitCastOrAddrSpaceCast(
+  CastItem, FromType->getPointerTo());
+  Builder.CreateStore(From, ValCastItem);
+  return Builder.CreateLoad(ToType, CastItem);
+}
+
+Value *OpenMPIRBuilder::createRuntimeShuffleFunction(InsertPointTy AllocaIP,
+ Value *Element,
+ Type *ElementType,
+ Value *Offset) {
+  uint64_t Size = M.getDataLayout().getTypeStoreSize(ElementType);
+  assert(Size <= 8 && "Unsupported bitwidth in shuffle instruction");
+
+  // Cast all types to 32- or 64-bit values before calling shuffle routines.
+  Type *CastTy = Builder.getIntNTy(Size <= 4 ? 32 : 64);
+  Value *ElemCast = castValueToType(AllocaIP, Element, CastTy);
+  Value *WarpSize =
+  Builder.CreateIntCast(getGPUWarpSize(), Builder.getInt16Ty(), true);
+  Function *ShuffleFunc = getOrCreateRuntimeFunctionPtr(
+  Size <= 4 ? RuntimeFunction::OMPRTL___kmpc_shuffle_int32
+: RuntimeFunction::OMPRTL___kmpc_shuffle_int64);
+  Value *WarpSizeCast =
+  Builder.CreateIntCast(WarpSize, Builder.getInt16Ty(), /*isSigned=*/true);
+  Value *ShuffleCall =
+  Builder.CreateCall(ShuffleFunc, {ElemCast, Offset, WarpSizeCast});
+  return castV

[clang] 5d8a731 - [clang][Interp] Support __builtin_eh_return_data_regno

2024-02-07 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-07T15:29:43+01:00
New Revision: 5d8a7318b2192ce8e396ec420f3f4d8f1a07cc10

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

LOG: [clang][Interp] Support __builtin_eh_return_data_regno

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 5976d4c3e7131..8f76b51ac0334 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -645,6 +645,19 @@ static bool interp__builtin_move(InterpState &S, CodePtr 
OpPC,
   return Func->getDecl()->isConstexpr();
 }
 
+static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func,
+ const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Arg = peekToAPSInt(S.Stk, ArgT);
+
+  int Result =
+  S.getCtx().getTargetInfo().getEHDataRegisterNumber(Arg.getZExtValue());
+  pushInt(S, Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -869,6 +882,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_eh_return_data_regno:
+if (!interp__builtin_eh_return_data_regno(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 return false;
   }

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index ce7c8bd357908..d6ed2d862b094 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -363,3 +363,16 @@ namespace ffs {
   char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1];
   char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1];
 }
+
+namespace EhReturnDataRegno {
+  void test11(int X) {
+switch (X) {
+  case __builtin_eh_return_data_regno(0):  // constant foldable.
+  break;
+}
+
+__builtin_eh_return_data_regno(X);  // expected-error {{argument to 
'__builtin_eh_return_data_regno' must be a constant integer}} \
+// ref-error {{argument to 
'__builtin_eh_return_data_regno' must be a constant integer}}
+
+  }
+}



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


[clang] [llvm] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets (PR #76955)

2024-02-07 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/76955

>From 616dda8bc9e000e4243ddb8f6b7f4b04f956a620 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:48:05 +0100
Subject: [PATCH 1/6] [AMDGPU] Introduce GFX9/10.1/10.3/11 Generic Targets

These generic targets include multiple GPUs and will, in the future, provide a 
way to build once and run on multiple GPU, at the cost of less optimization 
opportunities.
Note that this is just doing the compiler side of things, device libs an 
runtimes/loader/etc. don't know about these targets yet, so none of them 
actually work in practice right now. This is just the initial commit to make 
LLVM aware of them.

No docs in this patch either as I plan to do it all in a follow-up patch.
---
 clang/lib/Basic/Targets/AMDGPU.cpp|  20 +-
 clang/test/Driver/amdgpu-macros.cl|   5 +
 clang/test/Driver/amdgpu-mcpu.cl  |  10 +
 llvm/docs/AMDGPUUsage.rst | 325 +-
 llvm/include/llvm/BinaryFormat/ELF.h  |   6 +-
 llvm/include/llvm/TargetParser/TargetParser.h |  10 +
 llvm/lib/Object/ELFObjectFile.cpp |  10 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   4 +
 llvm/lib/Target/AMDGPU/AMDGPU.td  |  87 +++--
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   6 +
 .../AMDGPURemoveIncompatibleFunctions.cpp |   6 +-
 llvm/lib/Target/AMDGPU/GCNProcessors.td   |  22 ++
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   4 +
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  26 ++
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |  11 +
 llvm/lib/TargetParser/TargetParser.cpp|  46 +++
 .../GlobalISel/llvm.amdgcn.workitem.id.ll |   1 +
 .../CodeGen/AMDGPU/directive-amdgcn-target.ll |  14 +
 .../CodeGen/AMDGPU/elf-header-flags-mach.ll   |  10 +
 llvm/test/CodeGen/AMDGPU/gds-allocation.ll|   1 +
 llvm/test/CodeGen/AMDGPU/gds-atomic.ll|   1 +
 .../AMDGPU/generic-targets-require-v6.ll  |  18 +
 .../AMDGPU/hsa-generic-target-features.ll |  31 ++
 .../llvm.amdgcn.image.gather4.d16.dim.ll  |   3 +
 .../AMDGPU/llvm.amdgcn.image.sample.dim.ll|   3 +
 .../AMDGPU/unsupported-image-sample.ll|  12 +-
 .../Object/AMDGPU/elf-header-flags-mach.yaml  |  29 ++
 .../llvm-objdump/ELF/AMDGPU/subtarget.ll  |  20 ++
 .../llvm-readobj/ELF/AMDGPU/elf-headers.test  |  12 +
 llvm/tools/llvm-readobj/ELFDumper.cpp | 128 +++
 30 files changed, 689 insertions(+), 192 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/generic-targets-require-v6.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/hsa-generic-target-features.ll

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 141501e8a4d9a1..799634ccec7ba5 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -279,13 +279,25 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (GPUKind == llvm::AMDGPU::GK_NONE && !IsHIPHost)
 return;
 
-  StringRef CanonName = isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
-  : getArchNameR600(GPUKind);
+  std::string CanonName = (isAMDGCN(getTriple()) ? getArchNameAMDGCN(GPUKind)
+ : getArchNameR600(GPUKind))
+  .str();
+
+  // Sanitize the name of generic targets.
+  // e.g. gfx10.1-generic -> gfx10_1_generic
+  if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
+  GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
+std::replace(CanonName.begin(), CanonName.end(), '.', '_');
+std::replace(CanonName.begin(), CanonName.end(), '-', '_');
+  }
+
   Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
   // Emit macros for gfx family e.g. gfx906 -> __GFX9__, gfx1030 -> __GFX10___
   if (isAMDGCN(getTriple()) && !IsHIPHost) {
-assert(CanonName.starts_with("gfx") && "Invalid amdgcn canonical name");
-Builder.defineMacro(Twine("__") + Twine(CanonName.drop_back(2).upper()) +
+assert(StringRef(CanonName).starts_with("gfx") &&
+   "Invalid amdgcn canonical name");
+StringRef CanonFamilyName = getArchFamilyNameAMDGCN(GPUKind);
+Builder.defineMacro(Twine("__") + Twine(CanonFamilyName.upper()) +
 Twine("__"));
 Builder.defineMacro("__amdgcn_processor__",
 Twine("\"") + Twine(CanonName) + Twine("\""));
diff --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index 81c22af460d12d..3b10444ef71d36 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -131,6 +131,11 @@
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1200 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx1200 
-DFAMILY=GFX12
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx1201 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-GCN,FAST_FMAF

[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {

martinboehme wrote:

```suggestion
TEST(TransferTest, AssignmentOperatorReturnsVoid) {
```

(For consistency with tests above.)

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits

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


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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -535,7 +535,19 @@ class TransferVisitor : public 
ConstStmtVisitor {
 return;
 
   copyRecord(*LocSrc, *LocDst, Env);
-  Env.setStorageLocation(*S, *LocDst);
+
+  // If the expr is a glvalue, we can reasonably assume the operator is
+  // returning T& and thus we can assign it `LocDst`.
+  if (S->isGLValue()) {
+Env.setStorageLocation(*S, *LocDst);
+  } else if (S->getType()->isRecordType() && S->isPRValue()) {

martinboehme wrote:

```suggestion
  } else if (S->getType()->isRecordType()) {
```

`S->isPRValue()` is redundant here because `S->isPRValue() == !S->isGLValue()`.

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  void operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsPRValue) {

martinboehme wrote:

```suggestion
TEST(TransferTest, AssignmentOperatorReturnsByValue) {
```

Nit: The `CallExpr` is a prvalue, but the assignment operator itself returns a 
value rather than a reference.

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {

martinboehme wrote:

Can you rename this to `struct S`?

(The reason we have `B` in the test above is because it is the "base". But 
otherwise we typically call structs `S`.)

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -535,7 +535,19 @@ class TransferVisitor : public 
ConstStmtVisitor {
 return;
 
   copyRecord(*LocSrc, *LocDst, Env);
-  Env.setStorageLocation(*S, *LocDst);
+
+  // If the expr is a glvalue, we can reasonably assume the operator is
+  // returning T& and thus we can assign it `LocDst`.
+  if (S->isGLValue()) {
+Env.setStorageLocation(*S, *LocDst);
+  } else if (S->getType()->isRecordType() && S->isPRValue()) {
+// If the expr is a prvalue, we cannot really assume anything regarding
+// the new value being created. We should just propagate it to ensure a
+// `RecordValue` exist for it.
+if (Env.getValue(*S) == nullptr)
+  refreshRecordValue(*S, Env);

martinboehme wrote:

Is this actually necessary? (It's not really doing anything?)

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


[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

2024-02-07 Thread via cfe-commits


@@ -2313,6 +2313,42 @@ TEST(TransferTest, 
AssignmentOperatorWithInitAndInheritance) {
  ASTContext &ASTCtx) {});
 }
 
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsVoid) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {
+  void operator=(B&& other);
+};
+void target() {
+  B b;
+  b = B();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {});
+}
+
+TEST(TransferTest, CXXOperatorCallExprEqualReturnsPRValue) {
+  // This is a crash repro.
+  std::string Code = R"(
+struct B {

martinboehme wrote:

Rename to `struct S`.

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -3780,6 +3780,30 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << NI.getName() << ParamTy << Ty;
 return;
   }
+  VarDecl *VD = cast(D);
+  // Create a reference to the variable declaration. This is a fake/dummy
+  // reference.
+  DeclRefExpr *VariableReference = DeclRefExpr::Create(
+  S.Context, NestedNameSpecifierLoc{}, SourceLocation{Loc}, VD, false,
+  DeclarationNameInfo{VD->getDeclName(), VD->getLocation()}, VD->getType(),
+  VK_LValue);
+
+  // Create a unary operator expression that represents taking the address of
+  // the variable. This is a fake/dummy expression.
+  Expr *AddressOfVariable = UnaryOperator::Create(
+  S.Context, VariableReference, UnaryOperatorKind::UO_AddrOf,
+  S.Context.getPointerType(VD->getType()), VK_PRValue, OK_Ordinary,
+  SourceLocation{Loc}, false, FPOptionsOverride{});

erichkeane wrote:

```suggestion
  Loc, false, FPOptionsOverride{});
```

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -3780,6 +3780,30 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << NI.getName() << ParamTy << Ty;
 return;
   }
+  VarDecl *VD = cast(D);
+  // Create a reference to the variable declaration. This is a fake/dummy
+  // reference.
+  DeclRefExpr *VariableReference = DeclRefExpr::Create(
+  S.Context, NestedNameSpecifierLoc{}, SourceLocation{Loc}, VD, false,

erichkeane wrote:

Also note, Loc is the location of the attribute itself, and is probably not 
what you want to make the location here.  I would THINK we want the diagnostic 
to point to the function instead... WDYT?

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -3780,6 +3780,30 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << NI.getName() << ParamTy << Ty;
 return;
   }
+  VarDecl *VD = cast(D);
+  // Create a reference to the variable declaration. This is a fake/dummy
+  // reference.
+  DeclRefExpr *VariableReference = DeclRefExpr::Create(
+  S.Context, NestedNameSpecifierLoc{}, SourceLocation{Loc}, VD, false,
+  DeclarationNameInfo{VD->getDeclName(), VD->getLocation()}, VD->getType(),
+  VK_LValue);
+
+  // Create a unary operator expression that represents taking the address of
+  // the variable. This is a fake/dummy expression.
+  Expr *AddressOfVariable = UnaryOperator::Create(
+  S.Context, VariableReference, UnaryOperatorKind::UO_AddrOf,
+  S.Context.getPointerType(VD->getType()), VK_PRValue, OK_Ordinary,
+  SourceLocation{Loc}, false, FPOptionsOverride{});
+
+  // Create a function call expression. This is a fake/dummy call expression.
+  CallExpr *FunctionCallExpression = CallExpr::Create(
+  S.Context, E, ArrayRef{AddressOfVariable}, S.Context.VoidTy, VK_PRValue,
+  SourceLocation{Loc}, FPOptionsOverride{});

erichkeane wrote:

```suggestion
  Loc, FPOptionsOverride{});
```

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -3780,6 +3780,30 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << NI.getName() << ParamTy << Ty;
 return;
   }
+  VarDecl *VD = cast(D);
+  // Create a reference to the variable declaration. This is a fake/dummy
+  // reference.
+  DeclRefExpr *VariableReference = DeclRefExpr::Create(
+  S.Context, NestedNameSpecifierLoc{}, SourceLocation{Loc}, VD, false,

erichkeane wrote:

```suggestion
  S.Context, NestedNameSpecifierLoc{}, Loc, VD, false,
```

https://github.com/llvm/llvm-project/pull/80040
___
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-02-07 Thread Axel Lundberg via cfe-commits

https://github.com/Zonotora updated 
https://github.com/llvm/llvm-project/pull/75481

>From 3b0af99a0e13ed9d6b8c0365a9fa7ea68ec5 Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Sat, 16 Dec 2023 19:33:21 +0100
Subject: [PATCH 1/2] [clang] Extract negativity check lambda to function

---
 clang/lib/CodeGen/CGExprScalar.cpp | 47 --
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index df8f71cf1d900..b8caafb00847d 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1097,6 +1097,27 @@ void ScalarExprEmitter::EmitIntegerTruncationCheck(Value 
*Src, QualType SrcType,
 {Src, Dst});
 }
 
+static llvm::Value *EmitIsNegativeTestHelper(Value *V, QualType VType,
+ const char *Name,
+ CGBuilderTy &Builder) {
+  // NOTE: zero value is considered to be non-negative.
+  // Is this value a signed type?
+  bool VSigned = VType->isSignedIntegerOrEnumerationType();
+  llvm::Type *VTy = V->getType();
+  if (!VSigned) {
+// If the value is unsigned, then it is never negative.
+// FIXME: can we encounter non-scalar VTy here?
+return llvm::ConstantInt::getFalse(VTy->getContext());
+  }
+  // Get the zero of the same type with which we will be comparing.
+  llvm::Constant *Zero = llvm::ConstantInt::get(VTy, 0);
+  // %V.isnegative = icmp slt %V, 0
+  // I.e is %V *strictly* less than zero, does it have negative value?
+  return Builder.CreateICmp(llvm::ICmpInst::ICMP_SLT, V, Zero,
+llvm::Twine(Name) + "." + V->getName() +
+".negativitycheck");
+};
+
 // Should be called within CodeGenFunction::SanitizerScope RAII scope.
 // Returns 'i1 false' when the conversion Src -> Dst changed the sign.
 static std::pair Value * {
-// Is this value a signed type?
-bool VSigned = VType->isSignedIntegerOrEnumerationType();
-llvm::Type *VTy = V->getType();
-if (!VSigned) {
-  // If the value is unsigned, then it is never negative.
-  // FIXME: can we encounter non-scalar VTy here?
-  return llvm::ConstantInt::getFalse(VTy->getContext());
-}
-// Get the zero of the same type with which we will be comparing.
-llvm::Constant *Zero = llvm::ConstantInt::get(VTy, 0);
-// %V.isnegative = icmp slt %V, 0
-// I.e is %V *strictly* less than zero, does it have negative value?
-return Builder.CreateICmp(llvm::ICmpInst::ICMP_SLT, V, Zero,
-  llvm::Twine(Name) + "." + V->getName() +
-  ".negativitycheck");
-  };
-
   // 1. Was the old Value negative?
-  llvm::Value *SrcIsNegative = EmitIsNegativeTest(Src, SrcType, "src");
+  llvm::Value *SrcIsNegative =
+  EmitIsNegativeTestHelper(Src, SrcType, "src", Builder);
   // 2. Is the new Value negative?
-  llvm::Value *DstIsNegative = EmitIsNegativeTest(Dst, DstType, "dst");
+  llvm::Value *DstIsNegative =
+  EmitIsNegativeTestHelper(Dst, DstType, "dst", Builder);
   // 3. Now, was the 'negativity status' preserved during the conversion?
   //NOTE: conversion from negative to zero is considered to change the 
sign.
   //(We want to get 'false' when the conversion changed the sign)

>From 49e3c6be7ed4e3dcb403b2ea1994dafb6e3d638e Mon Sep 17 00:00:00 2001
From: Zonotora 
Date: Sat, 16 Dec 2023 19:36:04 +0100
Subject: [PATCH 2/2] [clang][UBSan] Add implicit conversion check for
 bitfields

This patch implements the implicit truncation and implicit
sign change checks for bitfields.
---
 clang/docs/ReleaseNotes.rst   |  25 ++
 clang/docs/UndefinedBehaviorSanitizer.rst |  47 ++-
 clang/include/clang/Basic/Sanitizers.def  |  32 +-
 clang/lib/CodeGen/CGExpr.cpp  |  33 +-
 clang/lib/CodeGen/CGExprScalar.cpp| 332 +-
 clang/lib/CodeGen/CodeGenFunction.h   |  14 +
 .../test/CodeGen/ubsan-bitfield-conversion.c  |  32 ++
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  64 +++-
 compiler-rt/lib/ubsan/ubsan_handlers.h|  12 +
 compiler-rt/lib/ubsan/ubsan_interface.inc |   2 +
 10 files changed, 553 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/CodeGen/ubsan-bitfield-conversion.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c8608..0f7465f66b53e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -119,6 +119,26 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- ``-fsanitize=implicit-unsigned-bitfield-truncation`` catches implicit
+  unsigned conversions involving bitfields.
+- ``-fsanitize=implicit-signed-bitfield-truncation`` catches implicit
+  signed conversions involving bitfields.
+- ``-fsanitize=implicit-bitfield-sign-change`` catches implicit
+  conversions i

  1   2   3   4   5   >