[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-11 Thread via cfe-commits

https://github.com/hiraditya updated 
https://github.com/llvm/llvm-project/pull/68735

>From 5b85613483861b3734edf9c94be390f2b3b0dd2a Mon Sep 17 00:00:00 2001
From: Alex Fan 
Date: Fri, 6 Oct 2023 12:32:38 -0700
Subject: [PATCH] add support for riscv64

Implements for sv39 and sv48 VMA layout.

Userspace only has access to the bottom half of vma range. The top half is used 
by kernel.
There is no dedicated vsyscall or heap segment.
PIE program is allocated to start at TASK_SIZE/3*2. Maximum ASLR is 
ARCH_MMAP_RND_BITS_MAX+PAGE_SHIFT=24+12=36
Loader, vdso and other libraries are allocated below stack from the top.

Also change RestoreAddr to use 4 bits to accommodate MappingRiscv64_48

Reviewed by: MaskRay, dvyukov, asb, StephenFan, luismarques, jrtc27, hiraditya, 
vitalybuka

Differential Revision: https://reviews.llvm.org/D145214
---
 clang/lib/Driver/ToolChains/Linux.cpp |   2 +-
 .../cmake/Modules/AllSupportedArchDefs.cmake  |   2 +-
 .../lib/sanitizer_common/sanitizer_platform.h |   2 +-
 compiler-rt/lib/tsan/rtl/CMakeLists.txt   |   4 +
 .../lib/tsan/rtl/tsan_interceptors_posix.cpp  |   2 +
 compiler-rt/lib/tsan/rtl/tsan_platform.h  |  76 ++-
 .../lib/tsan/rtl/tsan_platform_linux.cpp  |  34 ++-
 compiler-rt/lib/tsan/rtl/tsan_rtl.h   |   4 +-
 compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S   | 203 ++
 compiler-rt/test/tsan/map32bit.cpp|   1 +
 compiler-rt/test/tsan/mmap_large.cpp  |   3 +-
 compiler-rt/test/tsan/test.h  |   2 +
 12 files changed, 318 insertions(+), 17 deletions(-)
 create mode 100644 compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1ba222bf83b1032..735af54f114cef2 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -801,7 +801,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
-  IsLoongArch64)
+  IsLoongArch64 || IsRISCV64)
 Res |= SanitizerKind::Thread;
   if (IsX86_64 || IsSystemZ)
 Res |= SanitizerKind::KernelMemory;
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index e8ab660c1d83c0c..416777171d2ca75 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -66,7 +66,7 @@ set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} 
${ARM64} ${PPC32} ${PPC
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${RISCV32} ${RISCV64} ${LOONGARCH64})
 set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
-${LOONGARCH64})
+${LOONGARCH64} ${RISCV64})
 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index c1ca5c9ca44783b..5280416f8bd3029 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -303,7 +303,7 @@
 #define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 
40)
 #  endif
 #elif SANITIZER_RISCV64
-#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38)
+#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
 #elif defined(__aarch64__)
 #  if SANITIZER_APPLE
 #if SANITIZER_OSX || SANITIZER_IOSSIM
diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt 
b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
index 7b18d379e919776..791c0596f65abf7 100644
--- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt
+++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
@@ -220,6 +220,10 @@ else()
   set(TSAN_ASM_SOURCES
 tsan_rtl_mips64.S
 )
+elseif(arch MATCHES "riscv64")
+  set(TSAN_ASM_SOURCES
+tsan_rtl_riscv64.S
+)
 elseif(arch MATCHES "s390x")
   set(TSAN_ASM_SOURCES
 tsan_rtl_s390x.S
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 5add97ccd17a3ad..80f86ca98ed9cd9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -81,6 +81,8 @@ struct ucontext_t {
 #define PTHREAD_ABI_BASE  "GLIBC_2.17"
 #elif SANITIZER_LOONGARCH64
 #define PTHREAD_ABI_BASE  "GLIBC_2.36"
+#elif SANITIZER_RISCV64
+#  define PTHREAD_ABI_BASE "GLIBC_2.27"
 #endif
 
 extern "C" int pthread_attr_init(void *attr);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h 
b/compiler-rt/lib/tsan/rtl/tsan_platform.h
index f0cdaf48eaa3102..cfbb57d1d8d8d9b 100644
--- 

[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-11 Thread via cfe-commits

https://github.com/hiraditya updated 
https://github.com/llvm/llvm-project/pull/68735

>From bcd63227792a992d6e5cd851d2fa2355d2f3c4f8 Mon Sep 17 00:00:00 2001
From: Alex Fan 
Date: Fri, 6 Oct 2023 12:32:38 -0700
Subject: [PATCH] [TSAN] add support for riscv64

Implements for sv39 and sv48 VMA layout.

Userspace only has access to the bottom half of vma range. The top half is used 
by kernel.
There is no dedicated vsyscall or heap segment.
PIE program is allocated to start at TASK_SIZE/3*2. Maximum ASLR is 
ARCH_MMAP_RND_BITS_MAX+PAGE_SHIFT=24+12=36
Loader, vdso and other libraries are allocated below stack from the top.

Also change RestoreAddr to use 4 bits to accommodate MappingRiscv64_48

Reviewed by: MaskRay, dvyukov, asb, StephenFan, luismarques, jrtc27, hiraditya, 
vitalybuka

Differential Revision: https://reviews.llvm.org/D145214
---
 clang/lib/Driver/ToolChains/Linux.cpp |   2 +-
 .../cmake/Modules/AllSupportedArchDefs.cmake  |   2 +-
 .../lib/sanitizer_common/sanitizer_platform.h |   2 +-
 compiler-rt/lib/tsan/rtl/CMakeLists.txt   |   4 +
 .../lib/tsan/rtl/tsan_interceptors_posix.cpp  |   2 +
 compiler-rt/lib/tsan/rtl/tsan_platform.h  |  76 ++-
 .../lib/tsan/rtl/tsan_platform_linux.cpp  |  14 ++
 compiler-rt/lib/tsan/rtl/tsan_rtl.h   |   2 +-
 compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S   | 203 ++
 compiler-rt/test/tsan/map32bit.cpp|   1 +
 compiler-rt/test/tsan/mmap_large.cpp  |   3 +-
 compiler-rt/test/tsan/test.h  |   2 +
 12 files changed, 307 insertions(+), 6 deletions(-)
 create mode 100644 compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1ba222bf83b1032..735af54f114cef2 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -801,7 +801,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
-  IsLoongArch64)
+  IsLoongArch64 || IsRISCV64)
 Res |= SanitizerKind::Thread;
   if (IsX86_64 || IsSystemZ)
 Res |= SanitizerKind::KernelMemory;
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index e8ab660c1d83c0c..416777171d2ca75 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -66,7 +66,7 @@ set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} 
${ARM64} ${PPC32} ${PPC
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${RISCV32} ${RISCV64} ${LOONGARCH64})
 set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
-${LOONGARCH64})
+${LOONGARCH64} ${RISCV64})
 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index c1ca5c9ca44783b..5280416f8bd3029 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -303,7 +303,7 @@
 #define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 
40)
 #  endif
 #elif SANITIZER_RISCV64
-#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38)
+#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
 #elif defined(__aarch64__)
 #  if SANITIZER_APPLE
 #if SANITIZER_OSX || SANITIZER_IOSSIM
diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt 
b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
index 7b18d379e919776..791c0596f65abf7 100644
--- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt
+++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
@@ -220,6 +220,10 @@ else()
   set(TSAN_ASM_SOURCES
 tsan_rtl_mips64.S
 )
+elseif(arch MATCHES "riscv64")
+  set(TSAN_ASM_SOURCES
+tsan_rtl_riscv64.S
+)
 elseif(arch MATCHES "s390x")
   set(TSAN_ASM_SOURCES
 tsan_rtl_s390x.S
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 5add97ccd17a3ad..bb10b607278f91a 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -81,6 +81,8 @@ struct ucontext_t {
 #define PTHREAD_ABI_BASE  "GLIBC_2.17"
 #elif SANITIZER_LOONGARCH64
 #define PTHREAD_ABI_BASE  "GLIBC_2.36"
+#elif SANITIZER_RISCV64
+#define PTHREAD_ABI_BASE  "GLIBC_2.27"
 #endif
 
 extern "C" int pthread_attr_init(void *attr);
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h 
b/compiler-rt/lib/tsan/rtl/tsan_platform.h
index f0cdaf48eaa3102..43822020c0b4b30 100644
--- 

[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-11 Thread Alex Fan via cfe-commits

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

I missed a little piece for sv48 here
```
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -303,7 +303,7 @@
 #define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 
40)
 #  endif
 #elif SANITIZER_RISCV64
-#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38)
+#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
 #elif defined(__aarch64__)
 #  if SANITIZER_APPLE
 #if SANITIZER_OSX || SANITIZER_IOSSIM
```

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


[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-11 Thread Alex Fan via cfe-commits

alexfanqi wrote:

Sorry. It took some time to reply. Since newer linux kernel supports sv57 and 
sv48, I tested this again with latest qemu and 6.6 kernel, by passing `-cpu 
rv64,sv48=on` to qemu.

I missed a little piece here for sv48,

Also to note, if we want to support sv57, we could directly copy the aarch64_48 
scheme and append 8 bits to its addresses. That gives the maximum application 
space, a horrific ~2^24 tera byte.

I asked @hiraditya to land for me. Thanks for the help to drive the reland.

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


[clang] [Driver] Group together linker options using addAllArgs (PR #68349)

2023-10-11 Thread Brad Smith via cfe-commits

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


[clang] 894927b - [Driver] Group together linker options using addAllArgs (#68349)

2023-10-11 Thread via cfe-commits

Author: Brad Smith
Date: 2023-10-12T00:34:19-04:00
New Revision: 894927b491b7c62917ffa7ad665841683095317c

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

LOG: [Driver] Group together linker options using addAllArgs (#68349)

Added: 


Modified: 
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/NaCl.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/lib/Driver/ToolChains/ZOS.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4d998e884f8ad42..c936fb88d18ccd9 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,11 +262,9 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
-  Args.AddAllArgs(CmdArgs, options::OPT_r);
+  Args.addAllArgs(CmdArgs,
+  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
+   options::OPT_Z_Flag, options::OPT_r});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 55c966ff39cd451..300a57afd37afd9 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -133,8 +133,7 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5949d9872c54f72..cdd911af9a73361 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -530,8 +530,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
 ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 

diff  --git a/clang/lib/Driver/ToolChains/NaCl.cpp 
b/clang/lib/Driver/ToolChains/NaCl.cpp
index 38151735ee51fa6..5be08c42b528733 100644
--- a/clang/lib/Driver/ToolChains/NaCl.cpp
+++ b/clang/lib/Driver/ToolChains/NaCl.cpp
@@ -120,8 +120,7 @@ void nacltools::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 54b76ae8c8553ce..316e4d56c242acc 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -266,12 +266,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
-  Args.AddAllArgs(CmdArgs, options::OPT_r);
+  Args.addAllArgs(CmdArgs,
+  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
+   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);

diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index dd8066abbabd65d..5fd82d1da199263 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -208,11 +208,9 @@ void tools::PScpu::Linker::ConstructJob(Compilation , 
const JobAction ,
   CmdArgs.push_back("--lto=full");
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  

[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-11 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja created 
https://github.com/llvm/llvm-project/pull/68846

I'm unsure whether [P2460R2](https://wg21.link/p2460r2) should be listed in the 
page. The paper seemingly requires no changes.

### References
- [N4891](https://wg21.link/n4891)
  - [P1949R7](https://wg21.link/p1949r7) (C++ Identifier Syntax using Unicode 
Standard Annex 31)
- [N4898](https://wg21.link/n4898)
  - [P2036R3](https://wg21.link/p2036r3) (Change scope of lambda 
_trailing-return-type_)
- [N4916](https://wg21.link/n4916)
  - [P2468R2](https://wg21.link/p2468r2) (The Equality Operator You Are Looking 
For)
  - [P2327R1](https://wg21.link/p2327r1) (De-deprecating `volatile` compound 
operations)
  - [P2493R0](https://wg21.link/p2493r0) (Missing feature test macros for C++20 
core papers)
  - [P2513R3](https://wg21.link/p2513r3) (`char8_t` Compatibility and 
Portability Fix)
  - [P2460R2](https://wg21.link/p2460r2) (Relax requirements on `wchar_t` to 
match existing practices)
  - [P2579R0](https://wg21.link/p2579r0) (Mitigation strategies for 
[P2036](https://wg21.link/p2036) ”Changing scope for lambda 
_trailing-return-type_”)

### Unchanged
- [N4884](https://wg21.link/n4884) effectively specifies 
[P1787R6](https://wg21.link/p1787r6) (Declarations and where to find them) to 
be a DR, but it seems that we're tracking the DR(s) in [another 
page](https://clang.llvm.org/cxx_dr_status.html).
- [N4940](https://wg21.link/n4940) says [P2706R0](https://wg21.link/p2706r0) 
(Redundant specification for defaulted functions) is a DR, but it seems that 
the paper requires no changes.
- [P2647R1](https://wg21.link/p2647r1) (Permitting `static` `constexpr` 
variables in `constexpr` functions) was once specified to be a DR, but it 
turned out that the DR status was a mistake and then reverted 
([N4943](https://wg21.link/n4943)).

>From c8013dbdf6acdd0ca29ee871f9fef608c986916a Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Thu, 12 Oct 2023 11:29:08 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index e2cf9ab25465214..5244c7f666ad363 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -210,7 +210,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7;>P1949R7
+  https://wg21.link/P1949R7;>P1949R7 (DR)
   Clang 14
 
 
@@ -230,11 +230,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3;>P2036R3
+  https://wg21.link/P2036R3;>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0;>P2579R0
+  https://wg21.link/P2579R0;>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -303,12 +303,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2;>P2468R2
+  https://wg21.link/P2468R2;>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1;>P2327R1
+  https://wg21.link/P2327R1;>P2327R1 (DR)
   Clang 15
 
 
@@ -380,7 +380,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3;>P2513R3
+  https://wg21.link/P2513R3;>P2513R3 (DR)
   Clang 16
 
 
@@ -522,7 +522,7 @@ C++20 implementation status
 https://wg21.link/p2103r0;>P2103R0
   

-https://wg21.link/p2493r0;>P2493R0
+https://wg21.link/p2493r0;>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0;>P2092R0

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


[clang] [Driver] Group together linker options using addAllArgs (PR #68349)

2023-10-11 Thread Brad Smith via cfe-commits

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


[clang] [Driver] Group together usage of AddAllArgs (PR #68349)

2023-10-11 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/68349

>From c01c08f813264327f1c641b4aa49ea7a20dd45cd Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Thu, 5 Oct 2023 16:09:04 -0400
Subject: [PATCH] [Driver] Group together linker options using addAllArgs

---
 clang/lib/Driver/ToolChains/FreeBSD.cpp| 8 +++-
 clang/lib/Driver/ToolChains/Fuchsia.cpp| 3 +--
 clang/lib/Driver/ToolChains/Gnu.cpp| 3 +--
 clang/lib/Driver/ToolChains/NaCl.cpp   | 3 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp | 9 +++--
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 8 +++-
 clang/lib/Driver/ToolChains/RISCVToolchain.cpp | 4 ++--
 clang/lib/Driver/ToolChains/WebAssembly.cpp| 4 ++--
 clang/lib/Driver/ToolChains/ZOS.cpp| 5 ++---
 9 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4d998e884f8ad42..c936fb88d18ccd9 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -262,11 +262,9 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
-  Args.AddAllArgs(CmdArgs, options::OPT_r);
+  Args.addAllArgs(CmdArgs,
+  {options::OPT_T_Group, options::OPT_s, options::OPT_t,
+   options::OPT_Z_Flag, options::OPT_r});
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 55c966ff39cd451..300a57afd37afd9 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -133,8 +133,7 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5949d9872c54f72..cdd911af9a73361 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -530,8 +530,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
 ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
diff --git a/clang/lib/Driver/ToolChains/NaCl.cpp 
b/clang/lib/Driver/ToolChains/NaCl.cpp
index 38151735ee51fa6..5be08c42b528733 100644
--- a/clang/lib/Driver/ToolChains/NaCl.cpp
+++ b/clang/lib/Driver/ToolChains/NaCl.cpp
@@ -120,8 +120,7 @@ void nacltools::Linker::ConstructJob(Compilation , const 
JobAction ,
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_u);
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
 
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 54b76ae8c8553ce..316e4d56c242acc 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -266,12 +266,9 @@ void netbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
-  Args.AddAllArgs(CmdArgs, options::OPT_r);
+  Args.addAllArgs(CmdArgs,
+  {options::OPT_L, options::OPT_T_Group, options::OPT_s,
+   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index dd8066abbabd65d..5fd82d1da199263 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -208,11 +208,9 @@ void tools::PScpu::Linker::ConstructJob(Compilation , 
const JobAction ,
   CmdArgs.push_back("--lto=full");
   }
 
-  Args.AddAllArgs(CmdArgs, options::OPT_L);
-  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
-  Args.AddAllArgs(CmdArgs, options::OPT_s);
-  Args.AddAllArgs(CmdArgs, options::OPT_t);
-  

[clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2023-10-11 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

> we prioritize inlining the memcpy code for a specific range based on the 
> hotness of that range in a particular inline context

@htyu Pretty much a drive-by question if it's convenient for you to share more, 
how ranges are selected out of sampled values? For example, are ranges 
compile-time constant for all workloads or dynamically generated based on the 
distribution of size from the per-workload profile data?  



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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Chen Zheng via cfe-commits

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


[clang] c661c4f - [AIX] recognize vsr in inline asm for AIX (#68476)

2023-10-11 Thread via cfe-commits

Author: Chen Zheng
Date: 2023-10-12T08:54:45+08:00
New Revision: c661c4f57613b5f85af94ee4e905708e0ba820f8

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

LOG: [AIX] recognize vsr in inline asm for AIX (#68476)

Extend `PPCTargetInfo::getGCCAddlRegNames()` to aix as well. The
definition should be common between Linux PPC and AIX PPC.

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.cpp
clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 4e895cc7310c00e..0d87a3a4e8c20f3 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -753,6 +753,8 @@ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap 
,
   }
 }
 
+// Make sure that registers are added in the correct array index which should 
be
+// the DWARF number for PPC registers.
 const char *const PPCTargetInfo::GCCRegNames[] = {
 "r0",  "r1", "r2",   "r3",  "r4",  "r5",  "r6",  "r7",  "r8",
 "r9",  "r10","r11",  "r12", "r13", "r14", "r15", "r16", "r17",
@@ -807,6 +809,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definition "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.
+// And this mapping applies to all OSes which run on powerpc.
 const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 // Table of additional register names to use in user input.
 {{"vs0"}, 32},   {{"vs1"}, 33},   {{"vs2"}, 34},   {{"vs3"}, 35},
@@ -828,10 +831,7 @@ const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 };
 
 ArrayRef PPCTargetInfo::getGCCAddlRegNames() const {
-  if (ABI == "elfv2")
-return llvm::ArrayRef(GCCAddlRegNames);
-  else
-return TargetInfo::getGCCAddlRegNames();
+  return llvm::ArrayRef(GCCAddlRegNames);
 }
 
 static constexpr llvm::StringLiteral ValidCPUNames[] = {

diff  --git a/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c 
b/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
index a4fabd688175e14..842e9b533a97454 100644
--- a/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
+++ b/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
@@ -2,6 +2,12 @@
 
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -target-feature +vsx \
 // RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -target-feature +vsx \
+// RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +vsx \
+// RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -target-feature +vsx \
+// RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
 
 // This case is to test VSX register support in the clobbers list for inline 
asm.
 void testVSX (void) {
@@ -9,12 +15,12 @@ void testVSX (void) {
   unsigned int *dbell=
   int d;
   __asm__ __volatile__ (
-"lxvw4x  %%vs32, 0, %2\n\t"
-"stxvw4x %%vs32, 0, %1"
+"lxvw4x  32, 0, %2\n\t"
+"stxvw4x 32, 0, %1"
 : "=m"(*(volatile unsigned int*)(dbell))
 : "r" (dbell), "r" ()
 : "vs32"
   );
 }
 
-// CHECK: call void asm sideeffect "lxvw4x  %vs32, 0, $2\0A\09stxvw4x %vs32, 
0, $1", "=*m,r,r,~{vs32}"
+// CHECK: call void asm sideeffect "lxvw4x  32, 0, $2\0A\09stxvw4x 32, 0, $1", 
"=*m,r,r,~{vs32}"



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


[PATCH] D8484: Allow -gsplit-dwarf for all ELF targets, not just Linux

2023-10-11 Thread Ed Maste via Phabricator via cfe-commits
emaste abandoned this revision.
emaste added a comment.
Herald added a project: All.

Allowed for all ELF OSes as of

  commit ee957e045f526ce45d24b0f081f277262c3da43d
  Author: Fangrui Song 
  Date:   Thu Mar 28 08:24:00 2019 +
  
  [Driver] Allow -gsplit-dwarf on ELF OSes other than Linux and Fuchsia
  
  In gcc, -gsplit-dwarf is handled in gcc/gcc.c as a spec
  (ASM_FINAL_SPEC): objcopy --extract-dwo + objcopy --strip-dwo. In
  gcc/opts.c, -gsplit_dwarf has the same semantic of a -g. Except for the
  availability of the external command 'objcopy', nothing precludes the
  feature working on other ELF OSes. llvm doesn't use objcopy, so it doesn't
  have to exclude other OSes.
  
  llvm-svn: 357150


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

https://reviews.llvm.org/D8484

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


[clang] [Driver] Remove identifier with the comment (PR #68351)

2023-10-11 Thread Brad Smith via cfe-commits

brad0 wrote:

ping.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/68276

>From 3bb0c8483c61e04f5ff76de920dcad89793f1326 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 5 Oct 2023 02:39:12 +0200
Subject: [PATCH] [Sema] Add check for bitfield assignments to integral types

We noticed that clang does not check for bitfield assignment widths,
while gcc does check this.

gcc produced a warning like so for it's -Wconversion flag:

$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may
change value [-Wconversion]
   10 |  vxx.bf = x; // no warning
  |   ^

This change simply adds this for integral types under the -Wconversion
compiler option.
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/include/clang/Basic/DiagnosticGroups.td |  2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaChecking.cpp   | 13 ++-
 clang/test/SemaCXX/bitfield-width.c   | 37 +++
 5 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/bitfield-width.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..cd92012ef5f411c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,6 +185,9 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
+* ``-conversion-bitfield-assign`` was added to detect assignments of integral
+  types to a bitfield that may change the value.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..674eb9f4ef2e73f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,6 +53,7 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
+def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -933,6 +934,7 @@ def Conversion : DiagGroup<"conversion",
 ConstantConversion,
 EnumConversion,
 BitFieldEnumConversion,
+BitFieldConversion,
 FloatConversion,
 Shorten64To32,
 IntConversion,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..ab7fe881976aad2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,6 +6171,9 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+  InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2594a8f97f7d94e..1b2f8cf296d16b6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,6 +14298,18 @@ static bool AnalyzeBitFieldAssignment(Sema , 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
+} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
+  IntRange LikelySourceRange =
+  GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
+   /*Approximate=*/true);
+
+  if (LikelySourceRange.Width > FieldWidth) {
+Expr *WidthExpr = Bitfield->getBitWidth();
+S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
+<< Bitfield << FieldWidth << OriginalInit->getType()
+<< LikelySourceRange.Width;
+S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
+  }
 }
 
 return false;
@@ -15195,7 +15207,6 @@ static void CheckImplicitConversion(Sema , Expr *E, 
QualType T,
 
   if (LikelySourceRange.Width > TargetRange.Width) {
 // If the source is a constant, use a default-on diagnostic.
-// TODO: this should happen for 

[clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2023-10-11 Thread Snehasish Kumar via cfe-commits

snehasish wrote:

> @david-xl It's interesting to know this. How is that going on your end?

Currently we are exploring the design space to accommodate the variety of 
platforms and FDO types we use internally. This is a priority for us though so 
we should have some updates to share externally by the end of the year. 

> We've been using similar technique to do memcpy size optimization. 

It's interesting that you are exploring a profile-guided direction for this. 
Chatelet et. al (from Google) published a paper on [automatic generation of 
memcpy](https://conf.researchr.org/details/ismm-2021/ismm-2021/4/automemcpy-A-framework-for-automatic-generation-of-fundamental-memory-operations)
 which uses PMU based parameter profiling at ISMM'21. The technique does not 
use Intel DLA instead we use precise sampling on call instructions in the 
process and filter the functions of interest. We inspect the RDX register to 
collect the parameter value for size. The data in aggregate was used to 
auto-generate the memcpy implementation. Section 2.4 has the rationale for not 
using an FDO approach. @gchatelet is the primary owner for this work.

What is the memcpy implementation you are trying to optimize? Do you see 
context sensitivity or workload specificity an important dimension to consider?

> But a common problem here could be how to generalize the AutoFDO profile 
> format to incorporate both indirect call targets, callsite parameter values 
> and other types of values. Do you have a plan for that? Maybe we can work 
> together on this.

Extensions to the AutoFDO format to accommodate such hints sounds good. Happy 
to collaborate on the design which can be leveraged by future work. Perhaps 
start a separate issue for discussion on Github or a thread on Discourse? 




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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-11 Thread via cfe-commits

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


[clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2023-10-11 Thread Hongtao Yu via cfe-commits

htyu wrote:

> The AutoFDO support Mingming mentioned is the vtable profiling part using 
> MEM_INST_RETIRED event that captures data address. This data access profiling 
> will/can also be used for global variable layout. However this is current 
> Intel only so having a branch profiling based method can be useful overall.

@david-xl  It's interesting to know this. How is that going on your end? We've 
been using similar technique to do memcpy size optimization. We currently can 
generate a value profile that fits into the existing LBR profile format and 
consumed together by the compiler. We haven't upstreamed this work yet since we 
are still evaluating the effectiveness of the optimization. But a common 
problem here could be how to generalize the AutoFDO profile format to 
incorporate both indirect call targets, callsite parameter values and other 
types of values. Do you have a plan for that? Maybe we can work together on 
this.

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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Tom Eccles via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

tblah wrote:

Yeah that sounds good to me. I will update this patch to do that tomorrow. I 
only added it to the global tree because currently it only seemed to be used to 
represent global variables and I didn't think much about the heap data.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread via cfe-commits


@@ -6171,6 +6171,11 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+  InGroup, DefaultIgnore;
+def note_bitfield_assign : Note<
+  "Bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;

vabridgers wrote:

I believe the comments have been resolved. Please let me know if there's 
anything else to do here. Thank you!

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


[clang] [Clang] Implement the 'counted_by' attribute (PR #68750)

2023-10-11 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/68750

>From b7b0c40542589e9c54c21140dbb5b163dd8ffc7b Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 4 Oct 2023 17:55:49 -0700
Subject: [PATCH 1/4] [Clang] Implement the 'counted_by' attribute

The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound sanitizer
and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically
that 'p->array' must have *at least* 'p->count' number of elements available.
It's the user's responsibility to ensure that this relationship is maintained
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than
what's specified by 'p->count'. This would result in an out-of-bounds access not
not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/Decl.h|  24 ++
 clang/include/clang/AST/DeclBase.h|  10 +
 clang/include/clang/Basic/Attr.td |  18 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 .../clang/Basic/DiagnosticSemaKinds.td|  15 ++
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/AST/ASTImporter.cpp |  13 +
 clang/lib/AST/DeclBase.cpp|  77 +-
 clang/lib/AST/Expr.cpp|  83 +--
 clang/lib/CodeGen/CGBuiltin.cpp   |  51 
 clang/lib/CodeGen/CGExpr.cpp  |  64 -
 clang/lib/CodeGen/CodeGenFunction.h   |   6 +
 clang/lib/Sema/SemaDecl.cpp   |  12 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 132 ++
 clang/test/CodeGen/attr-counted-by.c  | 227 ++
 clang/test/CodeGen/bounds-checking.c  |  10 +-
 ...a-attribute-supported-attributes-list.test |   1 +
 clang/test/Sema/attr-counted-by.c |  42 
 19 files changed, 780 insertions(+), 78 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by.c
 create mode 100644 clang/test/Sema/attr-counted-by.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..1eebf5ea6b3e382 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ C Language Changes
 - ``structs``, ``unions``, and ``arrays`` that are const may now be used as
   constant expressions.  This change is more consistent with the behavior of
   GCC.
+- Clang now supports the C-only attribute ``counted_by``. When applied to a
+  struct's flexible array member, it points to the struct field that holds the
+  number of elements in the flexible array member. This information can improve
+  the results of the array bound sanitizer and the
+  ``__builtin_dynamic_object_size`` builtin.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 02e30e24c8be470..7f076cc77ea82cb 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4302,6 +4302,30 @@ class RecordDecl : public TagDecl {
 return field_begin() == field_end();
   }
 
+  FieldDecl *getLastField() {
+FieldDecl *FD = nullptr;
+for (FieldDecl *Field : fields())
+  FD = Field;
+return FD;
+  }
+  const FieldDecl *getLastField() const {
+return const_cast(this)->getLastField();
+  }
+
+  template 
+  const FieldDecl *findFieldIf(Functor ) const {
+for (const Decl *D : decls()) {
+  if (const auto *FD = dyn_cast(D); FD && Pred(FD))
+return FD;
+
+  if (const auto *RD = dyn_cast(D))
+if (const FieldDecl *FD = 

[clang] [Clang] Implement the 'counted_by' attribute (PR #68750)

2023-10-11 Thread Bill Wendling via cfe-commits

bwendling wrote:

@AaronBallman I just added a patch that modifies the diagnostics to be more in 
line with what you wanted. PTAL.

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


[clang] [Clang] Implement the 'counted_by' attribute (PR #68750)

2023-10-11 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/68750

>From b7b0c40542589e9c54c21140dbb5b163dd8ffc7b Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 4 Oct 2023 17:55:49 -0700
Subject: [PATCH 1/3] [Clang] Implement the 'counted_by' attribute

The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound sanitizer
and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically
that 'p->array' must have *at least* 'p->count' number of elements available.
It's the user's responsibility to ensure that this relationship is maintained
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than
what's specified by 'p->count'. This would result in an out-of-bounds access not
not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/Decl.h|  24 ++
 clang/include/clang/AST/DeclBase.h|  10 +
 clang/include/clang/Basic/Attr.td |  18 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 .../clang/Basic/DiagnosticSemaKinds.td|  15 ++
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/AST/ASTImporter.cpp |  13 +
 clang/lib/AST/DeclBase.cpp|  77 +-
 clang/lib/AST/Expr.cpp|  83 +--
 clang/lib/CodeGen/CGBuiltin.cpp   |  51 
 clang/lib/CodeGen/CGExpr.cpp  |  64 -
 clang/lib/CodeGen/CodeGenFunction.h   |   6 +
 clang/lib/Sema/SemaDecl.cpp   |  12 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 132 ++
 clang/test/CodeGen/attr-counted-by.c  | 227 ++
 clang/test/CodeGen/bounds-checking.c  |  10 +-
 ...a-attribute-supported-attributes-list.test |   1 +
 clang/test/Sema/attr-counted-by.c |  42 
 19 files changed, 780 insertions(+), 78 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by.c
 create mode 100644 clang/test/Sema/attr-counted-by.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..1eebf5ea6b3e382 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ C Language Changes
 - ``structs``, ``unions``, and ``arrays`` that are const may now be used as
   constant expressions.  This change is more consistent with the behavior of
   GCC.
+- Clang now supports the C-only attribute ``counted_by``. When applied to a
+  struct's flexible array member, it points to the struct field that holds the
+  number of elements in the flexible array member. This information can improve
+  the results of the array bound sanitizer and the
+  ``__builtin_dynamic_object_size`` builtin.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 02e30e24c8be470..7f076cc77ea82cb 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4302,6 +4302,30 @@ class RecordDecl : public TagDecl {
 return field_begin() == field_end();
   }
 
+  FieldDecl *getLastField() {
+FieldDecl *FD = nullptr;
+for (FieldDecl *Field : fields())
+  FD = Field;
+return FD;
+  }
+  const FieldDecl *getLastField() const {
+return const_cast(this)->getLastField();
+  }
+
+  template 
+  const FieldDecl *findFieldIf(Functor ) const {
+for (const Decl *D : decls()) {
+  if (const auto *FD = dyn_cast(D); FD && Pred(FD))
+return FD;
+
+  if (const auto *RD = dyn_cast(D))
+if (const FieldDecl *FD = 

[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread via cfe-commits

vabridgers wrote:

> > Hi @AaronBallman , I ran a compile using this change on clang as you asked 
> > and have results. The compile ran with no crashes or errors, and produced 
> > 1478 bitfield-conversion warnings. I'll show a few examples below. To put 
> > that number into context, I enabled -Wconversion to compare the new warning 
> > - bitfield-conversion - with the other conversion checks. You can see from 
> > the results that while 1478 findings is large, it's less than 10% of the 
> > total conversion findings that exist - so looking at those numbers in 
> > context is helpful.
> > Are there any other suggested improvements for this patch, or do you think 
> > it's ok to merge?
> > ![image](https://user-images.githubusercontent.com/58314289/273438293-44313d33-6763-434b-92cb-37df8173209a.png)
> 
> Thank you for running the experiment! From spot-checking the results, did 
> they help you to find any actual bugs? And did you notice any patterns in the 
> results that could be used to safely silence the diagnostic in some cases?

We did find issues in our code base, and an "interesting" study in coding style 
related to the bitfield-enum-conversion check I'll describe. 

For the bitfield-conversion check, we found no real interesting patterns other 
than maybe the developer could use a mask on the RHS. But we observed that can 
mask problems (pun intended!!!) because a value could actually be greater in 
rank than the bitfield. An improvement to be made is a static analysis check 
(flow and context sensitive) to check the range of a value to be assigned to a 
bitfield. This would be an additional check to bitfield-conversion, and could 
be used to "vote" on the presence of a real defect or not. This may seem a bit 
too pedantic, but it is what it is :) 

Back to the interesting topic of bitfield-enum-conversion, you may know some 
programmers use a style to define C enums where the last element of an enum is 
the number of enums. An example looks like this...

`
  1
  2 enum myenum {
  3 red,
  4 blue,
  5 numenums,
  6 };
  7
  8 struct bits1 {
  9 int bf:1;
 10 };
 11
 12 struct bits1 xx;
 13
 14 int test(enum myenum value) {
 15 xx.bf = value;
 16 }
`
We see false positives related to this style, but this actually caught a real 
bug where the bitfield was not large enough to contain the enum. The trouble is 
suppressing the false positives - and this is certainly possible. It's also 
possible to change the coding style to accommodate the compiler diagnostic 
behavior. 

But tying these two together,  

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


[clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-10-11 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-10-11 Thread Andrzej Warzyński via cfe-commits


@@ -5077,6 +5077,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[NoXarchOption]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption, 
FlangOption]>,

banach-space wrote:

How did you infer these visibility flags? Also, could you add a test for this 
flag?

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


[clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-10-11 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space requested changes to this pull request.

Thanks for working on. I would appreciate if you could add a bit more testing.

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


[clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-10-11 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang][driver] Mark -fcommon and -mtune as visible in Flang (PR #68657)

2023-10-11 Thread Andrzej Warzyński via cfe-commits


@@ -10,6 +10,9 @@
 ! Make sure that `-L' is "visible" to Flang's driver
 ! RUN: %flang -L/ -### %s
 
+! Make sure that `-fcommon' is "visible" to Flang's driver

banach-space wrote:

This is not clear because I didn't leave any comment in this file (mea culpa, 
sorry), but the other flags tested here are purely driver flags (i.e. there's 
is nothing for Flang to do here). However, IIUC, `-fcommon` will affect 
code-generation and that's what we should be testing here instead,

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


[clang] [WIP][-Wunsafe-buffer-usage] Start emitting std::array fixits (PR #68037)

2023-10-11 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

We will need a new warning text here. "To preserve bounds information" isn't 
our goal; the traditional C array already preserves bounds information as part 
of the type. Theoretically, we could teach the compiler to harden all raw C 
array operations without converting it to `std::array`; the bounds information 
is already there. The message should say that `std::array` is beneficial 
because it takes advantage of *library*-level hardening.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/68276

>From f70a9fb484d5bdee8319833cde28ee02f3a248ff Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 5 Oct 2023 02:39:12 +0200
Subject: [PATCH] [Sema] Add check for bitfield assignments to integral types

We noticed that clang does not check for bitfield assignment widths,
while gcc does check this.

gcc produced a warning like so for it's -Wconversion flag:

$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may
change value [-Wconversion]
   10 |  vxx.bf = x; // no warning
  |   ^

This change simply adds this for integral types under the -Wconversion
compiler option.
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/include/clang/Basic/DiagnosticGroups.td |  2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  5 +++
 clang/lib/Sema/SemaChecking.cpp   | 13 ++-
 clang/test/SemaCXX/bitfield-width.c   | 37 +++
 5 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/bitfield-width.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..cd92012ef5f411c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,6 +185,9 @@ New Compiler Flags
   the preprocessed text to the output. This can greatly reduce the size of the
   preprocessed output, which can be helpful when trying to reduce a test case.
 
+* ``-conversion-bitfield-assign`` was added to detect assignments of integral
+  types to a bitfield that may change the value.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..674eb9f4ef2e73f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -53,6 +53,7 @@ def SingleBitBitFieldConstantConversion :
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
+def BitFieldConversion : DiagGroup<"bitfield-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
 def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
@@ -933,6 +934,7 @@ def Conversion : DiagGroup<"conversion",
 ConstantConversion,
 EnumConversion,
 BitFieldEnumConversion,
+BitFieldConversion,
 FloatConversion,
 Shorten64To32,
 IntConversion,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..544b4ac7ab7af68 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6171,6 +6171,11 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+  InGroup, DefaultIgnore;
+def note_bitfield_assign : Note<
+  "Bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2594a8f97f7d94e..1b2f8cf296d16b6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14298,6 +14298,18 @@ static bool AnalyzeBitFieldAssignment(Sema , 
FieldDecl *Bitfield, Expr *Init,
 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
 << BitsNeeded << ED << WidthExpr->getSourceRange();
   }
+} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
+  IntRange LikelySourceRange =
+  GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
+   /*Approximate=*/true);
+
+  if (LikelySourceRange.Width > FieldWidth) {
+Expr *WidthExpr = Bitfield->getBitWidth();
+S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
+<< Bitfield << FieldWidth << OriginalInit->getType()
+<< LikelySourceRange.Width;
+S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
+  }
 }
 
 return false;
@@ -15195,7 +15207,6 @@ static void CheckImplicitConversion(Sema , Expr *E, 
QualType T,
 
   if (LikelySourceRange.Width > 

[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-11 Thread via cfe-commits

https://github.com/weltschildkroete updated 
https://github.com/llvm/llvm-project/pull/68540

>From 613ea6809b478ff7391614b24ec177fc19339cdd Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Sun, 8 Oct 2023 12:59:15 +0200
Subject: [PATCH 1/6] [clang][Sema] Emit more specific diagnostic for auto in
 lambda before C++14 (#46059)

Namely, we specify that `auto` in a lambda parameter is a C++14
extension in the error message, which now reads:

`'auto' not allowed in lambda parameter until C++14`

This does not change the behavior for `decltype(auto)` and `__auto_type`
though.

The relevant change to `SemaType.cpp` is the addition of a branch that
sets `Error = 24`, whilst the bulk of the change comes from formatting.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/Sema/SemaType.cpp  | 7 +--
 clang/test/SemaCXX/auto-cxx0x.cpp| 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..815f78675c72ec2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration|in lambda parameter until C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 068971f8130a4aa..52a8161797e15e1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState ,
 Info = ();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;
+  break;
+} else if (!Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) {
   Error = 16;
   break;
 }
diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp 
b/clang/test/SemaCXX/auto-cxx0x.cpp
index b4da3f9330c1045..65398de28e10cfb 100644
--- a/clang/test/SemaCXX/auto-cxx0x.cpp
+++ b/clang/test/SemaCXX/auto-cxx0x.cpp
@@ -12,7 +12,7 @@ thread_local auto x; // expected-error {{requires an 
initializer}}
 void g() {
   [](auto){}(0);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }
 
@@ -20,6 +20,6 @@ void rdar47689465() {
   int x = 0;
   [](auto __attribute__((noderef)) *){}();
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }

>From b884f2b79d57343dea6e7f9b16dfc96984ec1f5b Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 22:52:54 +0200
Subject: [PATCH 2/6] Slightly change wording in diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 815f78675c72ec2..02644a84b4f4ea4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration|in lambda parameter until C++14}1">;
+  "|in array declaration|in lambda parameter before C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"

>From 99bc3b6cb8d1a812b6dcd573261a77a2d50a79e2 Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 23:09:07 +0200
Subject: [PATCH 3/6] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..41d83791cb5f287 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -301,6 +301,9 @@ Improvements to Clang's diagnostics
 - Clang now always diagnoses when using non-standard layout types 

[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-11 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 606f89ab7d537ca068fb1be9fd89d96a30de38f8 
031e76900f6e63c97ed8666066ff98d967305af4 -- clang/lib/Sema/SemaType.cpp 
clang/test/SemaCXX/auto-cxx0x.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index da759ba340c7..4f54645a9c14 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3610,7 +3610,8 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState ,
   Error = 24; // auto not allowed in lambda parameter (before C++14)
   break;
 } else if (!Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) {
-  Error = 16; // __auto_type or decltype(auto) not allowed in lambda 
parameter
+  Error = 16; // __auto_type or decltype(auto) not allowed in lambda
+  // parameter
   break;
 }
 Info = SemaRef.getCurLambda();

``




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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

I am still struggling a bit with heap data being marked global.

What would make sense for me is:

A direct with no pointer/target would have its own TBAA node.
A global with no target would have its own TBBA node.
Anything else would point to the "Any Data Access" node?



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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-11 Thread via cfe-commits


@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState ,
 Info = ();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;

weltschildkroete wrote:

Makes sense. I added some similar comments as well.

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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-11 Thread via cfe-commits

https://github.com/weltschildkroete updated 
https://github.com/llvm/llvm-project/pull/68540

>From 613ea6809b478ff7391614b24ec177fc19339cdd Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Sun, 8 Oct 2023 12:59:15 +0200
Subject: [PATCH 1/5] [clang][Sema] Emit more specific diagnostic for auto in
 lambda before C++14 (#46059)

Namely, we specify that `auto` in a lambda parameter is a C++14
extension in the error message, which now reads:

`'auto' not allowed in lambda parameter until C++14`

This does not change the behavior for `decltype(auto)` and `__auto_type`
though.

The relevant change to `SemaType.cpp` is the addition of a branch that
sets `Error = 24`, whilst the bulk of the change comes from formatting.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/Sema/SemaType.cpp  | 7 +--
 clang/test/SemaCXX/auto-cxx0x.cpp| 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..815f78675c72ec2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration|in lambda parameter until C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 068971f8130a4aa..52a8161797e15e1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState ,
 Info = ();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;
+  break;
+} else if (!Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) {
   Error = 16;
   break;
 }
diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp 
b/clang/test/SemaCXX/auto-cxx0x.cpp
index b4da3f9330c1045..65398de28e10cfb 100644
--- a/clang/test/SemaCXX/auto-cxx0x.cpp
+++ b/clang/test/SemaCXX/auto-cxx0x.cpp
@@ -12,7 +12,7 @@ thread_local auto x; // expected-error {{requires an 
initializer}}
 void g() {
   [](auto){}(0);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }
 
@@ -20,6 +20,6 @@ void rdar47689465() {
   int x = 0;
   [](auto __attribute__((noderef)) *){}();
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }

>From b884f2b79d57343dea6e7f9b16dfc96984ec1f5b Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 22:52:54 +0200
Subject: [PATCH 2/5] Slightly change wording in diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 815f78675c72ec2..02644a84b4f4ea4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration|in lambda parameter until C++14}1">;
+  "|in array declaration|in lambda parameter before C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"

>From 99bc3b6cb8d1a812b6dcd573261a77a2d50a79e2 Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 23:09:07 +0200
Subject: [PATCH 3/5] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..41d83791cb5f287 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -301,6 +301,9 @@ Improvements to Clang's diagnostics
 - Clang now always diagnoses when using non-standard layout types 

[libunwind] [OpenMP] Improve omp offload profiler (PR #68016)

2023-10-11 Thread via cfe-commits

fel-cab wrote:

I have prepared a presentation to better explain the proposed changes
https://docs.google.com/presentation/d/1lLlR7g29MWidaX9BLCUaKZhdvN-dphUE2BGMXhZCIoA/edit?usp=sharing

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


[clang] [OpenMP] Improve omp offload profiler (PR #68016)

2023-10-11 Thread via cfe-commits

fel-cab wrote:

I have prepared a presentation to better explain the proposed changes
https://docs.google.com/presentation/d/1lLlR7g29MWidaX9BLCUaKZhdvN-dphUE2BGMXhZCIoA/edit?usp=sharing

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


[clang-tools-extra] [OpenMP] Improve omp offload profiler (PR #68016)

2023-10-11 Thread via cfe-commits

fel-cab wrote:

I have prepared a presentation to better explain the proposed changes
https://docs.google.com/presentation/d/1lLlR7g29MWidaX9BLCUaKZhdvN-dphUE2BGMXhZCIoA/edit?usp=sharing

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


[libunwind] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-10-11 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> This would look good to me, but we seem to be failing the Windows tests!

Unfortunately I can't see what's going wrong there and I don't have an easy way 
of reproducing it. I'll try to add some debugging code to this PR in the coming 
days.

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


[clang] [clang][dataflow] Add support for lambda captures (PR #68558)

2023-10-11 Thread Stanislav Gatev via cfe-commits

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


[clang] 52d0696 - [clang][dataflow] Add support for lambda captures (#68558)

2023-10-11 Thread via cfe-commits

Author: Stanislav Gatev
Date: 2023-10-11T22:18:46+02:00
New Revision: 52d06963551938cfe9a2cf481608699cd988d824

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

LOG: [clang][dataflow] Add support for lambda captures (#68558)

This adds support for copy, ref, and this lambda captures to the core
framework and also adds relevant tests in UncheckedOptionalAccessTest.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 4698f0616e66e82..c46109a02921e7f 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -98,7 +98,7 @@ class DataflowAnalysisContext {
   StorageLocation (QualType Type);
 
   /// Returns a stable storage location for `D`.
-  StorageLocation (const VarDecl );
+  StorageLocation (const ValueDecl );
 
   /// Returns a stable storage location for `E`.
   StorageLocation (const Expr );

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 73f747ff88cf447..56d647f35b08430 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -242,7 +242,7 @@ class Environment {
   /// Creates a storage location for `D`. Does not assign the returned storage
   /// location to `D` in the environment. Does not assign a value to the
   /// returned storage location in the environment.
-  StorageLocation (const VarDecl );
+  StorageLocation (const ValueDecl );
 
   /// Creates a storage location for `E`. Does not assign the returned storage
   /// location to `E` in the environment. Does not assign a value to the
@@ -408,7 +408,7 @@ class Environment {
   /// this value. Otherwise, initializes the object with a value created using
   /// `createValue()`.  Uses the storage location returned by
   /// `DataflowAnalysisContext::getStableStorageLocation(D)`.
-  StorageLocation (const VarDecl , const Expr *InitExpr) {
+  StorageLocation (const ValueDecl , const Expr *InitExpr) {
 return createObjectInternal(, D.getType(), InitExpr);
   }
 
@@ -614,7 +614,7 @@ class Environment {
 
   /// Shared implementation of `createObject()` overloads.
   /// `D` and `InitExpr` may be null.
-  StorageLocation (const VarDecl *D, QualType Ty,
+  StorageLocation (const ValueDecl *D, QualType Ty,
 const Expr *InitExpr);
 
   /// Shared implementation of `pushCall` overloads. Note that unlike

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index e81048ce9233808..fa9b40fc49b3ae7 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -73,7 +73,7 @@ StorageLocation 
::createStorageLocation(QualType Type) {
 }
 
 StorageLocation &
-DataflowAnalysisContext::getStableStorageLocation(const VarDecl ) {
+DataflowAnalysisContext::getStableStorageLocation(const ValueDecl ) {
   if (auto *Loc = DeclToLoc.lookup())
 return *Loc;
   auto  = createStorageLocation(D.getType().getNonReferenceType());

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 66d98c995468595..01c6cc69e2b9fac 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -448,11 +448,23 @@ Environment::Environment(DataflowAnalysisContext ,
   if (const auto *MethodDecl = dyn_cast()) {
 auto *Parent = MethodDecl->getParent();
 assert(Parent != nullptr);
-if (Parent->isLambda())
-  MethodDecl = dyn_cast(Parent->getDeclContext());
 
-// FIXME: Initialize the ThisPointeeLoc of lambdas too.
-if (MethodDecl && MethodDecl->isImplicitObjectMemberFunction()) {
+if (Parent->isLambda()) {
+  for (auto Capture : Parent->captures()) {
+if (Capture.capturesVariable()) {
+  const auto 

[clang] [flang] Add flags controlling whether to run the fir alias tags pass (PR #68595)

2023-10-11 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thank you for addressing my comments!

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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Tom Eccles via cfe-commits

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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Tom Eccles via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

tblah wrote:

So, if I understand correctly, it *is* safe for me to proceed treating these 
`Direct` source kinds as globals (I already handle pointer/target elsewhere)?

The information I am encoding in TBAA is roughly "if it is a pointer, target, 
or if I don't know what it is then assume it could alias with any other data 
access". I think this covers both the reflective and non-reflective cases:
1. `rhsSrc.isTargetOrPointer()` -> rhs may alias with any data access and so it 
would alias with lhsSrc no matter what lhsSrc is
2. `lhsSrc.isTargetOrPointer()` -> lhs will alias with rhs, no matter what rhs 
is.

This is less precise than `fir::AliasAnalysis::alias` but it shouldn't produce 
incorrect results.

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread via cfe-commits


@@ -6171,6 +6171,11 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+  InGroup, DefaultIgnore;
+def note_bitfield_assign : Note<
+  "Bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;

vabridgers wrote:

I'll address, thank you

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


[clang] Add support for -fcx-limited-range and #pragma CX_LIMITED_RANGE. (PR #68820)

2023-10-11 Thread Zahira Ammarguellat via cfe-commits

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

>From 91de35737b74233f29da76573b4099bf64e8bdd4 Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Tue, 10 Oct 2023 08:31:41 -0700
Subject: [PATCH 1/2] Add support for -fcx-limited-range and #pragma
 CX_LIMTED_RANGE.

---
 clang/include/clang/Basic/FPOptions.def  |  1 +
 clang/include/clang/Basic/LangOptions.def|  2 +
 clang/include/clang/Basic/TokenKinds.def |  5 ++
 clang/include/clang/Driver/Options.td|  6 ++
 clang/include/clang/Parse/Parser.h   |  4 ++
 clang/include/clang/Sema/Sema.h  |  4 ++
 clang/lib/CodeGen/CGExprComplex.cpp  | 59 ++--
 clang/lib/Driver/ToolChains/Clang.cpp|  2 +
 clang/lib/Parse/ParsePragma.cpp  | 40 ++-
 clang/lib/Parse/ParseStmt.cpp| 10 +++
 clang/lib/Parse/Parser.cpp   |  3 +
 clang/lib/Sema/SemaAttr.cpp  |  7 ++
 clang/test/CodeGen/cx-full-range.c   | 22 ++
 clang/test/CodeGen/pragma-cx-limited-range.c | 73 
 clang/test/CodeGenCXX/cx-limited-range.c | 18 +
 15 files changed, 233 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/CodeGen/cx-full-range.c
 create mode 100644 clang/test/CodeGen/pragma-cx-limited-range.c
 create mode 100644 clang/test/CodeGenCXX/cx-limited-range.c

diff --git a/clang/include/clang/Basic/FPOptions.def 
b/clang/include/clang/Basic/FPOptions.def
index 5b923a1944e509a..9e56d7fcf26fdcf 100644
--- a/clang/include/clang/Basic/FPOptions.def
+++ b/clang/include/clang/Basic/FPOptions.def
@@ -28,4 +28,5 @@ OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, 
AllowApproxFunc)
 OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
Float16ExcessPrecision)
 OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
+OPTION(CxLimitedRange, bool, 1, MathErrno)
 #undef OPTION
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..47513522a0d7719 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -219,6 +219,8 @@ BENIGN_LANGOPT(NoSignedZero  , 1, 0, "Permit Floating 
Point optimization wit
 BENIGN_LANGOPT(AllowRecip, 1, 0, "Permit Floating Point reciprocal")
 BENIGN_LANGOPT(ApproxFunc, 1, 0, "Permit Floating Point approximation")
 
+LANGOPT(CxLimitedRange, 1, 0, "Enable use of algebraic expansions of complex 
arithmetics.")
+
 BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for 
__weak/__strong ivars")
 
 BENIGN_LANGOPT(AccessControl , 1, 1, "C++ access control")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 94db56a9fd5d78c..5cd81a66ab57bc1 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -904,6 +904,11 @@ PRAGMA_ANNOTATION(pragma_fenv_access_ms)
 // handles them.
 PRAGMA_ANNOTATION(pragma_fenv_round)
 
+// Annotation for #pragma STDC CX_LIMITED_RANGE
+// The lexer produces these so that they only take effect when the parser
+// handles them.
+PRAGMA_ANNOTATION(pragma_cx_limited_range)
+
 // Annotation for #pragma float_control
 // The lexer produces these so that they only take effect when the parser
 // handles them.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ff2130c93f28ea0..a871bea6cf14cd4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1001,6 +1001,12 @@ defm offload_uniform_block : 
BoolFOption<"offload-uniform-block",
   NegFlag,
   BothFlags<[], [ClangOption], " that kernels are launched with uniform block 
sizes (default true for CUDA/HIP and false otherwise)">>;
 
+def fcx_limited_range : Joined<["-"], "fcx-limited-range">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Basic algebraic expansions of some arithmetic operations involving 
"
+   "data of type COMPLEX are disabled.">,
+  MarshallingInfoFlag>;
+
 // OpenCL-only Options
 def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 0e969f341bbe19f..8f2b4d50fd59e5b 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -767,6 +767,10 @@ class Parser : public CodeCompletionHandler {
   /// #pragma STDC FENV_ROUND...
   void HandlePragmaFEnvRound();
 
+  /// Handle the annotation token produced for
+  /// #pragma STDC CX_LIMITED_RANGE...
+  void HandlePragmaCXLimitedRange();
+
   /// Handle the annotation token produced for
   /// #pragma float_control
   void HandlePragmaFloatControl();
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h

[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-11 Thread Erich Keane via cfe-commits


@@ -274,20 +274,27 @@ class DefaultIntArgument : 
IntArgument {
 }
 
 // This argument is more complex, it includes the enumerator type name,
-// a list of strings to accept, and a list of enumerators to map them to.
-class EnumArgument values,
+// a list of possible values, and a list of enumerators to map them to.
+class EnumArgument 
values,

erichkeane wrote:

I think rather than splitting this into doing 2 things, we should instead have 
an `UnevaluatedStringArgument` type here.

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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

Would it help, if I just said that %val does not come from a global variable. 
It comes from the heap because glbl is an allocatable. The box is global, but 
the data it wraps is not. 

In the example below glbl is a global
```module mod
real, dimension(1000) :: glbl
contains
subroutine func(arg)
  real, intent(in), dimension(:) :: arg
  call escape(glbl)
end subroutine
end module
```

In this case the SourceKind is global and we can infer that it cannot alias 
with anything else because of where it is physically located. But if you prefer 
to stick to Fortran rules, you can say that it is an F77 construct (since it 
does not have any target attribute) and therefore does not alias with anything. 
It would be non-conformant to pass it as an argument. 

```
fir.global @_QMmodEglbl : !fir.array<1000xf32> {
  %0 = fir.zero_bits !fir.array<1000xf32>
  fir.has_value %0 : !fir.array<1000xf32>
}
func.func @_QMmodPfunc(%arg0: !fir.box> {fir.bindc_name = 
"arg"}) {
  %c1000 = arith.constant 1000 : index
  %0 = fir.address_of(@_QMmodEglbl) : !fir.ref>
  %1 = fir.shape %c1000 : (index) -> !fir.shape<1>
  %2 = fir.declare %0(%1) {uniq_name = "_QMmodEglbl"} : 
(!fir.ref>, !fir.shape<1>) -> 
!fir.ref>
  %3 = fir.declare %arg0 {fortran_attrs = #fir.var_attrs, uniq_name 
= "_QMmodFfuncEarg"} : (!fir.box>) -> 
!fir.box>
  fir.call @_QPescape(%2) fastmath : (!fir.ref>) 
-> ()
  return
}
```

In the case of the Direct SourceKind, the outcome w.r.t. `arg` is the same but 
the rule is different. We have a direct memory access because, despite the box 
load and indirect fir.box_addr operations, we could establish that %val is 
indexing into glbl.  There is no target or pointer attribute on `arg` so we say 
that it cannot alias with it. 

A couple of observations here is:
1. Direct SourceKind by itself is not sufficient to determine aliasing, the 
attributes need to be looked at as well.
2. Unlike the global case, the rule for direct is not reflective. Aliasing is 
established w.r.t. another value.

Hopefully, this clarifies things. But if none of that helps I am now wondering 
if we cannot alter the rule to make it reflective. Instead of 
```
lhsSrc.kind == SourceKind::Direct && !rhsSrc.isTargetOrPointer()
```
could we have

```
lhsSrc.kind == SourceKind::Direct && !lhsSrc.isTargetOrPointer()
```

I will play with it today.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -282,7 +282,7 @@ LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching 
API for HIP")
 LANGOPT(OffloadUniformBlock, 1, 0, "Assume that kernels are launched with 
uniform block sizes (default true for CUDA/HIP and false otherwise)")
 LANGOPT(HIPStdPar, 1, 0, "Enable Standard Parallel Algorithm Acceleration for 
HIP (experimental)")
 LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations / deallocations 
with HIP RT calls when Standard Parallel Algorithm Acceleration for HIP is 
enabled (Experimental)")
-
+LANGOPT(MSVCEnableStdcMacro , 1, 0, "define __STDC__ with -fms-compatability")

AaronBallman wrote:

```suggestion
LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with '-fms-compatability'")
```

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -2821,6 +2821,10 @@ def fms_compatibility : Flag<["-"], 
"fms-compatibility">, Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Enable full Microsoft Visual C++ compatibility">,
   MarshallingInfoFlag>;
+def fms_define_stdc : Flag<["-"], "fms-define-stdc">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Define __STDC__ in MSVC Compatibility mode">,

AaronBallman wrote:

```suggestion
  HelpText<"Define '__STDC__' to '1' in MSVC Compatibility mode">,
```

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -123,6 +123,10 @@
 // CHECK-CHAR8_T_: "-fno-char8_t"
 
 
+// RUN: %clang_cl /dev/null /E -Xclang -dM 2> /dev/null | FileCheck 
-match-full-lines %s --check-prefix=STDCOFF
+// RUN: %clang_cl /dev/null /E -Xclang -dM /Zc:__STDC__ 2> /dev/null | 
FileCheck -match-full-lines %s --check-prefix=STDCON

AaronBallman wrote:

I'd also like to see a test that ensures you can't *disable* the option. e.g., 
`-fno-ms-define-stdc` should be an error.

And this current test actually shows a bug -- this is a .cpp file, not a .c 
file; `/Zc:__STDC__` should do nothing/diagnose in C++ mode 
(https://godbolt.org/z/6W4oaKf9e); I'm on the fence as to whether 
`-fms-define-stdc` should be allowed in C++ mode or not (I'm inclined to say it 
should also be unsupported in C++ mode).

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! Please be sure to add a release note to 
`clang/docs/ReleaseNotes.rst` so users know about the new functionality.

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -7922,6 +7926,10 @@ void Clang::AddClangCLArgs(const ArgList , 
types::ID InputType,
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (Args.hasArg(options::OPT_fms_define_stdc)) {
+   CmdArgs.push_back("-fms-define-stdc");
+ }

AaronBallman wrote:

```suggestion
 if (Args.hasArg(options::OPT_fms_define_stdc))
   CmdArgs.push_back("-fms-define-stdc");
```

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


[clang] [clang] Add /Zc:__STDC__ flag to clang-cl (PR #68690)

2023-10-11 Thread Aaron Ballman via cfe-commits

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2023-10-11 Thread kleines Filmröllchen via cfe-commits


@@ -483,6 +483,56 @@ struct FragmentCompiler {
 FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end());
   });
 }
+auto QuotedFilter = compileHeaderRegexes(F.QuotedHeaders);
+if (QuotedFilter.has_value()) {
+  Out.Apply.push_back(
+  [QuotedFilter = *QuotedFilter](const Params &, Config ) {
+C.Style.QuotedHeaders.emplace_back(QuotedFilter);
+  });
+}
+auto AngledFilter = compileHeaderRegexes(F.AngledHeaders);
+if (AngledFilter.has_value()) {
+  Out.Apply.push_back(
+  [AngledFilter = *AngledFilter](const Params &, Config ) {
+C.Style.AngledHeaders.emplace_back(AngledFilter);
+  });
+}
+  }
+
+  auto compileHeaderRegexes(llvm::ArrayRef> 
HeaderPatterns)
+  -> std::optional> {
+// TODO: Share this code with Diagnostics.Includes.IgnoreHeader
+#ifdef CLANGD_PATH_CASE_INSENSITIVE
+static llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
+#else
+static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
+#endif
+auto Filters = std::make_shared>();
+for (auto  : HeaderPatterns) {
+  elog("found angle pattern {0}", *HeaderPattern);

kleinesfilmroellchen wrote:

Oops, that's not supposed to be there anymore 

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


[clang] [clang] Differentiate between identifier and string EnumArgument (PR #68550)

2023-10-11 Thread Alexander Richardson via cfe-commits


@@ -886,7 +893,7 @@ def ARMInterrupt : InheritableAttr, 
TargetSpecificAttr {
   // MSP430Interrupt's, MipsInterrupt's and AnyX86Interrupt's spellings
   // must match.
   let Spellings = [GCC<"interrupt">];
-  let Args = [EnumArgument<"Interrupt", "InterruptType",
+  let Args = [EnumArgument<"Interrupt", "InterruptType", /*is_string=*/true,

arichardson wrote:

It appears TableGen now supports named arguments 
(https://github.com/llvm/llvm-project/commit/91ccbc6c1c4c121935ee4fbfa0db13ad86590a59),
 probably makes sense to use them here?

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


[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Alexander Richardson via cfe-commits

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


[libunwind] eb21049 - [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (#68815)

2023-10-11 Thread via cfe-commits

Author: Alexander Richardson
Date: 2023-10-11T19:46:09+01:00
New Revision: eb21049b4b904b072679ece60e73c6b0dc0d1ebf

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

LOG: [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (#68815)

I was running the tests with baremetal picolibc which has a linker
script that __eh_frame_start==__eh_frame_end (not equal to zero) in
case there is no .eh_frame_hdr.
I noticed that libunwind was trying to read nonsense data because it
was printing messages such as
`libunwind: unsupported .eh_frame_hdr version: 20 at
https://github.com/llvm/llvm-project/commit/8000d308146ebf49cb364cb600e28a0a42e22c83`

This change adds a ehHdr size check to avoid reading this out-of-bounds
data and potentially crashing.

Added: 


Modified: 
libunwind/src/EHHeaderParser.hpp

Removed: 




diff  --git a/libunwind/src/EHHeaderParser.hpp 
b/libunwind/src/EHHeaderParser.hpp
index ed4317c89055c9e..0662a1321e2c75e 100644
--- a/libunwind/src/EHHeaderParser.hpp
+++ b/libunwind/src/EHHeaderParser.hpp
@@ -55,6 +55,19 @@ template 
 bool EHHeaderParser::decodeEHHdr(A , pint_t ehHdrStart,
 pint_t ehHdrEnd, EHHeaderInfo ) {
   pint_t p = ehHdrStart;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrEnd - ehHdrStart < 4) {
+// Don't print a message for an empty .eh_frame_hdr (this can happen if
+// the linker script defines symbols for it even in the empty case).
+if (ehHdrEnd == ehHdrStart)
+  return false;
+_LIBUNWIND_LOG("unsupported .eh_frame_hdr at %" PRIx64
+   ": need at least 4 bytes of data but only got %zd",
+   static_cast(ehHdrStart),
+   static_cast(ehHdrEnd - ehHdrStart));
+return false;
+  }
   uint8_t version = addressSpace.get8(p++);
   if (version != 1) {
 _LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64,



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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Hi @AaronBallman , I ran a compile using this change on clang as you asked 
> and have results. The compile ran with no crashes or errors, and produced 
> 1478 bitfield-conversion warnings. I'll show a few examples below. To put 
> that number into context, I enabled -Wconversion to compare the new warning - 
> bitfield-conversion - with the other conversion checks. You can see from the 
> results that while 1478 findings is large, it's less than 10% of the total 
> conversion findings that exist - so looking at those numbers in context is 
> helpful.
> 
> Are there any other suggested improvements for this patch, or do you think 
> it's ok to merge?
> 
> ![image](https://user-images.githubusercontent.com/58314289/273438293-44313d33-6763-434b-92cb-37df8173209a.png)

Thank you for running the experiment! From spot-checking the results, did they 
help you to find any actual bugs? And did you notice any patterns in the 
results that could be used to safely silence the diagnostic in some cases?

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -6171,6 +6171,11 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+  "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+  InGroup, DefaultIgnore;
+def note_bitfield_assign : Note<
+  "Bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;

AaronBallman wrote:

```suggestion
  "bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;
```
Actually, I don't think we need this note, but we could instead use the generic 
"declared here" diagnostic (`diag::note_declared_at`). The current note 
duplicates a lot of information already present in the warning or the source 
being noted, but once we remove the duplicate information, we're pretty much 
left with "bit-field declared here".

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


[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/68815

>From 5d4e2bc5570f9fbcdebff2532370ad21f5cef2bb Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 11 Oct 2023 08:52:45 -0700
Subject: [PATCH] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr

I was running the tests with baremetal picolibc which has a linker
script that __eh_frame_start==__eh_frame_end (not equal to zero) in
case there is no .eh_frame_hdr.
I noticed that libunwind was trying to read nonsense data because it
was printing messages such as
`libunwind: unsupported .eh_frame_hdr version: 20 at 8000d308`

This change adds a ehHdrSize check to avoid reading this out-of-bounds
data and potentially crashing.
---
 libunwind/src/EHHeaderParser.hpp | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libunwind/src/EHHeaderParser.hpp b/libunwind/src/EHHeaderParser.hpp
index ed4317c89055c9e..0662a1321e2c75e 100644
--- a/libunwind/src/EHHeaderParser.hpp
+++ b/libunwind/src/EHHeaderParser.hpp
@@ -55,6 +55,19 @@ template 
 bool EHHeaderParser::decodeEHHdr(A , pint_t ehHdrStart,
 pint_t ehHdrEnd, EHHeaderInfo ) {
   pint_t p = ehHdrStart;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrEnd - ehHdrStart < 4) {
+// Don't print a message for an empty .eh_frame_hdr (this can happen if
+// the linker script defines symbols for it even in the empty case).
+if (ehHdrEnd == ehHdrStart)
+  return false;
+_LIBUNWIND_LOG("unsupported .eh_frame_hdr at %" PRIx64
+   ": need at least 4 bytes of data but only got %zd",
+   static_cast(ehHdrStart),
+   static_cast(ehHdrEnd - ehHdrStart));
+return false;
+  }
   uint8_t version = addressSpace.get8(p++);
   if (version != 1) {
 _LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64,

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


[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/68815

>From 63415241cd457cd4bcd0661e077b9f8c48e246e2 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 11 Oct 2023 08:52:45 -0700
Subject: [PATCH] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr

I was running the tests with baremetal picolibc which has a linker
script that __eh_frame_start==__eh_frame_end (not equal to zero) in
case there is no .eh_frame_hdr.
I noticed that libunwind was trying to read nonsense data because it
was printing messages such as
`libunwind: unsupported .eh_frame_hdr version: 20 at 8000d308`

This change adds a ehHdrSize check to avoid reading this out-of-bounds
data and potentially crashing.
---
 libunwind/src/EHHeaderParser.hpp | 13 +
 1 file changed, 13 insertions(+)

diff --git a/libunwind/src/EHHeaderParser.hpp b/libunwind/src/EHHeaderParser.hpp
index ed4317c89055c9e..b0e3894188dd31a 100644
--- a/libunwind/src/EHHeaderParser.hpp
+++ b/libunwind/src/EHHeaderParser.hpp
@@ -55,6 +55,19 @@ template 
 bool EHHeaderParser::decodeEHHdr(A , pint_t ehHdrStart,
 pint_t ehHdrEnd, EHHeaderInfo ) {
   pint_t p = ehHdrStart;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrEnd - ehHdrStart < 4) {
+// Don't print a message for an empty .eh_frame_hdr (this can happen if
+// the linker script defines symbols for it even in the empty case).
+if (ehHdrEnd == ehHdrStart)
+  return false;
+_LIBUNWIND_LOG("unsupported .eh_frame_hdr at %" PRIx64
+   ": need at least 4 bytes of data but only got %zd",
+   static_cast(ehHdrStart),
+   (size_t)(ehHdrEnd - ehHdrStart));
+return false;
+  }
   uint8_t version = addressSpace.get8(p++);
   if (version != 1) {
 _LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64,

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


[libunwind] [libunwind] Fix wrong end argument passed to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

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


[libunwind] 05181a8 - [libunwind] Fix wrong end argument passed to decodeEHHdr() (#68813)

2023-10-11 Thread via cfe-commits

Author: Alexander Richardson
Date: 2023-10-11T19:35:11+01:00
New Revision: 05181a849b4c1ec14fdd6d667285d6f5ad34a5a2

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

LOG: [libunwind] Fix wrong end argument passed to decodeEHHdr() (#68813)

All but one callsite were actually passing start+length arguments.
This should not have any functional change since the end argument is
almost always ignored.
I noticed this while debugging some incorrect error messages being
printed while running the testsuite baremetal (using binaries that did
not have a valid eh_frame_hdr section): the tests print
`libunwind: unsupported .eh_frame_hdr version: 20 at
https://github.com/arichardson/upstream-llvm-project/commit/8000d308146ebf49cb364cb600e28a0a42e22c83`
because
libunwind is reading nonsense data for .eh_frame_hdr.

Added: 


Modified: 
libunwind/src/AddressSpace.hpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 1abbc822546878d..5551c7d4bef1c56 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -414,8 +414,8 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, 
size_t image_base,
 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
 if (EHHeaderParser::decodeEHHdr(
-*cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
-hdrInfo)) {
+*cbdata->addressSpace, eh_frame_hdr_start,
+eh_frame_hdr_start + phdr->p_memsz, hdrInfo)) {
   // .eh_frame_hdr records the start of .eh_frame, but not its size.
   // Rely on a zero terminator to find the end of the section.
   cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
@@ -638,7 +638,8 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t 
targetAddr,
 info.dwarf_index_section_length = SIZE_MAX;
 EHHeaderParser::EHHeaderInfo hdrInfo;
 if (!EHHeaderParser::decodeEHHdr(
-*this, info.dwarf_index_section, info.dwarf_index_section_length,
+*this, info.dwarf_index_section,
+info.dwarf_index_section + info.dwarf_index_section_length,
 hdrInfo)) {
   return false;
 }



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


[clang-tools-extra] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

https://github.com/shraiysh updated 
https://github.com/llvm/llvm-project/pull/68825

>From ff635ce0ce910f0cde248a4babb3c27333ddc108 Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay 
Date: Sun, 3 Sep 2023 22:40:10 -0500
Subject: [PATCH 1/3] [mlir][OpenMP] Added omp.region operation

This patch adds omp.region operation. This is equivalent to a code block 
surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 34 
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 15 ++
 mlir/test/Dialect/OpenMP/region.mlir  | 53 +++
 3 files changed, 102 insertions(+)
 create mode 100644 mlir/test/Dialect/OpenMP/region.mlir

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index b1e1fe00b8594a7..cf5b246178f5d7a 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1787,4 +1787,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def RegionOp : OpenMP_Op<"region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.region` operation and a terminator operation as shown
+below.
+
+```
+// Example with `omp.task`
+omp.task {
+  omp.region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$block);
+  let assemblyFormat = [{
+$block attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2ba5f1aca9cf6b2..2a2fcdb788cb99b 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1524,6 +1524,21 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult RegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  if (!parentOp)
+return emitOpError() << "`omp.region` must have a parent";
+
+  if (!isa(parentOp->getDialect()))
+return emitOpError()
+   << "`omp.region` must be used under an OpenMP Dialect operation.";
+  return success();
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
diff --git a/mlir/test/Dialect/OpenMP/region.mlir 
b/mlir/test/Dialect/OpenMP/region.mlir
new file mode 100644
index 000..4e0ddbc07e9ec9d
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}
+
+// CHECK-LABEL: @omp_region_with_branch
+// CHECK-NEXT: omp.task {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: %[[c:.*]] = "test.foo"() : () -> i1
+// CHECK-NEXT: cf.cond_br %[[c]], ^[[bb1:.*]](%[[c]] : i1), 
^[[bb2:.*]](%[[c]] : i1)
+// CHECK-NEXT:   ^[[bb1]](%[[arg:.*]]: i1):
+// CHECK-NEXT: "test.bar"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   ^[[bb2]](%[[arg2:.*]]: i1):
+// CHECK-NEXT: "test.baz"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @omp_region_with_branch(%a: i32) {
+  omp.task {
+omp.region {
+  %c = "test.foo"() : () -> i1
+  cf.cond_br %c, ^bb1(%c: i1), ^bb2(%c: i1)
+^bb1(%arg: i1):
+  "test.bar"() : () -> ()
+  omp.terminator
+^bb2(%arg2: i1):
+  "test.baz"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}

>From f88bfd4cad856e915cb96b1238aac978f3aeb6d4 Mon Sep 17 00:00:00 2001
From: 

[clang] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

https://github.com/shraiysh updated 
https://github.com/llvm/llvm-project/pull/68825

>From ff635ce0ce910f0cde248a4babb3c27333ddc108 Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay 
Date: Sun, 3 Sep 2023 22:40:10 -0500
Subject: [PATCH 1/3] [mlir][OpenMP] Added omp.region operation

This patch adds omp.region operation. This is equivalent to a code block 
surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 34 
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 15 ++
 mlir/test/Dialect/OpenMP/region.mlir  | 53 +++
 3 files changed, 102 insertions(+)
 create mode 100644 mlir/test/Dialect/OpenMP/region.mlir

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index b1e1fe00b8594a7..cf5b246178f5d7a 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1787,4 +1787,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def RegionOp : OpenMP_Op<"region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.region` operation and a terminator operation as shown
+below.
+
+```
+// Example with `omp.task`
+omp.task {
+  omp.region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$block);
+  let assemblyFormat = [{
+$block attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2ba5f1aca9cf6b2..2a2fcdb788cb99b 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1524,6 +1524,21 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult RegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  if (!parentOp)
+return emitOpError() << "`omp.region` must have a parent";
+
+  if (!isa(parentOp->getDialect()))
+return emitOpError()
+   << "`omp.region` must be used under an OpenMP Dialect operation.";
+  return success();
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
diff --git a/mlir/test/Dialect/OpenMP/region.mlir 
b/mlir/test/Dialect/OpenMP/region.mlir
new file mode 100644
index 000..4e0ddbc07e9ec9d
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}
+
+// CHECK-LABEL: @omp_region_with_branch
+// CHECK-NEXT: omp.task {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: %[[c:.*]] = "test.foo"() : () -> i1
+// CHECK-NEXT: cf.cond_br %[[c]], ^[[bb1:.*]](%[[c]] : i1), 
^[[bb2:.*]](%[[c]] : i1)
+// CHECK-NEXT:   ^[[bb1]](%[[arg:.*]]: i1):
+// CHECK-NEXT: "test.bar"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   ^[[bb2]](%[[arg2:.*]]: i1):
+// CHECK-NEXT: "test.baz"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @omp_region_with_branch(%a: i32) {
+  omp.task {
+omp.region {
+  %c = "test.foo"() : () -> i1
+  cf.cond_br %c, ^bb1(%c: i1), ^bb2(%c: i1)
+^bb1(%arg: i1):
+  "test.bar"() : () -> ()
+  omp.terminator
+^bb2(%arg2: i1):
+  "test.baz"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}

>From f88bfd4cad856e915cb96b1238aac978f3aeb6d4 Mon Sep 17 00:00:00 2001
From: 

[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Saleem Abdulrasool via cfe-commits

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

Thank you!

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


[clang-tools-extra] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

shraiysh wrote:

Restarting discussion about yield here because something went wrong with 
rebasing on previous PR. Hopefully this won't have the same issues. Sorry :(

I will push commit with yield as terminator soon.

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


[clang] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

shraiysh wrote:

Restarting discussion about yield here because something went wrong with 
rebasing on previous PR. Hopefully this won't have the same issues. Sorry :(

I will push commit with yield as terminator soon.

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


[clang-tools-extra] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Shraiysh (shraiysh)


Changes

This patch adds `omp.structured_region` operation. This is equivalent to a code 
block surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+34) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+13) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+22) 
- (added) mlir/test/Dialect/OpenMP/structured_region.mlir (+53) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 5da05476a683725..b9e041a22b5bffb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1987,4 +1987,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def StructuredRegionOp : OpenMP_Op<"structured_region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.structured_region` operation and a terminator operation as
+shown below.
+
+```
+// Example with `omp.sections`
+omp.sections {
+  omp.structured_region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$region);
+  let assemblyFormat = [{
+$region attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2bf9355ed62676b..70811a230b36ccd 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include "llvm/Support/Debug.h"
 #include 
 #include 
 
@@ -1468,6 +1469,18 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult StructuredRegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  assert(parentOp && "'omp.region' op must have a parent");
+  if (!isa(parentOp->getDialect()))
+return emitOpError() << "must be used under an OpenMP Dialect operation";
+  return success();
+}
+
 
//===--===//
 // DataBoundsOp
 
//===--===//
diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir 
b/mlir/test/Dialect/OpenMP/invalid.mlir
index c8025249e27004e..94814a4d398b8c7 100644
--- a/mlir/test/Dialect/OpenMP/invalid.mlir
+++ b/mlir/test/Dialect/OpenMP/invalid.mlir
@@ -1657,3 +1657,25 @@ func.func @omp_target_exit_data(%map1: memref) {
 }
 
 llvm.mlir.global internal @_QFsubEx() : i32
+
+// -
+
+func.func @omp_region_invalid() {
+  // expected-error @below {{'omp.structured_region' op must be used under an 
OpenMP Dialect operation}}
+  omp.structured_region {
+omp.terminator
+  }
+  return
+}
+
+// -
+
+func.func @omp_region_invalid(%c: i1) {
+  scf.if %c {
+// expected-error @below {{'omp.structured_region' op must be used under 
an OpenMP Dialect operation}}
+omp.structured_region {
+  omp.terminator
+}
+  }
+  return
+}
diff --git a/mlir/test/Dialect/OpenMP/structured_region.mlir 
b/mlir/test/Dialect/OpenMP/structured_region.mlir
new file mode 100644
index 000..fc1e0edb07388eb
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/structured_region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.structured_region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.structured_region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+

[clang] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Shraiysh (shraiysh)


Changes

This patch adds `omp.structured_region` operation. This is equivalent to a code 
block surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+34) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+13) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+22) 
- (added) mlir/test/Dialect/OpenMP/structured_region.mlir (+53) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 5da05476a683725..b9e041a22b5bffb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1987,4 +1987,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def StructuredRegionOp : OpenMP_Op<"structured_region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.structured_region` operation and a terminator operation as
+shown below.
+
+```
+// Example with `omp.sections`
+omp.sections {
+  omp.structured_region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$region);
+  let assemblyFormat = [{
+$region attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2bf9355ed62676b..70811a230b36ccd 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include "llvm/Support/Debug.h"
 #include 
 #include 
 
@@ -1468,6 +1469,18 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult StructuredRegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  assert(parentOp && "'omp.region' op must have a parent");
+  if (!isa(parentOp->getDialect()))
+return emitOpError() << "must be used under an OpenMP Dialect operation";
+  return success();
+}
+
 
//===--===//
 // DataBoundsOp
 
//===--===//
diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir 
b/mlir/test/Dialect/OpenMP/invalid.mlir
index c8025249e27004e..94814a4d398b8c7 100644
--- a/mlir/test/Dialect/OpenMP/invalid.mlir
+++ b/mlir/test/Dialect/OpenMP/invalid.mlir
@@ -1657,3 +1657,25 @@ func.func @omp_target_exit_data(%map1: memref) {
 }
 
 llvm.mlir.global internal @_QFsubEx() : i32
+
+// -
+
+func.func @omp_region_invalid() {
+  // expected-error @below {{'omp.structured_region' op must be used under an 
OpenMP Dialect operation}}
+  omp.structured_region {
+omp.terminator
+  }
+  return
+}
+
+// -
+
+func.func @omp_region_invalid(%c: i1) {
+  scf.if %c {
+// expected-error @below {{'omp.structured_region' op must be used under 
an OpenMP Dialect operation}}
+omp.structured_region {
+  omp.terminator
+}
+  }
+  return
+}
diff --git a/mlir/test/Dialect/OpenMP/structured_region.mlir 
b/mlir/test/Dialect/OpenMP/structured_region.mlir
new file mode 100644
index 000..fc1e0edb07388eb
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/structured_region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.structured_region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.structured_region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+

[clang-tools-extra] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

https://github.com/shraiysh created 
https://github.com/llvm/llvm-project/pull/68825

This patch adds `omp.structured_region` operation. This is equivalent to a code 
block surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.

>From ff635ce0ce910f0cde248a4babb3c27333ddc108 Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay 
Date: Sun, 3 Sep 2023 22:40:10 -0500
Subject: [PATCH 1/2] [mlir][OpenMP] Added omp.region operation

This patch adds omp.region operation. This is equivalent to a code block 
surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 34 
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 15 ++
 mlir/test/Dialect/OpenMP/region.mlir  | 53 +++
 3 files changed, 102 insertions(+)
 create mode 100644 mlir/test/Dialect/OpenMP/region.mlir

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index b1e1fe00b8594a7..cf5b246178f5d7a 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1787,4 +1787,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def RegionOp : OpenMP_Op<"region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.region` operation and a terminator operation as shown
+below.
+
+```
+// Example with `omp.task`
+omp.task {
+  omp.region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$block);
+  let assemblyFormat = [{
+$block attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2ba5f1aca9cf6b2..2a2fcdb788cb99b 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1524,6 +1524,21 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult RegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  if (!parentOp)
+return emitOpError() << "`omp.region` must have a parent";
+
+  if (!isa(parentOp->getDialect()))
+return emitOpError()
+   << "`omp.region` must be used under an OpenMP Dialect operation.";
+  return success();
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
diff --git a/mlir/test/Dialect/OpenMP/region.mlir 
b/mlir/test/Dialect/OpenMP/region.mlir
new file mode 100644
index 000..4e0ddbc07e9ec9d
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}
+
+// CHECK-LABEL: @omp_region_with_branch
+// CHECK-NEXT: omp.task {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: %[[c:.*]] = "test.foo"() : () -> i1
+// CHECK-NEXT: cf.cond_br %[[c]], ^[[bb1:.*]](%[[c]] : i1), 
^[[bb2:.*]](%[[c]] : i1)
+// CHECK-NEXT:   ^[[bb1]](%[[arg:.*]]: i1):
+// CHECK-NEXT: "test.bar"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   ^[[bb2]](%[[arg2:.*]]: i1):
+// CHECK-NEXT: "test.baz"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @omp_region_with_branch(%a: i32) {
+  omp.task {
+omp.region {
+  %c = "test.foo"() : () -> i1
+  cf.cond_br %c, ^bb1(%c: i1), ^bb2(%c: i1)
+^bb1(%arg: i1):
+  "test.bar"() : () 

[clang] [mlir][OpenMP] Added `omp.structured_region` operation (PR #68825)

2023-10-11 Thread via cfe-commits

https://github.com/shraiysh created 
https://github.com/llvm/llvm-project/pull/68825

This patch adds `omp.structured_region` operation. This is equivalent to a code 
block surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.

>From ff635ce0ce910f0cde248a4babb3c27333ddc108 Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay 
Date: Sun, 3 Sep 2023 22:40:10 -0500
Subject: [PATCH 1/2] [mlir][OpenMP] Added omp.region operation

This patch adds omp.region operation. This is equivalent to a code block 
surrounded by an OpenMP construct in C/C++/Fortran. This is a part of the 
effort to implement the canonical loop operation in OpenMP dialect.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 34 
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 15 ++
 mlir/test/Dialect/OpenMP/region.mlir  | 53 +++
 3 files changed, 102 insertions(+)
 create mode 100644 mlir/test/Dialect/OpenMP/region.mlir

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index b1e1fe00b8594a7..cf5b246178f5d7a 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1787,4 +1787,38 @@ def ClauseRequiresAttr :
   EnumAttr {
 }
 
+
+def RegionOp : OpenMP_Op<"region"> {
+  let summary = "Encapsulates a region in an OpenMP construct.";
+  let description = [{
+Encapsulates a region surrounded by an OpenMP Construct. The intended use
+of this operation is that within an OpenMP operation's region, there would
+be a single `omp.region` operation and a terminator operation as shown
+below.
+
+```
+// Example with `omp.task`
+omp.task {
+  omp.region {
+call @foo : () -> ()
+  }
+  omp.terminator
+}
+```
+
+This operation is especially more useful in operations that use `omp.yield`
+as a terminator. For example, in the proposed canonical loop operation,
+this operation would help fix the arguments of the yield operation and it
+is not affected by branches in the region assosciated with the canonical
+loop. In cases where the yielded value has to be a compile time constant,
+this provides a mechanism to avoid complex static analysis for the constant
+value.
+  }];
+  let regions = (region AnyRegion:$block);
+  let assemblyFormat = [{
+$block attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // OPENMP_OPS
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 2ba5f1aca9cf6b2..2a2fcdb788cb99b 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1524,6 +1524,21 @@ LogicalResult CancellationPointOp::verify() {
   return success();
 }
 
+//===--===//
+// RegionOp
+//===--===//
+
+LogicalResult RegionOp::verify() {
+  Operation *parentOp = (*this)->getParentOp();
+  if (!parentOp)
+return emitOpError() << "`omp.region` must have a parent";
+
+  if (!isa(parentOp->getDialect()))
+return emitOpError()
+   << "`omp.region` must be used under an OpenMP Dialect operation.";
+  return success();
+}
+
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc"
 
diff --git a/mlir/test/Dialect/OpenMP/region.mlir 
b/mlir/test/Dialect/OpenMP/region.mlir
new file mode 100644
index 000..4e0ddbc07e9ec9d
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/region.mlir
@@ -0,0 +1,53 @@
+// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: @basic_omp_region
+// CHECK-NEXT: omp.parallel {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @basic_omp_region() {
+  omp.parallel {
+omp.region {
+  "test.foo"() : () -> ()
+  omp.terminator
+}
+omp.terminator
+  }
+  return
+}
+
+// CHECK-LABEL: @omp_region_with_branch
+// CHECK-NEXT: omp.task {
+// CHECK-NEXT:   omp.region {
+// CHECK-NEXT: %[[c:.*]] = "test.foo"() : () -> i1
+// CHECK-NEXT: cf.cond_br %[[c]], ^[[bb1:.*]](%[[c]] : i1), 
^[[bb2:.*]](%[[c]] : i1)
+// CHECK-NEXT:   ^[[bb1]](%[[arg:.*]]: i1):
+// CHECK-NEXT: "test.bar"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   ^[[bb2]](%[[arg2:.*]]: i1):
+// CHECK-NEXT: "test.baz"() : () -> ()
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT:   }
+// CHECK-NEXT:   omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @omp_region_with_branch(%a: i32) {
+  omp.task {
+omp.region {
+  %c = "test.foo"() : () -> i1
+  cf.cond_br %c, ^bb1(%c: i1), ^bb2(%c: i1)
+^bb1(%arg: i1):
+  "test.bar"() : () 

[clang] [clang] static operators should evaluate object argument (PR #68485)

2023-10-11 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 1/6] [clang] static operators should evaluate object argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..a6c81f467fbe01c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..19406ff174dea14 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..a580c635998510f 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo  =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, , Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c95..42de125e7489911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *CE,
+   

[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-11 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -136,6 +136,17 @@ int main(void) {
 // Cleanup happens automatically -> no warning.
   }
 
+  /// Function pointers
+  {
+int __attribute__((requires_capability())) (*function_ptr)(int) = 
Foo_fun1;

AaronBallman wrote:

Er, not certain I agree that should be a separate change -- I don't see 
*anything* hooking this up as a type attribute beyond the change to 
`DeclOrTypeAttr` in `Attr.td`. Declaration attributes have a ton of 
tablegenerated code that hooks things up for them, but type attributes are 
special and require more involved manual work.

I would have expected to see changes [in 
here](https://github.com/llvm/llvm-project/blob/28b7e281d4eaea0d5d56b1a4cf7a550be746a007/clang/lib/Sema/SemaType.cpp#L8615)
 to hook this up with the type system. Once the type is wrapped in an 
attribute, the diagnostic behavior you're looking for should come along "for 
free".

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-11 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -8141,6 +8141,16 @@ static void handleRequiresCapabilityAttr(Sema , Decl 
*D,
   if (!AL.checkAtLeastNumArgs(S, 1))
 return;
 
+  // We allow this on function declaration as well as
+  // variable declarations of function pointer type.
+  if (!D->isFunctionPointerType() && !isa(D)) {

AaronBallman wrote:

Once the Subjects list is corrected, I believe this code can be removed.

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-11 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


https://github.com/AaronBallman commented:

The changes also need a release note at some point.

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-11 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2023-10-11 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -3315,7 +3315,7 @@ def RequiresCapability : InheritableAttr {
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
-  let Subjects = SubjectList<[Function]>;
+  /*let Subjects = SubjectList<[Function]>;*/

AaronBallman wrote:

Instead of removing it, can this be updated to be correct (we have 
`FunctionPointer` as a subject)?

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


[clang] [clang] Ignore GCC 11 `[[malloc(x)]]` attribute (PR #68059)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -289,6 +289,11 @@ Bug Fixes to Compiler Builtins
 Bug Fixes to Attribute Support
 ^^
 
+- Clang now emits a warning instead of an error when using the one or two
+  argument form of GCC 11's ``__attribute__((malloc(deallocator)))``
+  or ``__attribute__((malloc(deallocator, ptr-index)))``
+  (`#51607 `).

AaronBallman wrote:

```suggestion
  (`#51607 `_).
```

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


[clang] [clang] Ignore GCC 11 `[[malloc(x)]]` attribute (PR #68059)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -1,12 +1,14 @@
-// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused 
-Wunused-parameter -fsyntax-only %s
+// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused 
-Wunused-parameter -fsyntax-only -fdeclspec %s
 int a;
 
 inline __attribute__((noreturn(a))) void *f1(void);  // expected-error 
{{'noreturn' attribute takes no arguments}}
 inline __attribute__((always_inline(a))) void *f2(void);  // expected-error 
{{'always_inline' attribute takes no arguments}}
 inline __attribute__((cdecl(a))) void *f3(void);  // expected-error {{'cdecl' 
attribute takes no arguments}}
 inline __attribute__((const(a))) void *f4(void);  // expected-error {{'const' 
attribute takes no arguments}}
 inline __attribute__((fastcall(a))) void *f5(void);  // expected-error 
{{'fastcall' attribute takes no arguments}}
-inline __attribute__((malloc(a))) void *f5(void);  // expected-error 
{{'malloc' attribute takes no arguments}}
+inline __declspec(restrict(a)) void *f6_a(void);  // expected-error 
{{'restrict' attribute takes no arguments}}
+inline __attribute__((malloc(a, 1, a))) void *f6_b(void);  // expected-error 
{{'malloc' attribute takes no more than 2 arguments}}
+inline __attribute__((malloc(a, 1))) void *f6_c(void);  // expected-warning 
{{'malloc' attribute ignored because Clang does not support the one/two 
argument form}}

AaronBallman wrote:

One more test I'd like to see is:
```
inline __attribute__((malloc(1))) void *func(void) // error: '1' does not name 
a function
```


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


[clang] [clang] Ignore GCC 11 `[[malloc(x)]]` attribute (PR #68059)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -177,6 +177,10 @@ def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
+def warn_multiarg_malloc_attribute_ignored: Warning<
+  "'malloc' attribute ignored because"
+  " Clang does not support the one/two argument form">,
+  InGroup;

AaronBallman wrote:

```suggestion
def warn_attribute_form_ignored : Warning<
  "%0 attribute ignored; Clang does not yet support this attribute signature">,
  InGroup;
```
If we generalize the wording a bit, we can reuse this diagnostic for other 
circumstances where we don't yet support a particular signature.

Also, this diagnostic should be moved to DiagnosticSemaKinds.td (it's only 
diagnosed from `clang/lib/Sema`, so no need for it to be in the "common" 
diagnostics file for cross-lib diagnostics).

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Hubert Tong via cfe-commits

hubert-reinterpretcast wrote:

The code formatting check failure seems to be a infrastructure problem: 
https://discourse.llvm.org/t/clang-format-github-action-cannot-find-merge-base/73894

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Stefan Pintilie via cfe-commits

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Stefan Pintilie via cfe-commits

https://github.com/stefanp-ibm approved this pull request.

Thank you for fixing this!
LGTM.

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Stefan Pintilie via cfe-commits


@@ -828,10 +829,7 @@ const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 };
 
 ArrayRef PPCTargetInfo::getGCCAddlRegNames() const {
-  if (ABI == "elfv2")
-return llvm::ArrayRef(GCCAddlRegNames);
-  else
-return TargetInfo::getGCCAddlRegNames();
+  return llvm::ArrayRef(GCCAddlRegNames);

stefanp-ibm wrote:

Okay fair enough. If GCC accepts there on ELFv1 then we can too. 

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


[clang] Add support for -fcx-limited-range and #pragma CX_LIMITED_RANGE. (PR #68820)

2023-10-11 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 c1b6ed42b75a17d1718aa377f76633b27e15a4e2 
91de35737b74233f29da76573b4099bf64e8bdd4 -- clang/test/CodeGen/cx-full-range.c 
clang/test/CodeGen/pragma-cx-limited-range.c 
clang/test/CodeGenCXX/cx-limited-range.c clang/include/clang/Parse/Parser.h 
clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGExprComplex.cpp 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Parse/ParsePragma.cpp 
clang/lib/Parse/ParseStmt.cpp clang/lib/Parse/Parser.cpp 
clang/lib/Sema/SemaAttr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f206f5de1310..3f49788cf793 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8452,9 +8452,9 @@ public:
  SourceLocation PrevPtOfInstantiation,
  bool );
 
-  bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
-const TemplateArgumentListInfo ,
-LookupResult );
+  bool CheckDependentFunctionTemplateSpecialization(
+  FunctionDecl *FD, const TemplateArgumentListInfo ,
+  LookupResult );
 
   bool CheckFunctionTemplateSpecialization(
   FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs,
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index f18fdb170909..2ce60ea1d605 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -890,13 +890,13 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const 
BinOpInfo ) {
   DSTr = Builder.CreateFDiv(ACpBD, CCpDD);
   DSTi = Builder.CreateFDiv(BCmAD, CCpDD);
 } else if (RHSi && !CGF.getLangOpts().FastMath) {
-// If we have a complex operand on the RHS and FastMath is not allowed, we
-// delegate to a libcall to handle all of the complexities and minimize
-// underflow/overflow cases. When FastMath is allowed we construct the
-// divide inline using the same algorithm as for integer operands.
-//
-// FIXME: We would be able to avoid the libcall in many places if we
-// supported imaginary types in addition to complex types.
+  // If we have a complex operand on the RHS and FastMath is not allowed, 
we
+  // delegate to a libcall to handle all of the complexities and minimize
+  // underflow/overflow cases. When FastMath is allowed we construct the
+  // divide inline using the same algorithm as for integer operands.
+  //
+  // FIXME: We would be able to avoid the libcall in many places if we
+  // supported imaginary types in addition to complex types.
   BinOpInfo LibCallOp = Op;
   // If LHS was a real, supply a null imaginary part.
   if (!LHSi)
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index eae4b54ecfc5..6e4db5da9fdb 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -873,9 +873,9 @@ void Parser::HandlePragmaCXLimitedRange() {
 IsEnabled = false;
 break;
   case tok::OOS_DEFAULT:
-  // According to ISO C99 standard chapter 7.3.4, the default value
-  // for the pragma is ``off'. In GCC, the option -fcx-limited-range
-  // controls the default setting of the pragma.
+// According to ISO C99 standard chapter 7.3.4, the default value
+// for the pragma is ``off'. In GCC, the option -fcx-limited-range
+// controls the default setting of the pragma.
 IsEnabled = getLangOpts().CxLimitedRange ? true : false;
 break;
   }

``




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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2023-10-11 Thread Andrew Kaster via cfe-commits


@@ -483,6 +483,56 @@ struct FragmentCompiler {
 FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end());
   });
 }
+auto QuotedFilter = compileHeaderRegexes(F.QuotedHeaders);
+if (QuotedFilter.has_value()) {
+  Out.Apply.push_back(
+  [QuotedFilter = *QuotedFilter](const Params &, Config ) {
+C.Style.QuotedHeaders.emplace_back(QuotedFilter);
+  });
+}
+auto AngledFilter = compileHeaderRegexes(F.AngledHeaders);
+if (AngledFilter.has_value()) {
+  Out.Apply.push_back(
+  [AngledFilter = *AngledFilter](const Params &, Config ) {
+C.Style.AngledHeaders.emplace_back(AngledFilter);
+  });
+}
+  }
+
+  auto compileHeaderRegexes(llvm::ArrayRef> 
HeaderPatterns)
+  -> std::optional> {
+// TODO: Share this code with Diagnostics.Includes.IgnoreHeader
+#ifdef CLANGD_PATH_CASE_INSENSITIVE
+static llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
+#else
+static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
+#endif
+auto Filters = std::make_shared>();
+for (auto  : HeaderPatterns) {
+  elog("found angle pattern {0}", *HeaderPattern);

ADKaster wrote:

elog seems a bit high for this debugging output. 

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


[clang] Add support for -fcx-limited-range and #pragma CX_LIMITED_RANGE. (PR #68820)

2023-10-11 Thread Zahira Ammarguellat via cfe-commits

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


[clang] Add support for -fcx-limited-range and #pragma CX_LIMTED_RANGE. (PR #68820)

2023-10-11 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam created 
https://github.com/llvm/llvm-project/pull/68820

None

>From 91de35737b74233f29da76573b4099bf64e8bdd4 Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Tue, 10 Oct 2023 08:31:41 -0700
Subject: [PATCH] Add support for -fcx-limited-range and #pragma
 CX_LIMTED_RANGE.

---
 clang/include/clang/Basic/FPOptions.def  |  1 +
 clang/include/clang/Basic/LangOptions.def|  2 +
 clang/include/clang/Basic/TokenKinds.def |  5 ++
 clang/include/clang/Driver/Options.td|  6 ++
 clang/include/clang/Parse/Parser.h   |  4 ++
 clang/include/clang/Sema/Sema.h  |  4 ++
 clang/lib/CodeGen/CGExprComplex.cpp  | 59 ++--
 clang/lib/Driver/ToolChains/Clang.cpp|  2 +
 clang/lib/Parse/ParsePragma.cpp  | 40 ++-
 clang/lib/Parse/ParseStmt.cpp| 10 +++
 clang/lib/Parse/Parser.cpp   |  3 +
 clang/lib/Sema/SemaAttr.cpp  |  7 ++
 clang/test/CodeGen/cx-full-range.c   | 22 ++
 clang/test/CodeGen/pragma-cx-limited-range.c | 73 
 clang/test/CodeGenCXX/cx-limited-range.c | 18 +
 15 files changed, 233 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/CodeGen/cx-full-range.c
 create mode 100644 clang/test/CodeGen/pragma-cx-limited-range.c
 create mode 100644 clang/test/CodeGenCXX/cx-limited-range.c

diff --git a/clang/include/clang/Basic/FPOptions.def 
b/clang/include/clang/Basic/FPOptions.def
index 5b923a1944e509a..9e56d7fcf26fdcf 100644
--- a/clang/include/clang/Basic/FPOptions.def
+++ b/clang/include/clang/Basic/FPOptions.def
@@ -28,4 +28,5 @@ OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, 
AllowApproxFunc)
 OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
Float16ExcessPrecision)
 OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
+OPTION(CxLimitedRange, bool, 1, MathErrno)
 #undef OPTION
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..47513522a0d7719 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -219,6 +219,8 @@ BENIGN_LANGOPT(NoSignedZero  , 1, 0, "Permit Floating 
Point optimization wit
 BENIGN_LANGOPT(AllowRecip, 1, 0, "Permit Floating Point reciprocal")
 BENIGN_LANGOPT(ApproxFunc, 1, 0, "Permit Floating Point approximation")
 
+LANGOPT(CxLimitedRange, 1, 0, "Enable use of algebraic expansions of complex 
arithmetics.")
+
 BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for 
__weak/__strong ivars")
 
 BENIGN_LANGOPT(AccessControl , 1, 1, "C++ access control")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 94db56a9fd5d78c..5cd81a66ab57bc1 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -904,6 +904,11 @@ PRAGMA_ANNOTATION(pragma_fenv_access_ms)
 // handles them.
 PRAGMA_ANNOTATION(pragma_fenv_round)
 
+// Annotation for #pragma STDC CX_LIMITED_RANGE
+// The lexer produces these so that they only take effect when the parser
+// handles them.
+PRAGMA_ANNOTATION(pragma_cx_limited_range)
+
 // Annotation for #pragma float_control
 // The lexer produces these so that they only take effect when the parser
 // handles them.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ff2130c93f28ea0..a871bea6cf14cd4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1001,6 +1001,12 @@ defm offload_uniform_block : 
BoolFOption<"offload-uniform-block",
   NegFlag,
   BothFlags<[], [ClangOption], " that kernels are launched with uniform block 
sizes (default true for CUDA/HIP and false otherwise)">>;
 
+def fcx_limited_range : Joined<["-"], "fcx-limited-range">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Basic algebraic expansions of some arithmetic operations involving 
"
+   "data of type COMPLEX are disabled.">,
+  MarshallingInfoFlag>;
+
 // OpenCL-only Options
 def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 0e969f341bbe19f..8f2b4d50fd59e5b 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -767,6 +767,10 @@ class Parser : public CodeCompletionHandler {
   /// #pragma STDC FENV_ROUND...
   void HandlePragmaFEnvRound();
 
+  /// Handle the annotation token produced for
+  /// #pragma STDC CX_LIMITED_RANGE...
+  void HandlePragmaCXLimitedRange();
+
   /// Handle the annotation token produced for
   /// #pragma float_control
   void HandlePragmaFloatControl();
diff --git a/clang/include/clang/Sema/Sema.h 

[PATCH] D158069: [clang][Interp] Fix getIndex() for composite array elements

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

LGTM!


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

https://reviews.llvm.org/D158069

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


[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/68815

>From ff360ee7f304424dd0d12d00b8c0ba6801241410 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 11 Oct 2023 08:34:55 -0700
Subject: [PATCH 1/2] [libunwind] Fix wrong end argument passed to
 decodeEHHdr()

All but one callsite were actually passing start+length arguments.
This should not have any functional change since the end argument is
almost always ignored.
I noticed this while debugging some incorrect error messages being
printed while running the testsuite baremetal (using binaries that did
not have a valid eh_frame_hdr section): the tests print
`libunwind: unsupported .eh_frame_hdr version: 20 at 8000d308` because
libunwind is reading nonsense data for .eh_frame_hdr.
---
 libunwind/src/AddressSpace.hpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 1abbc822546878d..5551c7d4bef1c56 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -414,8 +414,8 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, 
size_t image_base,
 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
 if (EHHeaderParser::decodeEHHdr(
-*cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
-hdrInfo)) {
+*cbdata->addressSpace, eh_frame_hdr_start,
+eh_frame_hdr_start + phdr->p_memsz, hdrInfo)) {
   // .eh_frame_hdr records the start of .eh_frame, but not its size.
   // Rely on a zero terminator to find the end of the section.
   cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
@@ -638,7 +638,8 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t 
targetAddr,
 info.dwarf_index_section_length = SIZE_MAX;
 EHHeaderParser::EHHeaderInfo hdrInfo;
 if (!EHHeaderParser::decodeEHHdr(
-*this, info.dwarf_index_section, info.dwarf_index_section_length,
+*this, info.dwarf_index_section,
+info.dwarf_index_section + info.dwarf_index_section_length,
 hdrInfo)) {
   return false;
 }

>From 0190d73d214feb1737206223ae44d9fced51de4d Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 11 Oct 2023 08:52:45 -0700
Subject: [PATCH 2/2] [libunwind] Avoid reading OOB for non-existent
 .eh_frame_hdr

I was running the tests with baremetal picolibc which has a linker
script that __eh_frame_start==__eh_frame_end (not equal to zero) in
case there is no .eh_frame_hdr.
I noticed that libunwind was trying to read nonsense data because it
was printing messages such as
`libunwind: unsupported .eh_frame_hdr version: 20 at 8000d308`

This change adds a ehHdrSize check to avoid reading this out-of-bounds
data and potentially crashing.
---
 libunwind/src/EHHeaderParser.hpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/libunwind/src/EHHeaderParser.hpp b/libunwind/src/EHHeaderParser.hpp
index ed4317c89055c9e..edc77daae627e67 100644
--- a/libunwind/src/EHHeaderParser.hpp
+++ b/libunwind/src/EHHeaderParser.hpp
@@ -55,6 +55,18 @@ template 
 bool EHHeaderParser::decodeEHHdr(A , pint_t ehHdrStart,
 pint_t ehHdrEnd, EHHeaderInfo ) {
   pint_t p = ehHdrStart;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrEnd - ehHdrStart < 4) {
+// Don't print a message for an empty .eh_frame_hdr (this can happen if
+// the linker script defines symbols for it even in the empty case).
+if (ehHdrEnd == ehHdrStart)
+  return false;
+_LIBUNWIND_LOG("unsupported .eh_frame_hdr at %" PRIx64
+   ": need at least 4 bytes of data but only got %zd",
+   static_cast(ehHdrStart), ehHdrSize);
+return false;
+  }
   uint8_t version = addressSpace.get8(p++);
   if (version != 1) {
 _LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64,

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


[libunwind] [libunwind] Fix wrong end argument passed to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> > Can we merge this into #68815 please?
> 
> I'd like to keep the two commits separate since they are addressing different 
> bugs.

This would be a lot easier if I could chose rebase+merge in the PR flow.

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


[libunwind] [libunwind] Fix wrong end argument passed to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> Can we merge this into #68815 please?

I'd like to keep the two commits separate since they are addressing different 
bugs.

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-11 Thread Hubert Tong via cfe-commits

https://github.com/hubert-reinterpretcast approved this pull request.

LGTM, but I am not sure if @stefanp-ibm continues to be concerned about 
enabling this for ABIs that have not been updated to specify a treatment of the 
VSX registers.

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


[libunwind] [libunwind] Fix wrong end argument passed to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

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


[libunwind] [libunwind] Consistently pass start+length to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

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


[libunwind] [libunwind] Consistently pass start+length to decodeEHHdr() (PR #68813)

2023-10-11 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/68813

>From ff360ee7f304424dd0d12d00b8c0ba6801241410 Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 11 Oct 2023 08:34:55 -0700
Subject: [PATCH] [libunwind] Fix wrong end argument passed to decodeEHHdr()

All but one callsite were actually passing start+length arguments.
This should not have any functional change since the end argument is
almost always ignored.
I noticed this while debugging some incorrect error messages being
printed while running the testsuite baremetal (using binaries that did
not have a valid eh_frame_hdr section): the tests print
`libunwind: unsupported .eh_frame_hdr version: 20 at 8000d308` because
libunwind is reading nonsense data for .eh_frame_hdr.
---
 libunwind/src/AddressSpace.hpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 1abbc822546878d..5551c7d4bef1c56 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -414,8 +414,8 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, 
size_t image_base,
 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
 if (EHHeaderParser::decodeEHHdr(
-*cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
-hdrInfo)) {
+*cbdata->addressSpace, eh_frame_hdr_start,
+eh_frame_hdr_start + phdr->p_memsz, hdrInfo)) {
   // .eh_frame_hdr records the start of .eh_frame, but not its size.
   // Rely on a zero terminator to find the end of the section.
   cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
@@ -638,7 +638,8 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t 
targetAddr,
 info.dwarf_index_section_length = SIZE_MAX;
 EHHeaderParser::EHHeaderInfo hdrInfo;
 if (!EHHeaderParser::decodeEHHdr(
-*this, info.dwarf_index_section, info.dwarf_index_section_length,
+*this, info.dwarf_index_section,
+info.dwarf_index_section + info.dwarf_index_section_length,
 hdrInfo)) {
   return false;
 }

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


[libunwind] [libunwind] Avoid reading OOB for non-existent .eh_frame_hdr (PR #68815)

2023-10-11 Thread Saleem Abdulrasool via cfe-commits


@@ -53,8 +53,21 @@ template  class EHHeaderParser {
 
 template 
 bool EHHeaderParser::decodeEHHdr(A , pint_t ehHdrStart,
-pint_t ehHdrEnd, EHHeaderInfo ) {
+size_t ehHdrSize, EHHeaderInfo ) 
{
   pint_t p = ehHdrStart;
+  pint_t ehHdrEnd = ehHdrStart + ehHdrSize;
+
+  // Ensure that we don't read data beyond the end of .eh_frame_hdr
+  if (ehHdrSize < 4) {

compnerd wrote:

I kinda feel that its safer - its not changing the semantics of the parameter 
and can ensure that any downstream forks don't need to worry about the change 
in the internal call.

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


  1   2   3   >