[clang] [llvm] [WIP][AMDGPU] Enable hostcall printf for OpenCL (PR #70932)

2023-11-01 Thread Vikram Hegde via cfe-commits

https://github.com/vikramRH updated 
https://github.com/llvm/llvm-project/pull/70932

>From 4c0467078b2f38e814569ad351f86129d1c1d5ee Mon Sep 17 00:00:00 2001
From: Vikram 
Date: Wed, 4 Oct 2023 05:41:47 -0400
Subject: [PATCH] [WIP][AMDGPU] hostcall printf support for OpenCL

---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   8 +
 clang/include/clang/Basic/TargetOptions.h |  10 +-
 clang/include/clang/Driver/Options.td |   8 +-
 clang/lib/AST/Decl.cpp|   7 +
 clang/lib/Basic/Targets/AMDGPU.cpp|   2 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   8 +-
 clang/lib/CodeGen/CGGPUBuiltin.cpp|  27 ++-
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  10 +
 .../CodeGenHIP/printf-kind-module-flag.hip|   6 +-
 clang/test/CodeGenOpenCL/amdgpu-printf.cl | 205 +-
 .../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp | 135 +++-
 12 files changed, 359 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 532a91fd903e87c..b5e8be145b03a0d 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -21,6 +21,10 @@
 #if defined(BUILTIN) && !defined(TARGET_BUILTIN)
 #   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
+
+#if defined(BUILTIN) && !defined(LANGBUILTIN)
+#define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
+#endif
 
//===--===//
 // SI+ only builtins.
 
//===--===//
@@ -402,5 +406,9 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
 
+// OpenCL
+LANGBUILTIN(printf, "icC*4.", "fp:0:", ALL_OCL_LANGUAGES)
+
 #undef BUILTIN
 #undef TARGET_BUILTIN
+#undef LANGBUILTIN
diff --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index 8bb03249b7f8308..8ff07783b0dd5d1 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -92,16 +92,20 @@ class TargetOptions {
 
   /// \brief Enumeration values for AMDGPU printf lowering scheme
   enum class AMDGPUPrintfKind {
+/// Use deafult lowering scheme, HIP programs use hostcall and OpenCL uses
+/// buffered by default,
+None = 0,
+
 /// printf lowering scheme involving hostcalls, currently used by HIP
 /// programs by default
-Hostcall = 0,
+Hostcall = 1,
 
 /// printf lowering scheme involving implicit printf buffers,
-Buffered = 1,
+Buffered = 2,
   };
 
   /// \brief AMDGPU Printf lowering scheme
-  AMDGPUPrintfKind AMDGPUPrintfKindVal = AMDGPUPrintfKind::Hostcall;
+  AMDGPUPrintfKind AMDGPUPrintfKindVal = AMDGPUPrintfKind::None;
 
   // The code model to be used as specified by the user. Corresponds to
   // CodeModel::Model enum defined in include/llvm/Support/CodeGen.h, plus
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b1229b2f4562379..d62cfe8961db90a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1251,15 +1251,17 @@ def emit_static_lib : Flag<["--"], "emit-static-lib">,
 
 def mprintf_kind_EQ : Joined<["-"], "mprintf-kind=">, Group,
   HelpText<"Specify the printf lowering scheme (AMDGPU only), allowed values 
are "
+  "\"none\" (Use default lowering scheme for a language, HIP uses hostcalls 
and "
+  "OpenCL uses Buffered scheme), "
   "\"hostcall\"(printing happens during kernel execution, this scheme "
   "relies on hostcalls which require system to support pcie atomics) "
   "and \"buffered\"(printing happens after all kernel threads exit, "
   "this uses a printf buffer and does not rely on pcie atomic support)">,
   Visibility<[ClangOption, CC1Option]>,
-  Values<"hostcall,buffered">,
+  Values<"none,hostcall,buffered">,
   NormalizedValuesScope<"TargetOptions::AMDGPUPrintfKind">,
-  NormalizedValues<["Hostcall", "Buffered"]>,
-  MarshallingInfoEnum, "Hostcall">;
+  NormalizedValues<["None", "Hostcall", "Buffered"]>,
+  MarshallingInfoEnum, "None">;
 
 // HIP options
 let Group = hip_Group in {
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 6efc177d61c03ba..b99376e42b8e7ba 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -49,6 +49,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Visibility.h"
@@ -3585,6 +3586,12 @@ unsigned Functio

[clang] [clang][analyzer]][NFC] Simplify method 'ensureStreamNonNull' of StreamChecker (PR #70927)

2023-11-01 Thread Ben Shi via cfe-commits

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


[clang] e98f3bf - [clang][analyzer]][NFC] Simplify method 'ensureStreamNonNull' of StreamChecker (#70927)

2023-11-01 Thread via cfe-commits

Author: Ben Shi
Date: 2023-11-02T14:41:33+08:00
New Revision: e98f3bfff2c499e76ce8784ea15cedbfb83b33bf

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

LOG: [clang][analyzer]][NFC] Simplify method 'ensureStreamNonNull' of 
StreamChecker (#70927)

The passed in parameter 'State' is always identical to 'C.getState()'.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 4b7103c20557cc4..a5f8d855f8e06e1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1037,7 +1037,7 @@ StreamChecker::ensureStreamNonNull(SVal StreamVal, const 
Expr *StreamE,
   ConstraintManager &CM = C.getConstraintManager();
 
   ProgramStateRef StateNotNull, StateNull;
-  std::tie(StateNotNull, StateNull) = CM.assumeDual(C.getState(), *Stream);
+  std::tie(StateNotNull, StateNull) = CM.assumeDual(State, *Stream);
 
   if (!StateNotNull && StateNull) {
 if (ExplodedNode *N = C.generateErrorNode(StateNull)) {



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


[clang] [llvm] [WIP][AMDGPU] Enable hostcall printf for OpenCL (PR #70932)

2023-11-01 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

@arsenm, The choice of defaults is based on current state of printf.  HIP uses 
hostcalls and OpenCL uses buffered variant by default. However I'm willing to 
make one of the two variants consistent (preferably hostcalls for me). Do note 
that this would make all OpenCL printf to be lowered to hostcalls from this 
patch onwards. @b-sumner , are you okay with this ?

Also regarding point 2, The current behaviour is that with HIP,  printf is 
lowered at clang CodeGen (since it treats printf to be a builtin) while OpenCL 
uses the IR pass. This patch will make it so that we could remove the IR pass 
and handle all lowering at clang CodeGen

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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread Lu Weining via cfe-commits

SixWeining wrote:

Hi @xen0n @xry111, please help to review this. Thanks.

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread Freddy Ye via cfe-commits


@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.

FreddyLeaf wrote:

Added consumption on this IR in MBBPlacement: 
https://github.com/llvm/llvm-project/pull/71026

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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Lu Weining (SixWeining)


Changes

In g++, empty unions are not ignored like empty structs when flattening structs 
to examine whether the structs can be passed via FARs in C++. This patch aligns 
clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+4-3) 
- (modified) clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c (+1-1) 
- (modified) clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c (+1-2) 


``diff
diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index c4d886eb40725f8..7b2c31139b0b2a3 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -170,10 +170,11 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true, true))
-  return true;
 const RecordDecl *RD = RTy->getDecl();
-// Unions aren't eligible unless they're empty (which is caught above).
+if (isEmptyRecord(getContext(), Ty, true, true) &&
+(!RD->isUnion() || !isa(RD)))
+  return true;
+// Unions aren't eligible unless they're empty in C (which is caught 
above).
 if (RD->isUnion())
   return false;
 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index 281b7b15841a999..2f7596f0ebdc8be 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// Fields containing empty structs or unions are ignored when flattening
+// Fields containing empty structs are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
 // not ignored in C++. These rules are not documented in psABI 

diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
index b0607425336e285..363e37efb64691e 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -19,8 +19,7 @@ struct s1 {
 };
 
 // CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
-/// FIXME: This doesn't match g++.
-// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z5test22s1([2 x i64]{{[^,]*}})
 struct s1 test2(struct s1 a) {
   return a;
 }

``




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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: Lu Weining (SixWeining)


Changes

In g++, empty unions are not ignored like empty structs when flattening structs 
to examine whether the structs can be passed via FARs in C++. This patch aligns 
clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/Targets/LoongArch.cpp (+4-3) 
- (modified) clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c (+1-1) 
- (modified) clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c (+1-2) 


``diff
diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index c4d886eb40725f8..7b2c31139b0b2a3 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -170,10 +170,11 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true, true))
-  return true;
 const RecordDecl *RD = RTy->getDecl();
-// Unions aren't eligible unless they're empty (which is caught above).
+if (isEmptyRecord(getContext(), Ty, true, true) &&
+(!RD->isUnion() || !isa(RD)))
+  return true;
+// Unions aren't eligible unless they're empty in C (which is caught 
above).
 if (RD->isUnion())
   return false;
 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index 281b7b15841a999..2f7596f0ebdc8be 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// Fields containing empty structs or unions are ignored when flattening
+// Fields containing empty structs are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
 // not ignored in C++. These rules are not documented in psABI 

diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
index b0607425336e285..363e37efb64691e 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -19,8 +19,7 @@ struct s1 {
 };
 
 // CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
-/// FIXME: This doesn't match g++.
-// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z5test22s1([2 x i64]{{[^,]*}})
 struct s1 test2(struct s1 a) {
   return a;
 }

``




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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all exception objects' destructors are non-throwing

2023-11-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557976.
MaskRay marked an inline comment as done.
MaskRay added a comment.

remove unused err_ arguments.
fix and test `throw new B`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp
  clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp

Index: clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only %s -fcxx-exceptions -fassume-nothrow-exception-dtor -verify
+
+namespace test1 {
+template  struct A { A(); ~A(); };
+struct B { ~B() noexcept(false); };
+struct B1 : B {};
+struct B2 { B b; };
+struct C { virtual void f(); } c;
+struct MoveOnly { MoveOnly(); MoveOnly(MoveOnly&&); };
+void run() {
+  throw A();
+  throw B();  // expected-error{{cannot throw object of type 'B' with a potentially-throwing destructor}}
+  throw new B;
+  throw B1(); // expected-error{{cannot throw object of type 'B1' with a potentially-throwing destructor}}
+  B2 b2;
+  throw b2;   // expected-error{{cannot throw object of type 'B2' with a potentially-throwing destructor}}
+  throw c;
+  MoveOnly m;
+  throw m;
+}
+}
Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -68,13 +71,15 @@
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND:  [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK: [[Cont2]]:
+  // CHECK-NEXT:  br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +87,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.+]] = call ptr @llvm.coro.free(
+  // THROWEND:   call void @_ZdlPv(ptr noundef %[[Mem]])
 

[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread Lu Weining via cfe-commits

https://github.com/SixWeining created 
https://github.com/llvm/llvm-project/pull/71025

In g++, empty unions are not ignored like empty structs when flattening structs 
to examine whether the structs can be passed via FARs in C++. This patch aligns 
clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.

>From 6ead0f23b5f3f3bfba7446bc4bf723d8020700e7 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 2 Nov 2023 11:13:29 +0800
Subject: [PATCH] [LoongArch] Fix ABI mismatch with g++ when handling empty
 unions

In g++, empty unions are not ignored like empty structs when flattening
structs to examine whether the structs can be passed via FARs in C++.
This patch aligns clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.
---
 clang/lib/CodeGen/Targets/LoongArch.cpp| 7 ---
 clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c | 2 +-
 clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c  | 3 +--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index c4d886eb40725f8..7b2c31139b0b2a3 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -170,10 +170,11 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true, true))
-  return true;
 const RecordDecl *RD = RTy->getDecl();
-// Unions aren't eligible unless they're empty (which is caught above).
+if (isEmptyRecord(getContext(), Ty, true, true) &&
+(!RD->isUnion() || !isa(RD)))
+  return true;
+// Unions aren't eligible unless they're empty in C (which is caught 
above).
 if (RD->isUnion())
   return false;
 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index 281b7b15841a999..2f7596f0ebdc8be 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// Fields containing empty structs or unions are ignored when flattening
+// Fields containing empty structs are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
 // not ignored in C++. These rules are not documented in psABI 

diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
index b0607425336e285..363e37efb64691e 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -19,8 +19,7 @@ struct s1 {
 };
 
 // CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
-/// FIXME: This doesn't match g++.
-// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z5test22s1([2 x i64]{{[^,]*}})
 struct s1 test2(struct s1 a) {
   return a;
 }

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


[clang] [compiler-rt] [llvm] [Profile] Refactor profile correlation. (PR #70856)

2023-11-01 Thread David Tellenbach via cfe-commits

dtellenbach wrote:

@ZequanWu this seems to cause issues on macOS: 
https://green.lab.llvm.org/green/job/clang-stage1-RA/36184/console
```
Profile-x86_64 :: Darwin/instrprof-debug-info-correlate.c
Profile-x86_64 :: instrprof-darwin-
Profile-x86_64h :: Darwin/instrprof-debug-info-correlate.c
Profile-x86_64h :: instrprof-darwin-exports.c
```
are failing, could you please take a look or revert?


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


[clang] 749083b - [LoongArch] Pre-commit test for issue #70890

2023-11-01 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2023-11-02T14:18:19+08:00
New Revision: 749083b91f31f370cf64831d3e7e6215b6d51442

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

LOG: [LoongArch] Pre-commit test for issue #70890

Added: 
clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
new file mode 100644
index 000..b0607425336e285
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - | \
+// RUN:   FileCheck --check-prefix=CHECK-C %s
+// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
+// RUN:   FileCheck --check-prefix=CHECK-CXX %s
+
+#include 
+
+// CHECK-C: define{{.*}} void @test1()
+// CHECK-CXX: define{{.*}} i64 @_Z5test12u1(i64{{[^,]*}})
+union u1 { };
+union u1 test1(union u1 a) {
+  return a;
+}
+
+struct s1 {
+  union u1 u;
+  int i;
+  float f;
+};
+
+// CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
+/// FIXME: This doesn't match g++.
+// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+struct s1 test2(struct s1 a) {
+  return a;
+}



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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

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


[clang] 858b56e - [Clang] Preserve coroutine parameter referenced state (#70973)

2023-11-01 Thread via cfe-commits

Author: Yuxuan Chen
Date: 2023-11-02T14:03:47+08:00
New Revision: 858b56e4962749013ded409ff43370b542c8b6cb

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

LOG: [Clang] Preserve coroutine parameter referenced state (#70973)

This PR is proposing a fix for
https://github.com/llvm/llvm-project/issues/65971.

Previously, given a coroutine like this
```
task foo(int a) {
  co_return;
}
```
Parameter `a` is never used. However, because C++ coroutines move
constructs the variable to a heap allocated coroutine activation frame,
we considered all parameters referenced. When diagnosing unused
parameters, we cannot distinguish if the variable reference was due to
coroutine parameter moves.

Compiler Explorer shows that GCC warns against this case correctly, but
clang does not: https://godbolt.org/z/Wo7dfqeaf

This patch addresses this issue by preserving the original
`ParmVarDecl`'s `Referenced` state.

Added: 
clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp

Modified: 
clang/lib/Sema/SemaCoroutine.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 38ac406b14adadf..bee80db8d166a68 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+PD->setReferenced(DeclReferenced);
+
 if (PDRefExpr.isInvalid())
   return false;
 

diff  --git a/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp 
b/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp
new file mode 100644
index 000..b4c01550f9f7883
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -std=c++20 %s
+
+#include "Inputs/std-coroutine.h"
+
+struct awaitable {
+  bool await_ready() noexcept;
+  void await_resume() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+};
+
+struct task : awaitable {
+  struct promise_type {
+task get_return_object() noexcept;
+awaitable initial_suspend() noexcept;
+awaitable final_suspend() noexcept;
+void unhandled_exception() noexcept;
+void return_void() noexcept;
+  };
+};
+
+task foo(int a) { // expected-warning{{unused parameter 'a'}}
+  co_return;
+}
+
+task bar(int a, int b) { // expected-warning{{unused parameter 'b'}}
+  a = a + 1;
+  co_return;
+}
+
+void create_closure() {
+  auto closure = [](int c) -> task { // expected-warning{{unused parameter 
'c'}}
+co_return;
+  };
+}



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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();

ChuanqiXu9 wrote:

Cool.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

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

LGTM.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

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


[clang] d76b56f - [NFC] Eliminate warnings in SourceLocationEncodingTest.cpp

2023-11-01 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-11-02T14:01:17+08:00
New Revision: d76b56fd28582c1cc6663cefa5ae2f8a23492d0a

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

LOG: [NFC] Eliminate warnings in SourceLocationEncodingTest.cpp

There are 2 dangling else warnings and a warning pararences around bit 
operations.
This patch tries to eliminate that.

Added: 


Modified: 
clang/unittests/Serialization/SourceLocationEncodingTest.cpp

Removed: 




diff  --git a/clang/unittests/Serialization/SourceLocationEncodingTest.cpp 
b/clang/unittests/Serialization/SourceLocationEncodingTest.cpp
index 2640ea4a599893a..141da4c27f8d0b5 100644
--- a/clang/unittests/Serialization/SourceLocationEncodingTest.cpp
+++ b/clang/unittests/Serialization/SourceLocationEncodingTest.cpp
@@ -25,8 +25,9 @@ void roundTrip(SourceLocation::UIntTy Loc,
std::optional ExpectedEncoded = std::nullopt) {
   uint64_t ActualEncoded =
   SourceLocationEncoding::encode(SourceLocation::getFromRawEncoding(Loc));
-  if (ExpectedEncoded)
+  if (ExpectedEncoded) {
 ASSERT_EQ(ActualEncoded, *ExpectedEncoded) << "Encoding " << Loc;
+  }
   SourceLocation::UIntTy DecodedEncoded =
   SourceLocationEncoding::decode(ActualEncoded).getRawEncoding();
   ASSERT_EQ(DecodedEncoded, Loc) << "Decoding " << ActualEncoded;
@@ -41,9 +42,10 @@ void roundTrip(std::vector Locs,
 for (auto L : Locs)
   ActualEncoded.push_back(SourceLocationEncoding::encode(
   SourceLocation::getFromRawEncoding(L), Seq));
-if (!ExpectedEncoded.empty())
+if (!ExpectedEncoded.empty()) {
   ASSERT_EQ(ActualEncoded, ExpectedEncoded)
   << "Encoding " << testing::PrintToString(Locs);
+}
   }
   std::vector DecodedEncoded;
   {
@@ -70,7 +72,7 @@ TEST(SourceLocationEncoding, Individual) {
   roundTrip(Big);
   roundTrip(Big + 1);
   roundTrip(MacroBit | Big);
-  roundTrip(MacroBit | Big + 1);
+  roundTrip(MacroBit | (Big + 1));
 }
 
 TEST(SourceLocationEncoding, Sequence) {



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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Yuxuan Chen via cfe-commits

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Yuxuan Chen via cfe-commits

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Yuxuan Chen via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();

yuxuanchen1997 wrote:

`PD->isReferenced()` may be true. The order `Sema` processes things is based on 
how Parser is sending information to it. I can try to explain based on my 
limited understanding and corroborate with a test case. So please feel free to 
correct me if I am wrong. 

Let's take a look at this very simple coroutine. Suppose `task` is defined 
somewhere as a return object. 
```
task foo(int a, int b) {
  a = a + 1;
  co_return;
}
```
Sema is first asked to compile `foo` like a normal function. Decl `a` and `b` 
are processed normally. When we use `a` in the `a = a + 1` statement, 
references are setup.

When the parser encounters `co_return`, it calls `Sema::ActOnCoreturn`. 

What `Sema::ActOnCoreturn` (and its siblings handling other `co_` family of 
statements) does is to call `Sema::ActOnCoroutineBodyStart`. It checks if clang 
is already treating `foo` as a coroutine. It will find out that, no. We are not 
compiling `foo` like a coroutine yet, let's perform necessary checks and 
establish this context. `buildCoroutineParameterMoves` is called as a result. 
At that time `a` already has references we need to carry along. 

Suppose that our function has subsequent `co_*` statements, `Sema` knows that 
we already established the context and doesn't build them again.

The aforementioned `foo` coroutine will cause clang ICE if we 
`assert(!PD->isReferenced())` here.

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


[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-01 Thread Nick Desaulniers via cfe-commits

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

LGTM; might be nice if it's possible to set this for `opt`/`llc` invocations, 
but for now I'm just happy to have this in clang.

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all exception objects' destructors are non-throwing

2023-11-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.

LGTM. Thanks.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:1110
+!FT->isNothrow())
+  Diag(ThrowLoc, diag::err_throw_object_throwing_dtor) << Ty << 1 << 1;
+  }

It looks like err_throw_object_throwing_dtor doesn't require any parameters?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that all exception objects' destructors are non-throwing

2023-11-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557975.
MaskRay marked an inline comment as done.
MaskRay retitled this revision from "[ItaniumCXXABI] Add 
-fassume-nothrow-exception-dtor to assume that an exception object' destructor 
is nothrow" to "[ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume 
that all exception objects' destructors are non-throwing".
MaskRay edited the summary of this revision.
MaskRay added a comment.

Add a diagnostic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp
  clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp

Index: clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/assume-nothrow-exception-dtor.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only %s -fcxx-exceptions -fassume-nothrow-exception-dtor -verify
+
+namespace test1 {
+struct A {};
+struct B { ~B() noexcept(false); };
+struct B1 : B {};
+struct B2 { B b; };
+struct C { virtual void f(); } c;
+void run() {
+  throw A();
+  throw B();  // expected-error{{thrown object has a potentially-throwing destructor}}
+  throw B1(); // expected-error{{thrown object has a potentially-throwing destructor}}
+  throw B2(); // expected-error{{thrown object has a potentially-throwing destructor}}
+  throw c;
+}
+}
Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -68,13 +71,15 @@
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND:  [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK: [[Cont2]]:
+  // CHECK-NEXT:  br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +87,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.

[llvm] [clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-11-01 Thread via cfe-commits

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


[clang] 51abbf9 - [InstCombine] Deduce `align` and `nonnull` return attributes for `llvm.ptrmask`

2023-11-01 Thread Noah Goldstein via cfe-commits

Author: Noah Goldstein
Date: 2023-11-01T23:50:35-05:00
New Revision: 51abbf98d19cb1b89c6938811f2805bafe4b336e

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

LOG: [InstCombine] Deduce `align` and `nonnull` return attributes for 
`llvm.ptrmask`

We can deduce the former based on the mask / incoming pointer
alignment.  We can set the latter based if know the result in non-zero
(this is essentially just caching our analysis result).

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

Added: 


Modified: 
clang/test/CodeGen/arm64_32-vaarg.c
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/align-addr.ll
llvm/test/Transforms/InstCombine/consecutive-ptrmask.ll
llvm/test/Transforms/InstCombine/ptrmask.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm64_32-vaarg.c 
b/clang/test/CodeGen/arm64_32-vaarg.c
index 9fbcf88ecfdcc33..3f1f4443436da15 100644
--- a/clang/test/CodeGen/arm64_32-vaarg.c
+++ b/clang/test/CodeGen/arm64_32-vaarg.c
@@ -29,7 +29,7 @@ long long test_longlong(OneLongLong input, va_list *mylist) {
   // CHECK-LABEL: define{{.*}} i64 @test_longlong(i64 %input
   // CHECK: [[STARTPTR:%.*]] = load ptr, ptr %mylist
   // CHECK: [[ALIGN_TMP:%.+]] = getelementptr inbounds i8, ptr [[STARTPTR]], 
i32 7
-  // CHECK: [[ALIGNED_ADDR:%.+]] = tail call ptr @llvm.ptrmask.p0.i32(ptr 
nonnull [[ALIGN_TMP]], i32 -8)
+  // CHECK: [[ALIGNED_ADDR:%.+]] = tail call align 8 ptr 
@llvm.ptrmask.p0.i32(ptr nonnull [[ALIGN_TMP]], i32 -8)
   // CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, ptr [[ALIGNED_ADDR]], 
i32 8
   // CHECK: store ptr [[NEXT]], ptr %mylist
 

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 5c08ab190eba476..10a8bff700b7366 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1978,6 +1978,27 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst 
&CI) {
   *II, Builder.CreateIntrinsic(InnerPtr->getType(), Intrinsic::ptrmask,
{InnerPtr, NewMask}));
 }
+bool Changed = false;
+// See if we can deduce non-null.
+if (!CI.hasRetAttr(Attribute::NonNull) &&
+(Known.isNonZero() ||
+ isKnownNonZero(II, DL, /*Depth*/ 0, &AC, II, &DT))) {
+  CI.addRetAttr(Attribute::NonNull);
+  Changed = true;
+}
+
+unsigned NewAlignmentLog =
+std::min(Value::MaxAlignmentExponent,
+ std::min(BitWidth - 1, Known.countMinTrailingZeros()));
+// Known bits will capture if we had alignment information associated with
+// the pointer argument.
+if (NewAlignmentLog > Log2(CI.getRetAlign().valueOrOne())) {
+  CI.addRetAttr(Attribute::getWithAlignment(
+  CI.getContext(), Align(uint64_t(1) << NewAlignmentLog)));
+  Changed = true;
+}
+if (Changed)
+  return &CI;
 break;
   }
   case Intrinsic::uadd_with_overflow:

diff  --git a/llvm/test/Transforms/InstCombine/align-addr.ll 
b/llvm/test/Transforms/InstCombine/align-addr.ll
index 1e49cddf7ffe79d..facb5df08a82f43 100644
--- a/llvm/test/Transforms/InstCombine/align-addr.ll
+++ b/llvm/test/Transforms/InstCombine/align-addr.ll
@@ -135,7 +135,7 @@ define <16 x i8> @ptrmask_align_unknown_ptr_align1(ptr 
align 1 %ptr, i64 %mask)
 
 define <16 x i8> @ptrmask_align_unknown_ptr_align8(ptr align 8 %ptr, i64 
%mask) {
 ; CHECK-LABEL: @ptrmask_align_unknown_ptr_align8(
-; CHECK-NEXT:[[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr 
[[PTR:%.*]], i64 [[MASK:%.*]])
+; CHECK-NEXT:[[ALIGNED:%.*]] = call align 8 ptr @llvm.ptrmask.p0.i64(ptr 
[[PTR:%.*]], i64 [[MASK:%.*]])
 ; CHECK-NEXT:[[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
 ; CHECK-NEXT:ret <16 x i8> [[LOAD]]
 ;
@@ -147,7 +147,7 @@ define <16 x i8> @ptrmask_align_unknown_ptr_align8(ptr 
align 8 %ptr, i64 %mask)
 ; Increase load align from 1 to 2
 define <16 x i8> @ptrmask_align2_ptr_align1(ptr align 1 %ptr) {
 ; CHECK-LABEL: @ptrmask_align2_ptr_align1(
-; CHECK-NEXT:[[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr 
[[PTR:%.*]], i64 -2)
+; CHECK-NEXT:[[ALIGNED:%.*]] = call align 2 ptr @llvm.ptrmask.p0.i64(ptr 
[[PTR:%.*]], i64 -2)
 ; CHECK-NEXT:[[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
 ; CHECK-NEXT:ret <16 x i8> [[LOAD]]
 ;
@@ -159,7 +159,7 @@ define <16 x i8> @ptrmask_align2_ptr_align1(ptr align 1 
%ptr) {
 ; Increase load align from 1 to 4
 define <16 x i8> @ptrmask_align4_ptr_align1(ptr align 1 %ptr) {
 ; CHECK-LABEL: @ptrmask_align4_ptr_align1(
-; CHECK-NEXT:[[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr 
[[PTR:%.*]], i64 -4)
+; CHECK-NEXT:[[ALIGNED:%.*]] = call align

[compiler-rt] [clang] [clang-tools-extra] [llvm] [InferAddressSpaces] Fix constant replace to avoid modifying other functions (PR #70611)

2023-11-01 Thread Wenju He via cfe-commits


@@ -334,6 +335,15 @@ template<> struct simplify_type {
   }
 };
 
+template <> struct GraphTraits {

wenju-he wrote:

I measured llvm-project compile time impact of this change to llvm/IR/User.h on 
intel icx 8358 cpu.

Build command:
`
cmake -GNinja -DLLVM_ENABLE_PROJECTS="llvm;clang;clang-tools-extra" 
-DLLVM_INCLUDE_TESTS=ON -DLLVM_BUILD_TESTS=ON -DLLVM_ENABLE_ASSERTIONS=ON 
-DCMAKE_BUILD_TYPE=Release ../llvm -DBUILD_SHARED_LIBS=OFF 
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" -DCMAKE_INSTALL_PREFIX=install && ninja 
-j40
`

Ref: (https://github.com/llvm/llvm-project.git 
c0d78c4232057768b04d3330e581d81544391e68)
Exp: (https://github.com/llvm/llvm-project.git 
c0d78c4232057768b04d3330e581d81544391e68) + change to User.h

### OS: RHEL9   (note: llvm-project build on this system also builds 
https://github.com/KhronosGroup/SPIRV-LLVM-Translator as a project inside 
llvm/project folder)

REF: 
real10m39.052s
user398m36.074s
sys 19m26.839s

real10m39.058s
user398m31.903s
sys 19m18.405s

EXP:
real10m39.910s
user398m55.339s
sys 19m36.278s

real10m40.319s
user398m52.378s
sys 19m38.137s

### OS: Ubuntu 22
REF:
real10m2.783s
user376m47.038s
sys 18m35.310s

real10m2.983s
user376m47.032s
sys 18m46.517s

real10m3.059s
user376m52.423s
sys 18m45.694s

EXP:
real10m2.730s
user376m46.556s
sys 18m44.566s

real10m3.007s
user376m48.369s
sys 18m46.733s

real10m2.860s
user376m44.655s
sys 18m51.154s

Summary:
On RHEL9 build time is slowed down by ~1 second. On Ubuntu 22 there is no 
obvious change of compile time.

@nikic could we add GraphTraits to User.h since compile time impact is 
not obvious?

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-01 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 4fed3d374dfca82d0cb32bb444985ece04438376 
c9e4d58d1c2ecdbbbc4a518ee1698901d0b74e0d -- 
clang-tools-extra/clangd/ModuleDependencyScanner.cpp 
clang-tools-extra/clangd/ModuleDependencyScanner.h 
clang-tools-extra/clangd/ModulesBuilder.cpp 
clang-tools-extra/clangd/ModulesBuilder.h 
clang-tools-extra/clangd/PrerequisiteModules.h 
clang-tools-extra/clangd/ProjectModules.cpp 
clang-tools-extra/clangd/ProjectModules.h 
clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp 
clang-tools-extra/clangd/unittests/ModulesTestSetup.h 
clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp 
clang-tools-extra/clangd/ClangdServer.cpp 
clang-tools-extra/clangd/ClangdServer.h 
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
clang-tools-extra/clangd/GlobalCompilationDatabase.h 
clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp 
clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/TUScheduler.cpp 
clang-tools-extra/clangd/TUScheduler.h clang-tools-extra/clangd/tool/Check.cpp 
clang-tools-extra/clangd/tool/ClangdMain.cpp 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
clang-tools-extra/clangd/unittests/FileIndexTests.cpp 
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
clang-tools-extra/clangd/unittests/PreambleTests.cpp 
clang-tools-extra/clangd/unittests/TestTU.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/ProjectModules.h 
b/clang-tools-extra/clangd/ProjectModules.h
index 98720ee06d47..b9b693c3ec9b 100644
--- a/clang-tools-extra/clangd/ProjectModules.h
+++ b/clang-tools-extra/clangd/ProjectModules.h
@@ -45,7 +45,7 @@ public:
   virtual PathRef
   getSourceForModuleName(StringRef ModuleName,
  PathRef RequiredSrcFile = PathRef()) = 0;
-  
+
   virtual ~ProjectModules() = default;
 };
 

``




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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-01 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,53 @@
+//===-- ProjectModules.h -*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
+
+#include "ModuleDependencyScanner.h"
+
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// An interface to query the modules information in the project.
+/// Users should get instances of `ProjectModules` from
+/// `GlobalCompilationDatabase::getProjectModules(PathRef)`.
+///
+/// Currently, the modules information includes:
+/// - Given a source file, what are the required modules.
+/// - Given a module name and a required source file, what is
+///   the corresponding source file.
+///
+/// Note that there can be multiple source files declaring the same module
+/// in a valid project. Although the language specification requires that
+/// every module unit's name must be unique in valid program, there can be
+/// multiple program in a project. And it is technically valid if these program
+/// doesn't interfere with each other.
+///
+/// A module name should be in the format:
+/// `[:partition-name]`. So module names covers 
partitions.
+class ProjectModules {

ChuanqiXu9 wrote:

Nice catch! Thanks!

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-01 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/66462

>From 190e160868080f7d64c0c05de0fd4315a3ff2b93 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 15 Sep 2023 11:33:53 +0800
Subject: [PATCH 1/2] [clangd] [C++20] [Modules] Introduce initial support for
 C++20 Modules

Alternatives to https://reviews.llvm.org/D153114.

Try to address https://github.com/clangd/clangd/issues/1293.

See the links for design ideas. We want to have some initial support in
clang18.

This is the initial support for C++20 Modules in clangd.
As suggested by sammccall in https://reviews.llvm.org/D153114,
we should minimize the scope of the initial patch to make it easier
to review and understand so that every one are in the same page:

> Don't attempt any cross-file or cross-version coordination: i.e. don't
> try to reuse BMIs between different files, don't try to reuse BMIs
> between (preamble) reparses of the same file, don't try to persist the
> module graph. Instead, when building a preamble, synchronously scan
> for the module graph, build the required PCMs on the single preamble
> thread with filenames private to that preamble, and then proceed to
> build the preamble.

And this patch reflects the above opinions.
---
 clang-tools-extra/clangd/CMakeLists.txt   |   4 +
 clang-tools-extra/clangd/ClangdServer.cpp |   2 +
 clang-tools-extra/clangd/ClangdServer.h   |   3 +
 .../clangd/GlobalCompilationDatabase.cpp  |  23 ++
 .../clangd/GlobalCompilationDatabase.h|  14 +
 .../clangd/ModuleDependencyScanner.cpp|  81 
 .../clangd/ModuleDependencyScanner.h  | 106 ++
 clang-tools-extra/clangd/ModulesBuilder.cpp   | 347 ++
 clang-tools-extra/clangd/ModulesBuilder.h |  71 
 clang-tools-extra/clangd/ParsedAST.cpp|   7 +
 clang-tools-extra/clangd/Preamble.cpp |  28 +-
 clang-tools-extra/clangd/Preamble.h   |  10 +
 .../clangd/PrerequisiteModules.h  |  86 +
 clang-tools-extra/clangd/ProjectModules.cpp   |  60 +++
 clang-tools-extra/clangd/ProjectModules.h |  53 +++
 clang-tools-extra/clangd/TUScheduler.cpp  |  50 ++-
 clang-tools-extra/clangd/TUScheduler.h|   7 +
 clang-tools-extra/clangd/test/CMakeLists.txt  |   1 +
 clang-tools-extra/clangd/test/modules.test|  83 +
 clang-tools-extra/clangd/tool/Check.cpp   |  13 +-
 clang-tools-extra/clangd/tool/ClangdMain.cpp  |   8 +
 .../clangd/unittests/CMakeLists.txt   |   2 +
 .../clangd/unittests/CodeCompleteTests.cpp|  22 +-
 .../clangd/unittests/FileIndexTests.cpp   |   4 +-
 .../unittests/ModuleDependencyScannerTest.cpp | 176 +
 .../clangd/unittests/ModulesTestSetup.h   | 103 ++
 .../clangd/unittests/ParsedASTTests.cpp   |   8 +-
 .../clangd/unittests/PreambleTests.cpp|   6 +-
 .../unittests/PrerequisiteModulesTest.cpp | 238 
 clang-tools-extra/clangd/unittests/TestTU.cpp |  14 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +
 31 files changed, 1593 insertions(+), 40 deletions(-)
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.cpp
 create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.h
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.cpp
 create mode 100644 clang-tools-extra/clangd/ModulesBuilder.h
 create mode 100644 clang-tools-extra/clangd/PrerequisiteModules.h
 create mode 100644 clang-tools-extra/clangd/ProjectModules.cpp
 create mode 100644 clang-tools-extra/clangd/ProjectModules.h
 create mode 100644 clang-tools-extra/clangd/test/modules.test
 create mode 100644 
clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp
 create mode 100644 clang-tools-extra/clangd/unittests/ModulesTestSetup.h
 create mode 100644 
clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp

diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 3911fb6c6c746a8..242a8ad2e350be7 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -97,7 +97,10 @@ add_clang_library(clangDaemon
   IncludeFixer.cpp
   InlayHints.cpp
   JSONTransport.cpp
+  ModuleDependencyScanner.cpp
+  ModulesBuilder.cpp
   PathMapping.cpp
+  ProjectModules.cpp
   Protocol.cpp
   Quality.cpp
   ParsedAST.cpp
@@ -161,6 +164,7 @@ clang_target_link_libraries(clangDaemon
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning
   clangDriver
   clangFormat
   clangFrontend
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 13d788162817fb4..8ba4b38c420ab6a 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -202,6 +202,7 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
   Opts.UpdateDebounce = UpdateDebounce;
   Opts.ContextProvider = ContextProvider;
   Opts.PreambleThrottler = PreambleThrottler;
+  Opts.Experi

[clang] [flang] [flang][windows] Add option to link against specific MSVC CRT (PR #70833)

2023-11-01 Thread David Truby via cfe-commits


@@ -976,12 +976,46 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain &TC,
+void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-CmdArgs.push_back("Fortran_main.lib");
-CmdArgs.push_back("FortranRuntime.lib");
-CmdArgs.push_back("FortranDecimal.lib");
+CmdArgs.push_back(Args.MakeArgString(
+"/DEFAULTLIB:" + TC.getCompilerRTBasename(Args, "builtins")));
+unsigned RTOptionID = options::OPT__SLASH_MT;

DavidTruby wrote:

I should be adding the missing compiler-rt libs in this patch too. I don’t see 
any missing symbols in any of the configurations when testing an empty program 
locally. Could you share the error you’re seeing?

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


[clang] [flang] [flang][windows] Add option to link against specific MSVC CRT (PR #70833)

2023-11-01 Thread David Truby via cfe-commits

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 1/3] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/

[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits

smanna12 wrote:

Thank you @erichkeane and @AaronBallman for reviews and feedbacks.

>>Please be sure to add a reasonable description to the patch summary so that 
>>reviewers know more about what's going on, but thank you for already having 
>>written docs (that helps give context).

I have added description to the patch summary.

>>The changes should come with a release note as well.

Sure, I will add a release note.

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 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 ae7f7f2ef2033a48fb9db3cb70b88ad62019f40b 
d049dc9997bdb78ff7e7cbf9b04aa42b9274cfd9 -- clang/test/CodeGen/code_align.c 
clang/test/Sema/code_align.c clang/test/Sema/code_align_ast.c 
clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGLoopInfo.cpp 
clang/lib/CodeGen/CGLoopInfo.h clang/lib/Sema/SemaStmtAttr.cpp 
clang/lib/Sema/SemaTemplateInstantiate.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index c34fc4de5b0c..8a75b3021223 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -333,11 +333,9 @@ CodeAlignAttr *Sema::BuildCodeAlignAttr(const 
AttributeCommonInfo &CI,
 
 int align_value = ArgVal.getSExtValue();
 if (align_value < CodeAlignAttr::getMinValue() ||
-align_value > CodeAlignAttr::getMaxValue() ||
-!ArgVal.isPowerOf2()) {
-  Diag(CI.getLoc(), diag:: err_attribute_power_of_two_in_range)
-  << CI << CodeAlignAttr::getMinValue()
- << CodeAlignAttr::getMaxValue();
+align_value > CodeAlignAttr::getMaxValue() || !ArgVal.isPowerOf2()) {
+  Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
+  << CI << CodeAlignAttr::getMinValue() << 
CodeAlignAttr::getMaxValue();
   return nullptr;
 }
   }
@@ -362,8 +360,8 @@ CheckForDuplicateLoopAttribute(Sema &S,
   if (A) {
 // Cannot specify same type of attribute twice.
 S.Diag(I->getLocation(), diag::err_loop_attr_duplication) << A;
-   }
-   A = I;
+  }
+  A = I;
 }
   }
 }

``




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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c-local %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cpp-local -pedantic -x c++ 
-std=c++11 %s 
+
+// Add diagnostics tests for Loop attribute: [[clang::code_align()]].

smanna12 wrote:

Done. Removed

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c-local %s

smanna12 wrote:

Done

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c-local %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cpp-local -pedantic -x c++ 
-std=c++11 %s 
+
+// Add diagnostics tests for Loop attribute: [[clang::code_align()]].
+
+void foo() {
+  int i;
+  int a[10], b[10];
+
+  [[clang::code_align(8)]]
+  for (i = 0; i < 10; ++i) {  // this is OK
+a[i] = b[i] = 0;
+  }
+  // expected-error@+1 {{'code_align' attribute only applies to 'for', 
'while', and 'do' statements}}
+  [[clang::code_align(4)]]
+  i = 7;
+  for (i = 0; i < 10; ++i) {
+a[i] = b[i] = 0;
+  }
+
+  // expected-error@+1{{'code_align' attribute cannot be applied to a 
declaration}}
+  [[clang::code_align(12)]] int n[10];
+}
+
+void bar(int);
+#if __cplusplus >= 201103L
+// cpp-local-note@+2 {{declared here}}
+#endif
+void foo1(int A)
+{
+  // expected-error@+1 {{'code_align' attribute requires a positive integral 
compile time constant expression}}
+  [[clang::code_align(0)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute requires a positive integral 
compile time constant expression}}
+  [[clang::code_align(-4)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+#if __cplusplus >= 201103L
+// cpp-local-error@+4 {{integral constant expression must have integral or 
unscoped enumeration type, not 'double'}}
+#else
+// c-local-error@+2 {{integer constant expression must have integer type, 
not 'double'}}
+#endif
+  [[clang::code_align(64.0)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1 {{'code_align' attribute takes one argument}}
+  [[clang::code_align()]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1 {{'code_align' attribute takes one argument}}
+  [[clang::code_align(4,8)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // no diagnostic is expected
+  [[clang::code_align(32)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+#if __cplusplus >= 201103L
+  // cpp-local-error@+4 {{integral constant expression must have integral or 
unscoped enumeration type, not 'const char[4]'}}
+#else  
+  // c-local-error@+2 {{integer constant expression must have integer type, 
not 'char[4]'}}
+#endif
+  [[clang::code_align("abc")]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  [[clang::code_align(64)]]
+  // expected-error@+1 {{duplicate loop attribute 'code_align'}}
+  [[clang::code_align(64)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1 {{'code_align' attribute argument must be a constant 
power of two greater than zero}}
+  [[clang::code_align(7)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+#if __cplusplus >= 201103L
+  // cpp-local-error@+5 {{expression is not an integral constant expression}}
+  // cpp-local-note@+4 {{function parameter 'A' with unknown value cannot be 
used in a constant expression}}
+#else
+  // c-local-error@+2 {{expression is not an integer constant expression}}
+#endif  
+  [[clang::code_align(A)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+}
+
+#if __cplusplus >= 201103L
+void check_code_align_expression() {
+  int a[10];
+
+  // Test that checks expression is not a constant expression.
+  int foo2; // cpp-local-note {{declared here}}
+  // cpp-local-error@+2{{expression is not an integral constant expression}}
+  // cpp-local-note@+1{{read of non-const variable 'foo2' is not allowed in a 
constant expression}}
+  [[clang::code_align(foo2 + 1)]]
+  for (int i = 0; i != 10; ++i)
+a[i] = 0;
+
+  // Test that checks expression is a constant expression.
+  constexpr int bars = 0;
+  [[clang::code_align(bars + 1)]]
+  for (int i = 0; i != 10; ++i)
+a[i] = 0;
+}
+
+template 
+void code_align_dependent() {
+  [[clang::code_align(C)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  [[clang::code_align(A)]]
+  // cpp-local-error@+1 {{duplicate loop attribute 'code_align'}}
+  [[clang::code_align(B)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // cpp-local-error@+1{{'code_align' attribute requires a positive integral 
compile time constant expression}}
+  [[clang::code_align(D)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+}
+
+int main() {
+  code_align_dependent<8, 16, 32, -10>(); // cpp-local-note{{in instantiation 
of function template specialization 'code_align_dependent<8, 16, 32, -10>' 
requested here}}

smanna12 wrote:

Done

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata

smanna12 wrote:

Done

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the

smanna12 wrote:

Done

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];

smanna12 wrote:

I have updated the Args. 

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


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-coroutines

Author: Chuanqi Xu (ChuanqiXu9)


Changes

Close https://github.com/llvm/llvm-project/issues/56980.

This patch tries to introduce a light-weight optimization attribute for 
coroutines which are guaranteed to only be destroyed after it reached the final 
suspend.

The rationale behind the patch is simple. See the example:

```C++
A foo() {
  dtor d;
  co_await something();
  dtor d1;
  co_await something();
  dtor d2;
  co_return 43;
}
```

Generally the generated .destroy function may be:

```C++
void foo.destroy(foo.Frame *frame) {
  switch(frame->suspend_index()) {
case 1:
  frame->d.~dtor();
  break;
case 2:
  frame->d.~dtor();
  frame->d1.~dtor();
  break;
case 3:
  frame->d.~dtor();
  frame->d1.~dtor();
  frame->d2.~dtor();
  break;
default: // coroutine completed or haven't started
  break;
  }

  frame->promise.~promise_type();
  delete frame;
}
```

Since the compiler need to be ready for all the cases that the coroutine may be 
destroyed in a valid state.

However, from the user's perspective, we can understand that certain coroutine 
types may only be destroyed after it reached to the final suspend point. And we 
need a method to teach the compiler about this. Then this is the patch. After 
the compiler recognized that the coroutines can only be destroyed after 
complete, it can optimize the above example to:

```C++
void foo.destroy(foo.Frame *frame) {
  frame->promise.~promise_type();
  delete frame;
}
```

I spent a lot of time experimenting and experiencing this in the downstream. 
The numbers are really good. In a real-world coroutine-heavy workload, the size 
of the build dir (including .o files) reduces 14%. And the size of final 
libraries (excluding the .o files) reduces 8% in Debug mode and 1% in Release 
mode.

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+12) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+66) 
- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+6) 
- (added) clang/test/CodeGenCoroutines/coro-only-destroy-when-complete.cpp 
(+59) 
- (modified) clang/test/Misc/pragma-attribute-supported-attributes-list.test 
(+1) 
- (modified) llvm/docs/Coroutines.rst (+11) 
- (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (+1) 
- (modified) llvm/include/llvm/IR/Attributes.td (+3) 
- (modified) llvm/include/llvm/IR/Function.h (+7) 
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroSplit.cpp (+14-7) 
- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+1) 
- (added) llvm/test/Transforms/Coroutines/coro-only-destroy-when-done.ll (+137) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60b54c155e5..31434565becaec6 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1082,6 +1082,18 @@ def CFConsumed : InheritableParamAttr {
   let Documentation = [RetainBehaviorDocs];
 }
 
+
+// coro_only_destroy_when_complete indicates the coroutines whose return type
+// is marked by coro_only_destroy_when_complete can only be destroyed when the
+// coroutine completes. Then the space for the destroy functions can be saved.
+def CoroOnlyDestroyWhenComplete : InheritableAttr {
+  let Spellings = [Clang<"coro_only_destroy_when_complete">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroOnlyDestroyWhenCompleteDocs];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..dd1b44801a76947 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,69 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CoroOnlyDestroyWhenCompleteDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ 
class. The coroutines
+whose return type is marked as the attribute are assumed to be destroyed only 
after then coroutines
+reached to the final suspend point.
+
+This is helpful for the optimizers to perform more optimizations.
+
+For example,
+
+.. code-block:: c++
+
+  A foo() {
+dtor d;
+co_await something();
+dtor d1;
+co_await something();
+dtor d2;
+co_return 43;
+  }
+
+The compiler may generate the following pseudocode:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+switch(frame->suspend_index()) {
+  case 1:
+frame->d.~dtor();
+break;
+  case 2:
+frame->d.~dtor();

[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as

smanna12 wrote:

Done

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


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-01 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/71014

Close https://github.com/llvm/llvm-project/issues/56980.

This patch tries to introduce a light-weight optimization attribute for 
coroutines which are guaranteed to only be destroyed after it reached the final 
suspend.

The rationale behind the patch is simple. See the example:

```C++
A foo() {
  dtor d;
  co_await something();
  dtor d1;
  co_await something();
  dtor d2;
  co_return 43;
}
```

Generally the generated .destroy function may be:

```C++
void foo.destroy(foo.Frame *frame) {
  switch(frame->suspend_index()) {
case 1:
  frame->d.~dtor();
  break;
case 2:
  frame->d.~dtor();
  frame->d1.~dtor();
  break;
case 3:
  frame->d.~dtor();
  frame->d1.~dtor();
  frame->d2.~dtor();
  break;
default: // coroutine completed or haven't started
  break;
  }

  frame->promise.~promise_type();
  delete frame;
}
```

Since the compiler need to be ready for all the cases that the coroutine may be 
destroyed in a valid state.

However, from the user's perspective, we can understand that certain coroutine 
types may only be destroyed after it reached to the final suspend point. And we 
need a method to teach the compiler about this. Then this is the patch. After 
the compiler recognized that the coroutines can only be destroyed after 
complete, it can optimize the above example to:

```C++
void foo.destroy(foo.Frame *frame) {
  frame->promise.~promise_type();
  delete frame;
}
```

I spent a lot of time experimenting and experiencing this in the downstream. 
The numbers are really good. In a real-world coroutine-heavy workload, the size 
of the build dir (including .o files) reduces 14%. And the size of final 
libraries (excluding the .o files) reduces 8% in Debug mode and 1% in Release 
mode.

>From a2dae250abf20d47a7db4da65e25ff33bca28e67 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Thu, 2 Nov 2023 11:11:59 +0800
Subject: [PATCH] [Coroutines] Introduce
 [[clang::coro_only_destroy_when_complete]]

Close https://github.com/llvm/llvm-project/issues/56980.

This patch tries to introduce a light-weight optimizer for coroutines
which are guaranteed to only be destroyed afer it reached the final
suspend.

The rationale behind the patch is simple. See the example:

```C++
A foo() {
  dtor d;
  co_await something();
  dtor d1;
  co_await something();
  dtor d2;
  co_return 43;
}
```

Generally the generated .destroy function may be:

```C++
void foo.destroy(foo.Frame *frame) {
  switch(frame->suspend_index()) {
case 1:
  frame->d.~dtor();
  break;
case 2:
  frame->d.~dtor();
  frame->d1.~dtor();
  break;
case 3:
  frame->d.~dtor();
  frame->d1.~dtor();
  frame->d2.~dtor();
  break;
default: // coroutine completed or haven't started
  break;
  }

  frame->promise.~promise_type();
  delete frame;
}
```

Since the compiler need to be ready for all the cases that the coroutine
may be destroyed in a valid state.

However, from the user's perspective, we can understand that certain
coroutine types may only be destroyed after it reached to the final
suspend point. And we need a method to teach the compiler about this.
Then this is the patch. After the compiler recognized that the
coroutines can only be destroyed after complete, it can optimize the
above example to:

```C++
void foo.destroy(foo.Frame *frame) {
  frame->promise.~promise_type();
  delete frame;
}
```

I spent a lot of time experimenting and experiencing this in the
downstream. The numbers are really good. In a real-world coroutine-heavy
workload, the size of the build dir (including .o files) reduces 14%. And
the size of final libraries (excluding the .o files) reduces 8% in Debug
mode and 1% in Release mode.
---
 clang/include/clang/Basic/Attr.td |  12 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 clang/lib/CodeGen/CGCoroutine.cpp |   6 +
 .../coro-only-destroy-when-complete.cpp   |  59 
 ...a-attribute-supported-attributes-list.test |   1 +
 llvm/docs/Coroutines.rst  |  11 ++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |   1 +
 llvm/include/llvm/IR/Attributes.td|   3 +
 llvm/include/llvm/IR/Function.h   |   7 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |   2 +
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  21 ++-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |   1 +
 .../Coroutines/coro-only-destroy-when-done.ll | 137 ++
 14 files changed, 322 insertions(+), 7 deletions(-)
 create mode 100644 
clang/test/CodeGenCoroutines/coro-only-destroy-when-complete.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-only-destroy-when-done.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60b54c155e5..31434565becaec6 100644
--- a/cl

[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];

smanna12 wrote:

Done

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -788,6 +797,20 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 }
   }
 
+  // Translate 'loop attributes' arguments to equivalent Attr enums.
+  // It's being handled separately from LoopHintAttrs not to support
+  // legacy GNU attributes and pragma styles.

smanna12 wrote:

I have updated the comment. Please let me know if it is still unclear.


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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;

smanna12 wrote:

I have added new diagnostic to tell the user about   power of 2 with 
upper-bound 4096

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits


@@ -322,6 +322,56 @@ static Attr *handleUnlikely(Sema &S, Stmt *St, const 
ParsedAttr &A,
   return ::new (S.Context) UnlikelyAttr(S.Context, A);
 }
 
+CodeAlignAttr *Sema::BuildCodeAlignAttr(const AttributeCommonInfo &CI,
+Expr *E) {
+  if (!E->isValueDependent()) {
+llvm::APSInt ArgVal;
+ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
+if (Res.isInvalid())
+  return nullptr;
+E = Res.get();
+
+// This attribute requires a strictly positive value.
+if (ArgVal <= 0) {
+  Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer)
+  << CI << /*positive*/ 0;
+  return nullptr;
+}

smanna12 wrote:

I have added check for 4096 upper bounds.

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


[clang] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-01 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 1/2] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/

[clang] [clang][analyzer]][NFC] Simplify method 'ensureStreamNonNull' of StreamChecker (PR #70927)

2023-11-01 Thread Ben Shi via cfe-commits

benshi001 wrote:

> much, and I wonder if you have further ideas refactoring the checker; if so 
> we could probably bundle up similar changes into this one.

Thanks for your reply. Actually I have no plan about improving this checker. 
Currently I am just reading its code and trying to understand its details. 

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D108905#4655907 , @MaskRay wrote:

> In D108905#4655694 , @ChuanqiXu 
> wrote:
>
>> Oh, I am not saying the legacy and old comment. I mean you need to touch 
>> ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need 
>> either add a TODO/FIXME saying we need to emit an error in Sema if we find 
>> the the dtor of the exception we're throwing may throw or implement the 
>> semantics actually.
>
> Thanks for the reminder about `ReleaseNotes.rst` and `UsersManual.rst`!
>
> I think many changes don't update `UsersManual.rst` but this option is 
> probably quite useful and therefore deserves an entry. Added.
> The primary change is to `clang/lib/CodeGen/ItaniumCXXABI.cpp`, which does 
> not report warnings.
> If we want to implement a warning, we should probably do it in 
> clang/lib/Sema/SemaDeclCXX.cpp `Sema::BuildExceptionDeclaration`, which is 
> not touched in this file, so a TODO seems not appropriate...
>
> Is the warning to warn about `noexcept(false)` destructor in an 
> exception-declaration ? When?
> If at catch handlers, unfortunately we are cannot determine the exception 
> object for a `catch (...) { ... }` (used by coroutines).
> Technically, even if a destructor is `noexcept(false)`, the destructor may 
> not throw when `__cxa_end_catch` destroys the object.
>
> So we probably should warn about throw expressions, which can be done in 
> `Sema::CheckCXXThrowOperand` and I will investigate it.
> However, this warning appears orthogonal to `-fassume-nothrow-exception-dtor`.
> We can argue that even without `-fassume-nothrow-exception-dtor`, an thrown 
> object with a `noexcept(false)` destructor is probably not a good idea.
> However, I am on the fence whether the warning should be enabled-by-default.

The idea of diagnosing such cases is originally raised by @rjmccall  in 
https://github.com/llvm/llvm-project/issues/57375#issuecomment-1230590204. And 
in fact,  John is suggesting an error instead of a warning. To be honest, in 
our downstream implementation, we didn't implement that semantical check 
neither.

For the implementation, I think `Sema::CheckCXXThrowOperand` may be a good 
place and we can left a TODO there.

Technically, we're using a dialect after we enable 
`-fassume-nothrow-exception-dtor`.  In our dialect, we don't want to see an 
exception to throw exceptions. This is a rule for our dialect. And generally we 
have 2 strategies for implementing such language rules :

- Detect it and emit errors after we found users violating the rules.
- Don't detect it and claims it is the fault of the users.

No matter what the strategy we choose, it is not orthogonal to 
`-fassume-nothrow-exception-dtor` for sure. It is highly related. Then, I think 
the first strategy is always a better choice. Generally we only choose 2 when 
we can't diagnose such cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

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

In D108905#4655694 , @ChuanqiXu wrote:

> Oh, I am not saying the legacy and old comment. I mean you need to touch 
> ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need 
> either add a TODO/FIXME saying we need to emit an error in Sema if we find 
> the the dtor of the exception we're throwing may throw or implement the 
> semantics actually.

Thanks for the reminder about `ReleaseNotes.rst` and `UsersManual.rst`!

I think many changes don't update `UsersManual.rst` but this option is probably 
quite useful and therefore deserves an entry. Added.
The primary change is to `clang/lib/CodeGen/ItaniumCXXABI.cpp`, which does not 
report warnings.
If we want to implement a warning, we should probably do it in 
clang/lib/Sema/SemaDeclCXX.cpp `Sema::BuildExceptionDeclaration`, which is not 
touched in this file, so a TODO seems not appropriate...

Is the warning to warn about `noexcept(false)` destructor in an 
exception-declaration ? When?
If at catch handlers, unfortunately we are cannot determine the exception 
object for a `catch (...) { ... }` (used by coroutines).
Technically, even if a destructor is `noexcept(false)`, the destructor may not 
throw when `__cxa_end_catch` destroys the object.

So we probably should warn about throw expressions, which can be done in 
`Sema::CheckCXXThrowOperand` and I will investigate it.
However, this warning appears orthogonal to `-fassume-nothrow-exception-dtor`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/docs/UsersManual.rst:2145-2147
+   ``catch (...) { ... }``. This option tells Clang that an exception object's
+   destructor does not throw, even if the destructor is annotated as
+   ``noexcept(false)``.

I think it is better to treat the program as invalid if the compiler find the 
exception object's destructor is ``noexcept(false)``. The earlier error message 
is better than debugging and understanding what happened actually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-11-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557968.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Update clang/docs/UsersManual.rst and clang/docs/ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp

Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -68,13 +71,15 @@
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND:  [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK: [[Cont2]]:
+  // CHECK-NEXT:  br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +87,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.+]] = call ptr @llvm.coro.free(
+  // THROWEND:   call void @_ZdlPv(ptr noundef %[[Mem]])
 
   co_return;
 }
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++98 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
-// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck --check-prefixes=CHECK,CHECK11,THROWEND11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions -fassume-nothrow-exception-dtor | FileCheck --check-prefixes=CHECK,CHECK11,NOTHROWEND11 %s
 
 // CHECK: %[[STRUCT_TEST13_A:.*]] = type {

[clang] [clang] Separate bit-field padding diagnostics into -Wpadded-bitfield (PR #70978)

2023-11-01 Thread via cfe-commits

https://github.com/DanShaders updated 
https://github.com/llvm/llvm-project/pull/70978

>From 7906a4689d44a64ead5259f947049c862f6bf7e6 Mon Sep 17 00:00:00 2001
From: Dan Klishch 
Date: Wed, 1 Nov 2023 21:59:21 -0400
Subject: [PATCH] [clang] Separate bit-field padding diagnostics into
 -Wpadded-bitfield

-Wpadded diagnostics on usual struct fields are generally really noisy
and are of interest only for memory microoptimizations. However, this is
not the case for bit-fields. If one uses a bit-field, they most likely
intuitively expect the adjacent struct fields to be packed.
Unfortunately, in reality, layout of the bit-fields follows extremely
complicated, target-depended rules, which do not always result in the
aforementioned intuitive behavior.

The motivating example for this change was the following code:
```
union DoubleExtractor {
  double value;
  struct {
unsigned long long mantissa : 52;
unsigned exponent : 11;
unsigned sign : 1;
  }
};
```
which was used to extract parts of double-precision floating point
number memory representation. The snippet silently broke when compiled
for x86_64-pc-windows-msvc, since according to Microsoft ABI there
should be 12 bit padding between `mantissa` and `sign`.

Note however that this commit only alters `ItaniumRecordLayoutBuilder`,
so there will be no behavioral change for x86_64-pc-windows-msvc target.

The patch also revealed a bug in -Wpadded diagnostic text, where we
assumed that if it triggers for an anonymous field, that field must be a
bit-field.
---
 .../include/clang/Basic/DiagnosticASTKinds.td | 12 +-
 clang/include/clang/Basic/DiagnosticGroups.td |  3 +-
 clang/lib/AST/RecordLayoutBuilder.cpp | 19 +
 .../warn-all-padded-packed-packed-non-pod.cpp |  4 +-
 .../test/CodeGenCXX/warn-padded-bitfields.cpp | 41 +++
 5 files changed, 67 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/warn-padded-bitfields.cpp

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 031117f2c4137a4..c81d17ed641084a 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -998,6 +998,16 @@ def warn_npot_ms_struct : Warning<
   "data types with sizes that aren't a power of two">,
   DefaultError, InGroup;
 
+// -Wpadded-bitfield
+def warn_padded_struct_bitfield : Warning<
+  "padding %select{struct|interface|class}0 %1 with %2 "
+  "%select{byte|bit}3%s2 to align %4">,
+  InGroup, DefaultIgnore;
+def warn_padded_struct_anon_bitfield : Warning<
+  "padding %select{struct|interface|class}0 %1 with %2 "
+  "%select{byte|bit}3%s2 to align anonymous bit-field">,
+  InGroup, DefaultIgnore;
+
 // -Wpadded, -Wpacked
 def warn_padded_struct_field : Warning<
   "padding %select{struct|interface|class}0 %1 with %2 "
@@ -1005,7 +1015,7 @@ def warn_padded_struct_field : Warning<
   InGroup, DefaultIgnore;
 def warn_padded_struct_anon_field : Warning<
   "padding %select{struct|interface|class}0 %1 with %2 "
-  "%select{byte|bit}3%s2 to align anonymous bit-field">,
+  "%select{byte|bit}3%s2 to align anonymous field">,
   InGroup, DefaultIgnore;
 def warn_padded_struct_size : Warning<
   "padding size of %0 with %1 %select{byte|bit}2%s1 to alignment boundary">,
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 9a8f3f03b39d165..bfda89945d635bd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -586,7 +586,8 @@ def ExplicitInitializeCall : 
DiagGroup<"explicit-initialize-call">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def PackedNonPod : DiagGroup<"packed-non-pod">;
 def Packed : DiagGroup<"packed", [PackedNonPod]>;
-def Padded : DiagGroup<"padded">;
+def PaddedBitField : DiagGroup<"padded-bitfield">;
+def Padded : DiagGroup<"padded", [PaddedBitField]>;
 def UnalignedAccess : DiagGroup<"unaligned-access">;
 
 def PessimizingMove : DiagGroup<"pessimizing-move">;
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dcad..5d4f930fca50e2b 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2297,19 +2297,22 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
   PadSize = PadSize / CharBitNum;
   InBits = false;
 }
-if (D->getIdentifier())
-  Diag(D->getLocation(), diag::warn_padded_struct_field)
+if (D->getIdentifier()) {
+  auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
+: diag::warn_padded_struct_field;
+  Diag(D->getLocation(), Diagnostic)
   << getPaddingDiagFromTagKind(D->getParent()->getTagKind())
-  << Context.getTypeDeclType(D->getParent())
-  << PadSize
+  << Context.getTypeDeclType(D->getParent()) <

[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2023-11-01 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

> Can you clearly state why you are against this PR? You don't consider the 
> current behaviour of silently using the wrong headers a bug, or the proposed 
> solution is not correct?

>> Don't consider this an objection

I am not against it; I just wanted to talk through all the options.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();

ChuanqiXu9 wrote:

Since we will construct the parameter moves at the very beginning of the 
coroutine function, I am wondering if it is really possible that 
`PD->isReferenced()` may be true now. And if it is not possible,
we should convert it to  `assert(!PD->isReferenced());`. Please changing this 
after  verifying this with some actual coroutine related workloads.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.

ChuanqiXu9 wrote:

Readers can understand what is going on here. But they may be confused about 
the motivation. Let's add a comment to explain the reasons. I mean, something 
like, if we don't do so, we can't diagnose the unused parameter things.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

It looks much better now. Let's try to optimize it a bit futher.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-11-01 Thread Jerin Philip via cfe-commits

https://github.com/jerinphilip updated 
https://github.com/llvm/llvm-project/pull/65638

>From 947d4b418eb5b30f76ff262b1a19150aac10b9cc Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:43:53 +0530
Subject: [PATCH] [clang] Improve _Alignas on declaration diagnostic

Adds `isAlignas()` method on `AttributeCommonInfo` which accounts for
C++ `alignas` as well as C11 `_Alignas`.

The method is used to improve diagnostic in C when `_Alignas` is used in
C at the wrong location.  This corrects the previously suggested move
of `_Alignas` past the declaration specifier, now warns attribute
`_Alignas` is ignored.
---
 clang/docs/ReleaseNotes.rst   |  5 
 .../include/clang/Basic/AttributeCommonInfo.h |  9 
 clang/lib/Sema/SemaDecl.cpp   | 23 +++
 clang/test/C/drs/dr4xx.c  |  6 +
 clang/test/Parser/c1x-alignas.c   |  1 +
 clang/test/Parser/c2x-alignas.c   | 11 +
 clang/test/Parser/cxx0x-attributes.cpp|  2 ++
 7 files changed, 43 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/Parser/c2x-alignas.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3198d6bfe75a2e8..0505e1bd2c22a1e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -288,6 +288,11 @@ Attribute Changes in Clang
   When viewing ``S::FruitKind`` in a debugger, it will behave as if the member
   was declared as type ``E`` rather than ``unsigned``.
 
+- Clang now warns you that the ``_Alignas`` attribute on declaration specifiers
+  is ignored, changed from the former incorrect suggestion to move it past
+  declaration specifiers. (`#58637 
`_)
+
+
 Improvements to Clang's diagnostics
 ---
 - Clang constexpr evaluator now prints template arguments when displaying
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 7dc05418498d0ae..a8a5d3b475d2a69 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -192,6 +192,15 @@ class AttributeCommonInfo {
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
+  bool isAlignas() const {
+// FIXME: In the current state, the IsAlignas member variable is only true
+// with the C++  `alignas` keyword but not `_Alignas`. The following
+// expression works around the otherwise lost information so it will return
+// true for `alignas` or `_Alignas` while still returning false for things
+// like  `__attribute__((aligned))`.
+return (getParsedKind() == AT_Aligned && isKeywordAttribute());
+  }
+
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a8bad12b670fc75..57e0106e433264c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5343,16 +5343,21 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
 TypeSpecType == DeclSpec::TST_interface ||
 TypeSpecType == DeclSpec::TST_union ||
 TypeSpecType == DeclSpec::TST_enum) {
-  for (const ParsedAttr &AL : DS.getAttributes())
-Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
-  ? diag::err_declspec_keyword_has_no_effect
-  : diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(DS);
-  for (const ParsedAttr &AL : DeclAttrs)
-Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
-  ? diag::err_declspec_keyword_has_no_effect
-  : diag::warn_declspec_attribute_ignored)
+
+  auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) {
+unsigned DiagnosticId = diag::warn_declspec_attribute_ignored;
+if (AL.isAlignas() && !getLangOpts().CPlusPlus)
+  DiagnosticId = diag::warn_attribute_ignored;
+else if (AL.isRegularKeywordAttribute())
+  DiagnosticId = diag::err_declspec_keyword_has_no_effect;
+else
+  DiagnosticId = diag::warn_declspec_attribute_ignored;
+Diag(AL.getLoc(), DiagnosticId)
 << AL << GetDiagnosticTypeSpecifierID(DS);
+  };
+
+  llvm::for_each(DS.getAttributes(), EmitAttributeDiagnostic);
+  llvm::for_each(DeclAttrs, EmitAttributeDiagnostic);
 }
   }
 
diff --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c
index b8ccceaad12c59f..30145dcfeef1686 100644
--- a/clang/test/C/drs/dr4xx.c
+++ b/clang/test/C/drs/dr4xx.c
@@ -164,11 +164,7 @@ void dr444(void) {
   /* FIXME: This should be accepted as per this DR. */
   int j = (_Alignas(int) int){12}; /* expected-error {{expected express

[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

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

https://github.com/stefanp-ibm updated 
https://github.com/llvm/llvm-project/pull/70255

>From c57979d3d86362df239d3d3ff8cda124d40bb79d Mon Sep 17 00:00:00 2001
From: Stefan Pintilie 
Date: Wed, 25 Oct 2023 15:21:11 -0500
Subject: [PATCH 1/5] [PowerPC] Add an alias for -mregnames so that full
 register names used in assembly.

This option already exists on GCC and so it is being added to LLVM so that we
use the same option as them.
---
 clang/include/clang/Driver/Options.td |  4 +
 clang/lib/Basic/Targets/PPC.cpp   |  6 ++
 clang/lib/Basic/Targets/PPC.h |  1 +
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c | 78 +++
 .../PowerPC/MCTargetDesc/PPCInstPrinter.cpp   | 15 ++--
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h |  5 +-
 llvm/lib/Target/PowerPC/PPC.td|  4 +
 .../CodeGen/PowerPC/ppc-full-reg-names.ll | 62 +++
 8 files changed, 167 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
 create mode 100644 llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..74b92b76bc2d866 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4802,6 +4802,10 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
 Group;
 def mprivileged : Flag<["-"], "mprivileged">,
 Group;
+def mregnames : Flag<["-"], "mregnames">, Group,
+Visibility<[ClangOption]>;
+def mno_regnames : Flag<["-"], "mno-regnames">, Group,
+   Visibility<[ClangOption]>;
 } // let Flags = [TargetSpecific]
 def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
   Group,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..fa8f598c1843461 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -89,6 +89,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   IsISA3_1 = true;
 } else if (Feature == "+quadword-atomics") {
   HasQuadwordAtomics = true;
+} else if (Feature == "+regnames") {
+  FullRegisterNames = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -547,6 +549,9 @@ bool PPCTargetInfo::initFeatureMap(
   // off by default.
   Features["aix-small-local-exec-tls"] = false;
 
+  // By default full register names are not used in assembly.
+  Features["regnames"] = false;
+
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
@@ -696,6 +701,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("isa-v30-instructions", IsISA3_0)
   .Case("isa-v31-instructions", IsISA3_1)
   .Case("quadword-atomics", HasQuadwordAtomics)
+  .Case("regnames", FullRegisterNames)
   .Default(false);
 }
 
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..ddef057bb306cad 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;
 
 protected:
   std::string ABI;
diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c 
b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
new file mode 100644
index 000..c1bd22c1134c9a7
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -0,0 +1,78 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+
+// Also check the assembly to make sure that the full names are used.
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8

[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

isAssignmentToMemberOf will return `std::make_pair(nullptr, nullptr)` when 
failed.
Using `std::optional` can describe failed case clearly.

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


1 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp 
(+15-14) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index b6daf8b936bde0f..f0070265e6a734a 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -118,45 +118,45 @@ static void updateAssignmentLevel(
   }
 }
 
-static std::pair
+static std::optional>
 isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
const CXXConstructorDecl *Ctor) {
   if (const auto *BO = dyn_cast(S)) {
 if (BO->getOpcode() != BO_Assign)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *ME = dyn_cast(BO->getLHS()->IgnoreParenImpCasts());
 if (!ME)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *Field = dyn_cast(ME->getMemberDecl());
 if (!Field)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 if (!isa(ME->getBase()))
-  return std::make_pair(nullptr, nullptr);
+  return {};
 const Expr *Init = BO->getRHS()->IgnoreParenImpCasts();
 return std::make_pair(Field, Init);
   }
   if (const auto *COCE = dyn_cast(S)) {
 if (COCE->getOperator() != OO_Equal)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *ME =
 dyn_cast(COCE->getArg(0)->IgnoreParenImpCasts());
 if (!ME)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *Field = dyn_cast(ME->getMemberDecl());
 if (!Field)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 if (!isa(ME->getBase()))
-  return std::make_pair(nullptr, nullptr);
+  return {};
 const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts();
 return std::make_pair(Field, Init);
   }
-  return std::make_pair(nullptr, nullptr);
+  return {};
 }
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
@@ -216,11 +216,12 @@ void PreferMemberInitializerCheck::check(
 return;
 }
 
-const FieldDecl *Field = nullptr;
-const Expr *InitValue = nullptr;
-std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
-if (!Field)
+std::optional>
+AssignmentToMember = isAssignmentToMemberOf(Class, S, Ctor);
+if (!AssignmentToMember)
   continue;
+const FieldDecl *Field = AssignmentToMember.value().first;
+const Expr *InitValue = AssignmentToMember.value().second;
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;

``




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


[clang-tools-extra] [NFC][clang-tidy]refactor isAssignmentToMemberOf in PreferMemberInitializerCheck (PR #71006)

2023-11-01 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/71006

isAssignmentToMemberOf will return `std::make_pair(nullptr, nullptr)` when 
failed.
Using `std::optional` can describe failed case clearly.

>From 69b7688f56f7fe96031201eef1c3804f391c5abe Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 2 Nov 2023 08:49:22 +0800
Subject: [PATCH] [NFC][clang-tidy]refactor isAssignmentToMemberOf in
 PreferMemberInitializerCheck

---
 .../PreferMemberInitializerCheck.cpp  | 29 ++-
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index b6daf8b936bde0f..f0070265e6a734a 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -118,45 +118,45 @@ static void updateAssignmentLevel(
   }
 }
 
-static std::pair
+static std::optional>
 isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
const CXXConstructorDecl *Ctor) {
   if (const auto *BO = dyn_cast(S)) {
 if (BO->getOpcode() != BO_Assign)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *ME = dyn_cast(BO->getLHS()->IgnoreParenImpCasts());
 if (!ME)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *Field = dyn_cast(ME->getMemberDecl());
 if (!Field)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 if (!isa(ME->getBase()))
-  return std::make_pair(nullptr, nullptr);
+  return {};
 const Expr *Init = BO->getRHS()->IgnoreParenImpCasts();
 return std::make_pair(Field, Init);
   }
   if (const auto *COCE = dyn_cast(S)) {
 if (COCE->getOperator() != OO_Equal)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *ME =
 dyn_cast(COCE->getArg(0)->IgnoreParenImpCasts());
 if (!ME)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 const auto *Field = dyn_cast(ME->getMemberDecl());
 if (!Field)
-  return std::make_pair(nullptr, nullptr);
+  return {};
 
 if (!isa(ME->getBase()))
-  return std::make_pair(nullptr, nullptr);
+  return {};
 const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts();
 return std::make_pair(Field, Init);
   }
-  return std::make_pair(nullptr, nullptr);
+  return {};
 }
 
 PreferMemberInitializerCheck::PreferMemberInitializerCheck(
@@ -216,11 +216,12 @@ void PreferMemberInitializerCheck::check(
 return;
 }
 
-const FieldDecl *Field = nullptr;
-const Expr *InitValue = nullptr;
-std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
-if (!Field)
+std::optional>
+AssignmentToMember = isAssignmentToMemberOf(Class, S, Ctor);
+if (!AssignmentToMember)
   continue;
+const FieldDecl *Field = AssignmentToMember.value().first;
+const Expr *InitValue = AssignmentToMember.value().second;
 updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
 if (!canAdvanceAssignment(AssignedFields[Field]))
   continue;

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


[clang] [flang] [flang][windows] Add option to link against specific MSVC CRT (PR #70833)

2023-11-01 Thread via cfe-commits


@@ -976,12 +976,46 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain &TC,
+void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-CmdArgs.push_back("Fortran_main.lib");
-CmdArgs.push_back("FortranRuntime.lib");
-CmdArgs.push_back("FortranDecimal.lib");
+CmdArgs.push_back(Args.MakeArgString(
+"/DEFAULTLIB:" + TC.getCompilerRTBasename(Args, "builtins")));
+unsigned RTOptionID = options::OPT__SLASH_MT;

h-vetinari wrote:

Could you share the missing symbols? If it's something like `__udivti3` then 
that's an issue with not finding compiler-rt (those symbols are for 128 bit 
types and not contained in the MSVC rt libs of any flavour), see 
https://github.com/llvm/llvm-project/issues/25679. If so, there's perhaps a 
chance that things work with `flang-new -DAVOID_NATIVE_UINT128_T=1`...

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


[clang] [clang-tools-extra] [llvm] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -7584,11 +7584,22 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
 
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
-
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+for (const auto &attr :
+ RD->getUnderlyingDecl()->specific_attrs()) {
+  // Only for demonstration: Get feedback and add a clang annotation as an
+  // extension.
+  if (attr->getAnnotation() == "coro_type") {

bcardosolopes wrote:

I don't think you need this to find if a record is a "coroutine type", there 
are other ways, for example:
```
if (rec->getDeclName().isIdentifier() && rec->getName() == "promise_type") {

```

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


[clang] [flang] [flang][windows] Add option to link against specific MSVC CRT (PR #70833)

2023-11-01 Thread David Truby via cfe-commits

DavidTruby wrote:

> > Do we really need to have all 4 variants of the 3 fortran runtime 
> > libraries? That's a lot of complexity. Can we pare it down to just 
> > static/dynamic? It's also sometimes possible to generate code that works in 
> > both the static and dynamic context, depending on what is in those 
> > libraries. We don't create 4 variants of clang_rt.builtins, for examle.
> 
> From glancing at the fortran runtime code, I think the answer is probably 
> "no". There is too much C++ standard library usage. If you wish to avoid this 
> build complexity, you may consider writing code in the STL-less style that is 
> used for C++ code in the sanitizers in compiler-rt.

I don't think we can avoid it if we want to allow anyone to link 
flang-generated object files into a C/C++ application. I don't think we could 
even get it down to static/dynamic reliably without committing to not only not 
using the STL but not using any C/C++ functions that might call into the 
runtime (as compiler-rt builtins does). I don't think that's a route we want to 
go down with the flang runtime; I think we'd generally put build complexity 
secondary to code complexity in here (

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


[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2023-11-01 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

Can you clearly state why you are against this PR? You don't consider the 
current behaviour of silently using the wrong headers a bug, or the proposed 
solution is not correct?

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


[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2023-11-01 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

> changing the structure of the symlinks is not possible, it is done 
> automatically by a tool.

To be fair: tools can be changed, and in fact you're proposing to change one ;)

But that said, now I see what you're up against.

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


[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2023-11-01 Thread Liviu Ionescu via cfe-commits

ilg-ul wrote:

> for your use case, can you stick symlinks in to preserve that toolchain 
> folder structure relative to the ~/tmp/clang++ symlink? i.e. make that 
> ~/tmp/bin/clang++ -> 
> /Users/ilg/Library/xPacks/@xpack-dev-tools/clang/15.0.7-3.1/.content/bin/clang-15
>  and add ~/tmp/lib -> 
> /Users/ilg/Library/xPacks/@xpack-dev-tools/clang/15.0.7-3.1/.content/lib (and 
> same for include).

I'm not sure I understand your proposal, but I'm afraid changing the structure 
of the symlinks is not possible, it is done automatically by a tool.

The example above was just to demonstrate the bug.

In the actual use case, which is inspired by the npm use case, in the project 
there is a folder `xpacks` with symlinks to all dependent binaries, with dual 
indirections, something like this:

```
ilg@wksi native-cmake-clang13-debug % ls -lAR xpacks
total 0
drwxr-xr-x  61 ilg  staff  1952 Oct 31 14:42 .bin
drwxr-xr-x   3 ilg  staff96 Oct 31 14:42 @micro-os-plus
drwxr-xr-x   3 ilg  staff96 Oct 31 14:42 @xpack-dev-tools

xpacks/.bin:
total 0
lrwxr-xr-x  1 ilg  staff  44 Oct 31 14:42 clang -> 
../@xpack-dev-tools/clang/.content/bin/clang
lrwxr-xr-x  1 ilg  staff  46 Oct 31 14:42 clang++ -> 
../@xpack-dev-tools/clang/.content/bin/clang++
lrwxr-xr-x  1 ilg  staff  50 Oct 31 14:42 clang-check -> 
../@xpack-dev-tools/clang/.content/bin/clang-check
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 clang-cl -> 
../@xpack-dev-tools/clang/.content/bin/clang-cl
lrwxr-xr-x  1 ilg  staff  48 Oct 31 14:42 clang-cpp -> 
../@xpack-dev-tools/clang/.content/bin/clang-cpp
lrwxr-xr-x  1 ilg  staff  48 Oct 31 14:42 clang-doc -> 
../@xpack-dev-tools/clang/.content/bin/clang-doc
lrwxr-xr-x  1 ilg  staff  51 Oct 31 14:42 clang-format -> 
../@xpack-dev-tools/clang/.content/bin/clang-format
lrwxr-xr-x  1 ilg  staff  60 Oct 31 14:42 clang-offload-bundler -> 
../@xpack-dev-tools/clang/.content/bin/clang-offload-bundler
lrwxr-xr-x  1 ilg  staff  60 Oct 31 14:42 clang-offload-wrapper -> 
../@xpack-dev-tools/clang/.content/bin/clang-offload-wrapper
lrwxr-xr-x  1 ilg  staff  53 Oct 31 14:42 clang-refactor -> 
../@xpack-dev-tools/clang/.content/bin/clang-refactor
lrwxr-xr-x  1 ilg  staff  51 Oct 31 14:42 clang-rename -> 
../@xpack-dev-tools/clang/.content/bin/clang-rename
lrwxr-xr-x  1 ilg  staff  54 Oct 31 14:42 clang-scan-deps -> 
../@xpack-dev-tools/clang/.content/bin/clang-scan-deps
lrwxr-xr-x  1 ilg  staff  49 Oct 31 14:42 clang-tidy -> 
../@xpack-dev-tools/clang/.content/bin/clang-tidy
lrwxr-xr-x  1 ilg  staff  45 Oct 31 14:42 clangd -> 
../@xpack-dev-tools/clang/.content/bin/clangd
lrwxr-xr-x  1 ilg  staff  61 Oct 31 14:42 clangd-xpc-test-client -> 
../@xpack-dev-tools/clang/.content/bin/clangd-xpc-test-client
lrwxr-xr-x  1 ilg  staff  51 Oct 31 14:42 darwin-debug -> 
../@xpack-dev-tools/clang/.content/bin/darwin-debug
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 diagtool -> 
../@xpack-dev-tools/clang/.content/bin/diagtool
lrwxr-xr-x  1 ilg  staff  55 Oct 31 14:42 git-clang-format -> 
../@xpack-dev-tools/clang/.content/bin/git-clang-format
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 hmaptool -> 
../@xpack-dev-tools/clang/.content/bin/hmaptool
lrwxr-xr-x  1 ilg  staff  45 Oct 31 14:42 ld.lld -> 
../@xpack-dev-tools/clang/.content/bin/ld.lld
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 ld64.lld -> 
../@xpack-dev-tools/clang/.content/bin/ld64.lld
lrwxr-xr-x  1 ilg  staff  57 Oct 31 14:42 ld64.lld.darwinnew -> 
../@xpack-dev-tools/clang/.content/bin/ld64.lld.darwinnew
lrwxr-xr-x  1 ilg  staff  42 Oct 31 14:42 lld -> 
../@xpack-dev-tools/clang/.content/bin/lld
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 lld-link -> 
../@xpack-dev-tools/clang/.content/bin/lld-link
lrwxr-xr-x  1 ilg  staff  43 Oct 31 14:42 lldb -> 
../@xpack-dev-tools/clang/.content/bin/lldb
lrwxr-xr-x  1 ilg  staff  53 Oct 31 14:42 lldb-argdumper -> 
../@xpack-dev-tools/clang/.content/bin/lldb-argdumper
lrwxr-xr-x  1 ilg  staff  49 Oct 31 14:42 lldb-instr -> 
../@xpack-dev-tools/clang/.content/bin/lldb-instr
lrwxr-xr-x  1 ilg  staff  50 Oct 31 14:42 lldb-server -> 
../@xpack-dev-tools/clang/.content/bin/lldb-server
lrwxr-xr-x  1 ilg  staff  50 Oct 31 14:42 lldb-vscode -> 
../@xpack-dev-tools/clang/.content/bin/lldb-vscode
lrwxr-xr-x  1 ilg  staff  53 Oct 31 14:42 llvm-addr2line -> 
../@xpack-dev-tools/clang/.content/bin/llvm-addr2line
lrwxr-xr-x  1 ilg  staff  46 Oct 31 14:42 llvm-ar -> 
../@xpack-dev-tools/clang/.content/bin/llvm-ar
lrwxr-xr-x  1 ilg  staff  46 Oct 31 14:42 llvm-as -> 
../@xpack-dev-tools/clang/.content/bin/llvm-as
lrwxr-xr-x  1 ilg  staff  57 Oct 31 14:42 llvm-bitcode-strip -> 
../@xpack-dev-tools/clang/.content/bin/llvm-bitcode-strip
lrwxr-xr-x  1 ilg  staff  50 Oct 31 14:42 llvm-config -> 
../@xpack-dev-tools/clang/.content/bin/llvm-config
lrwxr-xr-x  1 ilg  staff  47 Oct 31 14:42 llvm-cov -> 
../@xpack-dev-tools/clang/.content/bin/llvm-cov
lrwxr-xr-x  1 ilg  staff  51 Oct 31 14:42 llvm-cxxdump -> 
../@xpack-dev-tools/clang/.content/bin/llvm-cxxdump
lrwxr-xr-x  1 ilg  

[clang] [llvm] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

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

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

LGTM

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


[clang] [libc] [flang] [lldb] [libcxx] [llvm] [lld] [clang-tools-extra] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -605,6 +605,17 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
   Builder.defineMacro("HIP_API_PER_THREAD_DEFAULT_STREAM");
 }
   }
+
+  if (LangOpts.OpenACC) {
+// FIXME: When we have full support for OpenACC, we should set this to the
+// version we support. Until then, set as '1' by default, but provide a
+// temporary mechanism for users to override this so real-world examples 
can
+// be tested against.
+if (!LangOpts.OpenACCMacroOverride.empty())
+  Builder.defineMacro("_OPENACC", LangOpts.OpenACCMacroOverride);
+else
+  Builder.defineMacro("_OPENACC", "1");

bcardosolopes wrote:

This probably deserves a test akin to `-E -dM` and FileCheck for the macro.

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


[flang] [clang] [llvm] [libc] [lld] [libcxx] [clang-tools-extra] [lldb] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang -S -### -fopenacc %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DRIVER
+// CHECK-DRIVER: "-cc1" {{.*}} "-fopenacc"

bcardosolopes wrote:

How does the interaction between using both `-fopenmp` and `-fopenacc` at the 
same time should look like? One takes precedence? Or should it be rejected?

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


[libcxx] [lld] [flang] [clang] [llvm] [lldb] [clang-tools-extra] [libc] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

https://github.com/bcardosolopes commented:

The changes in this patch looks pretty straightforward! Left some inline 
comments.

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


[libcxx] [llvm] [lld] [clang] [libc] [flang] [lldb] [clang-tools-extra] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

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


[libc] [clang] [lld] [llvm] [lldb] [libcxx] [clang-tools-extra] [flang] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -1342,6 +1342,15 @@ def err_opencl_logical_exclusive_or : Error<
 def err_openclcxx_virtual_function : Error<
   "virtual functions are not supported in C++ for OpenCL">;
 
+// OpenACC Support.
+def warn_pragma_acc_ignored : Warning<
+  "unexpected '#pragma acc ...' in program">, InGroup, 
DefaultIgnore;
+def err_acc_unexpected_directive : Error<
+  "unexpected OpenACC directive %select{|'#pragma acc %1'}0">;
+def warn_pragma_acc_unimplemented
+: Warning<"OpenACC Directives not yet implemented, pragma ignored">,

bcardosolopes wrote:

Does `Directives` need to be capitalized?

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


[flang] [clang] WIP: [flang] Enable fir alias tags pass by default when optimizing for speed (PR #68597)

2023-11-01 Thread Slava Zakharin via cfe-commits

vzakhari wrote:

Hi @tblah, is this ready for a merge?  Let me know if you are just waiting for 
a review.

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


[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

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

bwendling wrote:

@kees, @nickdesaulniers, @rapidsna, and @apple-fcloutier Should this feature 
support a `__bdos` to an address inside the FAM?

```
#include 
#include 

struct flex {
double dummy;
char count;
char fam[] __attribute__((counted_by(count)));
};

int main() {
struct flex *f = malloc(sizeof(struct flex) + 42 * sizeof(char));

f->count = 42;
printf("__bdos(&f->fam[3], 1) == %lu\n", 
__builtin_dynamic_object_size(&f->fam[3], 1));
return 0;
}
```

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


[libcxx] [llvm] [clang] [clang-tools-extra] [libc++] Allow running the test suite with optimizations (PR #68753)

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


@@ -87,6 +87,21 @@ def getStdFlag(cfg, std):
 return "-std=" + fallbacks[std]
 return None
 
+def getSpeedOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-O3"
+elif _isMSVC(cfg):
+return "/O2"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")
+
+def getSizeOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-Os"
+elif _isMSVC(cfg):
+return "/O1"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")

arichardson wrote:

`black` is unhappy with this formatting: 
https://github.com/llvm/llvm-project/pull/68753#issuecomment-1756472184

Personally, I'm not massively keen on the `black` coding style but it probably 
makes sense to keep it to something enforceable by a tool.

I do wonder if it would make sense to install it as a pre-commit hook to ensure 
the formatting stays consistent: 
https://github.com/akaihola/darker#using-as-a-pre-commit-hook

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


[libcxx] [llvm] [clang] [clang-tools-extra] [libc++] Allow running the test suite with optimizations (PR #68753)

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


@@ -121,6 +136,17 @@ def getStdFlag(cfg, std):
 AddCompileFlag(lambda cfg: getStdFlag(cfg, std)),
 ],
 ),
+Parameter(
+name="optimization",
+choices=["none", "speed", "size"],
+type=str,
+help="The version of the standard to compile the test suite with.",

arichardson wrote:

Thanks for the explanation, that makes sense.

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


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

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


@@ -1,7 +1,7 @@
 RUN: %clang_pgogen -O2 -fuse-ld=bfd -mllvm -disable-vp=false -mllvm 
-vp-static-alloc=true -DSTRESS=1 -o %t.ir.warn  
%S/../Inputs/instrprof-value-prof-real.c
 RUN: env LLVM_PROFILE_FILE=%t.ir.profraw LLVM_VP_MAX_NUM_VALS_PER_SITE=255  
%run %t.ir.warn 2>&1 |FileCheck --check-prefix=WARNING %s
 #  Test that enough static counters have been allocated
-RUN: env LLVM_PROFILE_FILE=%t.ir.profraw LLVM_VP_MAX_NUM_VALS_PER_SITE=130  
%run %t.ir.warn 2>&1 |FileCheck --check-prefix=NOWARNING --allow-empty %s
+RUN: env LLVM_PROFILE_FILE=%t.ir.profraw LLVM_VP_MAX_NUM_VALS_PER_SITE=80  
%run %t.ir.warn 2>&1 |FileCheck --check-prefix=NOWARNING --allow-empty %s

minglotus-6 wrote:

The TL,DR is this change is only needed when `enable-vtable-value-profiling` is 
true. Undo this change since `enable-vtable-value-profiling` is false by 
default.


This test expects errors like "LLVM Profile Warning: Unable to track new 
values: Running out of static counters.  Consider using option -mllvm 
-vp-counters-per-site= to allocate more value profile counters at compile 
time." when `LLVM_VP_MAX_NUM_VALS_PER_SITE` (the max number of allocated 
counters per instrumented site) is 255, and expects no such warnings when the 
env var is set to 130.
- The number of indirect callees in the tested c file is [approximately 
255](https://github.com/llvm/llvm-project/blob/ec350ad418a24f70c88758259c774a1e11c06d74/compiler-rt/test/profile/Inputs/instrprof-value-prof-real.c#L75-L328).

With `vp-static-alloc=true`, the number of counters is the `min(10, the number 
of instrumented sites in the function IR * the value of vp-counters-per-site`,  
computed at compile time 
[here](https://github.com/llvm/llvm-project/blob/ec350ad418a24f70c88758259c774a1e11c06d74/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L1402-L1412);
 and `LLVM_VP_MAX_NUM_VALS_PER_SITE` specifies the max number of collected 
values per site at runtime; when a site runs out of nodes, the coldest ones are 
[evicted 
first](https://github.com/llvm/llvm-project/blob/ec350ad418a24f70c88758259c774a1e11c06d74/compiler-rt/lib/profile/InstrProfilingValue.c#L178-L215).
 Without the refinement to insert type intrinsics and pick instrumentation 
points precisely, `enable-vtable-value-profiling` means false positives takes 
up some counters and thereby the need to reduce `LLVM_VP_MAX_NUM_VALS_PER_SITE` 
to make the test pass.



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


[clang] [lldb] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)

2023-11-01 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> 2) always put DW_AT_const_value in DW_TAG_member.

My understanding is that this is not possible. Dependent initializer 
expressions can't be evaluated in all cases - we're only allowed to evaluate 
them in the places the language allows us to, otherwise we might produce the 
wrong answer.

For non-dependent initializer expressions I think we could produce the answer 
in all cases.

And if we want type descriptions that are consistent (valuable for use with 
Type Units, and with @avl-llvm's DWARFLinker work) and we want to include 
static member variables in those descriptions, then we could put the constant 
value in the declaration of the member in cases where the initializer is 
non-dependent. But we'd still have to put it out in a definition in the 
dependent cases (if we want consistency).

And if we have to put it out in a separate definition DIE anyway - probably 
good to do that consistently so there's fewer special cases?

Admittedly there are other reasons type definitions are inconsistent (eg: 
implicit special members, nested types, and member function template 
specializations (& I guess static member variable template specializations)) - 
and we could move static variables out of the authoritative type definitions 
the same way we do for those cases. We can see this in type units (the type 
unit never has these entities in it, but the skeleton unit that references the 
type unit does have these features) - I'd expect something like that to be what 
@avl-llvm will want to do with DWARFLinker - though without type units in 
input, I'm not sure how easily it'll be to determine that those are the variant 
parts that shouldn't go in the canonical type definition... 

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Yuxuan Chen via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+PD->setReferenced(DeclReferenced);

yuxuanchen1997 wrote:

`BuildDeclRefExpr` builds a `DeclRef` `Expr` and marks the referenced `Decl` as 
`Referenced`. 

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

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

LGTM. @ChuanqiXu9 should give the final blessing though.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+PD->setReferenced(DeclReferenced);

bcardosolopes wrote:

As you mentioned offline, it's because creating the expression will mark it 
referenced, gotcha.

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits


@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation 
Loc) {
 if (PD->getType()->isDependentType())
   continue;
 
+// Preserve the referenced state for unused parameter diagnostics.
+bool DeclReferenced = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+PD->setReferenced(DeclReferenced);

bcardosolopes wrote:

What happens in `BuildDeclRefExpr` such that `PD` loses track of whether it is 
referenced? If something is changing `PD` in a bad way, perhaps at that point 
might be better to set the appropriated method instead. 

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


[clang] [Clang] Preserve coroutine parameter referenced state (PR #70973)

2023-11-01 Thread Bruno Cardoso Lopes via cfe-commits

https://github.com/bcardosolopes commented:

Thanks for improving this! I haven't looked at your previous review of this PR, 
but I like the simplicity of this one. 

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


[clang] [clang][driver] Add \/../include/c++/v1 to include path on Darwin (PR #70817)

2023-11-01 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

> In my use case, and probably in most use cases, the location where the link 
> comes from is a plain folder, not a hierarchy specific to a toolchain.

I would have expected the opposite. Most non-windows clang toolchains that I 
know of typically ship `clang` and `clang++` as symlinks to a single binary 
named `clang-${version}`, all of which are located in the typical 
bin-next-to-lib toolchain folder structure.  Darwin toolchains are a _little_ 
weird, since we don't ship libc++ & co. in `bin/../{lib,include}`, and instead 
those go in an "SDK" (much like a "sysroot" on other platforms).

As an aside, there is also driver mode selection logic that depends heavily on 
the specific names of these symlinks, e.g. for C vs C++ mode, clang-cl mode, 
and/or cross-compiling to a specific target when prefixed with the target 
triple e.g. `arm-none-eabi-clang -> clang`.


Don't consider this an objection, but: for your use case, can you stick 
symlinks in to preserve that toolchain folder structure relative to the 
`~/tmp/clang++` symlink? i.e. make that `~/tmp/bin/clang++ -> 
/Users/ilg/Library/xPacks/@xpack-dev-tools/clang/15.0.7-3.1/.content/bin/clang-15`
 and add `~/tmp/lib -> 
/Users/ilg/Library/xPacks/@xpack-dev-tools/clang/15.0.7-3.1/.content/lib` (and 
same for `include`).

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


[clang] Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (PR #69676)

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

aeubanks wrote:

thanks! I appreciate the quick response

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


[clang] [Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (PR #70841)

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


@@ -0,0 +1,145 @@
+// Test that type metadata are emitted with -fprofile-generate
+//
+// RUN: %clang -fprofile-generate -fno-lto -target x86_64-unknown-linux 
-emit-llvm -S %s -o - | FileCheck %s --check-prefix=ITANIUM
+// RUN: %clang -fprofile-generate -fno-lto -target x86_64-pc-windows-msvc 
-emit-llvm -S %s -o - | FileCheck %s --check-prefix=MS

teresajohnson wrote:

Yes I think that would be more typical and better imo (i.e. use %clang_cc to 
test)

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


[PATCH] D149917: [lld][WebAssembly] Add --keep-section flag

2023-11-01 Thread Derek Schuff via Phabricator via cfe-commits
dschuff accepted this revision.
dschuff added a comment.

otherwise LGTM




Comment at: lld/wasm/Options.td:196
 
+defm keep_section: Eq<"keep-section",
+ "Preserve a section even when --strip-all is given.  This is useful for 
compiler drivers such as clang or emcc that, for example, depend on the 
features section for post-link processing.">;

dschuff wrote:
> Can this flag be used more than once? From the code it looks like maybe it 
> can, but the description should maybe say that and there should be a test 
> (probably I should have written one for objcopy/strip too)
Should this description also say that keep-section can be used more than once? 
or is there some other way to know that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149917

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


[clang] Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (PR #69676)

2023-11-01 Thread via cfe-commits

antangelo wrote:

Apologies for the delay, I haven't been able to look into this until now. The 
patch has been reverted in 
https://github.com/llvm/llvm-project/commit/801c78d5b474c2319aa8ead44db7ba8cacac4714

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


[clang] 801c78d - Revert "Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (#69676)"

2023-11-01 Thread Antonio Abbatangelo via cfe-commits

Author: Antonio Abbatangelo
Date: 2023-11-01T18:10:02-04:00
New Revision: 801c78d5b474c2319aa8ead44db7ba8cacac4714

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

LOG: Revert "Reland "[clang][Sema] Use original template pattern when declaring 
implicit deduction guides for nested template classes" (#69676)"

This reverts commit f418319730341e9d41ce8ead6fbfe5603c343985.

Failing test case: 
https://github.com/llvm/llvm-project/pull/69676#issuecomment-1789255366

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/nested-deduction-guides.cpp

Removed: 
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3198d6bfe75a2e8..4696836b3a00caa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -665,11 +665,6 @@ Bug Fixes to C++ Support
   declaration definition. Fixes:
   (`#61763 `_)
 
-- Fix a bug where implicit deduction guides are not correctly generated for 
nested template
-  classes. Fixes:
-  (`#46200 `_)
-  (`#57812 `_)
-
 - Diagnose use of a variable-length array in a coroutine. The design of
   coroutines is such that it is not possible to support VLA use. Fixes:
   (`#65858 `_)

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 59721c8dc664aa9..9044400fbb1f3f3 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2253,7 +2253,6 @@ struct ConvertConstructorToDeductionGuideTransform {
 
   Sema &SemaRef;
   ClassTemplateDecl *Template;
-  ClassTemplateDecl *NestedPattern = nullptr;
 
   DeclContext *DC = Template->getDeclContext();
   CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2333,9 +2332,6 @@ struct ConvertConstructorToDeductionGuideTransform {
   Args.addOuterRetainedLevel();
 }
 
-if (NestedPattern)
-  Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
-
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
.getAsAdjusted();
 assert(FPTL && "no prototype for constructor declaration");
@@ -2445,17 +2441,10 @@ struct ConvertConstructorToDeductionGuideTransform {
 SmallVector ParamTypes;
 const FunctionProtoType *T = TL.getTypePtr();
 
-MultiLevelTemplateArgumentList OuterInstantiationArgs;
-if (NestedPattern)
-  OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
-
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
   ParmVarDecl *NewParam =
   transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
-NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
-  MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());
@@ -2661,24 +2650,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl 
*Template,
   if (BuildingDeductionGuides.isInvalid())
 return;
 
-  // If the template is nested, then we need to use the original
-  // pattern to iterate over the constructors.
-  ClassTemplateDecl *Pattern = Transform.Template;
-  while (Pattern->getInstantiatedFromMemberTemplate()) {
-if (Pattern->isMemberSpecialization())
-  break;
-Pattern = Pattern->getInstantiatedFromMemberTemplate();
-Transform.NestedPattern = Pattern;
-  }
-
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those
   // for which some class template parameter without a default argument never
   // appears in a deduced context).
-  ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
   llvm::SmallPtrSet ProcessedCtors;
   bool AddedAny = false;
-  for (NamedDecl *D : LookupConstructors(Pattern->getTemplatedDecl())) {
+  for (NamedDecl *D : LookupConstructors(Transform.Primary)) {
 D = D->getUnderlyingDecl();
 if (D->isInvalidDecl() || D->isImplicit())
   continue;
@@ -2724,8 +2702,6 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl 
*Template,
   Transform.buildSimpleDeductionGuide(Transform.DeducedType))
   ->getTemplatedDecl())
   ->setDeductionCandidateKind(DeductionCandidate::Copy);
-
-  SavedContext.pop();
 }
 
 /// Diagnose the presence of a default template argument on a

diff  --git a/clang/test/S

[flang] [compiler-rt] [llvm] [openmp] [clang] [libcxx] [lldb] [lld] [mlir] [clang-tools-extra] [AMDGPU] GCNRegPressure printing pass for testing. (PR #70031)

2023-11-01 Thread Valery Pykhtin via cfe-commits

vpykhtin wrote:

I've removed live-through registers printing from this PR and will submit it 
separately.

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


[flang] [compiler-rt] [llvm] [openmp] [clang] [libcxx] [lldb] [lld] [mlir] [clang-tools-extra] [AMDGPU] GCNRegPressure printing pass for testing. (PR #70031)

2023-11-01 Thread Valery Pykhtin via cfe-commits

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


[clang] [clang] Separate bit-field padding diagnostics into -Wpadded-bitfield (PR #70978)

2023-11-01 Thread via cfe-commits

https://github.com/DanShaders updated 
https://github.com/llvm/llvm-project/pull/70978

>From 5446542556971dfcfed097ad92925712cbe3a7a8 Mon Sep 17 00:00:00 2001
From: Dan Klishch 
Date: Wed, 1 Nov 2023 15:31:49 -0400
Subject: [PATCH 1/2] [clang] Separate bit-field padding diagnostics into
 -Wpadded-bitfield

---
 .../include/clang/Basic/DiagnosticASTKinds.td | 14 ++---
 clang/include/clang/Basic/DiagnosticGroups.td |  3 +-
 clang/lib/AST/RecordLayoutBuilder.cpp | 20 -
 .../warn-all-padded-packed-packed-non-pod.cpp |  4 +--
 .../test/CodeGenCXX/warn-padded-bitfields.cpp | 29 +++
 5 files changed, 55 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/warn-padded-bitfields.cpp

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 031117f2c4137a4..94d1907bce6d044 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -998,14 +998,20 @@ def warn_npot_ms_struct : Warning<
   "data types with sizes that aren't a power of two">,
   DefaultError, InGroup;
 
-// -Wpadded, -Wpacked
-def warn_padded_struct_field : Warning<
+// -Wpadded-bitfield
+def warn_padded_struct_bitfield : Warning<
   "padding %select{struct|interface|class}0 %1 with %2 "
   "%select{byte|bit}3%s2 to align %4">,
-  InGroup, DefaultIgnore;
-def warn_padded_struct_anon_field : Warning<
+  InGroup, DefaultIgnore;
+def warn_padded_struct_anon_bitfield : Warning<
   "padding %select{struct|interface|class}0 %1 with %2 "
   "%select{byte|bit}3%s2 to align anonymous bit-field">,
+  InGroup, DefaultIgnore;
+
+// -Wpadded, -Wpacked
+def warn_padded_struct_field : Warning<
+  "padding %select{struct|interface|class}0 %1 with %2 "
+  "%select{byte|bit}3%s2 to align %4">,
   InGroup, DefaultIgnore;
 def warn_padded_struct_size : Warning<
   "padding size of %0 with %1 %select{byte|bit}2%s1 to alignment boundary">,
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 9a8f3f03b39d165..bfda89945d635bd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -586,7 +586,8 @@ def ExplicitInitializeCall : 
DiagGroup<"explicit-initialize-call">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def PackedNonPod : DiagGroup<"packed-non-pod">;
 def Packed : DiagGroup<"packed", [PackedNonPod]>;
-def Padded : DiagGroup<"padded">;
+def PaddedBitField : DiagGroup<"padded-bitfield">;
+def Padded : DiagGroup<"padded", [PaddedBitField]>;
 def UnalignedAccess : DiagGroup<"unaligned-access">;
 
 def PessimizingMove : DiagGroup<"pessimizing-move">;
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dcad..982266488d488e2 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2297,19 +2297,23 @@ void ItaniumRecordLayoutBuilder::CheckFieldPadding(
   PadSize = PadSize / CharBitNum;
   InBits = false;
 }
-if (D->getIdentifier())
-  Diag(D->getLocation(), diag::warn_padded_struct_field)
+if (D->getIdentifier()) {
+  auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
+: diag::warn_padded_struct_field;
+  Diag(D->getLocation(), Diagnostic)
   << getPaddingDiagFromTagKind(D->getParent()->getTagKind())
-  << Context.getTypeDeclType(D->getParent())
-  << PadSize
+  << Context.getTypeDeclType(D->getParent()) << PadSize
   << (InBits ? 1 : 0) // (byte|bit)
   << D->getIdentifier();
-else
-  Diag(D->getLocation(), diag::warn_padded_struct_anon_field)
+} else {
+  assert(
+  D->isBitField() &&
+  "Introduced padding for an anonymous field which is not a 
bit-field");
+  Diag(D->getLocation(), diag::warn_padded_struct_anon_bitfield)
   << getPaddingDiagFromTagKind(D->getParent()->getTagKind())
-  << Context.getTypeDeclType(D->getParent())
-  << PadSize
+  << Context.getTypeDeclType(D->getParent()) << PadSize
   << (InBits ? 1 : 0); // (byte|bit)
+}
  }
  if (isPacked && Offset != UnpackedOffset) {
HasPackedField = true;
diff --git a/clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp 
b/clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
index 2a75498d87197a4..5e166deba0a3f05 100644
--- a/clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ b/clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -

  1   2   3   4   5   >