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

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

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/70611

>From 7c41be75c1ef661e757bfaca8d693b3937df649e Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 30 Oct 2023 08:36:52 +0800
Subject: [PATCH 1/3] [InferAddressSpaces] Fix constant replace to avoid
 modifying other functions

A constant value is unique in llvm context. InferAddressSpaces was
replacing its users in other functions as well. This leads to unexpected
behavior in our downstream use case after the pass.

InferAddressSpaces is a function passe, so it shall not modify functions
other than currently processed one.

Co-authored-by: Abhinav Gaba 
---
 llvm/include/llvm/IR/User.h   | 10 +
 .../Transforms/Scalar/InferAddressSpaces.cpp  | 20 +-
 .../ensure-other-funcs-unchanged.ll   | 40 +++
 3 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/ensure-other-funcs-unchanged.ll

diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h
index a9cf60151e5dc6c..d27d4bf4f5f1e66 100644
--- a/llvm/include/llvm/IR/User.h
+++ b/llvm/include/llvm/IR/User.h
@@ -18,6 +18,7 @@
 #ifndef LLVM_IR_USER_H
 #define LLVM_IR_USER_H
 
+#include "llvm/ADT/GraphTraits.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Use.h"
@@ -334,6 +335,15 @@ template<> struct simplify_type {
   }
 };
 
+template <> struct GraphTraits {
+  using NodeRef = User *;
+  using ChildIteratorType = Value::user_iterator;
+
+  static NodeRef getEntryNode(NodeRef N) { return N; }
+  static ChildIteratorType child_begin(NodeRef N) { return N->user_begin(); }
+  static ChildIteratorType child_end(NodeRef N) { return N->user_end(); }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_IR_USER_H
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp 
b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 2da521375c00161..828b1e765cb1af2 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -1166,6 +1166,8 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   }
 
   SmallVector DeadInstructions;
+  ValueToValueMapTy VMap;
+  ValueMapper VMapper(VMap, RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
 
   // Replaces the uses of the old address expressions with the new ones.
   for (const WeakTrackingVH &WVH : Postorder) {
@@ -1184,7 +1186,18 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   if (C != Replace) {
 LLVM_DEBUG(dbgs() << "Inserting replacement const cast: " << Replace
   << ": " << *Replace << '\n');
-C->replaceAllUsesWith(Replace);
+VMap[C] = Replace;
+for (User *U : make_early_inc_range(C->users())) {
+  for (auto It = df_begin(U), E = df_end(U); It != E;) {
+if (auto *I = dyn_cast(*It)) {
+  if (I->getFunction() == F)
+VMapper.remapInstruction(*I);
+  It.skipChildren();
+  continue;
+}
+++It;
+  }
+}
 V = Replace;
   }
 }
@@ -1210,6 +1223,11 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   // Skip if the current user is the new value itself.
   if (CurUser == NewV)
 continue;
+
+  if (auto *CurUserI = dyn_cast(CurUser);
+  CurUserI && CurUserI->getFunction() != F)
+continue;
+
   // Handle more complex cases like intrinsic that need to be remangled.
   if (auto *MI = dyn_cast(CurUser)) {
 if (!MI->isVolatile() && handleMemIntrinsicPtrUse(MI, V, NewV))
diff --git 
a/llvm/test/Transforms/InferAddressSpaces/ensure-other-funcs-unchanged.ll 
b/llvm/test/Transforms/InferAddressSpaces/ensure-other-funcs-unchanged.ll
new file mode 100644
index 000..ae052a69f9ed02d
--- /dev/null
+++ b/llvm/test/Transforms/InferAddressSpaces/ensure-other-funcs-unchanged.ll
@@ -0,0 +1,40 @@
+; RUN: opt -assume-default-is-flat-addrspace -print-module-scope 
-print-after-all -S -disable-output -passes=infer-address-spaces <%s 2>&1 | 
FileCheck %s
+
+; CHECK: IR Dump After InferAddressSpacesPass on f2
+
+; Check that after running infer-address-spaces on f2, the redundant addrspace 
cast %x1 in f2 is gone.
+; CHECK-LABEL: define spir_func void @f2()
+; CHECK: [[X:%.*]] = addrspacecast ptr addrspace(1) @x to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef [[X]])
+
+; But it should not affect f3.
+; CHECK-LABEL: define spir_func void @f3()
+; CHECK: %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @x to 
ptr) to ptr addrspace(1)
+; CHECK-NEXT:%x2 = addrspacecast ptr addrspace(1) %x1 to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef %x2)
+
+; Ensure that the pass hasn't run on f3 yet.
+; CHECK: IR Dump After InferAddressSpacesPass on f3
+
+target datalayout = 
"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256

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

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

https://github.com/wenju-he ready_for_review 
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] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

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

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/70567

>From 77b9cba0aaa1157cc323f2f3ef7b1cef536ef147 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Fri, 27 Oct 2023 16:37:40 -0700
Subject: [PATCH 1/6] [Clang] Coroutines: warn against unused parameters in C++
 coroutines with -Wunused-parameters

---
 clang/include/clang/AST/DeclBase.h| 18 +++-
 clang/lib/Sema/SemaCoroutine.cpp  |  6 
 clang/lib/Sema/SemaDecl.cpp   |  5 +++-
 .../warn-unused-parameters-coroutine.cpp  | 28 +++
 4 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 978e4255e877ec2..dc78ee37d16bea2 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -306,6 +306,11 @@ class alignas(8) Decl {
   /// are regarded as "referenced" but not "used".
   unsigned Referenced : 1;
 
+  /// Whether the last reference to this declaration happened in Coroutine
+  /// Parameter moves. Otherwise the reference caused by such moves would
+  /// prevent a warning against unused parameters in all coroutines.
+  unsigned LastReferenceInCoroutineParamMoves : 1;
+
   /// Whether this declaration is a top-level declaration (function,
   /// global variable, etc.) that is lexically inside an objc container
   /// definition.
@@ -609,11 +614,22 @@ class alignas(8) Decl {
   /// Whether any declaration of this entity was referenced.
   bool isReferenced() const;
 
+  bool isLastReferenceInCoroutineParamMoves() const {
+return LastReferenceInCoroutineParamMoves;
+  }
+
+  void setLastReferenceInCoroutineParamMoves(bool V = true) {
+LastReferenceInCoroutineParamMoves = true;
+  }
+
   /// Whether this declaration was referenced. This should not be relied
   /// upon for anything other than debugging.
   bool isThisDeclarationReferenced() const { return Referenced; }
 
-  void setReferenced(bool R = true) { Referenced = R; }
+  void setReferenced(bool R = true) {
+Referenced = R;
+LastReferenceInCoroutineParamMoves = false;
+  }
 
   /// Whether this declaration is a top-level declaration (function,
   /// global variable, etc.) that is lexically inside an objc container
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 38ac406b14adadf..3af42cae9ba0420 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;
 
+bool PDRefBefore = PD->isReferenced();
+
 ExprResult PDRefExpr =
 BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
+
+if (!PDRefBefore)
+  PD->setLastReferenceInCoroutineParamMoves();
+
 if (PDRefExpr.isInvalid())
   return false;
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 824267acbb1c04e..6ce4871152a4e78 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15092,7 +15092,10 @@ void 
Sema::DiagnoseUnusedParameters(ArrayRef Parameters) {
 return;
 
   for (const ParmVarDecl *Parameter : Parameters) {
-if (!Parameter->isReferenced() && Parameter->getDeclName() &&
+if (Parameter->isReferenced() && 
!Parameter->isLastReferenceInCoroutineParamMoves())
+  continue;
+
+if (Parameter->getDeclName() &&
 !Parameter->hasAttr() &&
 !Parameter->getIdentifier()->isPlaceholder()) {
   Diag(Parameter->getLocation(), diag::warn_unused_parameter)
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..0fd26ea4a21be79
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unused-parameters-coroutine.cpp
@@ -0,0 +1,28 @@
+// 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;
+}

>From c094a4fa29142b33cb15c41f5544395d3e87473c Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Sat, 28 Oct 2023 12:42:01 -0700
Subject: [PATCH 2/6] fix small bug: setLastReferenceInCoroutineParamMoves
 should respect pa

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

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Wenju He (wenju-he)


Changes

A constant value is unique in llvm context. InferAddressSpaces was
replacing its users in other functions as well. This leads to unexpected
behavior in our downstream use case after the pass.

InferAddressSpaces is a function passe, so it shall not modify functions
other than currently processed one.

Co-authored-by: Abhinav Gaba 

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


3 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+32-2) 
- (modified) llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll 
(+1-1) 
- (added) llvm/test/Transforms/InferAddressSpaces/optnone-func-unchanged.ll 
(+32) 


``diff
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp 
b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 28fe1b5e75327e6..1bf50d79e5331e9 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -477,7 +477,7 @@ void 
InferAddressSpacesImpl::appendsFlatAddressExpressionToPostorderStack(
 }
 
 // Returns all flat address expressions in function F. The elements are ordered
-// ordered in postorder.
+// in postorder.
 std::vector
 InferAddressSpacesImpl::collectFlatAddressExpressions(Function &F) const {
   // This function implements a non-recursive postorder traversal of a partial
@@ -1170,6 +1170,8 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   }
 
   SmallVector DeadInstructions;
+  ValueToValueMapTy VMap;
+  ValueMapper VMapper(VMap, RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
 
   // Replaces the uses of the old address expressions with the new ones.
   for (const WeakTrackingVH &WVH : Postorder) {
@@ -1188,7 +1190,30 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   if (C != Replace) {
 LLVM_DEBUG(dbgs() << "Inserting replacement const cast: " << Replace
   << ": " << *Replace << '\n');
-C->replaceAllUsesWith(Replace);
+SmallVector WorkList;
+for (User *U : make_early_inc_range(C->users())) {
+  if (auto *I = dyn_cast(U)) {
+if (I->getFunction() == F)
+  I->replaceUsesOfWith(C, Replace);
+  } else {
+WorkList.append(U->user_begin(), U->user_end());
+  }
+}
+if (!WorkList.empty()) {
+  VMap[C] = Replace;
+  DenseSet Visited{WorkList.begin(), WorkList.end()};
+  while (!WorkList.empty()) {
+User *U = WorkList.pop_back_val();
+if (auto *I = dyn_cast(U)) {
+  if (I->getFunction() == F)
+VMapper.remapInstruction(*I);
+  continue;
+}
+for (User *U2 : U->users())
+  if (Visited.insert(U2).second)
+WorkList.push_back(U2);
+  }
+}
 V = Replace;
   }
 }
@@ -1214,6 +1239,11 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
   // Skip if the current user is the new value itself.
   if (CurUser == NewV)
 continue;
+
+  if (auto *CurUserI = dyn_cast(CurUser);
+  CurUserI && CurUserI->getFunction() != F)
+continue;
+
   // Handle more complex cases like intrinsic that need to be remangled.
   if (auto *MI = dyn_cast(CurUser)) {
 if (!MI->isVolatile() && handleMemIntrinsicPtrUse(MI, V, NewV))
diff --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll 
b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
index b6713e96bed3ff5..422ac0dfd2cd470 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/noop-ptrint-pair.ll
@@ -70,7 +70,7 @@ define ptr @noop_ptrint_pair_ce2() {
 }
 
 ; COMMON-LABEL: @noop_ptrint_pair_ce2_vec(
-; AMDGCN-NEXT: ret <2 x ptr> 
+; AMDGCN-NEXT: ret <2 x ptr> 
 ; NOTTI-NEXT: ret <2 x ptr> 
 define <2 x ptr> @noop_ptrint_pair_ce2_vec() {
   ret <2 x ptr> 
diff --git a/llvm/test/Transforms/InferAddressSpaces/optnone-func-unchanged.ll 
b/llvm/test/Transforms/InferAddressSpaces/optnone-func-unchanged.ll
new file mode 100644
index 000..b0213f7486928ae
--- /dev/null
+++ b/llvm/test/Transforms/InferAddressSpaces/optnone-func-unchanged.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 3
+; RUN: opt -assume-default-is-flat-addrspace -S -passes=infer-address-spaces < 
%s 2>&1 | FileCheck %s
+
+@g = addrspace(1) global i32 0, align 4
+
+define ptr @f2() {
+; CHECK-LABEL: define ptr @f2() {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[X2:%.*]] = addrspacecast ptr addrspace(1) @g to ptr
+; CHECK-NEXT:ret ptr [[X2]]
+;
+entry:
+  %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @g to ptr) to ptr 
addrspace(1)
+  %x2 = addrspacecast ptr addrspac

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

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


@@ -0,0 +1,40 @@
+; RUN: opt -assume-default-is-flat-addrspace -print-module-scope 
-print-after-all -S -disable-output -passes=infer-address-spaces <%s 2>&1 | 
FileCheck %s
+
+; CHECK: IR Dump After InferAddressSpacesPass on f2
+
+; Check that after running infer-address-spaces on f2, the redundant addrspace 
cast %x1 in f2 is gone.
+; CHECK-LABEL: define spir_func void @f2()
+; CHECK: [[X:%.*]] = addrspacecast ptr addrspace(1) @x to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef [[X]])
+
+; But it should not affect f3.
+; CHECK-LABEL: define spir_func void @f3()
+; CHECK: %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @x to 
ptr) to ptr addrspace(1)
+; CHECK-NEXT:%x2 = addrspacecast ptr addrspace(1) %x1 to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef %x2)
+
+; Ensure that the pass hasn't run on f3 yet.
+; CHECK: IR Dump After InferAddressSpacesPass on f3

wenju-he wrote:

done

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] [llvm] [compiler-rt] [clang-tools-extra] [InferAddressSpaces] Fix constant replace to avoid modifying other functions (PR #70611)

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


@@ -0,0 +1,40 @@
+; RUN: opt -assume-default-is-flat-addrspace -print-module-scope 
-print-after-all -S -disable-output -passes=infer-address-spaces <%s 2>&1 | 
FileCheck %s
+
+; CHECK: IR Dump After InferAddressSpacesPass on f2
+
+; Check that after running infer-address-spaces on f2, the redundant addrspace 
cast %x1 in f2 is gone.
+; CHECK-LABEL: define spir_func void @f2()
+; CHECK: [[X:%.*]] = addrspacecast ptr addrspace(1) @x to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef [[X]])
+
+; But it should not affect f3.
+; CHECK-LABEL: define spir_func void @f3()
+; CHECK: %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @x to 
ptr) to ptr addrspace(1)
+; CHECK-NEXT:%x2 = addrspacecast ptr addrspace(1) %x1 to ptr
+; CHECK-NEXT:call spir_func void @f1(ptr noundef %x2)
+
+; Ensure that the pass hasn't run on f3 yet.
+; CHECK: IR Dump After InferAddressSpacesPass on f3
+
+target datalayout = 
"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
+target triple = "spir64"
+
+@x = addrspace(1) global i32 0, align 4
+
+define spir_func void @f2() {

wenju-he wrote:

done

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


[compiler-rt] [llvm] [clang] [clang-tools-extra] [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:

> In any case, this should not be in a public IR header.

I've reverted the change in this file.

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] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

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

https://github.com/ChuanqiXu9 commented:

Thanks for the very quick response. But I think it might be worthy to spend 
more time to find a light weight solution than RecursiveASTVisitors.

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


[clang] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

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


@@ -3165,7 +3165,16 @@ class Sema final {
 
   /// Diagnose any unused parameters in the given sequence of
   /// ParmVarDecl pointers.
-  void DiagnoseUnusedParameters(ArrayRef Parameters);
+  ///
+  /// Normally, we check if the parameter decls have the Referenced bit set.
+  /// C++ Coroutines, however, are a special case due to the existences of
+  /// parameter moves (See Sema::buildCoroutineParameterMoves), the parameters
+  /// are always referenced in coroutines. Therefore, in the case of 
coroutines,
+  /// CoroutineBodyRefs must be passed to correctly diagnose parameter usages
+  /// as written by the user.
+  void DiagnoseUnusedParameters(
+  ArrayRef Parameters,
+  llvm::SmallSet *CoroutineBodyRefs = nullptr);

yuxuanchen1997 wrote:

> Sorry, what do you mean by adding an assertion to DiagnoseUnusedParameters? 
> Do you say doing so after adopting my suggest? Then, it sounds good but how 
> can we do that? And it sounds not meaningful.

I didn't make it clear. I was asking what you may think about an assertion in 
DiagnoseUnusedParameters that !CurFunction()->isCoroutine()

> An instinct idea now is to mark all the parameters as non referenced/used 
> after building CoroutineParameterMoves. But it needs to be verified.

New to clang so I can't tell if I did something wrong. But the compiler crashed 
when I initially tried that. 

I have to sign off now. Catch up with you soon. 

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


[clang] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

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

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


[clang] [llvm] [compiler-rt] [clang-tools-extra] Changes to support running tests for Windows arm64 asan (PR #66973)

2023-11-01 Thread Vitaly Buka via cfe-commits

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

LGTM, but please address @omjavaid  comments.

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


[llvm] [clang] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

2023-11-01 Thread James Henderson via cfe-commits

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

I'd like @MaskRay to give this a once-over before merging this, but otherwise 
LGTM.

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


[clang] [clang] Do not clear FP pragma stack when instantiating functions (PR #70646)

2023-11-01 Thread John McCall via cfe-commits

rjmccall wrote:

It's certainly possible to see push/pop pragmas in late-parsed code, but Sema 
should immediately emit an error and ignore them because, like I said, they're 
only allowed at file context, and AFAIK late-parsed code is never at file 
context.  If there's some sneaky way to late-parse file-context declarations, 
that seems like a serious problem, because it's very important to process 
pragmas in order as we parse the top level.  And contrariwise, if there's some 
sneaky way to put push/pop pragmas in non-file contexts, that also seems like a 
serious problem, because the way we process them is not designed to understand 
local scopes, which means we're just doing random stuff instead of implementing 
any sort of intelligible language design.

Now, I don't really mind the late-parsing code being overly cautious about 
things possibly pushing and popping on the pragma stack as long as it's not 
costing us a significant amount of performance, but it would also be fine for 
it to assert that that hasn't happened and then just save and restore the 
active state, which is the only thing that late parsing should ever touch.

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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-NanHu (PR #70294)

2023-11-01 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/70294

>From 1222b8bda348af58f4921a45d8cddca726875bb9 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Thu, 26 Oct 2023 13:47:39 +0800
Subject: [PATCH 1/2] [RISCV] Add processor definition for XiangShan-NanHu

Co-authored-by: SForeKeeper 
---
 clang/test/Driver/riscv-cpus.c| 14 ++
 clang/test/Misc/target-invalid-cpu-note.c |  4 ++--
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 21 +
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 3eaceedce685fc6..70f0a63336bd478 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -20,6 +20,17 @@
 // MCPU-SYNTACORE-SCR1-MAX: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
 // MCPU-SYNTACORE-SCR1-MAX: "-target-abi" "ilp32"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-nanhu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-NANHU %s
+// MCPU-XIANGSHAN-NANHU: "-nostdsysteminc" "-target-cpu" "xiangshan-nanhu"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f" "-target-feature" "+d"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+c"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zicbom" "-target-feature" 
"+zicboz" "-target-feature" "+zicsr" "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zba" "-target-feature" "+zbb" 
"-target-feature" "+zbc"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zbkb" "-target-feature" "+zbkc" 
"-target-feature" "+zbkx" "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zkn" "-target-feature" "+zknd" 
"-target-feature" "+zkne" "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-NANHU: "-target-feature" "+zks" "-target-feature" "+zksed" 
"-target-feature" "+zksh" "-target-feature" "+svinval"
+// MCPU-XIANGSHAN-NANHU: "-target-abi" "lp64d"
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -62,6 +73,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=veyron-v1 | FileCheck 
-check-prefix=MTUNE-VEYRON-V1 %s
 // MTUNE-VEYRON-V1: "-tune-cpu" "veyron-v1"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
+// MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck 
-check-prefix=MTUNE-GENERIC-32 %s
 // MTUNE-GENERIC-32: "-tune-cpu" "generic"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index b2a04ebdbce628f..8e91eb4c62dd259 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, sifive-u74, 
sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
@@ -93,4 +93,4 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, generic, rocket, sifive-7-series{{$}}
+// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-s21, sifive-s51, sifive-s54, sifive-s76, sifive-u54, 
sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu, generic, rocket, 
sifive-7-series{{$}}
diff --git a/llvm/lib/Target/RISCV/RISCVProcessors.td 
b/llvm/lib/Target/RISCV/RISCVProcessors.td
index 5465e0c998ca6f8..a3dbcda3638f8f4 100644
--- a/llvm/lib/Target/RISCV/RISCVProcessors.td
+++ b/llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -244,3 +244,24 @@ def VENTANA_VEYRON_V1 : RISCVProcessorModel<"veyron-v1",
  FeatureStdExtZicboz,
  FeatureVendorXVentanaCondOps],
  [TuneVentanaVeyron]>;
+
+def XIANGSH

[clang] 760658c - [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (#70434)

2023-11-01 Thread via cfe-commits

Author: Brad Smith
Date: 2023-11-01T04:28:55-04:00
New Revision: 760658c118f491985ec00f62f5a261293db67b95

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

LOG: [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku 
(#70434)

Same as 12b87f6ef720080fab1e2d48ca2d8c5ba478ee5d and the addition to Gnu.

Added: 


Modified: 
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index ed7f751adc0efaf..cced977bf029256 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -144,6 +144,9 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index e7d9e9fc4c8..0b70ac7b76e6765 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -291,6 +291,9 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
@@ -364,9 +367,6 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
 
-  // Silence warnings when linking C code with a C++ '-stdlib' argument.
-  Args.ClaimAllArgs(options::OPT_stdlib_EQ);
-
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),

diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index b940150788f65c7..1df9c7b08879e45 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -95,6 +95,9 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 if (D.CCCIsCXX() && ToolChain.ShouldLinkCXXStdlib(Args))
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 7a1d4561c6f2f4f..cfde8d40a77ae16 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -315,6 +315,9 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.

diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 16a311be31be7bc..c5255573baf3ca5 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -214,6 +214,9 @@ void openbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("-lm");
 }
 
+// Silence warnings when linking C code with a C++ '-stdlib' argument.
+Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
 // Additional linker set-up and flags for Fortran. This is required in 
order
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dep

[clang] [Driver] Silence stdlib warning when linking C on *BSD / Solaris / Haiku (PR #70434)

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

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


[clang] b120fe8 - [clang][NFC] Refactor `ArgPassingKind`

2023-11-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-01T11:49:59+03:00
New Revision: b120fe8d3288c4dca1b5427ca34839ce8833f71c

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

LOG: [clang][NFC] Refactor `ArgPassingKind`

This patch moves `RecordDecl::ArgPassingKind` to DeclBase.h to namespace scope, 
so that it's complete at the time bit-field is declared.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..1c2158f51aa184d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4069,28 +4069,6 @@ class RecordDecl : public TagDecl {
 public:
   friend class DeclContext;
   friend class ASTDeclReader;
-  /// Enum that represents the 
diff erent ways arguments are passed to and
-  /// returned from function calls. This takes into account the target-specific
-  /// and version-specific rules along with the rules determined by the
-  /// language.
-  enum ArgPassingKind : unsigned {
-/// The argument of this type can be passed directly in registers.
-APK_CanPassInRegs,
-
-/// The argument of this type cannot be passed directly in registers.
-/// Records containing this type as a subobject are not forced to be passed
-/// indirectly. This value is used only in C++. This value is required by
-/// C++ because, in uncommon situations, it is possible for a class to have
-/// only trivial copy/move constructors even when one of its subobjects has
-/// a non-trivial copy/move constructor (if e.g. the corresponding 
copy/move
-/// constructor in the derived class is deleted).
-APK_CannotPassInRegs,
-
-/// The argument of this type cannot be passed directly in registers.
-/// Records containing this type as a subobject are forced to be passed
-/// indirectly.
-APK_CanNeverPassInRegs
-  };
 
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
@@ -4215,7 +4193,7 @@ class RecordDecl : public TagDecl {
   /// it must have at least one trivial, non-deleted copy or move constructor.
   /// FIXME: This should be set as part of completeDefinition.
   bool canPassInRegisters() const {
-return getArgPassingRestrictions() == APK_CanPassInRegs;
+return getArgPassingRestrictions() == ArgPassingKind::CanPassInRegs;
   }
 
   ArgPassingKind getArgPassingRestrictions() const {
@@ -4223,7 +4201,7 @@ class RecordDecl : public TagDecl {
   }
 
   void setArgPassingRestrictions(ArgPassingKind Kind) {
-RecordDeclBits.ArgPassingRestrictions = Kind;
+RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
   }
 
   bool isParamDestroyedInCallee() const {

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 978e4255e877ec2..ba6dadd7d3563c3 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1399,6 +1399,29 @@ enum class DeductionCandidate : unsigned char {
   Aggregate,
 };
 
+/// Enum that represents the 
diff erent ways arguments are passed to and
+/// returned from function calls. This takes into account the target-specific
+/// and version-specific rules along with the rules determined by the
+/// language.
+enum class ArgPassingKind {
+  /// The argument of this type can be passed directly in registers.
+  CanPassInRegs,
+
+  /// The argument of this type cannot be passed directly in registers.
+  /// Records containing this type as a subobject are not forced to be passed
+  /// indirectly. This value is used only in C++. This value is required by
+  /// C++ because, in uncommon situations, it is possible for a class to have
+  /// only trivial copy/move constructors even when one of its subobjects has
+  /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
+  /// constructor in the derived class is deleted).
+  CannotPassInRegs,
+
+  /// The argument of this type cannot be passed directly in registers.
+  /// Records containing this type as a subobject are forced to be passed
+  /// indirectly.
+  CanNeverPassInRegs
+};
+
 /// DeclContext - This is used only as base class of specific decl types that
 /// can act as declaration contexts. These decls are (only the top classes
 /// that directly derive from DeclContext are mentioned, not their subclasses):

diff  --git a/clan

[clang] [clang][analyzer] Restrict 'fopen' & 'tmpfile' modeling to POSIX versions in StreamChecker (PR #70540)

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

benshi001 wrote:

@balazske Do you have any further concern?

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


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

2023-11-01 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 3
+; RUN: opt -assume-default-is-flat-addrspace -S -passes=infer-address-spaces < 
%s 2>&1 | FileCheck %s
+
+@g = addrspace(1) global i32 0, align 4
+
+define ptr @f2() {
+; CHECK-LABEL: define ptr @f2() {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[X2:%.*]] = addrspacecast ptr addrspace(1) @g to ptr
+; CHECK-NEXT:ret ptr [[X2]]
+;
+entry:
+  %x1 = addrspacecast ptr addrspacecast (ptr addrspace(1) @g to ptr) to ptr 
addrspace(1)
+  %x2 = addrspacecast ptr addrspace(1) %x1 to ptr
+  ret ptr %x2
+}
+
+define ptr @f3() #0 {

arsenm wrote:

Should add a comment explaining why f3 is here. Maybe also rename it to 
something descriptive 

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


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

2023-11-01 Thread Matt Arsenault via cfe-commits


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

arsenm wrote:

What's the issue with putting this here? Seems nicer than inlining yet another 
DFS in another place 

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] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)

2023-11-01 Thread Ella Ma via cfe-commits

https://github.com/Snape3058 updated 
https://github.com/llvm/llvm-project/pull/70792

>From afda56104e079c177d7941ff1394636cb48e7347 Mon Sep 17 00:00:00 2001
From: Ella Ma 
Date: Tue, 31 Oct 2023 18:41:14 +0800
Subject: [PATCH] [analyzer] Fix uninitialized base class with initializer list
 when ctor is not declared in the base class

Fixes #70464

When ctor is not declared in the base class, initializing the base class
with the initializer list will not trigger a proper assignment of the
base region, as a CXXConstructExpr doing that is not available in the
AST.

This patch checks whether the init expr is an InitListExpr under a base
initializer, and adds a binding if so.
---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp |  8 +++
 clang/test/Analysis/issue-70464.cpp  | 68 
 2 files changed, 76 insertions(+)
 create mode 100644 clang/test/Analysis/issue-70464.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 2e67fb953e45611..24e91a22fd6884f 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1222,6 +1222,14 @@ void ExprEngine::ProcessInitializer(const CFGInitializer 
CFGInit,
   PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
   evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP);
 }
+  } else if (BMI->isBaseInitializer() && isa(Init)) {
+// When the base class is initialized with an initialization list and the
+// base class does not have a ctor, there will not be a CXXConstructExpr to
+// initialize the base region. Hence, we need to make the bind for it.
+SVal BaseLoc = getStoreManager().evalDerivedToBase(
+thisVal, QualType(BMI->getBaseClass(), 0), BMI->isBaseVirtual());
+SVal InitVal = State->getSVal(Init, stackFrame);
+evalBind(Tmp, Init, Pred, BaseLoc, InitVal, /*isInit=*/true);
   } else {
 assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer());
 Tmp.insert(Pred);
diff --git a/clang/test/Analysis/issue-70464.cpp 
b/clang/test/Analysis/issue-70464.cpp
new file mode 100644
index 000..f3b3072eb919823
--- /dev/null
+++ b/clang/test/Analysis/issue-70464.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_analyze_cc1 %s -verify 
-analyzer-checker=core,debug.ExprInspection
+
+// Refer to https://github.com/llvm/llvm-project/issues/70464 for more details.
+//
+// When the base class does not have a declared constructor, the base
+// initializer in the constructor of the derived class should use the given
+// initializer list to finish the initialization of the base class.
+//
+// Also testing base constructor and delegate constructor to make sure this
+// change will not break these two cases when a CXXConstructExpr is available.
+
+void clang_analyzer_dump(int);
+
+namespace init_list {
+
+struct Base {
+  int foox;
+};
+
+class Derived : public Base {
+public:
+  Derived() : Base{42} {
+// The dereference to this->foox below should be initialized properly.
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace init_list
+
+namespace base_ctor_call {
+
+struct Base {
+  int foox;
+  Base(int x) : foox(x) {}
+};
+
+class Derived : public Base {
+public:
+  Derived() : Base{42} {
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace base_ctor_call
+
+namespace delegate_ctor_call {
+
+struct Base {
+  int foox;
+};
+
+struct Derived : Base {
+  Derived(int parx) { this->foox = parx; }
+  Derived() : Derived{42} {
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace delegate_ctor_call

___
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

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

Looks reasonable to me. Probably best to have someone with more cmake 
experience double check that part.

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


[llvm] [clang] [clang-tools-extra] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-11-01 Thread via cfe-commits

zmodem wrote:

Just to double check: the commit message says "emit warning", but it should 
error by default, right?

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


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

2023-11-01 Thread Martin Storsjö via cfe-commits


@@ -53,3 +53,26 @@ add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN
   binary-to-decimal.cpp
   decimal-to-binary.cpp
 )
+
+if (DEFINED MSVC)
+  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)

mstorsjo wrote:

Instead of redefining `CMAKE_MSVC_RUNTIME_LIBRARY` repeatedly, if you really 
want to set it specifically for one library, it's better to set the 
`MSVC_RUNTIME_LIBRARY` target property instead - see 
https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html.

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] 50dec54 - [clang][NFC] Refactor `OMPDeclareReductionDecl::InitKind`

2023-11-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-01T12:40:13+03:00
New Revision: 50dec541f328a251c2830421f354e4439e635def

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

LOG: [clang][NFC] Refactor `OMPDeclareReductionDecl::InitKind`

This patch moves `OMPDeclareReductionDecl::InitKind` to DeclBase.h, so that 
it's complete at the point where corresponding bit-field is declared. This 
patch also converts it to scoped enum named `OMPDeclareReductionInitKind`

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclOpenMP.h
clang/lib/AST/DeclOpenMP.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index ba6dadd7d3563c3..7b743edf9452526 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1422,6 +1422,12 @@ enum class ArgPassingKind {
   CanNeverPassInRegs
 };
 
+enum class OMPDeclareReductionInitKind {
+  Call,   // Initialized by function call.
+  Direct, // omp_priv()
+  Copy// omp_priv = 
+};
+
 /// DeclContext - This is used only as base class of specific decl types that
 /// can act as declaration contexts. These decls are (only the top classes
 /// that directly derive from DeclContext are mentioned, not their subclasses):

diff  --git a/clang/include/clang/AST/DeclOpenMP.h 
b/clang/include/clang/AST/DeclOpenMP.h
index dd63a4f5d680cf5..2bbd159f59a3536 100644
--- a/clang/include/clang/AST/DeclOpenMP.h
+++ b/clang/include/clang/AST/DeclOpenMP.h
@@ -171,14 +171,7 @@ class OMPThreadPrivateDecl final : public 
OMPDeclarativeDirective {
 class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
   // This class stores some data in DeclContext::OMPDeclareReductionDeclBits
   // to save some space. Use the provided accessors to access it.
-public:
-  enum InitKind {
-CallInit,   // Initialized by function call.
-DirectInit, // omp_priv()
-CopyInit// omp_priv = 
-  };
 
-private:
   friend class ASTDeclReader;
   /// Combiner for declare reduction construct.
   Expr *Combiner = nullptr;
@@ -239,8 +232,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, 
public DeclContext {
   Expr *getInitializer() { return Initializer; }
   const Expr *getInitializer() const { return Initializer; }
   /// Get initializer kind.
-  InitKind getInitializerKind() const {
-return static_cast(OMPDeclareReductionDeclBits.InitializerKind);
+  OMPDeclareReductionInitKind getInitializerKind() const {
+return static_cast(
+OMPDeclareReductionDeclBits.InitializerKind);
   }
   /// Get Orig variable of the initializer.
   Expr *getInitOrig() { return Orig; }
@@ -249,9 +243,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, 
public DeclContext {
   Expr *getInitPriv() { return Priv; }
   const Expr *getInitPriv() const { return Priv; }
   /// Set initializer expression for the declare reduction construct.
-  void setInitializer(Expr *E, InitKind IK) {
+  void setInitializer(Expr *E, OMPDeclareReductionInitKind IK) {
 Initializer = E;
-OMPDeclareReductionDeclBits.InitializerKind = IK;
+OMPDeclareReductionDeclBits.InitializerKind = llvm::to_underlying(IK);
   }
   /// Set initializer Orig and Priv vars.
   void setInitializerData(Expr *OrigE, Expr *PrivE) {

diff  --git a/clang/lib/AST/DeclOpenMP.cpp b/clang/lib/AST/DeclOpenMP.cpp
index e29fc564fd34ac5..ac5780f82dbbb23 100644
--- a/clang/lib/AST/DeclOpenMP.cpp
+++ b/clang/lib/AST/DeclOpenMP.cpp
@@ -104,7 +104,7 @@ OMPDeclareReductionDecl::OMPDeclareReductionDecl(
 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
   PrevDeclInScope(PrevDeclInScope) {
-  setInitializer(nullptr, CallInit);
+  setInitializer(nullptr, OMPDeclareReductionInitKind::Call);
 }
 
 void OMPDeclareReductionDecl::anchor() {}

diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index daa219b43c4e6cf..98fba958064a106 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1866,17 +1866,17 @@ void 
DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
 if (auto *Init = D->getInitializer()) {
   Out << " initializer(";
   switch (D->getInitializerKind()) {
-  case OMPDeclareReductionDecl::DirectInit:
+  case OMPDeclareReductionInitKind::Direct:
 Out << "omp_priv(";
 break;
-  case OMPDeclareReductionDecl::CopyI

[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)

2023-11-01 Thread Nikita Popov via cfe-commits


@@ -5587,11 +5587,17 @@ Instruction 
*InstCombinerImpl::foldICmpWithZextOrSext(ICmpInst &ICmp) {
 return new ICmpInst(ICmp.getPredicate(), Builder.CreateOr(X, Y),
 Constant::getNullValue(X->getType()));
 
+  // Treat "zext nneg" as "sext"
+  bool IsNonNeg0 = isa(ICmp.getOperand(0));
+  bool IsNonNeg1 = isa(ICmp.getOperand(1));

nikic wrote:

This only checks whether the instruction *can* have an nneg flag, not whether 
it has it. You need to check `isNonNeg()` for that.

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


[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)

2023-11-01 Thread Nikita Popov via cfe-commits


@@ -0,0 +1,185 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --tool ./bin/opt --version 3
+; See PRXXX for more details
+; RUN-./bin/opt: opt < %s -S -passes=ipsccp | FileCheck %s

nikic wrote:

This is an ipsccp test in the InstCombine directory?

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


[clang] [llvm] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)

2023-11-01 Thread Nikita Popov via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -O2 -triple=x86_64-apple-darwin -emit-llvm -o - | 
FileCheck %s

nikic wrote:

We don't test end-to-end codegen with clang. If you want to test this, you 
should take the unoptimized clang IR and create a test in the 
llvm/test/PhaseOrdering directory using it.

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


[clang] b6b31e7 - [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class

2023-11-01 Thread via cfe-commits

Author: Ella Ma
Date: 2023-11-01T17:50:01+08:00
New Revision: b6b31e791b5ada286bace4c48243910985b0ac10

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

LOG: [analyzer] Fix uninitialized base class with initializer list when ctor is 
not declared in the base class

Fixes #70464

When ctor is not declared in the base class, initializing the base class
with the initializer list will not trigger a proper assignment of the
base region, as a CXXConstructExpr doing that is not available in the
AST.

This patch checks whether the init expr is an InitListExpr under a base
initializer, and adds a binding if so.

Added: 
clang/test/Analysis/issue-70464.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 2e67fb953e45611..24e91a22fd6884f 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1222,6 +1222,14 @@ void ExprEngine::ProcessInitializer(const CFGInitializer 
CFGInit,
   PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
   evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP);
 }
+  } else if (BMI->isBaseInitializer() && isa(Init)) {
+// When the base class is initialized with an initialization list and the
+// base class does not have a ctor, there will not be a CXXConstructExpr to
+// initialize the base region. Hence, we need to make the bind for it.
+SVal BaseLoc = getStoreManager().evalDerivedToBase(
+thisVal, QualType(BMI->getBaseClass(), 0), BMI->isBaseVirtual());
+SVal InitVal = State->getSVal(Init, stackFrame);
+evalBind(Tmp, Init, Pred, BaseLoc, InitVal, /*isInit=*/true);
   } else {
 assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer());
 Tmp.insert(Pred);

diff  --git a/clang/test/Analysis/issue-70464.cpp 
b/clang/test/Analysis/issue-70464.cpp
new file mode 100644
index 000..f3b3072eb919823
--- /dev/null
+++ b/clang/test/Analysis/issue-70464.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_analyze_cc1 %s -verify 
-analyzer-checker=core,debug.ExprInspection
+
+// Refer to https://github.com/llvm/llvm-project/issues/70464 for more details.
+//
+// When the base class does not have a declared constructor, the base
+// initializer in the constructor of the derived class should use the given
+// initializer list to finish the initialization of the base class.
+//
+// Also testing base constructor and delegate constructor to make sure this
+// change will not break these two cases when a CXXConstructExpr is available.
+
+void clang_analyzer_dump(int);
+
+namespace init_list {
+
+struct Base {
+  int foox;
+};
+
+class Derived : public Base {
+public:
+  Derived() : Base{42} {
+// The dereference to this->foox below should be initialized properly.
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace init_list
+
+namespace base_ctor_call {
+
+struct Base {
+  int foox;
+  Base(int x) : foox(x) {}
+};
+
+class Derived : public Base {
+public:
+  Derived() : Base{42} {
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace base_ctor_call
+
+namespace delegate_ctor_call {
+
+struct Base {
+  int foox;
+};
+
+struct Derived : Base {
+  Derived(int parx) { this->foox = parx; }
+  Derived() : Derived{42} {
+clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}}
+clang_analyzer_dump(foox); // expected-warning{{42 S32b}}
+  }
+};
+
+void entry() { Derived test; }
+
+} // namespace delegate_ctor_call



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


[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)

2023-11-01 Thread Ella Ma via cfe-commits

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


[clang] 39dfaf0 - [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (#68774)

2023-11-01 Thread via cfe-commits

Author: Exile
Date: 2023-11-01T18:29:37+08:00
New Revision: 39dfaf0d0d48ac53fca5a8123d2074dcc55ce6fd

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

LOG: [clang][ASTImporter] Fix crash when template class static member imported 
to other translation unit. (#68774)

Fixes: #68769

Co-authored-by: miaozhiyuan 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1cd8cf8fe328836..89c35af565fdeef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,6 +670,10 @@ Bug Fixes to C++ Support
   default initializing a base class in a constant expression context. Fixes:
   (`#69890 `_)
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 650ff201e66b72e..c4e931e220f69b5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4476,6 +4476,17 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 auto ToVTOrErr = import(D->getDescribedVarTemplate());
 if (!ToVTOrErr)
   return ToVTOrErr.takeError();
+  } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) 
{
+TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
+VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
+if (Expected ToInstOrErr = import(FromInst))
+  ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
+else
+  return ToInstOrErr.takeError();
+if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
+  ToVar->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+else
+  return POIOrErr.takeError();
   }
 
   if (Error Err = ImportInitializer(D, ToVar))

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 87e6cd1e160c4cc..0cbec5cf9ba062f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -1370,6 +1370,40 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportCorrectTemplatedDecl) {
   ASSERT_EQ(ToTemplated1, ToTemplated);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportTemplateSpecializationStaticMember) {
+  auto FromCode =
+  R"(
+  template  class Test{
+  public:
+static const unsigned int length;
+  };
+
+  template<> const unsigned int Test::length;
+  template<> const unsigned int Test::length = 0;
+  )";
+  auto ToCode =
+  R"(
+  template  class Test {
+  public:
+static const unsigned int length;
+  };
+
+  template <> const unsigned int Test::length;
+
+  void foo() { int i = 1 / Test::length; }
+  )";
+  Decl *FromTU = getTuDecl(FromCode, Lang_CXX14);
+  auto FromDecl = FirstDeclMatcher().match(
+  FromTU, varDecl(hasName("length"), isDefinition()));
+  Decl *ToTu = getToTuDecl(ToCode, Lang_CXX14);
+  auto ToX = Import(FromDecl, Lang_CXX03);
+  auto ToDecl = FirstDeclMatcher().match(
+  ToTu, varDecl(hasName("length"), isDefinition()));
+  EXPECT_TRUE(ToX);
+  EXPECT_EQ(ToX, ToDecl);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
   // This tests the import of isConditionTrue directly to make sure the 
importer
   // gets it right.



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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-11-01 Thread via cfe-commits

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


[clang] aaba376 - [clang][NFC] Refactor `ObjCMethodDecl::ImplementationControl`

2023-11-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-01T13:40:11+03:00
New Revision: aaba3761db84032541712899964714f3184e8b3d

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

LOG: [clang][NFC] Refactor `ObjCMethodDecl::ImplementationControl`

This patch moves `ObjCMethodDecl::ImplementationControl` to a DeclBase.h so 
that it's complete at the point where corresponsing bit-field is declared. This 
patch also converts it to a scoped enum `clang::ObjCImplementationControl`.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclObjC.h
clang/lib/ARCMigrate/ObjCMT.cpp
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/ODRDiagsEmitter.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaPseudoObject.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/tools/libclang/CIndex.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 7b743edf9452526..6f2c5b96554a9d1 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1428,6 +1428,8 @@ enum class OMPDeclareReductionInitKind {
   Copy// omp_priv = 
 };
 
+enum class ObjCImplementationControl { None, Required, Optional };
+
 /// DeclContext - This is used only as base class of specific decl types that
 /// can act as declaration contexts. These decls are (only the top classes
 /// that directly derive from DeclContext are mentioned, not their subclasses):

diff  --git a/clang/include/clang/AST/DeclObjC.h 
b/clang/include/clang/AST/DeclObjC.h
index ee8ec7a6a016ba3..2b205bee51de18e 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -139,10 +139,6 @@ class ObjCMethodDecl : public NamedDecl, public 
DeclContext {
   // This class stores some data in DeclContext::ObjCMethodDeclBits
   // to save some space. Use the provided accessors to access it.
 
-public:
-  enum ImplementationControl { None, Required, Optional };
-
-private:
   /// Return type of this method.
   QualType MethodDeclType;
 
@@ -168,14 +164,14 @@ class ObjCMethodDecl : public NamedDecl, public 
DeclContext {
   /// constructed by createImplicitParams.
   ImplicitParamDecl *CmdDecl = nullptr;
 
-  ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
- Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
- DeclContext *contextDecl, bool isInstance = true,
- bool isVariadic = false, bool isPropertyAccessor = false,
- bool isSynthesizedAccessorStub = false,
- bool isImplicitlyDeclared = false, bool isDefined = false,
- ImplementationControl impControl = None,
- bool HasRelatedResultType = false);
+  ObjCMethodDecl(
+  SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo,
+  QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl,
+  bool isInstance = true, bool isVariadic = false,
+  bool isPropertyAccessor = false, bool isSynthesizedAccessorStub = false,
+  bool isImplicitlyDeclared = false, bool isDefined = false,
+  ObjCImplementationControl impControl = ObjCImplementationControl::None,
+  bool HasRelatedResultType = false);
 
   SelectorLocationsKind getSelLocsKind() const {
 return static_cast(ObjCMethodDeclBits.SelLocsKind);
@@ -235,7 +231,7 @@ class ObjCMethodDecl : public NamedDecl, public DeclContext 
{
  bool isVariadic = false, bool isPropertyAccessor = false,
  bool isSynthesizedAccessorStub = false,
  bool isImplicitlyDeclared = false, bool isDefined = false,
- ImplementationControl impControl = None,
+ ObjCImplementationControl impControl = 
ObjCImplementationControl::None,
  bool HasRelatedResultType = false);
 
   static ObjCMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@@ -495,16 +491,17 @@ class ObjCMethodDecl : public NamedDecl, public 
DeclContext {
   const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
 
   // Related to protocols declared in  \@protocol
-  void setDeclImplementation(ImplementationControl ic) {
-ObjCMethodDeclBits.DeclImplementation = ic;
+  void setDeclImplementation(ObjCImplementationControl ic) {
+ObjCMethodDeclBits.DeclImplementation = llvm::to_underlying(ic);
   }
 
-  ImplementationControl getImplementa

[clang] ba31ed4 - Disable memtag sanitization for global fnptrs going into .ctors (#70186)

2023-11-01 Thread via cfe-commits

Author: Mitch Phillips
Date: 2023-11-01T11:43:28+01:00
New Revision: ba31ed472577aea1f4b5d6669bb1e717aaf1fb4f

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

LOG: Disable memtag sanitization for global fnptrs going into .ctors (#70186)

Looks like there's code out there that, instead of using
'__attribute__((constructor(x)))' to add constructor functions, they
just declare a global function pointer and use
'__attribute__((section('.ctors')))' instead.

Problem is, with memtag-globals, we pad the global function pointer to
be 16 bytes large. This of course means we have an 8-byte real function
pointer, then 8 bytes of zero padding, and this trips up the loader when
it processes this section.

Fixes #69939

Added: 


Modified: 
clang/test/CodeGen/memtag-globals-asm.cpp
llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

Removed: 




diff  --git a/clang/test/CodeGen/memtag-globals-asm.cpp 
b/clang/test/CodeGen/memtag-globals-asm.cpp
index 3f18671562def71..4b76b394e0c1dc3 100644
--- a/clang/test/CodeGen/memtag-globals-asm.cpp
+++ b/clang/test/CodeGen/memtag-globals-asm.cpp
@@ -259,3 +259,23 @@ int f(int x) {
   // CHECK-Q-DAG: ldr   {{.*}}, [[[REG_O2]]]
   function_int;
 }
+
+typedef void (*func_t)(void);
+#define CONSTRUCTOR(section_name) \
+  __attribute__((used)) __attribute__((section(section_name)))
+
+__attribute__((constructor(0))) void func_constructor() {}
+CONSTRUCTOR(".init") func_t func_init = func_constructor;
+CONSTRUCTOR(".fini") func_t func_fini = func_constructor;
+CONSTRUCTOR(".ctors") func_t func_ctors = func_constructor;
+CONSTRUCTOR(".dtors") func_t func_dtors = func_constructor;
+CONSTRUCTOR(".init_array") func_t func_init_array = func_constructor;
+CONSTRUCTOR(".fini_array") func_t func_fini_array = func_constructor;
+
+// CHECK-NOT: .memtag func_constructor
+// CHECK-NOT: .memtag func_init
+// CHECK-NOT: .memtag func_fini
+// CHECK-NOT: .memtag func_ctors
+// CHECK-NOT: .memtag func_dtors
+// CHECK-NOT: .memtag func_init_array
+// CHECK-NOT: .memtag func_fini_array

diff  --git a/llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp 
b/llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
index 2ed668712897ce7..88e44eb0bfbb99f 100644
--- a/llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp
@@ -43,6 +43,18 @@ static bool shouldTagGlobal(GlobalVariable &G) {
 return false;
   }
 
+  // Don't instrument function pointers that are going into various init arrays
+  // via `__attribute__((section()))`:
+  // https://github.com/llvm/llvm-project/issues/69939
+  if (G.hasSection() &&
+  (G.getSection() == ".init" || G.getSection() == ".fini" ||
+   G.getSection() == ".init_array" || G.getSection() == ".fini_array" ||
+   G.getSection() == ".ctors" || G.getSection() == ".dtors")) {
+Meta.Memtag = false;
+G.setSanitizerMetadata(Meta);
+return false;
+  }
+
   return true;
 }
 



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


[clang] [llvm] Disable memtag sanitization for global fnptrs going into .ctors (PR #70186)

2023-11-01 Thread Mitch Phillips via cfe-commits

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


[PATCH] D151188: [LLD][COFF] Add LLVM toolchain library paths by default.

2023-11-01 Thread Jason via Phabricator via cfe-commits
JasonWoodArm added a comment.

Is it possible to override this behaviour ? We have an issue where we have our 
own FortranRuntimelib built with MT linkage and in the past I could just 
specify a path and -lFortranRuntime and all was well. Having just moved our 
machines to llvm17 this no longer works as it always overrides our libraries 
with the installed (MD linkage) versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151188

___
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 Michael Buch via cfe-commits

Michael137 wrote:

Hmmm it seems like for `constexpr static` data members we don't get a symbol in 
the MachO the same way we do for out-of-line `const static`s that have a 
location:
```
struct Foo {   
static const int val1; 
static constexpr int val2 = 5; 
}; 
   
const int Foo::val1 = 10;  

$ nm a.out
00013fa4 S __ZN3Foo4val1E 
0001 T __mh_execute_header
00013f90 T _main
```

LLDB can fish out the value out of `val1` by doing a `FindSymbol` on the 
mangled name. But that doesn't work with `val2` because it's not in the symbol 
table. @clayborg or @jasonmolenda probably know more about this.

Seems to me like if we want to drop the constant off of the declaration 
entirely, we need to lookup the variable definition in the accelerator table in 
DWARFASTParserClang when we're constructing the VarDecls.

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] 5084891 - [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)

2023-11-01 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-11-01T12:02:19+01:00
New Revision: 50848916e5e4f07231c7366e6d0014de6f7bc362

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

LOG: [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)

We're working on a ConstantInt here, so folding cannot fail. Only
avoid the API use.

Added: 


Modified: 
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index c46f38d651972bc..cd91a698a9336f8 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1930,8 +1930,9 @@ ConstantLValueEmitter::tryEmitAbsolute(llvm::Type 
*destTy) {
   // FIXME: signedness depends on the original integer type.
   auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy);
   llvm::Constant *C;
-  C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy,
- /*isSigned*/ false);
+  C = llvm::ConstantFoldIntegerCast(getOffset(), intptrTy, /*isSigned*/ false,
+CGM.getDataLayout());
+  assert(C && "Must have folded, as Offset is a ConstantInt");
   C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy);
   return C;
 }



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


[flang] [clang] [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


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

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


@@ -53,3 +53,26 @@ add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN
   binary-to-decimal.cpp
   decimal-to-binary.cpp
 )
+
+if (DEFINED MSVC)
+  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)

DavidTruby wrote:

Yeah I tried this but inside add_flang_library these are made into custom 
targets (meaning the target property doesn’t do anything) and I’m not entirely 
sure why so I didn’t want to mess with it too much. I’ll give it another try

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


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

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

Michael137 wrote:

> One question I have here: where will the DW_TAG_variable get emitted for 
> these `constexpr`? For actual static member variables we emit a single 
> DW_TAG_variable in the file that declares the global variable, but for 
> `constexpr` we won't be able to do this will we? Will we end up emitting a 
> new copy each time someone include the header file? In that case we might end 
> up with many global variables being defined in a linked executable that 
> includes this header file more than once?

That's true, if defined in a header, we'll emit a `DW_TAG_variable` for the 
constant in each compile unit the header is included in. GCC does do the right 
thing and only emit the definition DIE in a single CU. We should probably do 
the same. Though not sure at which level. Possibly the DWARF linker?

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] Do not clear FP pragma stack when instantiating functions (PR #70646)

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

AaronBallman wrote:

> And contrariwise, if there's some sneaky way to put push/pop pragmas in 
> non-file contexts, that also seems like a serious problem, because the way we 
> process them is not designed to understand local scopes, which means we're 
> just doing random stuff instead of implementing any sort of intelligible 
> language design.

What if it's a non-sneaky way? ;-) C has several fp-related pragmas that are 
required to be supported at block scope. For example, the specification for 
`#pragma STDC FP_CONTRACT` (C23 7.12.2p2) says: 

> ... Each pragma can occur either outside external declarations or preceding 
> all explicit declarations and statements inside a compound statement. When 
> outside external declarations, the pragma takes effect from its occurrence 
> until another FP_CONTRACT pragma is encountered, or until the end of the 
> translation unit. When inside a compound statement, the pragma takes effect 
> from its occurrence until another FP_CONTRACT pragma is encountered 
> (including within a nested compound statement), or until the end of the 
> compound statement; at the end of a compound statement the state for the 
> pragma is restored to its condition just before the compound statement. If 
> this pragma is used in any other context, the behavior is undefined. ...

Other standard pragmas have similar wording. CC @zahiraam who has also been 
working on pragmas in this area.

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

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


@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;

AaronBallman wrote:

Go ahead and break clang-format; it's not paying attention to the surrounding 
coding style which is what we're supposed to do per community policy. No need 
to add clutter comments.

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


[clang] [Clang] Add __datasizeof (PR #67805)

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

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

LGTM with the new codegen test, thank you!

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


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

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

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/70927

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

>From 48dc5f677a5d4eb5e2bc012665f69cc038a20407 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 1 Nov 2023 17:32:10 +0800
Subject: [PATCH] [clang][analyzer] Simplify method 'ensureStreamNonNull' of
 StreamChecker

The passed in parameter 'State' is always identical to 'C.getState()'.
---
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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] [clang][analyzer] Simplify method 'ensureStreamNonNull' of StreamChecker (PR #70927)

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

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/70927

>From 1cb32d9bb1b48af8282799d9879b91ae45bf035e Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 1 Nov 2023 17:32:10 +0800
Subject: [PATCH] [clang][analyzer][NFC] Simplify method 'ensureStreamNonNull'
 of StreamChecker

The passed in parameter 'State' is always identical to 'C.getState()'.
---
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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] [clang][analyzer] Simplify method 'ensureStreamNonNull' of StreamChecker (PR #70927)

2023-11-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes

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

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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+1-1) 


``diff
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)) {

``




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] [clang][analyzer]][NFC] Simplify method 'ensureStreamNonNull' of StreamChecker (PR #70927)

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

https://github.com/benshi001 edited 
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-tools-extra] [clang] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

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


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

AaronBallman wrote:

> > Should we also consider updating 
> > https://clang.llvm.org/docs/InternalsManual.html#arguments to explain this 
> > particular argument in more detail given that it's a pretty complicated 
> > argument already?
> 
> Looks like this doesn't go into detail about the types of arguments at all 
> currently. I'll put a note on my todo list to update this separately if you 
> don't mind.

Yeah, I never documented the argument types because they used to be rather 
self-documenting in a lot of ways. We should have started updating these docs a 
while ago though. Doing it in a follow-up is fine by me (and even if you only 
do `EnumArgument`; I'm not asking you to sign up to document them all unless 
you want to).

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


[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

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

AaronBallman wrote:

This appears to have broken some bots:
https://lab.llvm.org/buildbot/#/builders/119/builds/15633
https://lab.llvm.org/buildbot/#/builders/60/builds/14449

Can you investigate and get those bots back to green?

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


[clang] [clang] Change representation of CurLexerKind (PR #70381)

2023-11-01 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/70381

>From 8ee0ca67fcd45ba462701ba2b4c58d412d77d2bd Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Thu, 26 Oct 2023 22:31:43 +0200
Subject: [PATCH 1/4] [clang] Change representation of CurLexerKind

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on
compile time tracker are consistent and range form -0.05% to -0.20%
for NewPM-O0-g, see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef&to=608c85ec1283638db949d73e062bcc3355001ce4&stat=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)
---
 clang/include/clang/Lex/Preprocessor.h| 46 +++-
 clang/lib/Lex/PPCaching.cpp   |  8 +--
 clang/lib/Lex/PPLexerChange.cpp   | 20 +++
 clang/lib/Lex/Preprocessor.cpp| 67 ++-
 clang/utils/ClangVisualizers/clang.natvis |  2 +-
 5 files changed, 62 insertions(+), 81 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4a99447e757c6ac..82792c5ec48dae5 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = &CLK_Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &&TheLexer,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &&TheTokenLexer,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -1914,7 +1909,7 @@ class Preprocessor {
 
   /// Recompute the current lexer kind based on the CurLexer/
   /// CurTokenLexer pointers.
-  void recomputeCurLexerKind();
+  void recomputeCurLexerCallback();
 
   /// Returns true if incremental processing is enabled
   bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+ 

[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)

2023-11-01 Thread via cfe-commits

MaggieYingYi wrote:

Hi @AaronBallman and @nikic, are you happy for me to recommit the change? Thanks

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


[clang] [llvm] [ASAN] For Asan instrumented global, emit two symbols, one with actual size and other with instrumented size. (PR #70166)

2023-11-01 Thread Mitch Phillips via cfe-commits

hctim wrote:

> > It's my understanding your problem is that you are asan-trapping on the 
> > redzones when you copy data to/from the device. Is it possible instead to 
> > just make those copy-from and copy-to functions in the runtime 
> > `__attribute__((no_sanitize("address")))` and copy the padding as well?
> 
> Yes it is possible, but it would result in bugs being hidden...the very bugs 
> that ASAN is meant to catch. This is not an acceptable option for us.

Only bugs in the `copy_from_` and `copy_to_` functions though (which should be 
pretty clear)?

--

Alright, let's give this a crack. I'll leave some comments here and on #68865, 
but let's not worry about potential unknown problems and we can see what shakes 
out once we actually submit the patches.

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


[clang] 47d9fbc - [LinkerWrapper] Add 'Freestanding' config to the LTO pass

2023-11-01 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-11-01T07:47:25-05:00
New Revision: 47d9fbc04b91fb03b6da294e82c2fb4bca6b6343

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

LOG: [LinkerWrapper] Add 'Freestanding' config to the LTO pass

Summary:
These GPU images are expected to be freestanding, so we should disable
emission of builtins for whatever target we are offloading to.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 1c269ce890b3b71..bafe8ace60d1cea 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -526,6 +526,7 @@ std::unique_ptr createLTO(
 
   Conf.CPU = Arch.str();
   Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
+  Conf.Freestanding = true;
 
   StringRef OptLevel = Args.getLastArgValue(OPT_opt_level, "O2");
   Conf.MAttrs = Features;



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


[clang-tools-extra] [clang] [llvm] [AMDGPU] GCNRegPressure printing pass for testing. (PR #70031)

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

vpykhtin wrote:

Should we move on and submit this patch? @jayfoad do you have concerns about 
live-through register set computation or others? I believe fixing trackers 
should go to another PR.

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] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)

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

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

LGTM, thank you!

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


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-01 Thread Björn Schäpers via cfe-commits


@@ -185,6 +191,8 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
+if args.non_zero_exit_code:
+sys.exit(1)

HazardyKnusperkeks wrote:

But it may be a breaking change for others if it suddenly does not return 0.

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


[clang] [llvm] [ASAN] For Asan instrumented global, emit two symbols, one with actual size and other with instrumented size. (PR #70166)

2023-11-01 Thread Mitch Phillips via cfe-commits

hctim wrote:

Will wait for a rebase on some changes requested in #68865, but it'd also be 
really important to write tests for a couple more scenarios:

 1. Building with `-fsanitize=address -S -emit-llvm` results in GVs with 
`sanitized_padded_global` (and results in GVs without `sanitized_padded_global` 
if they have `__attribute__((no_sanitize("address")))` for example). See 
`clang/test/CodeGen/memtag-globals.cpp`.
 2. Running #1 through bitcode back/forth to make sure you still have the same 
attributes sets (to ensure you got the parser/writer logic correct). See 
`llvm/test/Bitcode/compatibility.ll` and 
`llvm/test/Assembler/globalvariable-attributes.ll`.


https://github.com/llvm/llvm-project/pull/70166
___
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

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

Attempt to enable OpenCL hostcall printf (SWDEV-204804).  I would like to have 
some inputs regarding few key points listed here,

1. We continue to use "-mprintf-kind" option to decide the lowering scheme. It 
now supports a new value "none" that just makes compiler use default lowering 
scheme. (hostcalls for HIP, Buffered for OpenCL)
2. OpenCL now treats printf as a builtin so that the printf expansion happens 
via clang CodeGen. This would also mean that the "AMDGPUPrintfRuntimeBinding" 
pass would no longer be required since all printf calls would be expanded 
earlier.
3. The implementation adds vector processing support both for hostcall and 
buffered cases. The vector elements are extracted and pushed onto the buffer 
individually (each alingned to 8 byte boundary)
4. for OpenCL hostcall case, The format string pointer is addrspace casted to 
generic address space to be compatible with hostcall device lib functions.


>From 9eec2462d07122f8376f1e60b2e679cc69814430 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 c8b730e0f7ecd84..0fb7758845ff868 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 pri

[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

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

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


[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

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

https://github.com/AaronBallman commented:

FWIW, when the description for the PR says it can't be merged for some reason, 
it usually goes on the bottom of my review queue until those issues are 
addressed. It's difficult to accept known-broken code. :-(

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


[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

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


@@ -167,17 +169,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return add(A, One, A.bitWidth() + 1, R);
   }
 
   static bool decrement(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return sub(A, One, A.bitWidth() + 1, R);

AaronBallman wrote:

Why does this extend the bit width by 1?

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


[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

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


@@ -167,17 +169,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());

AaronBallman wrote:

```suggestion
static constexpr IntegralAP One(1, A.bitWidth());
```
Can we do this so we don't have to create the same `IntegralAP` object every 
time? (Same suggestion below.)

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


[clang] [clang-format] Treat empty for/while loops as short loops (PR #70768)

2023-11-01 Thread Björn Schäpers via cfe-commits


@@ -3117,9 +3117,16 @@ void UnwrappedLineParser::parseForOrWhileLoop(bool 
HasParens) {
   FormatTok->setFinalizedType(TT_ConditionLParen);
 parseParens();
   }
-  // Event control.
-  if (Style.isVerilog())
+
+  if (Style.isVerilog()) {
+// Event control.
 parseVerilogSensitivityList();
+  } else if (Style.AllowShortLoopsOnASingleLine && FormatTok->is(tok::semi) &&

HazardyKnusperkeks wrote:

Just asking.
But I believe if you use `getPreviousNonComment()` it would be formatted as 
that.

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


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

2023-11-01 Thread Brad King via cfe-commits

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


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


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

2023-11-01 Thread Brad King via cfe-commits

https://github.com/bradking 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


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

2023-11-01 Thread Brad King 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;
+if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
+  RTOptionID = llvm::StringSwitch(rtl->getValue())
+   .Case("static", options::OPT__SLASH_MT)
+   .Case("static_dbg", options::OPT__SLASH_MTd)
+   .Case("dll", options::OPT__SLASH_MD)
+   .Case("dll_dbg", options::OPT__SLASH_MDd)
+   .Default(options::OPT__SLASH_MT);
+}
+switch (RTOptionID) {
+case options::OPT__SLASH_MT:
+  CmdArgs.push_back("/DEFAULTLIB:libcmt");
+  CmdArgs.push_back("Fortran_main.static.lib");
+  CmdArgs.push_back("FortranRuntime.static.lib");
+  CmdArgs.push_back("FortranDecimal.static.lib");
+  break;
+case options::OPT__SLASH_MTd:
+  CmdArgs.push_back("/DEFAULTLIB:libcmtd");
+  CmdArgs.push_back("Fortran_main.static_debug.lib");
+  CmdArgs.push_back("FortranRuntime.static_debug.lib");
+  CmdArgs.push_back("FortranDecimal.static_debug.lib");
+  break;
+case options::OPT__SLASH_MD:
+  CmdArgs.push_back("/DEFAULTLIB:msvcrt");
+  CmdArgs.push_back("Fortran_main.dynamic.lib");
+  CmdArgs.push_back("FortranRuntime.dynamic.lib");
+  CmdArgs.push_back("FortranDecimal.dynamic.lib");
+  break;

bradking wrote:

>From https://github.com/llvm/llvm-project/pull/70833#issuecomment-1787651022:

> I think you're probably right in the linked issue that it'd be better to add 
> defaultlib directives to the object files, but that appears to be quite 
> difficult as we'd need to track the attributes all the way through our MLIR 
> lowering, so as a (hopefully temporary) shortcut I have just passed the 
> libraries on the link line.

This temporary approach will actually make things harder for CMake to support 
`flang-new`.  In order to support mixed-language (e.g., Fortran and C++) 
binaries we detect the implicit link directories and libraries that each 
compiler driver passes to the linker when used to drive linking.  Then if we 
have to link using a different language's tooling, we can add them explicitly.  
We don't typically do that for the MSVC ABI though because the set of runtime 
libraries varies with the CRT choice and the defaultlib directives in object 
files handle it automatically anyway.  Currently CMake is working around the 
lack of defaultlib directives for `flang-new` by using the 
implicit-lib-detection approach.  Once the implicitly linked runtime libraries 
vary with the CRT, we would need a lot of dedicated non-trivial infrastructure 
to handle all the `MSVC_RUNTIME_LIBRARY` variants, and I'm not sure it's 
possible in all cases.

Can you instead add these four CRT-specific libraries as defaultlib directives 
in all object files, and add the more detailed conditions to remove unnecessary 
libraries later?  Since they are all static `.lib` files, unused directives may 
not hurt.



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


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

2023-11-01 Thread Brad King via cfe-commits


@@ -53,3 +53,26 @@ add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN
   binary-to-decimal.cpp
   decimal-to-binary.cpp
 )
+
+if (DEFINED MSVC)
+  set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)

bradking wrote:

`add_flang_library` eventually ends up in `llvm/cmake/modules/AddLLVM.cmake`'s 
`llvm_add_library` which calls `add_library(${name} STATIC ...)`.  All 
`CMAKE_MSVC_RUNTIME_LIBRARY` does is initialize the `MSVC_RUNTIME_LIBRARY` 
property on that target when it is created.

You should be able to do

```cmake
add_flang_library(FortranDecimal.static ...)
set_property(TARGET FortranDecimal.static PROPERTY MSVC_RUNTIME_LIBRARY 
MultiThreaded)
```


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


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

2023-11-01 Thread Brad King 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;

bradking wrote:

As of LLVM 17.0's distribution, the Fortran runtime libraries are built with 
`msvcrt`, so I think the current default is actually `/MD`.  Since this wasn't 
really modeled before, and CMake will be taught to pass one of the four flags 
explicitly anyway, changing the default may not matter, but it's something to 
be aware of.


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]get non-injected-class before finding instantiated decl (PR #70886)

2023-11-01 Thread Henrik G. Olsson via cfe-commits


@@ -429,3 +429,19 @@ namespace qualified_friend_no_match {
 friend void Y::f(double); // expected-error {{friend declaration of 'f' 
does not match any declaration in 'qualified_friend_no_match::Y'}}
   };
 }
+
+namespace gh21483 {
+template 
+struct B {
+  struct mixin {
+int type;
+friend void foo(B::mixin it) {
+  (void)it.mixin::type;

hnrklssn wrote:

Why is `it.mixin` not an error? I thought `it` was of type `B::mixin`, 
which has no `mixin` field.

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


[clang] [clang]get non-injected-class before finding instantiated decl (PR #70886)

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


@@ -429,3 +429,19 @@ namespace qualified_friend_no_match {
 friend void Y::f(double); // expected-error {{friend declaration of 'f' 
does not match any declaration in 'qualified_friend_no_match::Y'}}
   };
 }
+
+namespace gh21483 {
+template 
+struct B {
+  struct mixin {
+int type;
+friend void foo(B::mixin it) {
+  (void)it.mixin::type;

HerrCai0907 wrote:

`::` is scope resolution operator.
A more clear example is 
```c++
struct T {
int a;
};
struct T1 : public T {
int a;
};

void foo () {
T1{}.T::a;
T1{}.T1::a;
}
```
https://godbolt.org/z/K1b1jodse

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


[clang] [AArch64][Clang] Refactor code to emit SVE & SME builtins (PR #70662)

2023-11-01 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.


https://github.com/llvm/llvm-project/pull/70662
___
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 Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/65638
___
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 Aaron Ballman via cfe-commits


@@ -5339,16 +5339,22 @@ 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;
+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;
+}

AaronBallman wrote:

```suggestion
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;
```
Changes for our odd choice coding style and to be slightly more succinct.

https://github.com/llvm/llvm-project/pull/65638
___
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 Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Aside from some nits, I think this looks reasonable to me. I'll leave the final 
sign-off to @erichkeane but if he doesn't approve in the next few days (WG21 
meetings are upcoming so he may be busy), I'll come back to approve.

Thank you for all the help on this one! It turns out `good first issue` is 
really hard to determine accurately. ;-)

https://github.com/llvm/llvm-project/pull/65638
___
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 Aaron Ballman via cfe-commits


@@ -264,6 +264,11 @@ Attribute Changes in Clang
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: `_)
 
+- 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.
+

AaronBallman wrote:

```suggestion
  declaration specifiers.
  (#58637 `_)
```

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


[clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-01 Thread Henrik G. Olsson via cfe-commits


@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,reorder 
-Wno-c99-designator -Werror=reorder-init-list -Wno-initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,override 
-Wno-c99-designator -Wno-reorder-init-list -Werror=initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected -Wno-c99-designator 
-Wno-reorder-init-list -Wno-initializer-overrides
-// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing 
-Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list 
-Wno-initializer-overrides
+// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing 
-Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list 
-Wno-initializer-overrides -D NON_PEDANTIC

hnrklssn wrote:

Imo it's clearer to unconditionally compile the same code for each test case, 
and instead introduce another `-verify` prefix for the diagnostics that aren't 
emitted by this invocation.

https://github.com/llvm/llvm-project/pull/70829
___
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 Aaron Ballman via cfe-commits


@@ -451,3 +451,5 @@ namespace P2361 {
  // expected-warning {{use of the 'deprecated' 
attribute is a C++14 extension}}
 [[nodiscard("\123")]] int b(); // expected-error{{invalid escape sequence 
'\123' in an unevaluated string literal}}
 }
+
+alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced 
attributes; expected attributes here}}

AaronBallman wrote:

Note to other reviewers, this C++ test exhibits the same behavior on trunk 
already: https://godbolt.org/z/s5T3hfxsr

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


[clang] [clang-tools-extra] [llvm] [AMDGPU] GCNRegPressure printing pass for testing. (PR #70031)

2023-11-01 Thread Jay Foad via cfe-commits

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

> Should we move on and submit this patch?

Yes!

> @jayfoad do you have concerns about live-through register set computation or 
> others?

I personally have no interest in the live-through part. You could remove it 
from this patch, but I don't mind if others want to keep it.

> I believe fixing trackers should go to another PR.

Agreed.

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] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-01 Thread Henrik G. Olsson via cfe-commits


@@ -2537,19 +2555,13 @@ class FieldInitializerValidatorCCC final : public 
CorrectionCandidateCallback {
 /// actually be initialized.

hnrklssn wrote:

The comment above looks like it needs to be updated with `@param`s for 
`FinishSubobjectInit`, `TopLevelObject` and `InitializedFields`.

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


[clang] 700d93b - Add two time-trace scope variables.

2023-11-01 Thread Ying Yi via cfe-commits

Author: Ying Yi
Date: 2023-11-01T13:37:52Z
New Revision: 700d93b0584c9d6401ec646fc3e343e90f326fa2

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

LOG: Add two time-trace scope variables.

A time trace scope variable of `ParseDeclarationOrFunctionDefinition`
with the function's source location is added to record the time spent
parsing the function's declaration or definition. Another time trace
scope variable of `ParseFunctionDefinition` is also added to record the
name of the defined function. A release note is added as well.

Reviewed by: Aaron Ballman
Pull request: #65268

Added: 
clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/Parser.cpp
clang/unittests/Support/TimeProfilerTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89c35af565fdeef..103dcbeb79624d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,14 @@ Improvements to Clang's diagnostics
   (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to 
be more consistent
   with GCC.
 
+Improvements to Clang's time-trace
+--
+- Two time-trace scope variables are added. A time trace scope variable of
+  ``ParseDeclarationOrFunctionDefinition`` with the function's source location
+  is added to record the time spent parsing the function's declaration or
+  definition. Another time trace scope variable of ``ParseFunctionDefinition``
+  is also added to record the name of the defined function.
+
 Bug Fixes in This Version
 -
 - Fixed an issue where a class template specialization whose declaration is

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 0f930248e77174b..176d2149e73184e 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -13,8 +13,8 @@
 #include "clang/Parse/Parser.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
@@ -22,6 +22,7 @@
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
 
@@ -1229,6 +1230,13 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclOrFunctionDefInternal(
 Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
 ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
 ParsingDeclSpec *DS, AccessSpecifier AS) {
+  // Add an enclosing time trace scope for a bunch of small scopes with
+  // "EvaluateAsConstExpr".
+  llvm::TimeTraceScope TimeScope("ParseDeclarationOrFunctionDefinition", [&]() 
{
+return Tok.getLocation().printToString(
+Actions.getASTContext().getSourceManager());
+  });
+
   if (DS) {
 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {
@@ -1259,6 +1267,10 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclarationOrFunctionDefinition(
 Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
   const ParsedTemplateInfo &TemplateInfo,
   LateParsedAttrList *LateParsedAttrs) {
+  llvm::TimeTraceScope TimeScope("ParseFunctionDefinition", [&]() {
+return Actions.GetNameForDeclarator(D).getName().getAsString();
+  });
+
   // Poison SEH identifiers so they are flagged as illegal in function bodies.
   PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true);
   const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();

diff  --git 
a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
new file mode 100644
index 000..f854cddadbfcc1d
--- /dev/null
+++ 
b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o 
%T/check-time-trace-ParseDeclarationOrFunctionDefinition %s
+// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \
+// RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN:   | FileCheck %s
+
+// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition"
+// CHECK-DAG: "detail": 
"{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1"
+// CHECK-DAG: "name": "ParseFunctionDefinition"
+// CHECK-DAG: "detail": "foo"
+// CHECK-DAG: "na

[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)

2023-11-01 Thread via cfe-commits

MaggieYingYi wrote:

Thanks @AaronBallman, the patch is recommitted. 

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


[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)

2023-11-01 Thread via cfe-commits

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


[clang] 6576120 - [clang][NFC] Refactor `LinkageSpecDecl::LanguageIDs`

2023-11-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-01T16:44:34+03:00
New Revision: 65761200ce4e1f366e8418652efdafd2f744291b

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

LOG: [clang][NFC] Refactor `LinkageSpecDecl::LanguageIDs`

This patch converts `LinkageSpecDecl::LanguageIDs` into scoped enum, and moves 
it to namespace scope, so that it can be forward-declared where required.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 6f2c5b96554a9d1..32b6aed6397668c 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1430,6 +1430,8 @@ enum class OMPDeclareReductionInitKind {
 
 enum class ObjCImplementationControl { None, Required, Optional };
 
+enum class LinkageSpecLanguageIDs;
+
 /// DeclContext - This is used only as base class of specific decl types that
 /// can act as declaration contexts. These decls are (only the top classes
 /// that directly derive from DeclContext are mentioned, not their subclasses):

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 5eaae6bdd2bc63e..df1dc5a401f39a5 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2897,6 +2897,12 @@ class CXXConversionDecl : public CXXMethodDecl {
   static bool classofKind(Kind K) { return K == CXXConversion; }
 };
 
+/// Represents the language in a linkage specification.
+///
+/// The values are part of the serialization ABI for
+/// ASTs and cannot be changed without altering that ABI.
+enum class LinkageSpecLanguageIDs { C = 1, CXX = 2 };
+
 /// Represents a linkage specification.
 ///
 /// For example:
@@ -2907,14 +2913,7 @@ class LinkageSpecDecl : public Decl, public DeclContext {
   virtual void anchor();
   // This class stores some data in DeclContext::LinkageSpecDeclBits to save
   // some space. Use the provided accessors to access it.
-public:
-  /// Represents the language in a linkage specification.
-  ///
-  /// The values are part of the serialization ABI for
-  /// ASTs and cannot be changed without altering that ABI.
-  enum LanguageIDs { lang_c = 1, lang_cxx = 2 };
 
-private:
   /// The source location for the extern keyword.
   SourceLocation ExternLoc;
 
@@ -2922,22 +2921,25 @@ class LinkageSpecDecl : public Decl, public DeclContext 
{
   SourceLocation RBraceLoc;
 
   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
-  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
+  SourceLocation LangLoc, LinkageSpecLanguageIDs lang,
+  bool HasBraces);
 
 public:
   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
  SourceLocation ExternLoc,
- SourceLocation LangLoc, LanguageIDs Lang,
- bool HasBraces);
+ SourceLocation LangLoc,
+ LinkageSpecLanguageIDs Lang, bool HasBraces);
   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   /// Return the language specified by this linkage specification.
-  LanguageIDs getLanguage() const {
-return static_cast(LinkageSpecDeclBits.Language);
+  LinkageSpecLanguageIDs getLanguage() const {
+return static_cast(LinkageSpecDeclBits.Language);
   }
 
   /// Set the language specified by this linkage specification.
-  void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
+  void setLanguage(LinkageSpecLanguageIDs L) {
+LinkageSpecDeclBits.Language = llvm::to_underlying(L);
+  }
 
   /// Determines whether this linkage specification had braces in
   /// its syntactic form.

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index a3847a73faf8183..3fd4751d6d1f31d 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1320,7 +1320,7 @@ bool DeclContext::isTransparentContext() const {
 }
 
 static bool isLinkageSpecContext(const DeclContext *DC,
- LinkageSpecDecl::LanguageIDs ID) {
+ LinkageSpecLanguageIDs ID) {
   while (DC->getDeclKind() != Decl::Translati

[clang] 128b3b6 - [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (#70548)

2023-11-01 Thread via cfe-commits

Author: 刘雨培
Date: 2023-11-01T06:45:48-07:00
New Revision: 128b3b61fe6768c724975fd1df2be0abec848cf6

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

LOG: [Clang] Defer the instantiation of explicit-specifier until constraint 
checking completes (#70548)

Modifications:

- Skip the instantiation of the explicit-specifier during Decl
substitution if we are deducing template arguments and the
explicit-specifier is value dependent.

- Instantiate the explicit-specifier after the constraint checking
completes.

- Make `instantiateExplicitSpecifier` a member function in order to
instantiate the explicit-specifier in different stages.


This PR doesn’t defer the instantiation of the explicit specifier for
deduction guides, because I’m not familiar with deduction guides yet.
I’ll dig into it after this PR.

According to my local test, GCC 13 tuple works with this PR.

Fixes #59827.

-

Co-authored-by: Erich Keane 

Added: 
clang/test/SemaCXX/cxx2a-explicit-bool-deferred.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 103dcbeb79624d9..3198d6bfe75a2e8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -682,6 +682,10 @@ Bug Fixes to C++ Support
   Fixes:
   (`#68769 `_)
 
+- Clang now defers the instantiation of explicit specifier until constraint 
checking
+  completes (except deduction guides). Fixes:
+  (`#59827 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 91a4211a5cf5cce..daed24be0a86d11 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10430,6 +10430,9 @@ class Sema final {
   const CXXConstructorDecl *Tmpl,
 const MultiLevelTemplateArgumentList 
&TemplateArgs);
 
+  ExplicitSpecifier instantiateExplicitSpecifier(
+  const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier 
ES);
+
   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
   const MultiLevelTemplateArgumentList &TemplateArgs,
   bool FindingInstantiatedContext = false);

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0b3f0247ea3bee3..699e0985e595b65 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3553,6 +3553,48 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`,
+// we'll try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult instantiateExplicitSpecifierDeferred(
+Sema &S, FunctionDecl *Specialization,
+const MultiLevelTemplateArgumentList &SubstArgs,
+TemplateDeductionInfo &Info, FunctionTemplateDecl *FunctionTemplate,
+ArrayRef DeducedArgs) {
+  auto GetExplicitSpecifier = [](FunctionDecl *D) {
+return isa(D)
+   ? cast(D)->getExplicitSpecifier()
+   : cast(D)->getExplicitSpecifier();
+  };
+  auto SetExplicitSpecifier = [](FunctionDecl *D, ExplicitSpecifier ES) {
+isa(D)
+? cast(D)->setExplicitSpecifier(ES)
+: cast(D)->setExplicitSpecifier(ES);
+  };
+
+  ExplicitSpecifier ES = GetExplicitSpecifier(Specialization);
+  Expr *ExplicitExpr = ES.getExpr();
+  if (!ExplicitExpr)
+return Sema::TDK_Success;
+  if (!ExplicitExpr->isValueDependent())
+return Sema::TDK_Success;
+
+  Sema::InstantiatingTemplate Inst(
+  S, Info.getLocation(), FunctionTemplate, DeducedArgs,
+  Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
+  if (Inst.isInvalid())
+return Sema::TDK_InstantiationDepth;
+  Sema::SFINAETrap Trap(S);
+  const ExplicitSpecifier InstantiatedES =
+  S.instantiateExplicitSpecifier(SubstArgs, ES);
+  if (InstantiatedES.isInvalid() || Trap.hasErrorOccurred()) {
+Specialization->setInvalidDecl(true);
+return Sema::TDK_SubstitutionFailure;
+  }
+  SetExplicitSpecifier(Specialization, InstantiatedES);
+  return Sema::TDK_Success;
+}
+
 /// Finish template argument deduction for a function template,
 /// checking the deduced template arguments for completeness and forming
 /// the function temp

[lld] [clang] [lldb] [llvm] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

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

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


[lld] [clang] [lldb] [llvm] [Clang] Defer the instantiation of explicit-specifier until constraint checking completes (PR #70548)

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

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/70548

>From 11ceaed39b3f0c60c5a44c3b3a2b5856e7ee9a8d Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sat, 28 Oct 2023 18:05:36 +0800
Subject: [PATCH 1/7] Defer the instantiation of explicit-specifier after
 constraint checking

---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/include/clang/Sema/Sema.h   |  3 +
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 59 +++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 40 -
 .../SemaCXX/cxx2a-explicit-bool-deferred.cpp  | 31 ++
 5 files changed, 123 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx2a-explicit-bool-deferred.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc28bb567f6932a..d9980694de40f6f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,6 +670,10 @@ Bug Fixes to C++ Support
   default initializing a base class in a constant expression context. Fixes:
   (`#69890 `_)
 
+- Clang now defers the instantiation of explicit specifier until constraint 
checking
+  completes (except deduction guides). Fixes:
+  (`#59827 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 91a4211a5cf5cce..daed24be0a86d11 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10430,6 +10430,9 @@ class Sema final {
   const CXXConstructorDecl *Tmpl,
 const MultiLevelTemplateArgumentList 
&TemplateArgs);
 
+  ExplicitSpecifier instantiateExplicitSpecifier(
+  const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier 
ES);
+
   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
   const MultiLevelTemplateArgumentList &TemplateArgs,
   bool FindingInstantiatedContext = false);
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0b3f0247ea3bee3..f06332770f51d1f 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3553,6 +3553,56 @@ static unsigned getPackIndexForParam(Sema &S,
   llvm_unreachable("parameter index would not be produced from template");
 }
 
+// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
+// we try to instantiate and update its explicit specifier after constraint
+// checking.
+static Sema::TemplateDeductionResult
+tryInstantiateExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
+const MultiLevelTemplateArgumentList 
&SubstArgs,
+TemplateDeductionInfo &Info,
+FunctionTemplateDecl *FunctionTemplate,
+ArrayRef DeducedArgs) {
+
+  const auto TryInstantiateExplicitSpecifierForSingleDecl =
+  [&](auto *ExplicitDecl) {
+ExplicitSpecifier ExplicitSpecifier =
+ExplicitDecl->getExplicitSpecifier();
+Expr *const Expr = ExplicitSpecifier.getExpr();
+if (!Expr) {
+  return Sema::TDK_Success;
+}
+if (!Expr->isValueDependent()) {
+  return Sema::TDK_Success;
+}
+// TemplateDeclInstantiator::InitFunctionInstantiation set the
+// ActiveInstType to TemplateInstantiation, but we need
+// to enable SFINAE when instantiating explicit specifier.
+Sema::InstantiatingTemplate Inst(
+S, Info.getLocation(), FunctionTemplate, DeducedArgs,
+Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
+Info);
+const auto Instantiated =
+S.instantiateExplicitSpecifier(SubstArgs, ExplicitSpecifier);
+if (Instantiated.isInvalid()) {
+  ExplicitDecl->setInvalidDecl(true);
+  return clang::Sema::TDK_SubstitutionFailure;
+}
+ExplicitDecl->setExplicitSpecifier(Instantiated);
+return clang::Sema::TDK_Success;
+  };
+  Sema::TemplateDeductionResult DeductionResult = clang::Sema::TDK_Success;
+  if (CXXConstructorDecl *ConstructorDecl =
+  dyn_cast_or_null(Specialization)) {
+DeductionResult =
+TryInstantiateExplicitSpecifierForSingleDecl(ConstructorDecl);
+  } else if (CXXConversionDecl *ConversionDecl =
+ dyn_cast_or_null(Specialization)) {
+DeductionResult =
+TryInstantiateExplicitSpecifierForSingleDecl(ConversionDecl);
+  }
+  return DeductionResult;
+}
+
 /// Finish template argument deduction for a function template,
 /// checking the deduced template arguments for completeness and forming
 /// the function template sp

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

2023-11-01 Thread Matt Arsenault via cfe-commits

arsenm wrote:

For point 1, I would prefer to decouple the printf implementation choice from 
the language. I would expect consistent defaults regardless of the language. 
This also contradicts point 2? I thought the clang emitted path used hostcall, 
and the backend path did not.

As for expanding the printf implementation capabilities to cover vectors, that 
should be a separate patch from any behavior change 

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-tools-extra] 008af1c - [clang][NFC] Fix leftovers from `LinkageSpecDecl::LanguageIDs` refactoring

2023-11-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-11-01T17:00:55+03:00
New Revision: 008af1c9f4cd0188a69bf42b821749154a8142c8

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

LOG: [clang][NFC] Fix leftovers from `LinkageSpecDecl::LanguageIDs` refactoring

This fixes bot failure 
https://lab.llvm.org/buildbot/#/builders/139/builds/52622 introduced by 
65761200ce4e1f366e8418652efdafd2f744291b

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/modularize/Modularize.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 9dacf1562429ce1..030a781e2099be7 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -57,7 +57,7 @@ class ExternCRefutationVisitor
   bool shouldVisitLambdaBody() const { return false; }
 
   bool VisitLinkageSpecDecl(LinkageSpecDecl *LinkSpecDecl) const {
-if (LinkSpecDecl->getLanguage() != LinkageSpecDecl::lang_c ||
+if (LinkSpecDecl->getLanguage() != LinkageSpecLanguageIDs::C ||
 !LinkSpecDecl->hasBraces())
   return true;
 

diff  --git a/clang-tools-extra/modularize/Modularize.cpp 
b/clang-tools-extra/modularize/Modularize.cpp
index a7db1df1a1d2542..daa9c048279e03f 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -574,10 +574,10 @@ class CollectEntitiesVisitor
 SourceRange BlockRange = D->getSourceRange();
 const char *LinkageLabel;
 switch (D->getLanguage()) {
-case LinkageSpecDecl::lang_c:
+case LinkageSpecLanguageIDs::C:
   LinkageLabel = "extern \"C\" {}";
   break;
-case LinkageSpecDecl::lang_cxx:
+case LinkageSpecLanguageIDs::CXX:
   LinkageLabel = "extern \"C++\" {}";
   break;
 }



___
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 Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/65638
___
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 Erich Keane via cfe-commits


@@ -192,6 +192,13 @@ class AttributeCommonInfo {
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
+  bool isAlignas() const {
+// In the current state of code, IsAlignas is only configured to return

erichkeane wrote:

This comment is immediately stale once we commit this, right?  Also, it refers 
to `IsAlignas`, but the function name is `isAlignas`. 

https://github.com/llvm/llvm-project/pull/65638
___
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 Erich Keane via cfe-commits

https://github.com/erichkeane commented:

The comments Aaron made should be fixed, plus 1 more from me, else LGTM.

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


[clang] bc44e6e - [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

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

Author: Youngsuk Kim
Date: 2023-11-01T09:06:15-05:00
New Revision: bc44e6e7c64ae7abd885fc31a62e37f649e307be

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

LOG: [clang] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque pointer cleanup effort.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7c2911468cad5f7..e047d31c012116f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5049,7 +5049,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__GetExceptionInfo: {
 if (llvm::GlobalVariable *GV =
 CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType()))
-  return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy));
+  return RValue::get(GV);
 break;
   }
 

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 9e4319d27858e6f..0420f438ec1392c 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -386,9 +386,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl &D,
 GV->takeName(OldGV);
 
 // Replace all uses of the old global with the new global
-llvm::Constant *NewPtrForOldDecl =
-llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-OldGV->replaceAllUsesWith(NewPtrForOldDecl);
+OldGV->replaceAllUsesWith(GV);
 
 // Erase the old global, since it is no longer used.
 OldGV->eraseFromParent();

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 63cdd0a047bcd84..7d6c69f22d0e562 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -960,9 +960,8 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, 
const Stmt *S,
 return;
 
   unsigned Counter = (*RegionCounterMap)[S];
-  auto *I8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
 
-  llvm::Value *Args[] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
+  llvm::Value *Args[] = {FuncNameVar,
  Builder.getInt64(FunctionHash),
  Builder.getInt32(NumRegionCounters),
  Builder.getInt32(Counter), StepV};
@@ -1000,7 +999,7 @@ void CodeGenPGO::valueProfile(CGBuilderTy &Builder, 
uint32_t ValueKind,
 auto BuilderInsertPoint = Builder.saveIP();
 Builder.SetInsertPoint(ValueSite);
 llvm::Value *Args[5] = {
-llvm::ConstantExpr::getBitCast(FuncNameVar, Builder.getInt8PtrTy()),
+FuncNameVar,
 Builder.getInt64(FunctionHash),
 Builder.CreatePtrToInt(ValuePtr, Builder.getInt64Ty()),
 Builder.getInt32(ValueKind),

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 7877235a63356fc..c7295b3144ed16e 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3938,9 +3938,7 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
   // If there's already an old global variable, replace it with the new one.
   if (OldGV) {
 GV->takeName(OldGV);
-llvm::Constant *NewPtr =
-  llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
-OldGV->replaceAllUsesWith(NewPtr);
+OldGV->replaceAllUsesWith(GV);
 OldGV->eraseFromParent();
   }
 



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


[clang-tools-extra] [clang] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

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


@@ -277,23 +277,28 @@ class DefaultIntArgument : 
IntArgument {
   int Default = default;
 }
 
-// This argument is more complex, it includes the enumerator type name,
-// a list of strings to accept, and a list of enumerators to map them to.
+// This argument is more complex, it includes the enumerator type
+// name, whether the enum type is externally defined, a list of
+// strings to accept, and a list of enumerators to map them to.
 class EnumArgument values,
-   list enums, bit opt = 0, bit fake = 0>
+   list enums, bit opt = 0, bit fake = 0,
+   bit external = 0>
 : Argument {
   string Type = type;
   list Values = values;
   list Enums = enums;
+  bit External = external;

erichkeane wrote:

I could have sworn you changed this at one point... Something like 
`IsExternalType` is significantly more self-documenting here.

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


[clang-tools-extra] [clang] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

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

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


[clang] [clang-tools-extra] [Attributes][HLSL] Teach EnumArgument to refer to an external enum (PR #70835)

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

https://github.com/erichkeane commented:

Just 1 more comment (the name of `External` everywhere), else LGTM.

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


[clang] [clang]get non-injected-class before finding instantiated decl (PR #70886)

2023-11-01 Thread Henrik G. Olsson via cfe-commits


@@ -429,3 +429,19 @@ namespace qualified_friend_no_match {
 friend void Y::f(double); // expected-error {{friend declaration of 'f' 
does not match any declaration in 'qualified_friend_no_match::Y'}}
   };
 }
+
+namespace gh21483 {
+template 
+struct B {
+  struct mixin {
+int type;
+friend void foo(B::mixin it) {
+  (void)it.mixin::type;

hnrklssn wrote:

Ah I see it now after playing around with it a bit. In this case line 439 could 
have accessed the same value through `(void)it.type` since `mixin` doesn't 
inherit anything, but `it.mixin::type` is allowed regardless.

https://github.com/llvm/llvm-project/pull/70886
___
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


@@ -192,6 +192,13 @@ class AttributeCommonInfo {
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
+  bool isAlignas() const {
+// In the current state of code, IsAlignas is only configured to return

jerinphilip wrote:

This refers to the variable `IsAlignAs` (not the parent function `isAlignas`), 
and the sentence holds for the current state of code. I believe I'm trying to 
explain why I cannot use `IsAlignas`'s current behaviour here (as it is more 
invasive). Normally I'd expect this function to be a `const` accessor to a 
private member per programming conventions, which is not the case here, hence a 
comment.

I'm sensing the review comment confusion indicates I need to communicate this 
better in source comments. Suggestions welcome. 

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


[llvm] [clang] [clang-tools-extra] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-11-01 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Just to double check: the commit message says "emit warning", but it should 
> error by default, right?

Yes, -failure-mode=any is default, which throws an error if there is any.

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


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

2023-11-01 Thread Balazs Benics via cfe-commits

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

You are right.
I'm not sure it improves the code too much, and I wonder if you have further 
ideas refactoring the checker; if so we could probably bundle up similar 
changes into this one.

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


  1   2   3   4   5   >