[flang] [clang] [flang][Driver] Support -nodefaultlibs, -nostartfiles and -nostdlib (PR #72601)

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

brad0 wrote:

@MaskRay ?

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


[clang] [Driver] Enable __float128 support on X86 on FreeBSD / NetBSD (PR #72788)

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

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


[clang] [Driver] Enable __float128 support on X86 and PPC64le on FreeBSD / NetBSD (PR #72788)

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

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

>From bde98ba852c456d95be75df7e9ecfa31b7d964ff Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 18 Nov 2023 22:04:19 -0500
Subject: [PATCH] [Driver] Enable __float128 support on X86 on FreeBSD / NetBSD

---
 clang/lib/Basic/Targets/OSTargets.h | 16 +++-
 clang/test/CodeGenCXX/float128-declarations.cpp | 12 ++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 23799d8a4ae17bc..342af4bbc42b7bc 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -187,6 +187,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
 DefineStd(Builder, "unix", Opts);
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 // On FreeBSD, wchar_t contains the number of the code point as
 // used by the character set of the locale. These character sets are
@@ -204,9 +206,11 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
 case llvm::Triple::mips:
@@ -372,12 +376,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__unix__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   NetBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "__mcount";
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 
diff --git a/clang/test/CodeGenCXX/float128-declarations.cpp 
b/clang/test/CodeGenCXX/float128-declarations.cpp
index ddfe9dce109c81e..84b8f7f33036b59 100644
--- a/clang/test/CodeGenCXX/float128-declarations.cpp
+++ b/clang/test/CodeGenCXX/float128-declarations.cpp
@@ -6,9 +6,17 @@
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86

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


[clang] [Driver] Enable __float128 support on X86 and PPC64le on FreeBSD / NetBSD (PR #72788)

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

brad0 wrote:

> Linux ppc64le does not support `__float128`. Should *BSD support it?

There was another patch floating around to add support for the driver. I'll 
remove it for now.

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


[clang] [Driver] Enable __float128 support on X86 and PPC64le on FreeBSD / NetBSD (PR #72788)

2023-11-18 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Linux ppc64le does not support `__float128`. Should *BSD support it?

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


[clang] [Driver] Enable __float128 support on X86 and PPC64le on FreeBSD / NetBSD (PR #72788)

2023-11-18 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver] Enable __float128 support on X86 and PPC64le on FreeBSD / NetBSD (PR #72788)

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

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


[clang] [Driver] Enable __float128 support on X86 and PowerPC64le on FreeBSD … (PR #72788)

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

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


[clang] [Driver] Enable __float128 support on X86 and PowerPC64le on FreeBSD … (PR #72788)

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

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

>From 851adf14958e9dac3d9143ca2e667cd9b4de2d8b Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 18 Nov 2023 22:04:19 -0500
Subject: [PATCH] [Driver] Enable __float128 support on X86 and PPC64le on
 FreeBSD / NetBSD

---
 clang/lib/Basic/Targets/OSTargets.h   | 20 +--
 .../test/CodeGenCXX/float128-declarations.cpp | 14 +++--
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 23799d8a4ae17bc..7cb4110921b9e62 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -187,6 +187,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
 DefineStd(Builder, "unix", Opts);
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 // On FreeBSD, wchar_t contains the number of the code point as
 // used by the character set of the locale. These character sets are
@@ -204,17 +206,21 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
+case llvm::Triple::ppc64le:
+  this->HasFloat128 = true;
+  [[fallthrough]];
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:
 case llvm::Triple::ppc:
 case llvm::Triple::ppcle:
 case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
   this->MCountName = "_mcount";
   break;
 case llvm::Triple::arm:
@@ -372,12 +378,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__unix__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   NetBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "__mcount";
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 
diff --git a/clang/test/CodeGenCXX/float128-declarations.cpp 
b/clang/test/CodeGenCXX/float128-declarations.cpp
index ddfe9dce109c81e..fd6c98fc4ba3d0b 100644
--- a/clang/test/CodeGenCXX/float128-declarations.cpp
+++ b/clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,13 +2,23 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-freebsd \
+// RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86

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


[clang] [Driver] Enable __float128 support on X86 and PowerPC64le on FreeBSD … (PR #72788)

2023-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brad Smith (brad0)


Changes

…/ NetBSD

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/OSTargets.h (+18-2) 
- (modified) clang/test/CodeGenCXX/float128-declarations.cpp (+12-2) 


``diff
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 23799d8a4ae17bc..7cb4110921b9e62 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -187,6 +187,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
 DefineStd(Builder, "unix", Opts);
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 // On FreeBSD, wchar_t contains the number of the code point as
 // used by the character set of the locale. These character sets are
@@ -204,17 +206,21 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
+case llvm::Triple::ppc64le:
+  this->HasFloat128 = true;
+  [[fallthrough]];
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:
 case llvm::Triple::ppc:
 case llvm::Triple::ppcle:
 case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
   this->MCountName = "_mcount";
   break;
 case llvm::Triple::arm:
@@ -372,12 +378,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__unix__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   NetBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "__mcount";
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 
diff --git a/clang/test/CodeGenCXX/float128-declarations.cpp 
b/clang/test/CodeGenCXX/float128-declarations.cpp
index ddfe9dce109c81e..fd6c98fc4ba3d0b 100644
--- a/clang/test/CodeGenCXX/float128-declarations.cpp
+++ b/clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,13 +2,23 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-freebsd \
+// RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86

``




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


[clang] [Driver] Enable __float128 support on X86 and PowerPC64le on FreeBSD … (PR #72788)

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

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/72788

…/ NetBSD

>From 96f280aa636c9858887d383d4cce7ee542d0b058 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 18 Nov 2023 22:04:19 -0500
Subject: [PATCH] [Driver] Enable __float128 support on X86 and PowerPC64le on
 FreeBSD / NetBSD

---
 clang/lib/Basic/Targets/OSTargets.h   | 20 +--
 .../test/CodeGenCXX/float128-declarations.cpp | 14 +++--
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 23799d8a4ae17bc..7cb4110921b9e62 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -187,6 +187,8 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
 DefineStd(Builder, "unix", Opts);
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
 
 // On FreeBSD, wchar_t contains the number of the code point as
 // used by the character set of the locale. These character sets are
@@ -204,17 +206,21 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo {
   FreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
-default:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  [[fallthrough]];
+default:
   this->MCountName = ".mcount";
   break;
+case llvm::Triple::ppc64le:
+  this->HasFloat128 = true;
+  [[fallthrough]];
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:
 case llvm::Triple::ppc:
 case llvm::Triple::ppcle:
 case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
   this->MCountName = "_mcount";
   break;
 case llvm::Triple::arm:
@@ -372,12 +378,22 @@ class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public 
OSTargetInfo {
 Builder.defineMacro("__unix__");
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");
+if (this->HasFloat128)
+  Builder.defineMacro("__FLOAT128__");
   }
 
 public:
   NetBSDTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 this->MCountName = "__mcount";
+switch (Triple.getArch()) {
+default:
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  this->HasFloat128 = true;
+  break;
+}
   }
 };
 
diff --git a/clang/test/CodeGenCXX/float128-declarations.cpp 
b/clang/test/CodeGenCXX/float128-declarations.cpp
index ddfe9dce109c81e..fd6c98fc4ba3d0b 100644
--- a/clang/test/CodeGenCXX/float128-declarations.cpp
+++ b/clang/test/CodeGenCXX/float128-declarations.cpp
@@ -2,13 +2,23 @@
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-unknown \
 // RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple powerpc64le-unknown-freebsd \
+// RUN:   -target-feature +float128 -std=c++11 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -triple i386-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-linux-gnu -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple i686-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-freebsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-netbsd -std=c++11 \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
+// RUN: %clang_cc1 -emit-llvm -triple i386-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
-// RUN: %clang_cc1 -emit-llvm -triple amd64-pc-openbsd -std=c++11 \
+// RUN: %clang_cc1 -emit-llvm -triple amd64-unknown-openbsd -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86
 // RUN: %clang_cc1 -emit-llvm -triple i386-pc-solaris2.11 -std=c++11 \
 // RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-X86

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


[clang] [CUDA][HIP] make trivial ctor/dtor host device (PR #72394)

2023-11-18 Thread Artem Belevich via cfe-commits

Artem-B wrote:

We've found a problem with the patch. https://godbolt.org/z/jcKo34vzG

```
template 
class C {
explicit C() {};
};

template <> C::C() {};
```
:6:21: error: __host__ function 'C' cannot overload __host__ __device__ 
function 'C'
6 | template <> C::C() {};
  | ^
:3:14: note: previous declaration is here
3 | explicit C() {};
```

```


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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

michael-kenzel wrote:

As discussed, I've removed unnecessary includes of `` as well as a 
couple other unnecessary includes. I've put the include of `` in 
`config.h` under an `#ifdef` so it only gets included when logging is 
potentially active. I've also moved the include of `` from `config.h` 
into only the files that actually need it. In two places, I replaced the 
include `` with an include of the header that was actually needed 
(`` or ``).

[AddressSpace.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-dc10e493a84f7de241e331f66a5af195689f08d45a6fd0da90b275a662856327)
 was using `snprintf` to copy strings into a buffer. I replaced those uses with 
`strncpy` to remove the need for ``.

Finally, I've added `_LIBUNWIND_TRACE_COMPACT_UNWIND` to also deal with the 
debug logging in 
[UnwindCursor.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-e59aa90030d7262678863315066b19c20f770a3b02ef960961d7d01fa4b15596).

Unfortunately, I can't really exercise all these code paths here as these 
changes now span code specific to multiple different platforms. I'll trust that 
if all the tests pass, that means it works…

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

michael-kenzel wrote:

As discussed, I've removed unnecessary includes of `` as well as a 
couple other unnecessary includes. I've put the include of `` in 
`config.h` under an `#ifdef` so it only gets included when logging is 
potentially active. I've also moved the include of `` from `config.h` 
into only the files that actually need it. In two places, I replaced the 
include `` with an include of the header that was actually needed 
(`` or ``).

[AddressSpace.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-dc10e493a84f7de241e331f66a5af195689f08d45a6fd0da90b275a662856327)
 was using `snprintf` to copy strings into a buffer. I replaced those uses with 
`strncpy` to remove the need for ``.

Finally, I've added `_LIBUNWIND_TRACE_COMPACT_UNWIND` to also deal with the 
debug logging in 
[UnwindCursor.hpp](https://github.com/llvm/llvm-project/pull/72040/files#diff-e59aa90030d7262678863315066b19c20f770a3b02ef960961d7d01fa4b15596).

Unfortunately, I can't really exercise all these code paths here as these 
changes now span code specific to multiple different platforms. I'll trust that 
if all the tests pass, that means it works…

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[clang] [HIP] fix stack marking for -fgpu-rdc (PR #72782)

2023-11-18 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/72782

>From b49127f7787b3f5943a879c0f30e26f0f3ac7ab6 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 17 Nov 2023 18:35:36 -0500
Subject: [PATCH] [HIP] fix stack marking for -fgpu-rdc

HIP toolchain uses llvm-mc to generate a host object embedding
device binary for -fgpu-rdc. Due to lack of .note.GNU-stack
section, the generated relocatable has executable stack
marking, which disables protection from executable stack
for any HIP programs compiled with -fgpu-rdc.

This patch adds .note.GNU-stack section to the input
to llvm-mc to fix the executable stack marking.

Fixes: https://github.com/llvm/llvm-project/issues/71711
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp | 2 ++
 clang/test/Driver/hip-toolchain-rdc.hip| 2 ++
 2 files changed, 4 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 04efdcba20ea740..f692458b775de2b 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   ObjStream << "  .incbin ";
   llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
   ObjStream << "\n";
+  if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
+ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
   ObjStream.flush();
 
   // Dump the contents of the temp object file gen if the user requested that.
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index fa30bb8a9f5f576..1827531f9cab7a3 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -32,6 +32,8 @@
 // CHECK: .p2align 12
 // CHECK: __hip_fatbin:
 // CHECK: .incbin "[[BUNDLE:.*hipfb]]"
+// LNX: .section .note.GNU-stack, "", @progbits
+// MSVC-NOT: .note.GNU-stack
 
 // emit objects for host side path
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]

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


[clang] [HIP] fix stack marking for -fgpu-rdc (PR #72782)

2023-11-18 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 5237193b87721134541f228e28edfd544a9c8ac8 
adf19a8c09fc4ed82e4b42c735452e8c4ed8d84f -- 
clang/lib/Driver/ToolChains/HIPUtility.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 671cd060e0..f692458b77 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -151,7 +151,7 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
   ObjStream << "\n";
   if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
- ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
+ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
   ObjStream.flush();
 
   // Dump the contents of the temp object file gen if the user requested that.

``




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


[clang] [HIP] fix stack marking for -fgpu-rdc (PR #72782)

2023-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Yaxun (Sam) Liu (yxsamliu)


Changes

HIP toolchain uses llvm-mc to generate a host object embedding device binary 
for -fgpu-rdc. Due to lack of .note.GNU-stack section, the generated 
relocatable has executable stack marking, which disables protection from 
executable stack for any HIP programs compiled with -fgpu-rdc.

This patch adds .note.GNU-stack section to the input to llvm-mc to fix the 
executable stack marking.

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

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/HIPUtility.cpp (+2) 
- (modified) clang/test/Driver/hip-toolchain-rdc.hip (+2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 04efdcba20ea740..671cd060e0d810d 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   ObjStream << "  .incbin ";
   llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
   ObjStream << "\n";
+  if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
+ ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
   ObjStream.flush();
 
   // Dump the contents of the temp object file gen if the user requested that.
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index fa30bb8a9f5f576..1827531f9cab7a3 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -32,6 +32,8 @@
 // CHECK: .p2align 12
 // CHECK: __hip_fatbin:
 // CHECK: .incbin "[[BUNDLE:.*hipfb]]"
+// LNX: .section .note.GNU-stack, "", @progbits
+// MSVC-NOT: .note.GNU-stack
 
 // emit objects for host side path
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]

``




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


[clang] [HIP] fix stack marking for -fgpu-rdc (PR #72782)

2023-11-18 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu created 
https://github.com/llvm/llvm-project/pull/72782

HIP toolchain uses llvm-mc to generate a host object embedding device binary 
for -fgpu-rdc. Due to lack of .note.GNU-stack section, the generated 
relocatable has executable stack marking, which disables protection from 
executable stack for any HIP programs compiled with -fgpu-rdc.

This patch adds .note.GNU-stack section to the input to llvm-mc to fix the 
executable stack marking.

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

>From adf19a8c09fc4ed82e4b42c735452e8c4ed8d84f Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 17 Nov 2023 18:35:36 -0500
Subject: [PATCH] [HIP] fix stack marking for -fgpu-rdc

HIP toolchain uses llvm-mc to generate a host object embedding
device binary for -fgpu-rdc. Due to lack of .note.GNU-stack
section, the generated relocatable has executable stack
marking, which disables protection from executable stack
for any HIP programs compiled with -fgpu-rdc.

This patch adds .note.GNU-stack section to the input
to llvm-mc to fix the executable stack marking.

Fixes: https://github.com/llvm/llvm-project/issues/71711
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp | 2 ++
 clang/test/Driver/hip-toolchain-rdc.hip| 2 ++
 2 files changed, 4 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 04efdcba20ea740..671cd060e0d810d 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -150,6 +150,8 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   ObjStream << "  .incbin ";
   llvm::sys::printArg(ObjStream, BundleFile, /*Quote=*/true);
   ObjStream << "\n";
+  if (HostTriple.isOSLinux() && HostTriple.isOSBinFormatELF())
+ ObjStream << "  .section .note.GNU-stack, \"\", @progbits\n";
   ObjStream.flush();
 
   // Dump the contents of the temp object file gen if the user requested that.
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index fa30bb8a9f5f576..1827531f9cab7a3 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -32,6 +32,8 @@
 // CHECK: .p2align 12
 // CHECK: __hip_fatbin:
 // CHECK: .incbin "[[BUNDLE:.*hipfb]]"
+// LNX: .section .note.GNU-stack, "", @progbits
+// MSVC-NOT: .note.GNU-stack
 
 // emit objects for host side path
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From f8b562dbd0c5927b92c5314ea70745b9b3ec1535 Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Remove unnecessary dependencies on stdio.h for
 increased baremetal friendliness

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  79 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   3 +-
 libunwind/src/config.h|  37 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 142 insertions(+), 172 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   

[clang-tools-extra] [clang] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-18 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

It looks like the issue is, if the invented CallExpr is ill-formed and the 
compiler needs to issue a diagnostic about it, with the invalid SourceLocation 
it doesn't have a source location to attach to the diagnostic.

I guess this means the approach of using an invalid SourceLocation doesn't work 
after all?

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[clang] [clang-tools-extra] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-18 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

The CI run shows the test 
[Sema/builtin-dump-struct.c](https://searchfox.org/llvm/source/clang/test/Sema/builtin-dump-struct.c)
 is failing.

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From a72cef20e847e85a5fedb56d1b9d1414dbd7e516 Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  79 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   3 +-
 libunwind/src/config.h|  37 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 142 insertions(+), 172 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   

[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

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


[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From 0bedd8b680bf8f2957a6056e92eb1cb92a8666e3 Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  79 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   3 +-
 libunwind/src/config.h|  31 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 137 insertions(+), 171 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   

[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: dong jianqiang (dongjianqiang2)


Changes

clang splits -export-dynamic into "-e" and "xport-dynamic", and gets ld 
warning: cannot find entry symbol xport-dynamic; defaulting to , which is 
unexpected from user.

Adjust the driver to support -export-dynamic, which can match GCC behavior.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1) 
- (modified) clang/test/Driver/dynamic-linker.c (+6) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296a..3bb764a1e46ab8a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1453,6 +1453,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], 
"extract-api-ignores=">,
 HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
 MarshallingInfoStringVector>;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
+def export_dynamic : Flag<["-"], "export-dynamic">, Flags<[LinkerInput]>, 
Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
diff --git a/clang/test/Driver/dynamic-linker.c 
b/clang/test/Driver/dynamic-linker.c
index 978907e0adee697..d202f537b44fb98 100644
--- a/clang/test/Driver/dynamic-linker.c
+++ b/clang/test/Driver/dynamic-linker.c
@@ -23,6 +23,12 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu -### -static /dev/null -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -### -static /dev/null -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
 
+// RUN: %clang -target armv7-unknown-linux-gnueabi -### -export-dynamic 
/dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target i386-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target mips64-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu -### -export-dynamic 
/dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+
 // CHECK-SHARED: "-shared"
 // CHECK-RDYNAMIC: "-export-dynamic"
 // CHECK-STATIC: "-{{B?}}static"

``




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


[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From f98bbd27427a3cc03dbb933c2fccbab73b557cec Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  79 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   3 +-
 libunwind/src/config.h|  31 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 137 insertions(+), 171 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   

[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2023-11-18 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 created 
https://github.com/llvm/llvm-project/pull/72781

clang splits -export-dynamic into "-e" and "xport-dynamic", and gets ld 
warning: cannot find entry symbol xport-dynamic; defaulting to , which is 
unexpected from user.

Adjust the driver to support -export-dynamic, which can match GCC behavior.

>From 4eb84135489b28f3b06085693dc79928b7b7e3ff Mon Sep 17 00:00:00 2001
From: Dong JianQiang 
Date: Sun, 19 Nov 2023 11:23:31 +0800
Subject: [PATCH] [Driver] Add support for -export-dynamic which can match GCC
 behavior.

clang splits -export-dynamic into "-e" and "xport-dynamic", and gets
ld warning: cannot find entry symbol xport-dynamic; defaulting to ,
which is unexpected from user.

Adjust the driver to support -export-dynamic, which can match GCC behavior.
---
 clang/include/clang/Driver/Options.td | 1 +
 clang/test/Driver/dynamic-linker.c| 6 ++
 2 files changed, 7 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296a..3bb764a1e46ab8a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1453,6 +1453,7 @@ def extract_api_ignores_EQ: CommaJoined<["--"], 
"extract-api-ignores=">,
 HelpText<"Comma separated list of files containing a new line separated 
list of API symbols to ignore when extracting API information.">,
 MarshallingInfoStringVector>;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
+def export_dynamic : Flag<["-"], "export-dynamic">, Flags<[LinkerInput]>, 
Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
diff --git a/clang/test/Driver/dynamic-linker.c 
b/clang/test/Driver/dynamic-linker.c
index 978907e0adee697..d202f537b44fb98 100644
--- a/clang/test/Driver/dynamic-linker.c
+++ b/clang/test/Driver/dynamic-linker.c
@@ -23,6 +23,12 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu -### -static /dev/null -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -### -static /dev/null -o 
/dev/null 2>&1 | FileCheck -check-prefix CHECK-STATIC %s
 
+// RUN: %clang -target armv7-unknown-linux-gnueabi -### -export-dynamic 
/dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target i386-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target mips64-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu -### -export-dynamic 
/dev/null -o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -### -export-dynamic /dev/null 
-o /dev/null 2>&1 | FileCheck -check-prefix CHECK-RDYNAMIC %s
+
 // CHECK-SHARED: "-shared"
 // CHECK-RDYNAMIC: "-export-dynamic"
 // CHECK-STATIC: "-{{B?}}static"

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


[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From c78b3f5267a5809f1d29a17dd392a8a2d0b4147c Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  77 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   1 -
 libunwind/src/config.h|  31 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 135 insertions(+), 169 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   p 

[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From 42bfd80e85095d8a1c94926fb907874f1c73f5c3 Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  77 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   1 -
 libunwind/src/config.h|  33 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 136 insertions(+), 170 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   p 

[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

2023-11-18 Thread Michael Kenzel via cfe-commits

https://github.com/michael-kenzel updated 
https://github.com/llvm/llvm-project/pull/72040

>From ef0ec53cdcc3cd2b42bfaafe2504f4e90fbf0c2e Mon Sep 17 00:00:00 2001
From: Michael Kenzel 
Date: Sat, 11 Nov 2023 22:09:05 +0100
Subject: [PATCH] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL

---
 libunwind/src/AddressSpace.hpp|   5 +-
 libunwind/src/DwarfInstructions.hpp   | 173 +++---
 libunwind/src/DwarfParser.hpp |   2 +-
 libunwind/src/Unwind-EHABI.cpp|   2 +-
 libunwind/src/UnwindCursor.hpp|  77 
 libunwind/src/UnwindLevel1-gcc-ext.c  |   1 -
 libunwind/src/UnwindLevel1.c  |   1 -
 libunwind/src/config.h|  33 +++-
 libunwind/test/aix_signal_unwind.pass.sh.S|   2 +-
 libunwind/test/bad_unwind_info.pass.cpp   |   1 -
 libunwind/test/forceunwind.pass.cpp   |   3 -
 libunwind/test/frameheadercache_test.pass.cpp |   2 +-
 libunwind/test/signal_unwind.pass.cpp |   2 -
 libunwind/test/unwind_leaffunction.pass.cpp   |   2 -
 14 files changed, 136 insertions(+), 170 deletions(-)

diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 5551c7d4bef1c56..7044c492e7adb6c 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -13,7 +13,6 @@
 #define __ADDRESSSPACE_HPP__
 
 #include 
-#include 
 #include 
 #include 
 
@@ -672,7 +671,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   Dl_info dyldInfo;
   if (dladdr((void *)addr, )) {
 if (dyldInfo.dli_sname != NULL) {
-  snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
+  strncpy(buf, dyldInfo.dli_sname, bufLen);
   *offset = (addr - (pint_t) dyldInfo.dli_saddr);
   return true;
 }
@@ -681,7 +680,7 @@ inline bool LocalAddressSpace::findFunctionName(pint_t 
addr, char *buf,
   uint16_t nameLen;
   char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);
   if (funcName != NULL) {
-snprintf(buf, bufLen, "%.*s", nameLen, funcName);
+strncpy(buf, funcName, nameLen < bufLen ? nameLen : bufLen);
 return true;
   }
 #else
diff --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index bd9ece60ee5881a..9a46833e6726081 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -12,8 +12,8 @@
 #ifndef __DWARF_INSTRUCTIONS_HPP__
 #define __DWARF_INSTRUCTIONS_HPP__
 
+#include 
 #include 
-#include 
 #include 
 
 #include "DwarfParser.hpp"
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions::evaluateExpression(pint_t expression, A ,
 const R ,
 pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-(uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+  (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-if (log) {
-  for (pint_t *t = sp; t > stack; --t) {
-fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-  }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
+for (pint_t *t = sp; t > stack; --t) {
+  _LIBUNWIND_TRACE_DWARF_EVAL("sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
 }
+#endif
 uint8_t opcode = addressSpace.get8(p++);
 sint_t svalue, svalue2;
 pint_t value;
@@ -409,16 +407,15 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.getP(p);
   p += sizeof(pint_t);
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_deref:
   // pop stack, dereference, push result
   value = *sp--;
   *(++sp) = addressSpace.getP(value);
-  if (log)
-fprintf(stderr, "dereference 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("dereference 0x%" PRIx64 "\n",
+  (uint64_t)value);
   break;
 
 case DW_OP_const1u:
@@ -426,8 +423,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   value = addressSpace.get8(p);
   p += 1;
   *(++sp) = value;
-  if (log)
-fprintf(stderr, "push 0x%" PRIx64 "\n", (uint64_t)value);
+  _LIBUNWIND_TRACE_DWARF_EVAL("push 0x%" PRIx64 "\n", (uint64_t)value);
   break;
 
 case DW_OP_const1s:
@@ -435,8 +431,7 @@ DwarfInstructions::evaluateExpression(pint_t 
expression, A ,
   svalue = (int8_t) addressSpace.get8(p);
   p 

[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-18 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-18 Thread Owen Pan via cfe-commits

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


[clang] 5237193 - [NFC] Fix typos in comments

2023-11-18 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2023-11-19T10:14:34+08:00
New Revision: 5237193b87721134541f228e28edfd544a9c8ac8

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

LOG: [NFC] Fix typos in comments

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 64521ce7182eee6..2199d7b58fb96e6 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -495,12 +495,12 @@ void CodeGenFunction::FinishFunction(SourceLocation 
EndLoc) {
   if (CurFnInfo->getMaxVectorWidth() > LargestVectorWidth)
 LargestVectorWidth = CurFnInfo->getMaxVectorWidth();
 
-  // Add the required-vector-width attribute. This contains the max width from:
+  // Add the min-legal-vector-width attribute. This contains the max width 
from:
   // 1. min-vector-width attribute used in the source program.
   // 2. Any builtins used that have a vector width specified.
   // 3. Values passed in and out of inline assembly.
   // 4. Width of vector arguments and return types for this function.
-  // 5. Width of vector aguments and return types for functions called by this
+  // 5. Width of vector arguments and return types for functions called by this
   //function.
   if (getContext().getTargetInfo().getTriple().isX86())
 CurFn->addFnAttr("min-legal-vector-width",



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


[llvm] [clang] [flang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-18 Thread via cfe-commits

shraiysh wrote:

One thing I wanted to point out was that with this patch clang will accept 
`#pragma omp declare target enter(x)` when compiled with version 5.2. I don't 
think clang is handling it accurately yet though. Is there a way to report 
"unimplemented" errors in clang? Or is it okay this way?

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


[llvm] [clang] [flang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-parser

@llvm/pr-subscribers-flang-fir-hlfir

Author: Shraiysh (shraiysh)


Changes

This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE TARGET` 
construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Last attempt to add this caused issues in buildbots - #71861. It should 
pass now.

---

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


24 Files Affected:

- (modified) clang/lib/Parse/ParseOpenMP.cpp (+1) 
- (modified) clang/test/OpenMP/target_enter_data_nowait_messages.cpp (+13-1) 
- (modified) flang/lib/Lower/OpenMP.cpp (+15) 
- (modified) flang/lib/Parser/openmp-parsers.cpp (+2) 
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+39-12) 
- (modified) flang/lib/Semantics/check-omp-structure.h (+2) 
- (modified) flang/lib/Semantics/resolve-directives.cpp (+3) 
- (modified) flang/test/Lower/OpenMP/FIR/declare-target-data.f90 (+16) 
- (modified) flang/test/Lower/OpenMP/FIR/declare-target-func-and-subr.f90 (+68) 
- (added) 
flang/test/Lower/OpenMP/FIR/declare-target-implicit-func-and-subr-cap-enter.f90 
(+192) 
- (modified) flang/test/Lower/OpenMP/declare-target-data.f90 (+16) 
- (modified) flang/test/Lower/OpenMP/declare-target-func-and-subr.f90 (+68) 
- (added) 
flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90 
(+192) 
- (modified) flang/test/Lower/OpenMP/declare-target-implicit-tarop-cap.f90 
(+14) 
- (modified) flang/test/Lower/OpenMP/function-filtering-2.f90 (+8) 
- (modified) flang/test/Lower/OpenMP/function-filtering.f90 (+18) 
- (modified) flang/test/Parser/OpenMP/declare_target-device_type.f90 (+21-6) 
- (modified) flang/test/Semantics/OpenMP/declarative-directive.f90 (+11-1) 
- (modified) flang/test/Semantics/OpenMP/declare-target01.f90 (+48) 
- (modified) flang/test/Semantics/OpenMP/declare-target02.f90 (+54) 
- (modified) flang/test/Semantics/OpenMP/declare-target06.f90 (+5) 
- (modified) flang/test/Semantics/OpenMP/requires04.f90 (+4-1) 
- (modified) flang/test/Semantics/OpenMP/requires05.f90 (+2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+5-1) 


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 3e7d8274aeefc52..ff3417f5a251ade 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3369,6 +3369,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind 
DKind,
   case OMPC_exclusive:
   case OMPC_affinity:
   case OMPC_doacross:
+  case OMPC_enter:
 if (getLangOpts().OpenMP >= 52 && DKind == OMPD_ordered &&
 CKind == OMPC_depend)
   Diag(Tok, diag::warn_omp_depend_in_ordered_deprecated);
diff --git a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp 
b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
index 3f5dde00b814ca4..ba5eaf1d2214a07 100644
--- a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
+++ b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
@@ -6,14 +6,26 @@ int main(int argc, char **argv) {
   int i;
 
   #pragma omp nowait target enter data map(to: i) // expected-error {{expected 
an OpenMP directive}}
-  #pragma omp target nowait enter data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}}
+  {}
+  #pragma omp target nowait foo data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}}
+  {}
+  #pragma omp target nowait enter data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}} expected-error 
{{unexpected OpenMP clause 'enter' in directive '#pragma omp target'}} 
expected-error {{expected '(' after 'enter'}}
+  {}
   #pragma omp target enter nowait data map(to: i) // expected-error {{expected 
an OpenMP directive}}
+  {}
   #pragma omp target enter data nowait() map(to: i) // expected-warning 
{{extra tokens at the end of '#pragma omp target enter data' are ignored}} 
expected-error {{expected at least one 'map' clause for '#pragma omp target 
enter data'}}
+  {}
   #pragma omp target enter data map(to: i) nowait( // expected-warning {{extra 
tokens at the end of '#pragma omp target enter data' are ignored}}
+  {}
   #pragma omp target enter data map(to: i) nowait (argc)) // expected-warning 
{{extra tokens at the end of '#pragma omp target enter data' are ignored}}
+  {}
   #pragma omp target enter data map(to: i) nowait device (-10u)
+  {}
   #pragma omp target enter data map(to: i) nowait (3.14) device (-10u) // 
expected-warning {{extra tokens at the end of '#pragma omp target enter data' 
are ignored}}
+  {}
   #pragma omp target enter data map(to: i) nowait nowait // expected-error 
{{directive '#pragma 

[llvm] [flang] [clang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-18 Thread via cfe-commits

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

This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE TARGET` 
construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Last attempt to add this caused issues in buildbots - #71861. It should pass 
now.

>From 70e5a05ad2a65f824fa1c8248513e402e8af210f Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay 
Date: Sat, 18 Nov 2023 20:02:30 -0600
Subject: [PATCH] [flang][OpenMP] Add semantic check for declare target

This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE
TARGET` construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```
---
 clang/lib/Parse/ParseOpenMP.cpp   |   1 +
 .../target_enter_data_nowait_messages.cpp |  14 +-
 flang/lib/Lower/OpenMP.cpp|  15 ++
 flang/lib/Parser/openmp-parsers.cpp   |   2 +
 flang/lib/Semantics/check-omp-structure.cpp   |  51 +++--
 flang/lib/Semantics/check-omp-structure.h |   2 +
 flang/lib/Semantics/resolve-directives.cpp|   3 +
 .../Lower/OpenMP/FIR/declare-target-data.f90  |  16 ++
 .../FIR/declare-target-func-and-subr.f90  |  68 +++
 ...arget-implicit-func-and-subr-cap-enter.f90 | 192 ++
 .../test/Lower/OpenMP/declare-target-data.f90 |  16 ++
 .../OpenMP/declare-target-func-and-subr.f90   |  68 +++
 ...arget-implicit-func-and-subr-cap-enter.f90 | 192 ++
 .../declare-target-implicit-tarop-cap.f90 |  14 ++
 .../Lower/OpenMP/function-filtering-2.f90 |   8 +
 .../test/Lower/OpenMP/function-filtering.f90  |  18 ++
 .../OpenMP/declare_target-device_type.f90 |  27 ++-
 .../OpenMP/declarative-directive.f90  |  12 +-
 .../Semantics/OpenMP/declare-target01.f90 |  48 +
 .../Semantics/OpenMP/declare-target02.f90 |  54 +
 .../Semantics/OpenMP/declare-target06.f90 |   5 +
 flang/test/Semantics/OpenMP/requires04.f90|   5 +-
 flang/test/Semantics/OpenMP/requires05.f90|   2 +
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |   6 +-
 24 files changed, 817 insertions(+), 22 deletions(-)
 create mode 100644 
flang/test/Lower/OpenMP/FIR/declare-target-implicit-func-and-subr-cap-enter.f90
 create mode 100644 
flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap-enter.f90

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 3e7d8274aeefc52..ff3417f5a251ade 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3369,6 +3369,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind 
DKind,
   case OMPC_exclusive:
   case OMPC_affinity:
   case OMPC_doacross:
+  case OMPC_enter:
 if (getLangOpts().OpenMP >= 52 && DKind == OMPD_ordered &&
 CKind == OMPC_depend)
   Diag(Tok, diag::warn_omp_depend_in_ordered_deprecated);
diff --git a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp 
b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
index 3f5dde00b814ca4..ba5eaf1d2214a07 100644
--- a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
+++ b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp
@@ -6,14 +6,26 @@ int main(int argc, char **argv) {
   int i;
 
   #pragma omp nowait target enter data map(to: i) // expected-error {{expected 
an OpenMP directive}}
-  #pragma omp target nowait enter data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}}
+  {}
+  #pragma omp target nowait foo data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}}
+  {}
+  #pragma omp target nowait enter data map(to: i) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}} expected-error 
{{unexpected OpenMP clause 'enter' in directive '#pragma omp target'}} 
expected-error {{expected '(' after 'enter'}}
+  {}
   #pragma omp target enter nowait data map(to: i) // expected-error {{expected 
an OpenMP directive}}
+  {}
   #pragma omp target enter data nowait() map(to: i) // expected-warning 
{{extra tokens at the end of '#pragma omp target enter data' are ignored}} 
expected-error {{expected at least one 'map' clause for '#pragma omp target 
enter data'}}
+  {}
   #pragma omp target enter data map(to: i) nowait( // expected-warning {{extra 
tokens at the end of '#pragma omp target enter data' are ignored}}
+  {}
   #pragma omp target enter data map(to: i) nowait (argc)) // expected-warning 
{{extra tokens at the end of '#pragma omp target enter data' are ignored}}
+  {}
   #pragma omp 

[clang] [clang-format] Fix a bug in isStartOfName() on macro definitions (PR #72768)

2023-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixed #72751.

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+4-2) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7-1) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1d376cd8b5794dd..a23a1b28330fe57 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2206,8 +2206,10 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference() ||
-NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
+(!NextNonComment && !Line.InMacroBody) ||
+(NextNonComment &&
+ (NextNonComment->isPointerOrReference() ||
+  NextNonComment->isOneOf(tok::identifier, tok::string_literal {
   return false;
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a986806b7a44069..b6abf34c589b146 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2390,7 +2390,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
-TEST_F(TokenAnnotatorTest, NotStartOfName) {
+TEST_F(TokenAnnotatorTest, StartOfName) {
   auto Tokens = annotate("#pragma clang diagnostic push");
   ASSERT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
@@ -2402,6 +2402,12 @@ TEST_F(TokenAnnotatorTest, NotStartOfName) {
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#define FOO Foo foo");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName);
 }
 
 } // namespace

``




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


[clang] [clang-format] Fix a bug in isStartOfName() on macro definitions (PR #72768)

2023-11-18 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72768

Fixed #72751.

>From 188eeabc89cfc4851ad1943d5ef6bf11bc6cb629 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 18 Nov 2023 16:37:45 -0800
Subject: [PATCH] [clang-format] Fix a bug in isStartOfName() on macro
 definitions

Fixed #72751.
---
 clang/lib/Format/TokenAnnotator.cpp   | 6 --
 clang/unittests/Format/TokenAnnotatorTest.cpp | 8 +++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1d376cd8b5794dd..a23a1b28330fe57 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2206,8 +2206,10 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference() ||
-NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
+(!NextNonComment && !Line.InMacroBody) ||
+(NextNonComment &&
+ (NextNonComment->isPointerOrReference() ||
+  NextNonComment->isOneOf(tok::identifier, tok::string_literal {
   return false;
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a986806b7a44069..b6abf34c589b146 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2390,7 +2390,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
-TEST_F(TokenAnnotatorTest, NotStartOfName) {
+TEST_F(TokenAnnotatorTest, StartOfName) {
   auto Tokens = annotate("#pragma clang diagnostic push");
   ASSERT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
@@ -2402,6 +2402,12 @@ TEST_F(TokenAnnotatorTest, NotStartOfName) {
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#define FOO Foo foo");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName);
 }
 
 } // namespace

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


[clang] 1c12278 - [clang] Remove unused selStructPtrTy in CGObjCGNU.cpp (NFC)

2023-11-18 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2023-11-19T08:19:47+08:00
New Revision: 1c1227846425883a3d39ff56700660236a97152c

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

LOG: [clang] Remove unused selStructPtrTy in CGObjCGNU.cpp (NFC)

/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp:3674:15: error: variable 
'selStructPtrTy' set but not used [-Werror,-Wunused-but-set-variable]
  llvm::Type *selStructPtrTy = SelectorTy;
  ^
1 error generated.

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 68ec457e426a933..4ca1a8cce64d895 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3671,11 +3671,9 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
   GenerateProtocolHolderCategory();
 
   llvm::StructType *selStructTy = dyn_cast(SelectorElemTy);
-  llvm::Type *selStructPtrTy = SelectorTy;
   if (!selStructTy) {
 selStructTy = llvm::StructType::get(CGM.getLLVMContext(),
 { PtrToInt8Ty, PtrToInt8Ty });
-selStructPtrTy = llvm::PointerType::getUnqual(selStructTy);
   }
 
   // Generate statics list:



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


[clang] 695662b - [clang] Remove ConstantAggregateBuilderBase::addBitCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T17:46:08-06:00
New Revision: 695662b00c993dc33f7196c6d156c967a0aad6af

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

LOG: [clang] Remove ConstantAggregateBuilderBase::addBitCast (NFC)

* Replace all existing uses of ConstantAggregateBuilderBase::addBitCast,
  as they involve a no-op ptr-to-ptr bitcast
* Remove method ConstantAggregateBuilderBase::addBitCast

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/include/clang/CodeGen/ConstantInitBuilder.h
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/ConstantInitBuilder.h 
b/clang/include/clang/CodeGen/ConstantInitBuilder.h
index 9e0d0fa0d8e8243..498acfd38013183 100644
--- a/clang/include/clang/CodeGen/ConstantInitBuilder.h
+++ b/clang/include/clang/CodeGen/ConstantInitBuilder.h
@@ -204,11 +204,6 @@ class ConstantAggregateBuilderBase {
 add(llvm::ConstantPointerNull::get(ptrTy));
   }
 
-  /// Add a bitcast of a value to a specific type.
-  void addBitCast(llvm::Constant *value, llvm::Type *type) {
-add(llvm::ConstantExpr::getBitCast(value, type));
-  }
-
   /// Add a bunch of new values to this initializer.
   void addAll(llvm::ArrayRef values) {
 assert(!Finished && "cannot add more values after finishing builder");

diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 01fd8f5a00ee39f..68ec457e426a933 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1725,9 +1725,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   SmallVector ClassMethods;
   ClassMethods.insert(ClassMethods.begin(), OID->classmeth_begin(),
   OID->classmeth_end());
-  metaclassFields.addBitCast(
-  GenerateMethodList(className, "", ClassMethods, true),
-  PtrTy);
+  metaclassFields.add(
+  GenerateMethodList(className, "", ClassMethods, true));
 }
 // void *dtable;
 metaclassFields.addNullPointer(PtrTy);
@@ -1894,9 +1893,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 if (InstanceMethods.size() == 0)
   classFields.addNullPointer(PtrTy);
 else
-  classFields.addBitCast(
-  GenerateMethodList(className, "", InstanceMethods, false),
-  PtrTy);
+  classFields.add(
+  GenerateMethodList(className, "", InstanceMethods, false));
+
 // void *dtable;
 classFields.addNullPointer(PtrTy);
 // IMP cxx_construct;
@@ -2887,14 +2886,14 @@ GenerateMethodList(StringRef ClassName,
 assert(FnPtr && "Can't generate metadata for method that doesn't exist");
 auto Method = MethodArray.beginStruct(ObjCMethodTy);
 if (isV2ABI) {
-  Method.addBitCast(FnPtr, IMPTy);
+  Method.add(FnPtr);
   Method.add(GetConstantSelector(OMD->getSelector(),
   Context.getObjCEncodingForMethodDecl(OMD)));
   Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD, 
true)));
 } else {
   Method.add(MakeConstantString(OMD->getSelector().getAsString()));
   
Method.add(MakeConstantString(Context.getObjCEncodingForMethodDecl(OMD)));
-  Method.addBitCast(FnPtr, IMPTy);
+  Method.add(FnPtr);
 }
 Method.finishAndAddTo(MethodArray);
   }
@@ -2993,7 +2992,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   // Fill in the structure
 
   // isa
-  Elements.addBitCast(MetaClass, PtrToInt8Ty);
+  Elements.add(MetaClass);
   // super_class
   Elements.add(SuperClass);
   // name
@@ -3022,7 +3021,7 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
   // sibling_class
   Elements.add(NULLPtr);
   // protocols
-  Elements.addBitCast(Protocols, PtrTy);
+  Elements.add(Protocols);
   // gc_object_type
   Elements.add(NULLPtr);
   // abi_version
@@ -3094,7 +3093,7 @@ CGObjCGNU::GenerateProtocolList(ArrayRef 
Protocols) {
 } else {
   protocol = value->getValue();
 }
-Elements.addBitCast(protocol, PtrToInt8Ty);
+Elements.add(protocol);
   }
   Elements.finishAndAddTo(ProtocolList);
   return ProtocolList.finishAndCreateGlobal(".objc_protocol_list",
@@ -3224,11 +3223,9 @@ void CGObjCGNU::GenerateProtocolHolderCategory() {
   Elements.add(MakeConstantString(CategoryName));
   Elements.add(MakeConstantString(ClassName));
   // Instance method list
-  Elements.addBitCast(GenerateMethodList(
-  ClassName, CategoryName, {}, false), PtrTy);
+  Elements.add(GenerateMethodList(ClassName, CategoryName, {}, false));
   // Class method list
-  Elements.addBitCast(GenerateMethodList(
-  ClassName, CategoryName, {}, true), PtrTy);
+  Elements.add(GenerateMethodList(ClassName, CategoryName, {}, true));
 
   // Protocol list
   ConstantInitBuilder ProtocolListBuilder(CGM);
@@ -3238,13 +3235,11 @@ void 

[clang] b08960f - [CGObjCMac] Replace calls to ConstantAggregateBuilderBase::addBitCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T17:03:48-06:00
New Revision: b08960f1e96d64874486354c16b4116c5f8f

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

LOG: [CGObjCMac] Replace calls to ConstantAggregateBuilderBase::addBitCast (NFC)

Replace calls to `ConstantAggregateBuilderBase::addBitCast` that involve a
no-op ptr-to-ptr bitcast.

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 4ac8c4dc9a38745..ba52b23be018b85 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2014,7 +2014,7 @@ CGObjCCommonMac::GenerateConstantNSString(const 
StringLiteral *Literal) {
   // Don't enforce the target's minimum global alignment, since the only use
   // of the string is via this class initializer.
   GV->setAlignment(llvm::Align(1));
-  Fields.addBitCast(GV, CGM.Int8PtrTy);
+  Fields.add(GV);
 
   // String length.
   Fields.addInt(CGM.IntTy, StringLength);
@@ -3557,8 +3557,7 @@ void CGObjCMac::GenerateClass(const 
ObjCImplementationDecl *ID) {
 // Record a reference to the super class.
 LazySymbols.insert(Super->getIdentifier());
 
-values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
-  ObjCTypes.ClassPtrTy);
+values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
   } else {
 values.addNullPointer(ObjCTypes.ClassPtrTy);
   }
@@ -3612,14 +3611,12 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const 
ObjCImplementationDecl *ID,
   const ObjCInterfaceDecl *Root = ID->getClassInterface();
   while (const ObjCInterfaceDecl *Super = Root->getSuperClass())
 Root = Super;
-  values.addBitCast(GetClassName(Root->getObjCRuntimeNameAsString()),
-ObjCTypes.ClassPtrTy);
+  values.add(GetClassName(Root->getObjCRuntimeNameAsString()));
   // The super class for the metaclass is emitted as the name of the
   // super class. The runtime fixes this up to point to the
   // *metaclass* for the super class.
   if (ObjCInterfaceDecl *Super = ID->getClassInterface()->getSuperClass()) {
-values.addBitCast(GetClassName(Super->getObjCRuntimeNameAsString()),
-  ObjCTypes.ClassPtrTy);
+values.add(GetClassName(Super->getObjCRuntimeNameAsString()));
   } else {
 values.addNullPointer(ObjCTypes.ClassPtrTy);
   }
@@ -3815,8 +3812,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const 
ObjCImplementationDecl *ID,
 void CGObjCMac::emitMethodDescriptionConstant(ConstantArrayBuilder ,
   const ObjCMethodDecl *MD) {
   auto description = builder.beginStruct(ObjCTypes.MethodDescriptionTy);
-  description.addBitCast(GetMethodVarName(MD->getSelector()),
- ObjCTypes.SelectorPtrTy);
+  description.add(GetMethodVarName(MD->getSelector()));
   description.add(GetMethodVarType(MD));
   description.finishAndAddTo(builder);
 }
@@ -3834,10 +3830,9 @@ void CGObjCMac::emitMethodConstant(ConstantArrayBuilder 
,
   assert(fn && "no definition registered for method");
 
   auto method = builder.beginStruct(ObjCTypes.MethodTy);
-  method.addBitCast(GetMethodVarName(MD->getSelector()),
-ObjCTypes.SelectorPtrTy);
+  method.add(GetMethodVarName(MD->getSelector()));
   method.add(GetMethodVarType(MD));
-  method.addBitCast(fn, ObjCTypes.Int8PtrTy);
+  method.add(fn);
   method.finishAndAddTo(builder);
 }
 
@@ -5191,10 +5186,10 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() {
   if (ID->isWeakImported() && !IMP->isWeakImported())
 DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage);
 
-array.addBitCast(DefinedClasses[i], ObjCTypes.Int8PtrTy);
+array.add(DefinedClasses[i]);
   }
   for (unsigned i=0; igetSelector()),
-ObjCTypes.SelectorPtrTy);
+  method.add(GetMethodVarName(MD->getSelector()));
   method.add(GetMethodVarType(MD));
 
   if (forProtocol) {
@@ -6745,7 +6739,7 @@ void 
CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder ,
   } else {
 llvm::Function *fn = GetMethodDefinition(MD);
 assert(fn && "no definition for method?");
-method.addBitCast(fn, ObjCTypes.Int8PtrProgramASTy);
+method.add(fn);
   }
 
   method.finishAndAddTo(builder);



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


[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-11-18 Thread Richard Smith via cfe-commits


@@ -713,6 +713,11 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 return ExprError();
   }
   const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
+  if (!RD->isCompleteDefinition()) {

zygoloid wrote:

You need to use `RequireCompleteType` here to properly trigger instantiation of 
templated classes and handle definition visibility checking for modules.

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


[compiler-rt] [flang] [clang] [clang-tools-extra] [llvm] [clang] Add `::_placement_new` expression for built-in global placement new (PR #72209)

2023-11-18 Thread via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/72209

>From 75cf305fe732d00be910a6aa0afe79953c5b7186 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sun, 12 Nov 2023 11:36:58 -0500
Subject: [PATCH 1/4] Implement `::_placement_new` expression for built-in
 global placement new without header includes, overload resolution or dealing
 with std libraries that declare the global placement new with attributes that
 cannot be redeclared.

---
 clang/include/clang/AST/ExprCXX.h | 23 +
 clang/include/clang/AST/Stmt.h|  4 ++
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/Sema.h   |  4 +-
 clang/lib/AST/ASTImporter.cpp | 18 ---
 clang/lib/AST/ExprCXX.cpp | 34 +
 clang/lib/AST/ExprConstant.cpp|  7 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |  1 +
 clang/lib/AST/StmtPrinter.cpp |  5 +-
 clang/lib/AST/StmtProfile.cpp |  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  2 +
 clang/lib/CodeGen/CGExprCXX.cpp   |  8 ++--
 clang/lib/CodeGen/CodeGenModule.cpp   |  5 +-
 clang/lib/Interpreter/Interpreter.cpp |  4 +-
 clang/lib/Parse/ParseDecl.cpp |  6 ++-
 clang/lib/Parse/ParseExpr.cpp |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 19 ++--
 clang/lib/Parse/ParseObjc.cpp |  1 +
 clang/lib/Parse/ParseTentative.cpp|  3 +-
 clang/lib/Sema/SemaExprCXX.cpp| 48 ++-
 clang/lib/Sema/TreeTransform.h|  6 +--
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +
 .../Checkers/CheckPlacementNew.cpp|  2 +-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp |  9 ++--
 clang/test/AST/ast-dump-expr.cpp  | 14 ++
 clang/test/CodeGenCXX/new.cpp | 44 -
 clang/test/SemaCXX/new-delete.cpp |  7 +++
 29 files changed, 234 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837b..d760af796aea28f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2282,6 +2282,13 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Build a c++ builtin placement new expression
+  CXXNewExpr(Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Build an empty c++ new expression.
   CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
  bool IsParenTypeId);
@@ -2297,6 +2304,14 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Create a c++ builtin placement new expression.
+  static CXXNewExpr *
+  CreatePlacementNew(const ASTContext , Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr 
*Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, 
SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Create an empty c++ new expression.
   static CXXNewExpr *CreateEmpty(const ASTContext , bool IsArray,
  bool HasInit, unsigned NumPlacementArgs,
@@ -2332,6 +2347,12 @@ class CXXNewExpr final
   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
 
+  bool isReservedPlacementNew() const {
+if (CXXNewExprBits.IsPlacementNewExpr)
+  return true;
+return OperatorNew->isReservedGlobalPlacementOperator();
+  }
+
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
   /// This might return std::nullopt even if isArray() returns true,
@@ -2387,6 +2408,8 @@ class CXXNewExpr final
 
   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
 
+  bool isPlacementNewExpr() const { return CXXNewExprBits.IsPlacementNewExpr; }
+
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
 switch (getInitializationStyle()) {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211f..2dc3746aee4fd71 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -878,6 +878,10 @@ class alignas(void *) Stmt {
 

[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-18 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 558132.
jaredgrubb marked 3 inline comments as done.
jaredgrubb added a comment.

Update to address all the review comments.


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

https://reviews.llvm.org/D150083

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp

Index: clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
@@ -0,0 +1,423 @@
+//===- unittest/Format/ObjCPropertyAttributeOrderFixerTest.cpp - unit tests
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../lib/Format/ObjCPropertyAttributeOrderFixer.h"
+#include "FormatTestBase.h"
+#include "TestLexer.h"
+
+#define DEBUG_TYPE "format-objc-property-attribute-order-fixer-test"
+
+namespace clang {
+namespace format {
+namespace test {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, ).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, ).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase {
+protected:
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle  = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+};
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, ParsesStyleOption) {
+  FormatStyle Style = {};
+  Style.Language = FormatStyle::LK_ObjC;
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: [class]", ObjCPropertyAttributeOrder,
+  std::vector({"class"}));
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: ["
+  "class, direct, atomic, nonatomic, "
+  "assign, retain, strong, copy, weak, unsafe_unretained, "
+  "readonly, readwrite, getter, setter, "
+  "nullable, nonnull, null_resettable, null_unspecified"
+  "]",
+  ObjCPropertyAttributeOrder,
+  std::vector({
+  "class",
+  "direct",
+  "atomic",
+  "nonatomic",
+  "assign",
+  "retain",
+  "strong",
+  "copy",
+  "weak",
+  "unsafe_unretained",
+  "readonly",
+  "readwrite",
+  "getter",
+  "setter",
+  "nullable",
+  "nonnull",
+  "null_resettable",
+  "null_unspecified",
+  }));
+}
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, SortsSpecifiedAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Language = FormatStyle::LK_ObjC;
+  Style.ObjCPropertyAttributeOrder = {"a", "b", "c"};
+
+  // Zero: nothing to do, but is legal.
+  verifyFormat("@property() int p;", Style);
+
+  // One: shouldn't move.
+  verifyFormat("@property(a) int p;", Style);
+  verifyFormat("@property(b) int p;", Style);
+  verifyFormat("@property(c) int p;", Style);
+
+  // Two in correct order already: no change.
+  verifyFormat("@property(a, b) int p;", Style);
+  verifyFormat("@property(a, c) int p;", Style);
+  verifyFormat("@property(b, c) int p;", Style);
+
+  // Three in correct order already: no change.
+  verifyFormat("@property(a, b, c) int p;", Style);
+
+  // Two wrong order.
+  verifyFormat("@property(a, b) int p;", "@property(b, a) int p;", Style);
+  verifyFormat("@property(a, c) int p;", "@property(c, a) int p;", Style);
+  verifyFormat("@property(b, c) int p;", "@property(c, b) int p;", Style);
+
+  // Three wrong order.
+  verifyFormat("@property(a, b, c) int p;", "@property(b, a, c) int p;", Style);
+  verifyFormat("@property(a, b, c) int p;", "@property(c, b, a) int p;", Style);
+
+  // Check that properties preceded by @optional/@required work.
+  verifyFormat("@optional\n"
+   "@property(a, b) int p;",
+  

[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-18 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb marked 7 inline comments as done.
jaredgrubb added inline comments.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:113
+
+  // Deduplicate the attributes.
+  Indices.erase(std::unique(Indices.begin(), Indices.end(),

owenpan wrote:
> jaredgrubb wrote:
> > owenpan wrote:
> > > Is it valid in Objective-C to have duplicate attributes?
> > It's silly, but clang doesn't seem to care. I tried this, so duplicate was 
> > ok, but contradiction was flagged:
> > ```
> > @property (strong, nonatomic, nonatomic) X *X;   // duplicate, but no error
> > @property (strong, nonatomic, weak) Y *y;   // error: Property attributes 
> > 'strong' and 'weak' are mutually exclusive
> > ```
> > 
> > I wasn't sure whether to do this, but went that way since that's what "sort 
> > include files" did. However, it seems like an odd corner case so I'd be ok 
> > removing this uniquing if you prefer.
> We should keep the duplicates if clang accepts them. What happens to e.g. 
> `@property(x=a, y=b, x=a, y=c)`?
Looks like clang does not reject duplicates like that either, even though I 
can't imagine that it results in anything sane:
```
@property (getter=Foo, getter=Bar) int x;
```

I'll remove the de-dup code as you request -- it'll make the pass simpler and 
marginally faster :)

For dup-cases where the values differ (eg, `y=b, y=c`), the pass will just 
stable-sort them. This is the simplest thing to do and IMO is good-enough as I 
think dup's are questionable anyway.

I've added some test cases for this (and removed the original de-dup test 
cases).

I'll add a couple unit tests to confirm this and include your example.



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:184
+  for (AnnotatedLine *Line : AnnotatedLines) {
+if (!Line->Affected || Line->InPPDirective)
+  continue;

owenpan wrote:
> jaredgrubb wrote:
> > owenpan wrote:
> > > Why not `InPPDirective`?
> > I copy-pasted this from `LeftRightQualifierAlignmentFixer::analyze`, which 
> > I used as a template since I'm still getting used to the codebase. I wasn't 
> > sure whether this was important, so I left it in. But I don't think I have 
> > a good reason. 
> > 
> > I've added a new test case `SortsInPPDirective` that spot-checks some macro 
> > definition examples (which did fail unless this `Line->InPPDirective` check 
> > was removed, as expected.).
> What about `Line->Type != LT_ObjCProperty` I suggested?
Ah, I missed that suggestion. 

I don't have enough understanding of clang-format to say whether that would be 
correct, but I'll trust you :) 

When I add this check it doesn't break unit tests or cause any 
change-in-behavior on my ObjC test repo (~10K .h/.m files). So, it -seems- like 
this is a valid check to add, so I'll do it!



Comment at: clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp:190
+  continue;
+
+const auto *Last = Line->Last;

owenpan wrote:
> jaredgrubb wrote:
> > owenpan wrote:
> > > Must `@property` be the first non-comment tokens of an unwrapped line in 
> > > Objective-C? And at most one `@property` per line?
> > I can't think of any token that should precede a `@property`. Aka, I don't 
> > think there are any `__attribute__` that can fill that slot. 
> > 
> > You could have `@optional` or `@required` floating around between 
> > property/method declarations. I've added a test-case for a `@property` that 
> > is preceded by these tokens and proved that the reordering is handled 
> > correctly.
> > 
> > As for multiple properties in one line, I've never seen a codebase with 
> > that. clang-format does split them already.
> I asked the questions because if yes, we could move on to the next line 
> before hitting the last token of the current line.
In testing, it seems that some other pass (not sure which) will split the line 
before this new pass sees it. So if I can rely on that (I think I can?), then 
we can early-break like you propose.

I've added a unit test to cover this scenario.


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

https://reviews.llvm.org/D150083

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


[clang] [clang codegen][regression] Add dso_local/hidden/etc. markings to VTT definitions and declarations (PR #72452)

2023-11-18 Thread via cfe-commits

bd1976bris wrote:

> I mean, looking at the code, as far as I can tell, we always call 
> GetAddrOfVTT immediately before EmitVTTDefinition, so setGVProperties() has 
> already run, so running it again shouldn't do anything... unless somehow 
> EmitVTTDefinition is overwriting the visibility, or setGVProperties() behaves 
> differently for declarations vs. definitions. If something like that is 
> happening, I'd like to explicitly document it.

Thanks for clarifying. Luckily a full understanding of the VTT emission isn't 
isn't needed to answer your question :)

When the visibility is applied via visibility attributes there is no difference 
for a definition or a declaration. However, for the visibility from 
-fvisibility=, the visibility is applied only to definitions and 
not to declarations. My understanding is that this is by design - so that 
system headers do not have to be marked with explicit visibility annotations.

You can see this in the code in setGlobalVisibility():

```
  if (LV.isVisibilityExplicit() || getLangOpts().SetVisibilityForExternDecls ||
  !GV->isDeclarationForLinker())
GV->setVisibility(GetLLVMVisibility(LV.getVisibility()));
```

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


[clang] a540808 - [CGObjCGNU] Remove unneeded method 'CGObjCGNUstep2::EnforceType' (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T14:06:45-06:00
New Revision: a540808de254b18b304aa0915638a0900b36d9fa

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

LOG: [CGObjCGNU] Remove unneeded method 'CGObjCGNUstep2::EnforceType' (NFC)

Method CGObjCGNUstep2::EnforceType is called from 2 call-sites to perform
bitcasts which are no-ops given that opaque pointers are enabled in LLVM.

Remove the method. Opaque ptr cleanup effort (NFC).

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index bd9e8b2b3bf..01fd8f5a00ee39f 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1421,11 +1421,6 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 Protocol = GV;
 return GV;
   }
-  llvm::Constant *EnforceType(llvm::Constant *Val, llvm::Type *Ty) {
-if (Val->getType() == Ty)
-  return Val;
-return llvm::ConstantExpr::getBitCast(Val, Ty);
-  }
   llvm::Value *GetTypedSelector(CodeGenFunction , Selector Sel,
 const std::string ) override {
 return GetConstantSelector(Sel, TypeEncoding);
@@ -1462,7 +1457,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" +
   MangledTypes).str();
 if (auto *GV = TheModule.getNamedGlobal(SelVarName))
-  return EnforceType(GV, SelectorTy);
+  return GV;
 ConstantInitBuilder builder(CGM);
 auto SelBuilder = builder.beginStruct();
 SelBuilder.add(ExportUniqueString(Sel.getAsString(), ".objc_sel_name_",
@@ -1473,8 +1468,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 GV->setComdat(TheModule.getOrInsertComdat(SelVarName));
 GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
 GV->setSection(sectionName());
-auto *SelVal = EnforceType(GV, SelectorTy);
-return SelVal;
+return GV;
   }
   llvm::StructType *emptyStruct = nullptr;
 



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


[clang] [Clang] Correct handling of negative and out-of-bounds indices (PR #71877)

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


@@ -827,6 +827,165 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const 
Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
+llvm::Value *
+CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type,
+ llvm::IntegerType *ResType) {

bwendling wrote:

I'll create a NFC patch that just does the refactoring and rebase this onto it.

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


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-18 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb added a comment.

In D150083#4656832 , @owenpan wrote:

> Thank you for your patience!

I appreciate the help :) I'm excited to get this in!

> In D150083#4655528 , @owenpan wrote:
>
>> See also D153228 .
>
> Would this patch have a similar performance issue?

Reading through the issue, I don't think so. As I understand that issue, the 
scale-problem is due to how the passes interact with one another as a whole 
(since that setting creates a Pass for _each_ qualifier). This ObjC pass uses 
only ONE pass to handle the ordering of all property attributes. I 
intentionally did not copy that part of the Qualifier pass because it didn't 
seem to actually help my use-case, which is much narrower (primarily that I 
only have to operate on lines that look like properties, not in arbitrary 
places like function args and variable declarations, etc.).

Please correct me if I missed something about that patch that could apply.


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

https://reviews.llvm.org/D150083

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


[libunwind] [compiler-rt] [libcxx] [mlir] [lldb] [lld] [flang] [clang-tools-extra] [libc] [libcxxabi] [llvm] [clang] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-18 Thread Todd A. Anderson via cfe-commits


@@ -17,6 +17,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GraphWriter.h"
 
+static std::vector nameObj;

DrTodd13 wrote:

I don't know if there is some LLVM code approach that would dictate what to do 
here.  We can have some kind of a data structure to remember names to try to 
avoid duplicates or we can accept that there may be duplicates but just make 
them probabilistically rare.  I guess I am leaning toward the latter where you 
do something like take up to a certain number of characters of the filename as 
they are but then you take the rest of the characters of the filename and hash 
them and add the hash to the filename.  This latter approach works even if you 
are going in and out of llvm whereas having a data structure to remember names 
would only work in the context of single execution of LLVM.  Again, that is 
just my opinion and I'm not sure what people with approval authority here will 
say.

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


[mlir] [lldb] [libc] [libcxxabi] [flang] [compiler-rt] [lld] [clang-tools-extra] [libcxx] [clang] [llvm] [libunwind] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-18 Thread Todd A. Anderson via cfe-commits


@@ -83,10 +85,29 @@ struct DOTGraphTraitsViewer
   StringRef Name;
 };
 
+static void shortenFileName(std::string , unsigned char len = 250) {
+
+  FN = FN.substr(0, len);
+  if (nameObj.empty())
+nameObj.push_back(FN);
+
+  else {
+for (auto it = nameObj.begin(); it != nameObj.end(); it++) {
+  if (*it == FN) {
+FN = FN.substr(0, --len);

DrTodd13 wrote:

Let's say that I have 3 filenames submitted in a row that share the same first 
250 characters.  Line 92 will add the first one truncated to 250.  Then, line 
97 will add the second one truncated to 249.  But then, for the third one, the 
first time through the nameObj list, it is going to match with the first name 
you added, decrement len by 1 and then add to nameObj.  So, I think the 2nd and 
3rd names in your list are going to be duplicates.

Maybe a more classic way of doing this would be to use a set instead of a list, 
check if the FN truncated to 250 is in the set and if not add it.  If it is 
then truncate to 249 and repeat the process of checking if it is in the set.  
Add if it isn't and if it is then truncate to 248 and keep repeating the 
process until it can be added.  Of course, this approach has the problem that 
if you have more than 250 names that shared the first 250 characters then len 
would go to 0 and you'd try to have a filename that was empty.  Then the 251st 
time you tried it you'd have a negative substr len.  If that is equivalent to 0 
len then you could end up in an infinite loop.

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


[llvm] [libc] [libunwind] [clang-tools-extra] [flang] [libcxxabi] [lldb] [mlir] [libcxx] [compiler-rt] [lld] [clang] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-18 Thread Todd A. Anderson via cfe-commits

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

I like the idea of that new function but I don't think it does what you 
intended.

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


[lld] [llvm] [clang-tools-extra] [lldb] [compiler-rt] [libunwind] [libc] [mlir] [clang] [libcxxabi] [libcxx] [flang] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-18 Thread Todd A. Anderson via cfe-commits

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread J. Ryan Stinnett via cfe-commits

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

> This patch makes sure we encode the constant in a `DIExpression` on 
> definitions, which is tested. And we have tests for ensuring that 
> `DW_OP_constu` expressions get turned into `DW_AT_const_value`s (I know of at 
> least `llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll`)

Ah okay, then with that in mind, I think the test changes here are likely 
enough to merge.  

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72730

>From 6dcb09dcc50a9b9e92640412242927b3e226929e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:20:05 +
Subject: [PATCH 1/5] [clang][DebugInfo][NFC] Create
 evaluateConstantInitializer helper function

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4840581b5d03f89 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,19 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext ) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
+  assert (VD != nullptr);
+
+  VD = VD->getCanonicalDecl();
+  if (!VD)
+return nullptr;
+
+  if (!VD->hasConstantInitialization() || !VD->hasInit())
+return nullptr;
+
+  return VD->evaluateValue();
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule )
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5609,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  auto const * InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From fcc6e19d108798fb18c1973e4d4cc3800da07f9f Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:52:24 +
Subject: [PATCH 2/5] fixup! clang-format

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4840581b5d03f89..9bba6e6b13e9318 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,8 +69,8 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext ) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
-  assert (VD != nullptr);
+APValue const *evaluateConstantInitializer(clang::VarDecl const *VD) {
+  assert(VD != nullptr);
 
   VD = VD->getCanonicalDecl();
   if (!VD)
@@ -5613,7 +5613,7 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const * InitVal = evaluateConstantInitializer(VD);
+  auto const *InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From 148ab1793a866111060f77807ff065040fad92d8 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:22:06 +
Subject: [PATCH 3/5] [clang][DebugInfo] Attach DW_AT_const_value to static
 data-member definitions if available

---
 clang/lib/CodeGen/CGDebugInfo.cpp  | 10 --
 .../CodeGenCXX/debug-info-static-inline-member.cpp |  2 +-
 clang/test/CodeGenCXX/inline-dllexport-member.cpp  |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9bba6e6b13e9318..e01c57baef19931 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5516,11 +5516,17 @@ void 
CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
 }
 AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+llvm::DIExpression *E = nullptr;
+if (Expr.empty()) {
+  if (auto const *InitVal = evaluateConstantInitializer(D))
+E = createConstantValueExpression(D, *InitVal);
+} else
+  E = DBuilder.createExpression(Expr);
+
 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
 GVE = DBuilder.createGlobalVariableExpression(
 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, 
Unit),
-Var->hasLocalLinkage(), true,
-Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
+Var->hasLocalLinkage(), true, E,
 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
 Align, Annotations);
 Var->addDebugInfo(GVE);
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..950ea9b302b290c 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -43,7 +43,7 @@ int main() {
 // CHECK:  @{{.*}}cexpr_struct_with_addr{{.*}} = 
 // CHECK-SAME!dbg ![[EMPTY_GLOBAL:[0-9]+]]
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: 
!DIExpression())
+// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], 

[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread Michael Buch via cfe-commits

Michael137 wrote:

> Overall this looks good, thanks!
> 
> I think we may want to add a test to check that the output DWARF has a const 
> value in the expected place, since consumers are relying on it.

Any suggestions where to put such end-to-end test?

This patch makes sure we encode the constant in a `DIExpression` on 
definitions, which is tested. And we have tests for ensuring that 
`DW_OP_constu` expressions get turned into `DW_AT_const_value`s (I know of at 
least `llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll`)

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


[clang] [clang-tools-extra] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Younan Zhang (zyn0217)


Changes

This reflects the comment in 
https://github.com/llvm/llvm-project/pull/71366#issuecomment-1817271492.

As that PR suggests, the invented CallExpr's source location previously pointed 
to the beginning of the `__builtin_dump_struct`. These spurious AST nodes 
confused clangd while displaying parameter inlay hints.

This patch takes another approach to address the same issue, by turning the 
location for each _argument_ within an invented call to printf to empty, 
(maybe) at the risk of breaking the invariant for CallExpr -- The source 
location for an argument could be invalid from now on.

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+27) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+3-3) 


``diff
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 20c1cdd985dbc01..47af261fad850e8 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1724,6 +1724,33 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for 
this ill-formed expression.
+};
+
+int printf(const char *Format, ...);
+
+int main() {
+  S s;
+  __builtin_dump_struct(, printf); // Not `Format: 
__builtin_dump_struct()`
+  printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
+  return s.x[ $two[[1]] ][ $three[[2]] ]; // `x[y: 1][z: 2]`
+}
+  )cpp");
+  auto TU = TestTU::withCode(Code.code());
+  TU.ExtraArgs.push_back("-fms-extensions");
+  auto AST = TU.build();
+  EXPECT_THAT(inlayHints(AST, std::nullopt),
+  ElementsAre(HintMatcher(ExpectedHint{"y: ", "one"}, Code),
+  HintMatcher(ExpectedHint{"Format: ", "Param"}, Code),
+  HintMatcher(ExpectedHint{"y: ", "two"}, Code),
+  HintMatcher(ExpectedHint{"z: ", "three"}, Code)));
+}
+
 TEST(ParameterHints, ArgPacksAndConstructors) {
   assertParameterHints(
   R"cpp(
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ae588db02bbe722..5d348bd712dd104 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -454,13 +454,13 @@ namespace {
 struct BuiltinDumpStructGenerator {
   Sema 
   CallExpr *TheCall;
-  SourceLocation Loc = TheCall->getBeginLoc();
+  SourceLocation Loc;
   SmallVector Actions;
   DiagnosticErrorTrap ErrorTracker;
   PrintingPolicy Policy;
 
   BuiltinDumpStructGenerator(Sema , CallExpr *TheCall)
-  : S(S), TheCall(TheCall), ErrorTracker(S.getDiagnostics()),
+  : S(S), TheCall(TheCall), Loc(), ErrorTracker(S.getDiagnostics()),
 Policy(S.Context.getPrintingPolicy()) {
 Policy.AnonymousTagLocations = false;
   }
@@ -491,7 +491,7 @@ struct BuiltinDumpStructGenerator {
 // Register a note to explain why we're performing the call.
 Sema::CodeSynthesisContext Ctx;
 Ctx.Kind = Sema::CodeSynthesisContext::BuildingBuiltinDumpStructCall;
-Ctx.PointOfInstantiation = Loc;
+Ctx.PointOfInstantiation = TheCall->getBeginLoc();
 Ctx.CallArgs = Args.data();
 Ctx.NumCallArgs = Args.size();
 S.pushCodeSynthesisContext(Ctx);

``




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


[clang] [clang-tools-extra] [clang] Turn invented Exprs' source locations in __builtin_dump_struct to empty (PR #72750)

2023-11-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/72750

This reflects the comment in 
https://github.com/llvm/llvm-project/pull/71366#issuecomment-1817271492.

As that PR suggests, the invented CallExpr's source location previously pointed 
to the beginning of the `__builtin_dump_struct`. These spurious AST nodes 
confused clangd while displaying parameter inlay hints.

This patch takes another approach to address the same issue, by turning the 
location for each _argument_ within an invented call to printf to empty, 
(maybe) at the risk of breaking the invariant for CallExpr -- The source 
location for an argument could be invalid from now on.

>From cf12f37b477e53f60f22bbdd23eb44a1d0c9b91f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 6 Nov 2023 16:50:02 +0800
Subject: [PATCH] [clang] Turn invented Exprs' source locations in
 __builtin_dump_struct to empty

This reflects the comment in
https://github.com/llvm/llvm-project/pull/71366#issuecomment-1817271492.

As that PR suggests, the invented CallExpr's source location previously
pointed to the beginning of the __builtin_dump_struct. These spurious
AST nodes confused clangd while displaying parameter inlay hints.

This patch takes another approach to address the same issue, by turning
the location for each _argument_ within an invented call to printf to empty,
(maybe) at the risk of breaking the invariant for CallExpr -- The source
location for an argument could be invalid from now on.
---
 .../clangd/unittests/InlayHintTests.cpp   | 27 +++
 clang/lib/Sema/SemaChecking.cpp   |  6 ++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 20c1cdd985dbc01..47af261fad850e8 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1724,6 +1724,33 @@ TEST(InlayHints, RestrictRange) {
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, PseudoObjectExpr) {
+  Annotations Code(R"cpp(
+struct S {
+  __declspec(property(get=GetX, put=PutX)) int x[];
+  int GetX(int y, int z) { return 42 + y; }
+  void PutX(int y) { x = $one[[y]]; } // FIXME: Undesired `x = y: y` for 
this ill-formed expression.
+};
+
+int printf(const char *Format, ...);
+
+int main() {
+  S s;
+  __builtin_dump_struct(, printf); // Not `Format: 
__builtin_dump_struct()`
+  printf($Param[["Hello, %d"]], 42); // Normal calls are not affected.
+  return s.x[ $two[[1]] ][ $three[[2]] ]; // `x[y: 1][z: 2]`
+}
+  )cpp");
+  auto TU = TestTU::withCode(Code.code());
+  TU.ExtraArgs.push_back("-fms-extensions");
+  auto AST = TU.build();
+  EXPECT_THAT(inlayHints(AST, std::nullopt),
+  ElementsAre(HintMatcher(ExpectedHint{"y: ", "one"}, Code),
+  HintMatcher(ExpectedHint{"Format: ", "Param"}, Code),
+  HintMatcher(ExpectedHint{"y: ", "two"}, Code),
+  HintMatcher(ExpectedHint{"z: ", "three"}, Code)));
+}
+
 TEST(ParameterHints, ArgPacksAndConstructors) {
   assertParameterHints(
   R"cpp(
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ae588db02bbe722..5d348bd712dd104 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -454,13 +454,13 @@ namespace {
 struct BuiltinDumpStructGenerator {
   Sema 
   CallExpr *TheCall;
-  SourceLocation Loc = TheCall->getBeginLoc();
+  SourceLocation Loc;
   SmallVector Actions;
   DiagnosticErrorTrap ErrorTracker;
   PrintingPolicy Policy;
 
   BuiltinDumpStructGenerator(Sema , CallExpr *TheCall)
-  : S(S), TheCall(TheCall), ErrorTracker(S.getDiagnostics()),
+  : S(S), TheCall(TheCall), Loc(), ErrorTracker(S.getDiagnostics()),
 Policy(S.Context.getPrintingPolicy()) {
 Policy.AnonymousTagLocations = false;
   }
@@ -491,7 +491,7 @@ struct BuiltinDumpStructGenerator {
 // Register a note to explain why we're performing the call.
 Sema::CodeSynthesisContext Ctx;
 Ctx.Kind = Sema::CodeSynthesisContext::BuildingBuiltinDumpStructCall;
-Ctx.PointOfInstantiation = Loc;
+Ctx.PointOfInstantiation = TheCall->getBeginLoc();
 Ctx.CallArgs = Args.data();
 Ctx.NumCallArgs = Args.size();
 S.pushCodeSynthesisContext(Ctx);

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread J. Ryan Stinnett via cfe-commits


@@ -5503,11 +5516,17 @@ void 
CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
 }
 AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+llvm::DIExpression *E = nullptr;
+if (Expr.empty()) {
+  if (auto const *InitVal = evaluateConstantInitializer(D))
+E = createConstantValueExpression(D, *InitVal);
+} else

jryans wrote:

I believe code style says this else block should use braces because the if 
block has them.

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread J. Ryan Stinnett via cfe-commits

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-18 Thread J. Ryan Stinnett via cfe-commits

https://github.com/jryans commented:

Overall this looks good, thanks!

I think we may want to add a test to check that the output DWARF has a const 
value in the expected place, since consumers are relying on it.

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


[clang-tools-extra] f9974f7 - [clang-tidy] Improve alternate snake case warnings (#71385)

2023-11-18 Thread via cfe-commits

Author: J.C. Moyer
Date: 2023-11-18T14:23:36+01:00
New Revision: f9974f7fe15a9e97ceb7514d437bef6ee46ccc38

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

LOG: [clang-tidy] Improve alternate snake case warnings (#71385)

Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
cases matched identifiers with **only** a leading upper case letter or
leading lower case letter respectively. Now, uppercase letters can only
appear at the start of an identifier or directly following an
underscore.

---

Currently, the regex for `Camel_Snake_Case` matches any identifier that
starts with a capital letter:

```
^[A-Z]([a-z0-9]*(_[A-Z])?)*
^-- underscore + capital letter after the first capital 
is optional
```

This means that `Camel_Snake_Case` matches other cases - in particular
`CamelCase` and `Leading_upper_snake_case` - which causes clang-tidy to
sometimes not flag incorrect casing. It also matches `UPPER_CASE`, but I
think it's reasonable to consider this a subset of `Camel_Snake_Case`
since some users may prefer e.g. `XML_Parser` to `Xml_Parser`. It's
really easy to accidentally type an identifier that clang-tidy doesn't
catch; all you have to do is omit an underscore or forget to capitalize
a letter. The same problem also applies to `camel_Snake_Back` except
that any identifier starting with a lower case letter matches, so I went
ahead and adjusted its regex too. Fixing it also uncovered a minor error
in an existing test.

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 066057fa7208d55..18c5e144e46fe77 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -872,8 +872,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
   };
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 23111be4371e2e1..6d5f49dc0625451 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -416,7 +416,8 @@ Changes in existing checks
   ``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
   has been enhanced, particularly within complex types like function pointers
   and cases where style checks were omitted when functions started with macros.
-  Added support for C++20 ``concept`` declarations.
+  Added support for C++20 ``concept`` declarations. ``Camel_Snake_Case`` and
+  ``camel_Snake_Case`` now detect more invalid identifier names.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
new file mode 100644
index 000..f692b01923455e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
+// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
+// RUN:   }}'
+
+// clang-format off
+
+//===--===//
+// Camel_Snake_Case tests
+//===--===//
+class XML_Parser {};
+class Xml_Parser {};
+class XML_Parser_2 {};
+// NO warnings or fixes expected as these identifiers are Camel_Snake_Case
+
+class XmlParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'XmlParser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class Xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 

[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-18 Thread Piotr Zegar via cfe-commits

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -24153,6 +24153,113 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   verifyNoChange("FOO(String-ized+But: :Still=Intentional);", Style);
 }
 
+TEST_F(FormatTest, IgnorePPDefinitions) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IgnorePPDefinitions = true;
+
+  verifyNoChange("#define  A", Style);
+  verifyNoChange("#define A   b", Style);
+  verifyNoChange("#define A  (  args   )", Style);
+  verifyNoChange("#define A  (  args   )  =  func  (  args  )", Style);
+
+  verifyNoChange("#define A x:", Style);
+  verifyNoChange("#define A a. b", Style);
+
+  // Surrounded with formatted code.
+  verifyFormat("int a;\n"
+   "#define  A  a\n"
+   "int a;",
+   "int  a ;\n"

tomekpaszek wrote:

This practical line is the start of the code that should be formatted. The 
expected output starts 3 lines above

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits

https://github.com/tomekpaszek commented:

>Something here doesn't feel right

Could you be more specific?

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -24206,10 +24206,11 @@ TEST_F(FormatTest, IgnorePPDefinitions) {
   Style.IndentPPDirectives = FormatStyle::PPDIS_None;
   verifyNoChange("#if A\n"
  "#define A  a\n"
- "#endif",
+ "#endif\n",

tomekpaszek wrote:

no reason. removed the trailing line breaks now

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -1134,6 +1134,14 @@ void UnwrappedLineParser::parsePPDefine() {
 return;
   }
 
+  if (Style.IgnorePPDefinitions) {
+do {
+  nextToken();
+} while (!eof());

tomekpaszek wrote:

In this case, `eof` is a marker for the end of the unwrapped line that is being 
parsed. It's a pattern used in other parts of the file. 

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)

tomekpaszek wrote:

Yes, a good catch. Fixed is now and added a test case for it

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -24153,6 +24153,113 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   verifyNoChange("FOO(String-ized+But: :Still=Intentional);", Style);
 }
 
+TEST_F(FormatTest, IgnorePPDefinitions) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IgnorePPDefinitions = true;
+
+  verifyNoChange("#define  A", Style);
+  verifyNoChange("#define A   b", Style);
+  verifyNoChange("#define A  (  args   )", Style);
+  verifyNoChange("#define A  (  args   )  =  func  (  args  )", Style);
+
+  verifyNoChange("#define A x:", Style);
+  verifyNoChange("#define A a. b", Style);
+
+  // Surrounded with formatted code.
+  verifyFormat("int a;\n"
+   "#define  A  a\n"
+   "int a;",
+   "int  a ;\n"

tomekpaszek wrote:

Not sure what are you referring to in this case

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits


@@ -1355,8 +1355,11 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
-if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective 
&&
+TheLine.getFirstNonComment()->Next->is(tok::pp_define)) {

tomekpaszek wrote:

Good point, better safe than sorry. I've refactored the condition in the next 
changeset.

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-18 Thread via cfe-commits

https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From b5ba0b3fde2c6662e19dfdf96a787621ec767460 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 01/10] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..3af7241441c8b13 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2442,6 +2442,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4719,6 +4723,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edb33f4af4defef..6e5ec754dfdcdd9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1000,6 +1000,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1504,6 +1505,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index f90ed178d99c286..110df624d44573c 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -166,6 +166,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -198,7 +199,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b2d84f2ee389551..659132dcb9c3970 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24153,6 +24153,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   

[compiler-rt] [libcxx] [flang] [clang-tools-extra] [llvm] [clang] [libc] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-18 Thread via cfe-commits

https://github.com/thyecust updated 
https://github.com/llvm/llvm-project/pull/72257

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

>From bcb3f98540cefc570432e541a929b61e9b89e08d Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:09:16 +0800
Subject: [PATCH 3/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 0123730d8ff9798..257fb19e0fcfeb9 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static isBuiltinUnreachable(const Stmt *S) {
+static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&

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


[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

We used to assume that the CXXRecordDecl passed to the 1st argument always had 
a definition. This is not true since a pointer to an incomplete type was not 
excluded.

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


4 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1-1) 
- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5) 
- (modified) clang/test/SemaCXX/builtin-dump-struct.cpp (+4) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 30e288f986782fd..e80a096357b1deb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2809,7 +2809,7 @@ Example output:
 
 The ``__builtin_dump_struct`` function is used to print the fields of a simple
 structure and their values for debugging purposes. The first argument of the
-builtin should be a pointer to the struct to dump. The second argument ``f``
+builtin should be a pointer to a complete record type to dump. The second 
argument ``f``
 should be some callable expression, and can be a function object or an overload
 set. The builtin calls ``f``, passing any further arguments ``args...``
 followed by a ``printf``-compatible format string and the corresponding
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 74358219ba9fb22..f2903c1684dcb60 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -691,6 +691,9 @@ Bug Fixes to C++ Support
   Fixes:
   (`#68769 `_)
 
+- Clang now rejects incomplete types for ``__builtin_dump_struct``. Fixes:
+  (`#63506 `_)
+
 - Clang now defers the instantiation of explicit specifier until constraint 
checking
   completes (except deduction guides). Fixes:
   (`#59827 `_)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ae588db02bbe722..20ff3ce722da80a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -713,6 +713,11 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 return ExprError();
   }
   const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
+  if (!RD->isCompleteDefinition()) {
+S.Diag(PtrArgResult.get()->getBeginLoc(), diag::err_incomplete_type)
+<< PtrArgType->getPointeeType();
+return ExprError();
+  }
 
   // Second argument is a callable, but we can't fully validate it until we try
   // calling it.
diff --git a/clang/test/SemaCXX/builtin-dump-struct.cpp 
b/clang/test/SemaCXX/builtin-dump-struct.cpp
index b3d2a2d808ce267..477bbcf07a41fa4 100644
--- a/clang/test/SemaCXX/builtin-dump-struct.cpp
+++ b/clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -149,7 +149,10 @@ B {
 }
 )"[1]);
 
+class Incomplete;
+
 void errors(B b) {
+  ConstexprString cs;
   __builtin_dump_struct(); // expected-error {{too few arguments to function 
call, expected 2, have 0}}
   __builtin_dump_struct(1); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
   __builtin_dump_struct(1, 2); // expected-error {{expected pointer to struct 
as 1st argument to '__builtin_dump_struct', found 'int'}}
@@ -157,6 +160,7 @@ void errors(B b) {
   __builtin_dump_struct(, Format, 0); // expected-error {{no matching 
function for call to 'Format'}}
 // expected-note@-1 {{in call to 
printing function with arguments '(0, "%s", "B")' while dumping struct}}
 // expected-note@#Format {{no known 
conversion from 'int' to 'ConstexprString &' for 1st argument}}
+  __builtin_dump_struct((Incomplete *)nullptr, Format, cs); // expected-error 
{{incomplete type 'Incomplete' where a complete type is required}}
 }
 #endif
 

``




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


[clang] [clang] Reject incomplete type arguments for __builtin_dump_struct (PR #72749)

2023-11-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/72749

We used to assume that the CXXRecordDecl passed to the 1st argument always had 
a definition. This is not true since a pointer to an incomplete type was not 
excluded.

>From d23305db7faba1ed1464aeee6d9e0f2ee1994226 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 6 Nov 2023 16:50:02 +0800
Subject: [PATCH] [clang] Reject incomplete type arguments for
 __builtin_dump_struct

We used to assume that the CXXRecordDecl passed to the 1st argument
always had a definition. This is not true since a pointer to an
incomplete type was not excluded.
---
 clang/docs/LanguageExtensions.rst  | 2 +-
 clang/docs/ReleaseNotes.rst| 3 +++
 clang/lib/Sema/SemaChecking.cpp| 5 +
 clang/test/SemaCXX/builtin-dump-struct.cpp | 4 
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 30e288f986782fd..e80a096357b1deb 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2809,7 +2809,7 @@ Example output:
 
 The ``__builtin_dump_struct`` function is used to print the fields of a simple
 structure and their values for debugging purposes. The first argument of the
-builtin should be a pointer to the struct to dump. The second argument ``f``
+builtin should be a pointer to a complete record type to dump. The second 
argument ``f``
 should be some callable expression, and can be a function object or an overload
 set. The builtin calls ``f``, passing any further arguments ``args...``
 followed by a ``printf``-compatible format string and the corresponding
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 74358219ba9fb22..f2903c1684dcb60 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -691,6 +691,9 @@ Bug Fixes to C++ Support
   Fixes:
   (`#68769 `_)
 
+- Clang now rejects incomplete types for ``__builtin_dump_struct``. Fixes:
+  (`#63506 `_)
+
 - Clang now defers the instantiation of explicit specifier until constraint 
checking
   completes (except deduction guides). Fixes:
   (`#59827 `_)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ae588db02bbe722..20ff3ce722da80a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -713,6 +713,11 @@ static ExprResult SemaBuiltinDumpStruct(Sema , CallExpr 
*TheCall) {
 return ExprError();
   }
   const RecordDecl *RD = PtrArgType->getPointeeType()->getAsRecordDecl();
+  if (!RD->isCompleteDefinition()) {
+S.Diag(PtrArgResult.get()->getBeginLoc(), diag::err_incomplete_type)
+<< PtrArgType->getPointeeType();
+return ExprError();
+  }
 
   // Second argument is a callable, but we can't fully validate it until we try
   // calling it.
diff --git a/clang/test/SemaCXX/builtin-dump-struct.cpp 
b/clang/test/SemaCXX/builtin-dump-struct.cpp
index b3d2a2d808ce267..477bbcf07a41fa4 100644
--- a/clang/test/SemaCXX/builtin-dump-struct.cpp
+++ b/clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -149,7 +149,10 @@ B {
 }
 )"[1]);
 
+class Incomplete;
+
 void errors(B b) {
+  ConstexprString cs;
   __builtin_dump_struct(); // expected-error {{too few arguments to function 
call, expected 2, have 0}}
   __builtin_dump_struct(1); // expected-error {{too few arguments to function 
call, expected 2, have 1}}
   __builtin_dump_struct(1, 2); // expected-error {{expected pointer to struct 
as 1st argument to '__builtin_dump_struct', found 'int'}}
@@ -157,6 +160,7 @@ void errors(B b) {
   __builtin_dump_struct(, Format, 0); // expected-error {{no matching 
function for call to 'Format'}}
 // expected-note@-1 {{in call to 
printing function with arguments '(0, "%s", "B")' while dumping struct}}
 // expected-note@#Format {{no known 
conversion from 'int' to 'ConstexprString &' for 1st argument}}
+  __builtin_dump_struct((Incomplete *)nullptr, Format, cs); // expected-error 
{{incomplete type 'Incomplete' where a complete type is required}}
 }
 #endif
 

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-18 Thread J.C. Moyer via cfe-commits

jcmoyer wrote:

@PiotrZSL I don't mind but I changed it just in case it's an issue.

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-18 Thread J.C. Moyer via cfe-commits

https://github.com/jcmoyer updated 
https://github.com/llvm/llvm-project/pull/71385

>From 09c49dca700a5c01bee96765f1eede1808540af4 Mon Sep 17 00:00:00 2001
From: "J.C. Moyer" 
Date: Sat, 18 Nov 2023 07:06:07 -0500
Subject: [PATCH] [clang-tidy] Improve alternate snake case warnings

Improves the accuracy of `readability-identifier-naming` for cases
`Camel_Snake_Case` and `camel_Snake_Back`. Prior to this commit, these
cases matched identifiers with only a leading upper case letter or
leading lower case letter respectively. Now, uppercase letters can only
appear at the start of an identifier or directly following an
underscore.
---
 .../readability/IdentifierNamingCheck.cpp |  4 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../identifier-naming-case-match.cpp  | 60 +++
 .../readability/identifier-naming.cpp |  3 +-
 4 files changed, 66 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 066057fa7208d55..18c5e144e46fe77 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -872,8 +872,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),
   };
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f49c412118e7d98..3e8f77f9e00566d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -405,7 +405,8 @@ Changes in existing checks
   ``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
   has been enhanced, particularly within complex types like function pointers
   and cases where style checks were omitted when functions started with macros.
-  Added support for C++20 ``concept`` declarations.
+  Added support for C++20 ``concept`` declarations. ``Camel_Snake_Case`` and
+  ``camel_Snake_Case`` now detect more invalid identifier names.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
new file mode 100644
index 000..f692b01923455e8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-match.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: { \
+// RUN: readability-identifier-naming.ClassCase: Camel_Snake_Case, \
+// RUN: readability-identifier-naming.StructCase: camel_Snake_Back, \
+// RUN:   }}'
+
+// clang-format off
+
+//===--===//
+// Camel_Snake_Case tests
+//===--===//
+class XML_Parser {};
+class Xml_Parser {};
+class XML_Parser_2 {};
+// NO warnings or fixes expected as these identifiers are Camel_Snake_Case
+
+class XmlParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'XmlParser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class Xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'Xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Parser'
+// CHECK-FIXES: {{^}}class Xml_Parser {};{{$}}
+
+class xml_Parser_2 {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'xml_Parser_2'
+// CHECK-FIXES: {{^}}class Xml_Parser_2 {};{{$}}
+
+class t {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 't'
+// CHECK-FIXES: {{^}}class T {};{{$}}
+
+//===--===//
+// camel_Snake_Back tests
+//===--===//
+struct json_Parser {};
+struct json_Parser_2 {};
+struct u {};
+// NO warnings or fixes expected as these identifiers are camel_Snake_Back
+
+struct JsonParser {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: 

[clang-tools-extra] [libc] [lldb] [compiler-rt] [mlir] [flang] [libunwind] [libcxxabi] [clang] [llvm] [libcxx] [lld] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-18 Thread Shahid Iqbal via cfe-commits

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

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

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

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

>From 7662d4f177d32c3159c1c48b11ce3884e4ea78c8 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:26:31 -0500
Subject: [PATCH 2/5] PR#72453 : Exceeding maximum file name length

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index 07c08bc1cc3bcb6..f78d8ff52ee3932 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -17,6 +17,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GraphWriter.h"
 
+#define MAX_FILENAME_LEN 255
+
 namespace llvm {
 
 /// Default traits class for extracting a graph from an analysis pass.
@@ -94,7 +96,7 @@ void printGraphForFunction(Function , GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -280,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC)
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -310,7 +312,7 @@ void WriteDOTGraphToFile(Function , GraphT &,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple, Title);
   else
 errs() << "  error opening file for writing!";

>From d3d33e5bfe907b761ecb9065fe45b698c3ce0672 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:48:43 -0500
Subject: [PATCH 3/5] Reverted the earlier test text

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

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

>From 41c19e2ceee80cce8a60d0fd869958a0783ddb7f Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 10:06:52 -0500
Subject: [PATCH 4/5] Code refactoring

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index f78d8ff52ee3932..f7ab6df3b4dd819 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -96,7 +96,7 @@ void printGraphForFunction(Function , GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -282,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -312,7 +312,7 @@ void WriteDOTGraphToFile(Function , GraphT &,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC && (Filename.length() <= MAX_FILENAME_LEN 

[lldb] [flang] [clang] [llvm] [compiler-rt] [clang-tools-extra] [mlir] [CodeGen][DebugInfo] Add missing debug info for jump table BB (PR #71021)

2023-11-18 Thread via cfe-commits

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


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-18 Thread Koute via Phabricator via cfe-commits
koute added a comment.

Sorry for the comment spam, but could we please get this merged in finally? (:

To people who hold the decision making power as to whether this is merged: are 
there still any blockers left, considering the consensus was to merge it? 
What's the hold up? Is there anything I can do to help?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[flang] [clang-tools-extra] [lldb] [clang] [llvm] [mlir] [compiler-rt] [CodeGen][DebugInfo] Add missing debug info for jump table BB (PR #71021)

2023-11-18 Thread via cfe-commits

HaohaiWen wrote:

Thanks!

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


[clang] b4db24e - [CGOpenMPRuntimeGPU] Replace unneeded use of CreatePointerBitCastOrAddrSpaceCast (NFC)

2023-11-18 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2023-11-18T04:17:46-06:00
New Revision: b4db24e33008660d11d703c19d8affaf5f9a843e

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

LOG: [CGOpenMPRuntimeGPU] Replace unneeded use of 
CreatePointerBitCastOrAddrSpaceCast (NFC)

Opaque ptr cleanup effort (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index abecf5250f4cf96..2f7dd83bd2d65c9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1418,9 +1418,7 @@ static llvm::Value *castValueToType(CodeGenFunction , 
llvm::Value *Val,
 return CGF.Builder.CreateIntCast(Val, LLVMCastTy,
  CastTy->hasSignedIntegerRepresentation());
   Address CastItem = CGF.CreateMemTemp(CastTy);
-  Address ValCastItem = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  CastItem, Val->getType()->getPointerTo(CastItem.getAddressSpace()),
-  Val->getType());
+  Address ValCastItem = CastItem.withElementType(Val->getType());
   CGF.EmitStoreOfScalar(Val, ValCastItem, /*Volatile=*/false, ValTy,
 LValueBaseInfo(AlignmentSource::Type),
 TBAAAccessInfo());



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


[clang] [Clang][InstrProf] Allow mix-up of absolute path with relative path on command line when using -fprofile-list= (PR #67519)

2023-11-18 Thread Shivam Gupta via cfe-commits

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


[clang] [Clang][InstrProf] Allow mix-up of absolute path with relative path on command line when using -fprofile-list= (PR #67519)

2023-11-18 Thread Shivam Gupta via cfe-commits

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


[clang] [Clang][InstrProf] Allow mix-up of absolute path with relative path on command line when using -fprofile-list= (PR #67519)

2023-11-18 Thread Shivam Gupta via cfe-commits


@@ -4,7 +4,8 @@
 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FILE
+// RUN: cd %S
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm profile-filter.c 
-o - | FileCheck %s --check-prefix=FILE

xgupta wrote:

Shall I close this PR or it continue in case it will be useful for someone else?

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


[clang] [Clang][InstrProf] Allow mix-up of absolute path with relative path on command line when using -fprofile-list= (PR #67519)

2023-11-18 Thread Shivam Gupta via cfe-commits


@@ -4,7 +4,8 @@
 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FILE
+// RUN: cd %S
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm profile-filter.c 
-o - | FileCheck %s --check-prefix=FILE

xgupta wrote:

Yes, I misunderstood the concept wrt ninja build and fun.list. Only 
modification is required in fun.list to supply full path, not required to 
update ProfileList.cpp

 Apologies for taking so much time to realize this simple concept. 

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


[clang] [Clang][InstrProf] Allow mix-up of absolute path with relative path on command line when using -fprofile-list= (PR #67519)

2023-11-18 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/67519

>From a7f4b08b54350ebbe4b115214a84669eb69aee3e Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 18:20:05 +0530
Subject: [PATCH] [Clang][InstrProf] Allow absolute path in fun.list of
 -fprofile-list=

---
 clang/lib/Basic/ProfileList.cpp | 9 +
 clang/test/CodeGen/profile-filter.c | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 8fa16e2eb069a52..3dc01096a69e2ef 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -146,5 +146,14 @@ ProfileList::isFileExcluded(StringRef FileName,
 return Forbid;
   if (SCL->inSection(Section, "src", FileName))
 return Allow;
+  // Convert the input file path to its canonical (absolute) form
+  llvm::SmallString<128> CanonicalFileName(FileName);
+  llvm::sys::fs::make_absolute(CanonicalFileName);
+  if (auto V = inSection(Section, "source", CanonicalFileName))
+return V;
+  if (SCL->inSection(Section, "!src", CanonicalFileName))
+return Forbid;
+  if (SCL->inSection(Section, "src", CanonicalFileName))
+return Allow;
   return std::nullopt;
 }
diff --git a/clang/test/CodeGen/profile-filter.c 
b/clang/test/CodeGen/profile-filter.c
index e33e4a0a60b3d4f..86ee79c04747101 100644
--- a/clang/test/CodeGen/profile-filter.c
+++ b/clang/test/CodeGen/profile-filter.c
@@ -6,6 +6,9 @@
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | 
FileCheck %s --check-prefix=FILE
 
+// RUN: cd %S
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm profile-filter.c 
-o - | FileCheck %s --check-prefix=FILE
+
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION
 

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


[clang] [Driver] Simply some gcc search logic (PR #72558)

2023-11-18 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver] Simply some gcc search logic (PR #72558)

2023-11-18 Thread Fangrui Song via cfe-commits

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


[clang] [Driver] Simply some gcc search logic (PR #72558)

2023-11-18 Thread Fangrui Song via cfe-commits


@@ -2117,14 +2117,17 @@ void Generic_GCC::GCCInstallationDetector::init(
   // The compatible GCC triples for this particular architecture.
   SmallVector CandidateTripleAliases;
   SmallVector CandidateBiarchTripleAliases;
+  // Add some triples that we want to check first.
+  CandidateTripleAliases.push_back(TargetTriple.str());
+  std::string TripleNoVendor = TargetTriple.getArchName().str() + "-" +
+   TargetTriple.getOSAndEnvironmentName().str();
+  if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
+CandidateTripleAliases.push_back(TripleNoVendor);
+  }

MaskRay wrote:

drop braces

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