[clang] [X86_64] fix SSE type error in vaarg. (PR #86377)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [X86_64] fix SSE type error in vaarg. (PR #86377)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [X86_64] fix SSE type error in vaarg. (PR #86377)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Longsheng Mou (CoTinker)


Changes

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix 
#86371.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-2) 
- (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+15) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..6931768147a9b2 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2788,12 +2788,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, 
unsigned freeIntRegs,
 // memory), except in situations involving unions.
   case X87Up:
   case SSE:
+++neededSSE;
 HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
 
 if (Lo == NoClass)  // Pass HighPart at offset 8 in memory.
   return ABIArgInfo::getDirect(HighPart, 8);
-
-++neededSSE;
 break;
 
 // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index f0177906a09a81..82c32329502816 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
   __builtin_va_start(list, z);
   return __builtin_va_arg(list, empty);
 }
+
+typedef struct {
+  struct{} a;
+  double b;
+} s1;
+
+// CHECK-LABEL: define{{.*}} double @{{.*}}f
+// CHECK: vaarg.in_reg:
+// CHECK: vaarg.in_mem:
+// CHECK: vaarg.end:
+s1 f(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, s1);
+}

``




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


[clang] [X86_64] fix SSE type error in vaarg. (PR #86377)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Longsheng Mou (CoTinker)


Changes

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix 
#86371.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-2) 
- (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+15) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..6931768147a9b2 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2788,12 +2788,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, 
unsigned freeIntRegs,
 // memory), except in situations involving unions.
   case X87Up:
   case SSE:
+++neededSSE;
 HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
 
 if (Lo == NoClass)  // Pass HighPart at offset 8 in memory.
   return ABIArgInfo::getDirect(HighPart, 8);
-
-++neededSSE;
 break;
 
 // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index f0177906a09a81..82c32329502816 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
   __builtin_va_start(list, z);
   return __builtin_va_arg(list, empty);
 }
+
+typedef struct {
+  struct{} a;
+  double b;
+} s1;
+
+// CHECK-LABEL: define{{.*}} double @{{.*}}f
+// CHECK: vaarg.in_reg:
+// CHECK: vaarg.in_mem:
+// CHECK: vaarg.end:
+s1 f(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, s1);
+}

``




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


[clang] [X86_64] fix SSE type error in vaarg. (PR #86377)

2024-03-22 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker created 
https://github.com/llvm/llvm-project/pull/86377

tweak the position of the ++neededSSE when Lo is NoClass and Hi is SSE. Fix 
#86371.

>From 551d1cd574cdf66a73dbe4e384a21949013e0baa Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Sat, 23 Mar 2024 11:52:04 +0800
Subject: [PATCH] [X86_64] fix SSE type error in vaarg.

tweak the position of the ++neededSSE when Lo is NoClass
and Hi is SSE.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  3 +--
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 15 +++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..6931768147a9b2 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2788,12 +2788,11 @@ X86_64ABIInfo::classifyArgumentType(QualType Ty, 
unsigned freeIntRegs,
 // memory), except in situations involving unions.
   case X87Up:
   case SSE:
+++neededSSE;
 HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
 
 if (Lo == NoClass)  // Pass HighPart at offset 8 in memory.
   return ABIArgInfo::getDirect(HighPart, 8);
-
-++neededSSE;
 break;
 
 // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index f0177906a09a81..82c32329502816 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -21,3 +21,18 @@ empty empty_record_test(int z, ...) {
   __builtin_va_start(list, z);
   return __builtin_va_arg(list, empty);
 }
+
+typedef struct {
+  struct{} a;
+  double b;
+} s1;
+
+// CHECK-LABEL: define{{.*}} double @{{.*}}f
+// CHECK: vaarg.in_reg:
+// CHECK: vaarg.in_mem:
+// CHECK: vaarg.end:
+s1 f(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, s1);
+}

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-22 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

LGTM overall, but the CI failure looks real.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits


@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema 
, VarDecl *CoroPromise,
 return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null(
-  BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", 
CoroHandle);
+if (!SubExpr)
+  return nullptr;
+if (auto *E = dyn_cast(SubExpr)) {
+  // This happens when await_suspend return type is not trivially
+  // destructible. This doesn't happen for the permitted return types of
+  // such function. Diagnose it later.
+  return cast_or_null(E->getSubExpr());
+} else {
+  return cast_or_null(SubExpr);
+}

yuxuanchen1997 wrote:

I was hoping to obtain the return type from the CallExpr.

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(
+ .bind("enum"),
+ this);
+}
+
+void EnumInitialValueCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Enum = Result.Nodes.getNodeAs("enum");
+  assert(Enum != nullptr);

5chmidti wrote:

`Enum` can't be a `nullptr` (single matcher binding to the top-level matcher)

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(
+ .bind("enum"),
+ this);
+}
+
+void EnumInitialValueCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Enum = Result.Nodes.getNodeAs("enum");
+  assert(Enum != nullptr);
+  SourceLocation Loc = Enum->getBeginLoc();
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+  DiagnosticBuilder Diag =
+  diag(Loc, "inital value in enum %0 has readability issue, "
+"explicit initialization of all of enumerators")
+  << Enum->getName();

5chmidti wrote:

No need for the `->getName()`. The name will also be `'quoted'` automatically.

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- EnumInitialValueCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "EnumInitialValueCheck.h"
+#include "../utils/LexerUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isNoneEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() == nullptr;
+  });
+}
+
+AST_MATCHER(EnumDecl, isOnlyFirstEnumeratorsInitialized) {
+  for (EnumConstantDecl const *ECD : Node.enumerators())
+if (ECD == *Node.enumerator_begin()) {
+  if (ECD->getInitExpr() == nullptr)
+return false;
+} else {
+  if (ECD->getInitExpr() != nullptr)
+return false;
+}
+  return true;
+}
+
+AST_MATCHER(EnumDecl, isAllEnumeratorsInitialized) {
+  return llvm::all_of(Node.enumerators(), [](EnumConstantDecl const *ECD) {
+return ECD->getInitExpr() != nullptr;
+  });
+}
+
+} // namespace
+
+void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(enumDecl(unless(anyOf(isNoneEnumeratorsInitialized(),
+   isOnlyFirstEnumeratorsInitialized(),
+   isAllEnumeratorsInitialized(

5chmidti wrote:

I think it's possible to detect these linear enum initializations and remove a 
lot of false positives by placing some restrictions on which ones to diagnose.
I came up with:
- must be linear
- must include an enumerator whose value is not a power of two
- every enumeration value must be initialized with a (potentially negative) 
integer literal

Code:
```c++
/// Check if \p Enumerator is initialized with a (potentially negated)
/// \c IntegerLiteral.
bool isInitializedByLiteral(const EnumConstantDecl *Enumerator) {
  const Expr *const Init = Enumerator->getInitExpr();
  if (!Init)
return false;
  const auto *const Constant = llvm::dyn_cast(Init);
  if (!Constant)
return false;
  if (llvm::isa(Constant->getSubExpr()))
return true;
  const auto *const NegativeValue =
  llvm::dyn_cast(Constant->getSubExpr());
  if (!NegativeValue)
return false;
  return llvm::isa(NegativeValue->getSubExpr());
}

/// Excludes bitfields because enumerators initialized with the result of a
/// bitwise operator on enumeration values or any other expr that is not a
/// potentially negative integer literal.
/// Enumerations where it is not directly clear if they are used with
/// bitmasking, evident when enumerators are only inintialized with (potentially
/// negative) integer literals, are ignored. This is also the case when all
/// enumerators are powers of two (e.g., 0, 1, 2).
bool isLinearAndDiagnosable(const EnumDecl *Enum) {
  if (Enum->enumerators().empty())
return false;

  const EnumConstantDecl *const FirstEnumerator = *Enum->enumerator_begin();
  llvm::APSInt PrevValue = FirstEnumerator->getInitVal();
  if (!isInitializedByLiteral(FirstEnumerator))
return false;
  bool AllEnumeratorsArePowersOfTwo = true;
  for (const EnumConstantDecl *Enumerator :
   llvm::drop_begin(Enum->enumerators())) {
const llvm::APSInt NewValue = Enumerator->getInitVal();
if (NewValue != ++PrevValue)
  return false;

if (!isInitializedByLiteral(Enumerator))
  return false;

PrevValue = NewValue;
AllEnumeratorsArePowersOfTwo &= NewValue.isPowerOf2();
  }

  return !AllEnumeratorsArePowersOfTwo;
}
```
to test: 
Add 
```c++
  if (isLinearAndDiagnosable(Enum)) {
diag(Loc, "linear enum %0") << Enum;
  }
  return; // to only test matching linear enums
```
after the `Loc.isInvalid()...` check in `check` and remove 
`isAllEnumeratorsInitialized` from the matcher.

Example Enums
enum class EAllUnclear {
  EAll_a = 0,
  EAll_b = 1,
  EAll_c = 2,
};

enum class EAllBitmask {
  EAll_a = 1,
  EAll_b = 2,
  EAll_c = EAll_a | EAll_b,
};

enum class EAllWithNegative {
  EAll_n2 = -2,
  EAll_n1 = -1,
  EAll_0 = 0,
  EAll_a = 1,
  EAll_b = 2,
};

enum class EAllWithNegative1 {
  EAll_n1 = -1,
  EAll_0 = 0,
  EAll_a = 1,
  EAll_b = 2,
};

enum class EAllWithNegative3 {
  EAll_n3 = -3,
  EAll_n2 = -2,
  EAll_n1 = -1,
  EAll_0 = 0,
  EAll_a = 1,
  EAll_b = 2,
};


enum class EAllOffset {
  EAll_a = 8,
  EAll_b = 9,
  EAll_c = 10,
  EAll_d = 11,
};


Findings when running clang-tidy over `clang/lib/Basic` with 
`-header-filter="-*"`:

[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

Just nits and a comment regarding the linear, all initialized enum. and all 
other checks use west-const from what I can tell.

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


[clang-tools-extra] [clang-tidy] add new check readability-enum-initial-value (PR #86129)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s readability-enum-initial-value %t
+
+enum EError {
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital value in enum EError has 
readability issue, explicit initialization of all of enumerators
+  EError_a = 1,
+  EError_b,
+  // CHECK-FIXES: EError_b = 2,
+  EError_c = 3,
+};
+
+enum ENone {
+  ENone_a,
+  ENone_b,
+  eENone_c,

5chmidti wrote:

The leading `e` was probably a typo, same in the cpp test file.

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


[clang] b723c57 - [Clang] Update the C++ page with papers approved in Tokyo

2024-03-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-03-23T10:04:45+09:00
New Revision: b723c57f8fdb12ca8eaa6c5ee2afb820aaeb56c5

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

LOG: [Clang] Update the C++ page with papers approved in Tokyo

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 1e36b90356c3e1..c1d95dadbb27e2 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -163,7 +163,47 @@ C++2c implementation status
   https://wg21.link/P2864R2;>P2864R2
   Clang 18
  
-
+ 
+ 
+  Disallow Binding a Returned Glvalue to a Temporary
+  https://wg21.link/P2748R5;>P2748R5
+  No
+ 
+ 
+  Clarifying rules for brace elision in aggregate initialization
+  https://wg21.link/P3106R1;>P3106R1 (DR)
+  No
+ 
+ 
+  Attributes for Structured Bindings
+  https://wg21.link/P0609R3;>P0609R3
+  No
+ 
+ 
+  Module Declarations Shouldn’t be Macros
+  https://wg21.link/P3034R1;>P3034R1 (DR)
+  No
+ 
+ 
+  Trivial infinite loops are not Undefined Behavior
+  https://wg21.link/P2809R3;>P2809R3 (DR)
+  No
+ 
+ 
+  Erroneous behaviour for uninitialized reads
+  https://wg21.link/P2795R5;>P2795R5
+  No
+ 
+ 
+  = delete("should have a reason");
+  https://wg21.link/P2573R2;>P2573R2
+  No
+ 
+ 
+  Variadic friends
+  https://wg21.link/P2893R3;>P2893R3
+  No
+ 
 
 
 



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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Chuanqi Xu via cfe-commits


@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema 
, VarDecl *CoroPromise,
 return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null(
-  BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", 
CoroHandle);
+if (!SubExpr)
+  return nullptr;
+if (auto *E = dyn_cast(SubExpr)) {
+  // This happens when await_suspend return type is not trivially
+  // destructible. This doesn't happen for the permitted return types of
+  // such function. Diagnose it later.
+  return cast_or_null(E->getSubExpr());
+} else {
+  return cast_or_null(SubExpr);
+}

ChuanqiXu9 wrote:

I mean, how about diagnose `InvalidAwaitSuspendReturnType` directly if it is 
null. And we can use `dyn_cast_if_present` instead of `cast_or_null`. WDYT?

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits


@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema 
, VarDecl *CoroPromise,
 return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null(
-  BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", 
CoroHandle);
+if (!SubExpr)
+  return nullptr;
+if (auto *E = dyn_cast(SubExpr)) {
+  // This happens when await_suspend return type is not trivially
+  // destructible. This doesn't happen for the permitted return types of
+  // such function. Diagnose it later.
+  return cast_or_null(E->getSubExpr());
+} else {
+  return cast_or_null(SubExpr);
+}

yuxuanchen1997 wrote:

This is necessary for the diagnostic to work. If the return type of 
`await_suspend` is a type that has a user defined destructor we will get a 
`CXXBindTemporaryExpr`. The original `cast_or_null` here was the reason it was 
crashing.

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


[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)

2024-03-22 Thread Tom Stellard via cfe-commits

tstellar wrote:

Do we need to backport this to release/18.x?

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


[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

I'm sorry to hear that. I've only used the ENABLE_RUNTIMES in the context of 
compiling clang first, and then compiling the libraries under runtime with that 
clang. The recursive invocation drops (most) arguments passed to cmake which 
has been obstructive in the past.

With standalone build (presumably ENABLE_PROJECTS) removed, how does one build 
the libraries using an existing compiler?

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


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread Mike Rice via cfe-commits

mikerice1969 wrote:

> This could use a test.

I thought about it, but I have no idea how to write that test. Do you have an 
idea?

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Chuanqi Xu via cfe-commits


@@ -418,39 +448,60 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema 
, VarDecl *CoroPromise,
 return Calls;
   }
   Expr *CoroHandle = CoroHandleRes.get();
-  CallExpr *AwaitSuspend = cast_or_null(
-  BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle));
+  auto *AwaitSuspend = [&]() -> CallExpr * {
+auto *SubExpr = BuildSubExpr(ACT::ACT_Suspend, "await_suspend", 
CoroHandle);
+if (!SubExpr)
+  return nullptr;
+if (auto *E = dyn_cast(SubExpr)) {
+  // This happens when await_suspend return type is not trivially
+  // destructible. This doesn't happen for the permitted return types of
+  // such function. Diagnose it later.
+  return cast_or_null(E->getSubExpr());
+} else {
+  return cast_or_null(SubExpr);
+}

ChuanqiXu9 wrote:

I don't understand why we need to do this here. Can't it be handled by the 
following check?

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Chuanqi Xu via cfe-commits


@@ -339,6 +339,9 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- Clang now emits errors for coroutine `await_suspend` functions whose return 
type is not
+  one of `void`, `bool`, or `std::coroutine_handle`.

ChuanqiXu9 wrote:

Maybe we should move this to `Potential Breaking Section` and mention it 
conforms the standard wording.


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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Chuanqi Xu via cfe-commits


@@ -358,6 +364,30 @@ static Expr *maybeTailCall(Sema , QualType RetType, Expr 
*E,
   return S.MaybeCreateExprWithCleanups(JustAddress);
 }
 
+static bool isSpecializationOfCoroutineHandle(Sema , QualType Ty,
+  SourceLocation Loc) {
+  auto *CoroutineHandleClassTemplateDecl =
+  lookupCoroutineHandleTemplate(S, Loc);

ChuanqiXu9 wrote:

Maybe it can be better to cache the coroutine handle declaration to avoid 
redundant looking up. But it may be fine for the number of `await_suspend` in 
practical.

We can send another patch for this if we want.

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


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

This could use a test.

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


[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/86358

>From 109e6039abe8bd3b598f1fdc2dbd7bca783ff4e6 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 22 Mar 2024 15:54:14 -0700
Subject: [PATCH 1/3] [clang] Move state out of `PreprocessorOptions` (1/n)

An instance of `PreprocessorOptions` is part of `CompilerInvocation` which is 
supposed to be a value type. The `DependencyDirectivesForFile` member is 
problematic, since it holds an owning reference of the scanning VFS. This makes 
it not a true value type, and it can keep potentially large chunk of memory 
(the local cache in the scanning VFS) alive for longer than clients might 
expect. Let's move it into the `Preprocessor` instead.
---
 .../include/clang/Frontend/FrontendActions.h  | 12 +--
 clang/include/clang/Lex/Preprocessor.h| 18 
 clang/include/clang/Lex/PreprocessorOptions.h | 13 
 clang/lib/Frontend/FrontendActions.cpp|  7 ++-
 clang/lib/Lex/PPLexerChange.cpp   | 12 +++
 .../DependencyScanningWorker.cpp  | 21 +++
 6 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..575cf9ed2ac777 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -34,12 +34,17 @@ class InitOnlyAction : public FrontendAction {
 
 /// Preprocessor-based frontend action that also loads PCH files.
 class ReadPCHAndPreprocessAction : public FrontendAction {
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override;
 
 public:
+  ReadPCHAndPreprocessAction(llvm::function_ref OnCI)
+  : OnCI(OnCI) {}
+
   bool usesPreprocessorOnly() const override { return false; }
 };
 
@@ -321,11 +326,14 @@ class PrintPreprocessedAction : public 
PreprocessorFrontendAction {
 
 class GetDependenciesByModuleNameAction : public PreprocessOnlyAction {
   StringRef ModuleName;
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
 public:
-  GetDependenciesByModuleNameAction(StringRef ModuleName)
-  : ModuleName(ModuleName) {}
+  GetDependenciesByModuleNameAction(
+  StringRef ModuleName, llvm::function_ref OnCI)
+  : ModuleName(ModuleName), OnCI(OnCI) {}
 };
 
 }  // end namespace clang
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 0836b7d439bb04..10a7ba4db25625 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -736,6 +736,19 @@ class Preprocessor {
 State ConditionalStackState = Off;
   } PreambleConditionalStack;
 
+  /// Function for getting the dependency preprocessor directives of a file.
+  ///
+  /// These are directives derived from a special form of lexing where the
+  /// source input is scanned for the preprocessor directives that might have 
an
+  /// effect on the dependencies for a compilation unit.
+  ///
+  /// Enables a client to cache the directives for a file and provide them
+  /// across multiple compiler invocations.
+  /// FIXME: Allow returning an error.
+  using DependencyDirectivesFn = std::function>(FileEntryRef)>;
+  DependencyDirectivesFn DependencyDirectivesForFile;
+
   /// The current top of the stack that we're lexing from if
   /// not expanding a macro and we are lexing directly from source code.
   ///
@@ -1270,6 +1283,11 @@ class Preprocessor {
   /// false if it is producing tokens to be consumed by Parse and Sema.
   bool isPreprocessedOutput() const { return PreprocessedOutput; }
 
+  /// Set the function used to get dependency directives for a file.
+  void setDependencyDirectivesFn(DependencyDirectivesFn Fn) {
+DependencyDirectivesForFile = std::move(Fn);
+  }
+
   /// Return true if we are lexing directly from the specified lexer.
   bool isCurrentLexer(const PreprocessorLexer *L) const {
 return CurPPLexer == L;
diff --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index f841e4a028df50..24e0ca61d41432 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -208,19 +208,6 @@ class PreprocessorOptions {
   /// build it again.
   std::shared_ptr FailedModules;
 
-  /// Function for getting the dependency preprocessor directives of a file.
-  ///
-  /// These are directives derived from a special form of lexing where the
-  /// source input is scanned for the preprocessor directives that might have 
an
-  /// effect on the dependencies for a compilation unit.
-  ///
-  /// Enables a client to cache the directives for a file and provide them
-  /// across multiple compiler invocations.
-  /// FIXME: Allow returning an error.
-  

[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread Alexander Richardson via cfe-commits

arichardson wrote:

It might make sense to restore the `message(FATAL_ERROR)` since that is any 
easy mistake to make considering it used to be the default way of building 
libunwind.

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


[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/86358

>From 109e6039abe8bd3b598f1fdc2dbd7bca783ff4e6 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 22 Mar 2024 15:54:14 -0700
Subject: [PATCH 1/2] [clang] Move state out of `PreprocessorOptions` (1/n)

An instance of `PreprocessorOptions` is part of `CompilerInvocation` which is 
supposed to be a value type. The `DependencyDirectivesForFile` member is 
problematic, since it holds an owning reference of the scanning VFS. This makes 
it not a true value type, and it can keep potentially large chunk of memory 
(the local cache in the scanning VFS) alive for longer than clients might 
expect. Let's move it into the `Preprocessor` instead.
---
 .../include/clang/Frontend/FrontendActions.h  | 12 +--
 clang/include/clang/Lex/Preprocessor.h| 18 
 clang/include/clang/Lex/PreprocessorOptions.h | 13 
 clang/lib/Frontend/FrontendActions.cpp|  7 ++-
 clang/lib/Lex/PPLexerChange.cpp   | 12 +++
 .../DependencyScanningWorker.cpp  | 21 +++
 6 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..575cf9ed2ac777 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -34,12 +34,17 @@ class InitOnlyAction : public FrontendAction {
 
 /// Preprocessor-based frontend action that also loads PCH files.
 class ReadPCHAndPreprocessAction : public FrontendAction {
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override;
 
 public:
+  ReadPCHAndPreprocessAction(llvm::function_ref OnCI)
+  : OnCI(OnCI) {}
+
   bool usesPreprocessorOnly() const override { return false; }
 };
 
@@ -321,11 +326,14 @@ class PrintPreprocessedAction : public 
PreprocessorFrontendAction {
 
 class GetDependenciesByModuleNameAction : public PreprocessOnlyAction {
   StringRef ModuleName;
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
 public:
-  GetDependenciesByModuleNameAction(StringRef ModuleName)
-  : ModuleName(ModuleName) {}
+  GetDependenciesByModuleNameAction(
+  StringRef ModuleName, llvm::function_ref OnCI)
+  : ModuleName(ModuleName), OnCI(OnCI) {}
 };
 
 }  // end namespace clang
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 0836b7d439bb04..10a7ba4db25625 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -736,6 +736,19 @@ class Preprocessor {
 State ConditionalStackState = Off;
   } PreambleConditionalStack;
 
+  /// Function for getting the dependency preprocessor directives of a file.
+  ///
+  /// These are directives derived from a special form of lexing where the
+  /// source input is scanned for the preprocessor directives that might have 
an
+  /// effect on the dependencies for a compilation unit.
+  ///
+  /// Enables a client to cache the directives for a file and provide them
+  /// across multiple compiler invocations.
+  /// FIXME: Allow returning an error.
+  using DependencyDirectivesFn = std::function>(FileEntryRef)>;
+  DependencyDirectivesFn DependencyDirectivesForFile;
+
   /// The current top of the stack that we're lexing from if
   /// not expanding a macro and we are lexing directly from source code.
   ///
@@ -1270,6 +1283,11 @@ class Preprocessor {
   /// false if it is producing tokens to be consumed by Parse and Sema.
   bool isPreprocessedOutput() const { return PreprocessedOutput; }
 
+  /// Set the function used to get dependency directives for a file.
+  void setDependencyDirectivesFn(DependencyDirectivesFn Fn) {
+DependencyDirectivesForFile = std::move(Fn);
+  }
+
   /// Return true if we are lexing directly from the specified lexer.
   bool isCurrentLexer(const PreprocessorLexer *L) const {
 return CurPPLexer == L;
diff --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index f841e4a028df50..24e0ca61d41432 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -208,19 +208,6 @@ class PreprocessorOptions {
   /// build it again.
   std::shared_ptr FailedModules;
 
-  /// Function for getting the dependency preprocessor directives of a file.
-  ///
-  /// These are directives derived from a special form of lexing where the
-  /// source input is scanned for the preprocessor directives that might have 
an
-  /// effect on the dependencies for a compilation unit.
-  ///
-  /// Enables a client to cache the directives for a file and provide them
-  /// across multiple compiler invocations.
-  /// FIXME: Allow returning an error.
-  

[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Mike Rice (mikerice1969)


Changes

If any return from overwriteChangedFiles is true some fixes were not applied.

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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+1-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 40ac6918faf407..b877ea06dc05cd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -233,7 +233,7 @@ class ErrorReporter {
 if (!tooling::applyAllReplacements(Replacements.get(), Rewrite)) {
   llvm::errs() << "Can't apply replacements for file " << File << "\n";
 }
-AnyNotWritten &= Rewrite.overwriteChangedFiles();
+AnyNotWritten |= Rewrite.overwriteChangedFiles();
   }
 
   if (AnyNotWritten) {

``




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


[clang-tools-extra] [clang-tidy] Fix result check after overwriteChangedFiles() (PR #86360)

2024-03-22 Thread Mike Rice via cfe-commits

https://github.com/mikerice1969 created 
https://github.com/llvm/llvm-project/pull/86360

If any return from overwriteChangedFiles is true some fixes were not applied.

>From 492e0fc4e146d7321003470a9cd0b4be4ae39d7a Mon Sep 17 00:00:00 2001
From: Mike Rice 
Date: Fri, 22 Mar 2024 16:02:54 -0700
Subject: [PATCH] [clang-tidy] Fix result check after overwriteChangedFiles()

If any return from overwriteChangedFiles is true some fixes were not
applied.
---
 clang-tools-extra/clang-tidy/ClangTidy.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 40ac6918faf407..b877ea06dc05cd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -233,7 +233,7 @@ class ErrorReporter {
 if (!tooling::applyAllReplacements(Replacements.get(), Rewrite)) {
   llvm::errs() << "Can't apply replacements for file " << File << "\n";
 }
-AnyNotWritten &= Rewrite.overwriteChangedFiles();
+AnyNotWritten |= Rewrite.overwriteChangedFiles();
   }
 
   if (AnyNotWritten) {

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


[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

An instance of `PreprocessorOptions` is part of `CompilerInvocation` which is 
supposed to be a value type. The `DependencyDirectivesForFile` member is 
problematic, since it holds an owning reference of the scanning VFS. This makes 
it not a true value type, and it can keep potentially large chunk of memory 
(the local cache in the scanning VFS) alive for longer than clients might 
expect. Let's move it into the `Preprocessor` instead.

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


6 Files Affected:

- (modified) clang/include/clang/Frontend/FrontendActions.h (+10-2) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+18) 
- (modified) clang/include/clang/Lex/PreprocessorOptions.h (-13) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+6-1) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+3-9) 
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
(+12-9) 


``diff
diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..575cf9ed2ac777 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -34,12 +34,17 @@ class InitOnlyAction : public FrontendAction {
 
 /// Preprocessor-based frontend action that also loads PCH files.
 class ReadPCHAndPreprocessAction : public FrontendAction {
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override;
 
 public:
+  ReadPCHAndPreprocessAction(llvm::function_ref OnCI)
+  : OnCI(OnCI) {}
+
   bool usesPreprocessorOnly() const override { return false; }
 };
 
@@ -321,11 +326,14 @@ class PrintPreprocessedAction : public 
PreprocessorFrontendAction {
 
 class GetDependenciesByModuleNameAction : public PreprocessOnlyAction {
   StringRef ModuleName;
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
 public:
-  GetDependenciesByModuleNameAction(StringRef ModuleName)
-  : ModuleName(ModuleName) {}
+  GetDependenciesByModuleNameAction(
+  StringRef ModuleName, llvm::function_ref OnCI)
+  : ModuleName(ModuleName), OnCI(OnCI) {}
 };
 
 }  // end namespace clang
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 0836b7d439bb04..10a7ba4db25625 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -736,6 +736,19 @@ class Preprocessor {
 State ConditionalStackState = Off;
   } PreambleConditionalStack;
 
+  /// Function for getting the dependency preprocessor directives of a file.
+  ///
+  /// These are directives derived from a special form of lexing where the
+  /// source input is scanned for the preprocessor directives that might have 
an
+  /// effect on the dependencies for a compilation unit.
+  ///
+  /// Enables a client to cache the directives for a file and provide them
+  /// across multiple compiler invocations.
+  /// FIXME: Allow returning an error.
+  using DependencyDirectivesFn = std::function>(FileEntryRef)>;
+  DependencyDirectivesFn DependencyDirectivesForFile;
+
   /// The current top of the stack that we're lexing from if
   /// not expanding a macro and we are lexing directly from source code.
   ///
@@ -1270,6 +1283,11 @@ class Preprocessor {
   /// false if it is producing tokens to be consumed by Parse and Sema.
   bool isPreprocessedOutput() const { return PreprocessedOutput; }
 
+  /// Set the function used to get dependency directives for a file.
+  void setDependencyDirectivesFn(DependencyDirectivesFn Fn) {
+DependencyDirectivesForFile = std::move(Fn);
+  }
+
   /// Return true if we are lexing directly from the specified lexer.
   bool isCurrentLexer(const PreprocessorLexer *L) const {
 return CurPPLexer == L;
diff --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index f841e4a028df50..24e0ca61d41432 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -208,19 +208,6 @@ class PreprocessorOptions {
   /// build it again.
   std::shared_ptr FailedModules;
 
-  /// Function for getting the dependency preprocessor directives of a file.
-  ///
-  /// These are directives derived from a special form of lexing where the
-  /// source input is scanned for the preprocessor directives that might have 
an
-  /// effect on the dependencies for a compilation unit.
-  ///
-  /// Enables a client to cache the directives for a file and provide them
-  /// across multiple compiler invocations.
-  /// FIXME: Allow returning an error.
-  std::function>(
-  FileEntryRef)>
-  DependencyDirectivesForFile;
-
   /// Set up preprocessor for RunAnalysis action.
   bool SetUpStaticAnalyzer = 

[clang] [clang] Move state out of `PreprocessorOptions` (1/n) (PR #86358)

2024-03-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/86358

An instance of `PreprocessorOptions` is part of `CompilerInvocation` which is 
supposed to be a value type. The `DependencyDirectivesForFile` member is 
problematic, since it holds an owning reference of the scanning VFS. This makes 
it not a true value type, and it can keep potentially large chunk of memory 
(the local cache in the scanning VFS) alive for longer than clients might 
expect. Let's move it into the `Preprocessor` instead.

>From 109e6039abe8bd3b598f1fdc2dbd7bca783ff4e6 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 22 Mar 2024 15:54:14 -0700
Subject: [PATCH] [clang] Move state out of `PreprocessorOptions` (1/n)

An instance of `PreprocessorOptions` is part of `CompilerInvocation` which is 
supposed to be a value type. The `DependencyDirectivesForFile` member is 
problematic, since it holds an owning reference of the scanning VFS. This makes 
it not a true value type, and it can keep potentially large chunk of memory 
(the local cache in the scanning VFS) alive for longer than clients might 
expect. Let's move it into the `Preprocessor` instead.
---
 .../include/clang/Frontend/FrontendActions.h  | 12 +--
 clang/include/clang/Lex/Preprocessor.h| 18 
 clang/include/clang/Lex/PreprocessorOptions.h | 13 
 clang/lib/Frontend/FrontendActions.cpp|  7 ++-
 clang/lib/Lex/PPLexerChange.cpp   | 12 +++
 .../DependencyScanningWorker.cpp  | 21 +++
 6 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..575cf9ed2ac777 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -34,12 +34,17 @@ class InitOnlyAction : public FrontendAction {
 
 /// Preprocessor-based frontend action that also loads PCH files.
 class ReadPCHAndPreprocessAction : public FrontendAction {
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
  StringRef InFile) override;
 
 public:
+  ReadPCHAndPreprocessAction(llvm::function_ref OnCI)
+  : OnCI(OnCI) {}
+
   bool usesPreprocessorOnly() const override { return false; }
 };
 
@@ -321,11 +326,14 @@ class PrintPreprocessedAction : public 
PreprocessorFrontendAction {
 
 class GetDependenciesByModuleNameAction : public PreprocessOnlyAction {
   StringRef ModuleName;
+  llvm::function_ref OnCI;
+
   void ExecuteAction() override;
 
 public:
-  GetDependenciesByModuleNameAction(StringRef ModuleName)
-  : ModuleName(ModuleName) {}
+  GetDependenciesByModuleNameAction(
+  StringRef ModuleName, llvm::function_ref OnCI)
+  : ModuleName(ModuleName), OnCI(OnCI) {}
 };
 
 }  // end namespace clang
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 0836b7d439bb04..10a7ba4db25625 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -736,6 +736,19 @@ class Preprocessor {
 State ConditionalStackState = Off;
   } PreambleConditionalStack;
 
+  /// Function for getting the dependency preprocessor directives of a file.
+  ///
+  /// These are directives derived from a special form of lexing where the
+  /// source input is scanned for the preprocessor directives that might have 
an
+  /// effect on the dependencies for a compilation unit.
+  ///
+  /// Enables a client to cache the directives for a file and provide them
+  /// across multiple compiler invocations.
+  /// FIXME: Allow returning an error.
+  using DependencyDirectivesFn = std::function>(FileEntryRef)>;
+  DependencyDirectivesFn DependencyDirectivesForFile;
+
   /// The current top of the stack that we're lexing from if
   /// not expanding a macro and we are lexing directly from source code.
   ///
@@ -1270,6 +1283,11 @@ class Preprocessor {
   /// false if it is producing tokens to be consumed by Parse and Sema.
   bool isPreprocessedOutput() const { return PreprocessedOutput; }
 
+  /// Set the function used to get dependency directives for a file.
+  void setDependencyDirectivesFn(DependencyDirectivesFn Fn) {
+DependencyDirectivesForFile = std::move(Fn);
+  }
+
   /// Return true if we are lexing directly from the specified lexer.
   bool isCurrentLexer(const PreprocessorLexer *L) const {
 return CurPPLexer == L;
diff --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index f841e4a028df50..24e0ca61d41432 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -208,19 +208,6 @@ class PreprocessorOptions {
   /// build it again.
   std::shared_ptr FailedModules;
 
-  /// Function for getting the dependency 

[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

This build configuration was explicitly made disallowed in 
6f17768e11480063f4c2bcbeea559505fee3ea19, with an error message explaining the 
situation. However that error message was later removed in 
0a22dfcb11c05cbd4f654c8ef1868a4bc6085140.

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-22 Thread Alexander Richardson via cfe-commits

arichardson wrote:

CI looks unhappy, mlir also seems to need updates:

MLIR :: Target/LLVMIR/llvmir.mlir
MLIR :: mlir-cpu-runner/x86-varargs.mlir

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread Jan Svoboda via cfe-commits

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


[clang] b768a8c - [clang][deps] Lazy dependency directives (#86347)

2024-03-22 Thread via cfe-commits

Author: Jan Svoboda
Date: 2024-03-22T16:09:34-07:00
New Revision: b768a8c1db85b9e84fd8b356570a3a8fbe37acf6

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

LOG: [clang][deps] Lazy dependency directives (#86347)

Since b4c83a13f664582015ea22924b9a0c6290d41f5b, `Preprocessor` and
`Lexer` are aware of the concept of scanning dependency directives. This
makes it possible to scan for them on-demand rather than eagerly on the
first filesystem operation (open, or even just stat).

This might improve performance, but is also necessary for the "PCH as
module" mode. Some precompiled header sources use the ".pch" file
extension, which means they were not getting scanned for dependency
directives. This was okay when the PCH was the main input file in a
separate scan step, because there we just lex the file in a
scanning-specific frontend action. But when such source gets treated as
a module implicitly loaded from a TU, it will get compiled as any other
module - with Sema - which will result in compilation errors. (See
attached test case.)

rdar://107663951

Added: 
clang/test/ClangScanDeps/modules-extension.c

Modified: 

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 846fdc7253977f..9a522a3e2fe252 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -242,6 +242,8 @@ class EntryRef {
   /// The underlying cached entry.
   const CachedFileSystemEntry 
 
+  friend class DependencyScanningWorkerFilesystem;
+
 public:
   EntryRef(StringRef Name, const CachedFileSystemEntry )
   : Filename(Name), Entry(Entry) {}
@@ -300,14 +302,15 @@ class DependencyScanningWorkerFilesystem
   ///
   /// Attempts to use the local and shared caches first, then falls back to
   /// using the underlying filesystem.
-  llvm::ErrorOr
-  getOrCreateFileSystemEntry(StringRef Filename,
- bool DisableDirectivesScanning = false);
+  llvm::ErrorOr getOrCreateFileSystemEntry(StringRef Filename);
 
-private:
-  /// Check whether the file should be scanned for preprocessor directives.
-  bool shouldScanForDirectives(StringRef Filename);
+  /// Ensure the directive tokens are populated for this file entry.
+  ///
+  /// Returns true if the directive tokens are populated for this file entry,
+  /// false if not (i.e. this entry is not a file or its scan fails).
+  bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
   /// shared cache indexed by unique ID, or creates new entry from scratch.
@@ -317,11 +320,6 @@ class DependencyScanningWorkerFilesystem
   computeAndStoreResult(StringRef OriginalFilename,
 StringRef FilenameForLookup);
 
-  /// Scan for preprocessor directives for the given entry if necessary and
-  /// returns a wrapper object with reference semantics.
-  EntryRef scanForDirectivesIfNecessary(const CachedFileSystemEntry ,
-StringRef Filename, bool Disable);
-
   /// Represents a filesystem entry that has been stat-ed (and potentially 
read)
   /// and that's about to be inserted into the cache as 
`CachedFileSystemEntry`.
   struct TentativeEntry {

diff  --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 1b750cec41e1cc..9b7812a1adb9e3 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -41,24 +41,25 @@ DependencyScanningWorkerFilesystem::readFile(StringRef 
Filename) {
   return TentativeEntry(Stat, std::move(Buffer));
 }
 
-EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary(
-const CachedFileSystemEntry , StringRef Filename, bool Disable) {
-  if (Entry.isError() || Entry.isDirectory() || Disable ||
-  !shouldScanForDirectives(Filename))
-return EntryRef(Filename, Entry);
+bool DependencyScanningWorkerFilesystem::ensureDirectiveTokensArePopulated(
+EntryRef Ref) {
+  auto  = Ref.Entry;
+
+  if (Entry.isError() || Entry.isDirectory())
+return false;
 
   CachedFileContents *Contents = 

[clang] Raise an error on namespace aliases with qualified names. (PR #86122)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



@katzdm Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] Raise an error on namespace aliases with qualified names. (PR #86122)

2024-03-22 Thread via cfe-commits

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


[clang] 0024875 - [Clang] Raise an error on namespace aliases with qualified names. (#86122)

2024-03-22 Thread via cfe-commits

Author: Daniel M. Katz
Date: 2024-03-23T00:08:02+01:00
New Revision: 00248754176d74aed2e0785d9982a5ea8e91a71a

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

LOG: [Clang] Raise an error on namespace aliases with qualified names. (#86122)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/SemaCXX/namespace-alias.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6e179ca9d6904..8054d90fc70f93 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -437,6 +437,8 @@ Bug Fixes to C++ Support
 - Clang's __builtin_bit_cast will now produce a constant value for records 
with empty bases. See:
   (#GH82383)
 - Fix a crash when instantiating a lambda that captures ``this`` outside of 
its context. Fixes (#GH85343).
+- Fix an issue where a namespace alias could be defined using a qualified name 
(all name components
+  following the first `::` were ignored).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 48de5e2ef5f4af..46a44418a3153b 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -268,6 +268,8 @@ def err_expected_semi_after_namespace_name : Error<
   "expected ';' after namespace name">;
 def err_unexpected_namespace_attributes_alias : Error<
   "attributes cannot be specified on namespace alias">;
+def err_unexpected_qualified_namespace_alias : Error<
+  "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 77d2382ea6d907..63fe678cbb29e2 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -140,6 +140,14 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
   SkipUntil(tok::semi);
   return nullptr;
 }
+if (!ExtraNSs.empty()) {
+  Diag(ExtraNSs.front().NamespaceLoc,
+   diag::err_unexpected_qualified_namespace_alias)
+  << SourceRange(ExtraNSs.front().NamespaceLoc,
+ ExtraNSs.back().IdentLoc);
+  SkipUntil(tok::semi);
+  return nullptr;
+}
 if (attrLoc.isValid())
   Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
 if (InlineLoc.isValid())

diff  --git a/clang/test/SemaCXX/namespace-alias.cpp 
b/clang/test/SemaCXX/namespace-alias.cpp
index 281ee9962e8b52..591957a657c03a 100644
--- a/clang/test/SemaCXX/namespace-alias.cpp
+++ b/clang/test/SemaCXX/namespace-alias.cpp
@@ -47,6 +47,8 @@ namespace I {
   namespace A1 { int i; }
   
   namespace A2 = A1;
+
+  namespace A3::extra::specifiers = A2;  // expected-error {{alias must be a 
single identifier}}
 }
 
 int f() {



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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

https://github.com/usama54321 updated 
https://github.com/llvm/llvm-project/pull/86220

>From 0dab57b9f541a9fb6cbbe85f034117a19227c331 Mon Sep 17 00:00:00 2001
From: usama 
Date: Thu, 21 Mar 2024 16:56:32 -0700
Subject: [PATCH] Get the linker version and pass the it to compiler-rt tests
 on Darwin.

The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects
the linker version at configure time. The driver uses this information
to build the correct set of arguments for the linker. This patch detects
the linker version again during compiler-rt configuration and passes it
to the tests. This allows a clang built on a machine with a new linker
to run compiler-rt tests on a machine with an old linker.

rdar://125198603
---
 clang/CMakeLists.txt   | 16 ++--
 cmake/Modules/GetDarwinLinkerVersion.cmake | 19 +++
 compiler-rt/CMakeLists.txt | 10 ++
 compiler-rt/test/lit.common.cfg.py |  4 
 compiler-rt/test/lit.common.configured.in  |  1 +
 5 files changed, 36 insertions(+), 14 deletions(-)
 create mode 100644 cmake/Modules/GetDarwinLinkerVersion.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 761dab8c28c134..ee783d52e4a4e2 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -15,6 +15,7 @@ endif()
 
 # Must go below project(..)
 include(GNUInstallDirs)
+include(GetDarwinLinkerVersion)
 
 if(CLANG_BUILT_STANDALONE)
   set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -346,20 +347,7 @@ endif ()
 # Determine HOST_LINK_VERSION on Darwin.
 set(HOST_LINK_VERSION)
 if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
-  set(LD_V_OUTPUT)
-  execute_process(
-COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
-RESULT_VARIABLE HAD_ERROR
-OUTPUT_VARIABLE LD_V_OUTPUT
-  )
-  if (HAD_ERROR)
-message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
-  endif()
-  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
-string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
-string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION 
${LD_V_OUTPUT})
-  endif()
+  get_darwin_linker_version(HOST_LINK_VERSION)
   message(STATUS "Host linker version: ${HOST_LINK_VERSION}")
 endif()
 
diff --git a/cmake/Modules/GetDarwinLinkerVersion.cmake 
b/cmake/Modules/GetDarwinLinkerVersion.cmake
new file mode 100644
index 00..c27e50128586db
--- /dev/null
+++ b/cmake/Modules/GetDarwinLinkerVersion.cmake
@@ -0,0 +1,19 @@
+# Get the linker version on Darwin
+function(get_darwin_linker_version variable)
+  set(LINK_VERSION)
+  set(LD_V_OUTPUT)
+  execute_process(
+COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
+RESULT_VARIABLE HAD_ERROR
+OUTPUT_VARIABLE LD_V_OUTPUT
+)
+  if (HAD_ERROR)
+message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
+  endif()
+  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
+string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
+string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" LINK_VERSION 
${LD_V_OUTPUT})
+  endif()
+  set(${variable} ${LINK_VERSION} PARENT_SCOPE)
+endfunction()
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index d562a6206c00e7..f4e92f14db8570 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -36,6 +36,7 @@ include(SetPlatformToolchainTools)
 include(base-config-ix)
 include(CompilerRTUtils)
 include(CMakeDependentOption)
+include(GetDarwinLinkerVersion)
 
 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
@@ -444,6 +445,15 @@ else()
   set(SANITIZER_USE_SYMBOLS FALSE)
 endif()
 
+# Get the linker version while configuring compiler-rt and explicitly pass it
+# in cflags during testing. This fixes the compiler/linker version mismatch
+# issue when running a clang built with a newer Xcode in an older Xcode
+set(COMPILER_RT_DARWIN_LINKER_VERSION)
+if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
+  get_darwin_linker_version(COMPILER_RT_DARWIN_LINKER_VERSION)
+  message(STATUS "Host linker version: ${COMPILER_RT_DARWIN_LINKER_VERSION}")
+endif()
+
 # Build sanitizer runtimes with debug info.
 if(MSVC)
   # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
diff --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index bd9b926c1505b1..0ac20a9831d950 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -882,6 +882,10 @@ def is_windows_lto_supported():
 elif config.use_lld and (not config.has_lld):
 config.unsupported = True
 
+if config.host_os == "Darwin":
+if getattr(config, "darwin_linker_version", None):
+extra_cflags += ["-mlinker-version=" + config.darwin_linker_version]
+
 # Append any extra 

[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread Argyrios Kyrtzidis via cfe-commits

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

Nice! Note that you implemented rdar://107663951 

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-22 Thread Yeoul Na via cfe-commits

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


[clang] b1e97d6 - Unwrap CountAttributed for debug info (#86017)

2024-03-22 Thread via cfe-commits

Author: Yeoul Na
Date: 2024-03-23T07:26:35+09:00
New Revision: b1e97d60bd5b1d3f994345caa4012ea11c2a0f62

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

LOG: Unwrap CountAttributed for debug info (#86017)

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9

Added: 
clang/test/CodeGen/attr-counted-by-debug-info.c

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const 
ASTContext ) {
 case Type::BTFTagAttributed:
   T = cast(T)->getWrappedType();
   break;
+case Type::CountAttributed:
+  T = cast(T)->desugar();
+  break;
 case Type::Elaborated:
   T = cast(T)->getNamedType();
   break;

diff  --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00..a6c2b1382b796b
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)__attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: {{.*}}, encoding: 
DW_ATE_signed)
+// CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
+// CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file



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


[clang-tools-extra] [clang-tidy] Ignore expresions in unevaluated context in bugprone-inc-dec-in-conditions (PR #85849)

2024-03-22 Thread Julian Schmidt via cfe-commits

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

Looks good, but the `operand` node may also be in an unevaluated context, you 
only guard against the non `++/--` expr being in an unevaluated context here. 
Fix: add `unless(IsInUnevaluatedContext)` to both `expr().bind("operand")`.
Example: `if (foo < static_cast(bar)) {}`

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread Ben Langmuir via cfe-commits

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


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


[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Jon Chesterfield (JonChesterfield)


Changes

When a CMakeLists.txt is missing a 'project' statement you get the default 
supported languages of C and CXX. 
https://cmake.org/cmake/help/latest/command/project.html. The help says ASM 
should be listed last.

CMake doesn't raise an error about the .S files it has been told about when 
project is missing. It silently ignores them. In this case, the symptom is an 
undefined symbol *jumpto in the library.

Working theory for why this isn't more obviously broken everywhere is the 
'runtimes' CMakeLists.txt does contain a 'project' statement which lists ASM 
and/or by default linking shared libraries with undefined symbols succeeds.

The string immediately after project appears to be arbitrary, chosen 'Unwind' 
to match the capitalization of 'Runtimes'. 

For completeness, this also removes the following warning when building 
libunwind by itself:

CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
 This warning is for project developers.  Use -Wno-dev to suppress it.

This gives no hint that the consequence of ignoring this warning is cmake will 
ignore your assembly.

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


1 Files Affected:

- (modified) libunwind/CMakeLists.txt (+1) 


``diff
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 806d5a783ec39c..01d3b72b73e842 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -3,6 +3,7 @@
 
#===
 
 cmake_minimum_required(VERSION 3.20.0)
+project(Unwind LANGUAGES C CXX ASM)
 
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
 

``




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


[libunwind] [libunwind] Compile the asm as well as the C++ source (PR #86351)

2024-03-22 Thread Jon Chesterfield via cfe-commits

https://github.com/JonChesterfield created 
https://github.com/llvm/llvm-project/pull/86351

When a CMakeLists.txt is missing a 'project' statement you get the default 
supported languages of C and CXX. 
https://cmake.org/cmake/help/latest/command/project.html. The help says ASM 
should be listed last.

CMake doesn't raise an error about the .S files it has been told about when 
project is missing. It silently ignores them. In this case, the symptom is an 
undefined symbol *jumpto in the library.

Working theory for why this isn't more obviously broken everywhere is the 
'runtimes' CMakeLists.txt does contain a 'project' statement which lists ASM 
and/or by default linking shared libraries with undefined symbols succeeds.

The string immediately after project appears to be arbitrary, chosen 'Unwind' 
to match the capitalization of 'Runtimes'. 

For completeness, this also removes the following warning when building 
libunwind by itself:

>CMake Warning (dev) in CMakeLists.txt:
>  No project() command is present.  The top-level CMakeLists.txt file must
>  contain a literal, direct call to the project() command.  Add a line of
>  code such as
>
>project(ProjectName)
>
>  near the top of the file, but after cmake_minimum_required().
>
>  CMake is pretending there is a "project(Project)" command on the first
>  line.
> This warning is for project developers.  Use -Wno-dev to suppress it.

This gives no hint that the consequence of ignoring this warning is cmake will 
ignore your assembly.

>From 3cacdbc0585d00c8820dc7baa0cba378beeff339 Mon Sep 17 00:00:00 2001
From: Jon Chesterfield 
Date: Fri, 22 Mar 2024 22:02:06 +
Subject: [PATCH] [libunwind] Compile the asm as well as the C source

---
 libunwind/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 806d5a783ec39c..01d3b72b73e842 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -3,6 +3,7 @@
 
#===
 
 cmake_minimum_required(VERSION 3.20.0)
+project(Unwind LANGUAGES C CXX ASM)
 
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
 

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

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


[clang] [compiler-rt] [llvm] Get the linker version and pass the it to compiler-rt tests on Darwin. (PR #86220)

2024-03-22 Thread Usama Hameed via cfe-commits

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)


Changes

Since b4c83a13f664582015ea22924b9a0c6290d41f5b, `Preprocessor` and `Lexer` are 
aware of the concept of scanning dependency directives. This makes it possible 
to scan for them on-demand rather than eagerly on the first filesystem 
operation (open, or even just stat).

This might improve performance, but is also necessary for the "PCH as module" 
mode. Some precompiled header sources use the ".pch" file extension, which 
means they were not getting scanned for dependency directives. This was okay 
when the PCH was the main input file in a separate scan step, because there we 
just lex the file in a scanning-specific frontend action. But when such source 
gets treated as a module implicitly loaded from a TU, it will get compiled as 
any other module - with Sema - which will result in compilation errors. (See 
attached test case.)

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


4 Files Affected:

- (modified) 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
(+7-11) 
- (modified) 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp (+15-47) 
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
(+3-1) 
- (added) clang/test/ClangScanDeps/modules-extension.c (+33) 


``diff
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 846fdc7253977f..870ef8b2f45bb0 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -242,6 +242,8 @@ class EntryRef {
   /// The underlying cached entry.
   const CachedFileSystemEntry 
 
+  friend class DependencyScanningWorkerFilesystem;
+
 public:
   EntryRef(StringRef Name, const CachedFileSystemEntry )
   : Filename(Name), Entry(Entry) {}
@@ -300,14 +302,13 @@ class DependencyScanningWorkerFilesystem
   ///
   /// Attempts to use the local and shared caches first, then falls back to
   /// using the underlying filesystem.
-  llvm::ErrorOr
-  getOrCreateFileSystemEntry(StringRef Filename,
- bool DisableDirectivesScanning = false);
+  llvm::ErrorOr getOrCreateFileSystemEntry(StringRef Filename);
 
-private:
-  /// Check whether the file should be scanned for preprocessor directives.
-  bool shouldScanForDirectives(StringRef Filename);
+  /// Scan for preprocessor directives for the given entry if necessary and
+  /// returns a wrapper object with reference semantics.
+  bool scanForDirectives(EntryRef Entry);
 
+private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
   /// shared cache indexed by unique ID, or creates new entry from scratch.
@@ -317,11 +318,6 @@ class DependencyScanningWorkerFilesystem
   computeAndStoreResult(StringRef OriginalFilename,
 StringRef FilenameForLookup);
 
-  /// Scan for preprocessor directives for the given entry if necessary and
-  /// returns a wrapper object with reference semantics.
-  EntryRef scanForDirectivesIfNecessary(const CachedFileSystemEntry ,
-StringRef Filename, bool Disable);
-
   /// Represents a filesystem entry that has been stat-ed (and potentially 
read)
   /// and that's about to be inserted into the cache as 
`CachedFileSystemEntry`.
   struct TentativeEntry {
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 1b750cec41e1cc..8fd1990440bbb2 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -41,24 +41,24 @@ DependencyScanningWorkerFilesystem::readFile(StringRef 
Filename) {
   return TentativeEntry(Stat, std::move(Buffer));
 }
 
-EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary(
-const CachedFileSystemEntry , StringRef Filename, bool Disable) {
-  if (Entry.isError() || Entry.isDirectory() || Disable ||
-  !shouldScanForDirectives(Filename))
-return EntryRef(Filename, Entry);
+bool DependencyScanningWorkerFilesystem::scanForDirectives(EntryRef Ref) {
+  auto  = Ref.Entry;
+
+  if (Entry.isError() || Entry.isDirectory())
+return false;
 
   CachedFileContents *Contents = Entry.getCachedContents();
   assert(Contents && "contents not initialized");
 
   // Double-checked locking.
   if (Contents->DepDirectives.load())
-return EntryRef(Filename, Entry);
+return true;
 
   std::lock_guard GuardLock(Contents->ValueLock);
 
   // Double-checked locking.
   if (Contents->DepDirectives.load())
-return EntryRef(Filename, 

[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,68 @@
+//===--- MathMissingParenthesesCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MathMissingParenthesesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
+hasDescendant(binaryOperator()))
+ .bind("binOp"),
+ this);
+}
+
+void addParantheses(
+const BinaryOperator *BinOp, const BinaryOperator *ParentBinOp,
+bool ,
+std::vector>
+) {
+  if (!BinOp)
+return;
+
+  if (ParentBinOp != nullptr &&
+  ParentBinOp->getOpcode() != BinOp->getOpcode()) {
+NeedToDiagnose = true;
+  }
+  const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
+  const clang::SourceLocation EndLoc = BinOp->getEndLoc().getLocWithOffset(1);
+  Insertions.push_back({StartLoc, EndLoc});
+  addParantheses(dyn_cast(BinOp->getLHS()->IgnoreImpCasts()),
+ BinOp, NeedToDiagnose, Insertions);
+  addParantheses(dyn_cast(BinOp->getRHS()->IgnoreImpCasts()),
+ BinOp, NeedToDiagnose, Insertions);
+}
+
+void MathMissingParenthesesCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *BinOp = Result.Nodes.getNodeAs("binOp");
+  bool NeedToDiagnose = false;
+  std::vector>
+  Insertions;
+  addParantheses(BinOp, nullptr, NeedToDiagnose, Insertions);
+  const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
+  const clang::SourceLocation EndLoc = BinOp->getEndLoc().getLocWithOffset(1);
+  const clang::SourceRange range(StartLoc, EndLoc);
+  if (!Insertions.empty()) {
+Insertions.erase(Insertions.begin());
+  }
+  if (NeedToDiagnose) {
+auto const  = diag(
+StartLoc, "add parantheses to clarify the precedence of operations");
+for (const auto  : Insertions) {
+  Diag << FixItHint::CreateInsertion(Insertion.first, "(");
+  Diag << FixItHint::CreateInsertion(Insertion.second, ")");

5chmidti wrote:

You can stream a range into the diagnostic here, such that the affected 
operator is underlined. This would also make it easier to find and hit the 
range in an editor when using clangd.
Overlapping operators will just be a single line, and holes in the underline 
may occur (e.g., 2nd diagnostic).

| Without the range | With the range |
| --- | --- |
| 
![image](https://github.com/llvm/llvm-project/assets/44101708/e19e01bb-786d-4c2a-9af7-66f156ca9cc2)
 | 
![image](https://github.com/llvm/llvm-project/assets/44101708/fa758c46-e06d-4215-bd43-b71a3ca78c1c)
 |

The code I used to make the example: `Diag << SourceRange(Insertion.first, 
Insertion.second);`, and when you change the type that you use to track the 
insertion locations to a `SourceRange`, like Piotr suggested, then you can just 
use that (`Diag << Insertion`).

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/86347

>From 9536d6007457091ff27da3dd38405382ae9000f1 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 22 Mar 2024 13:29:43 -0700
Subject: [PATCH] [clang][deps] Lazy dependency directives

Since b4c83a13f664582015ea22924b9a0c6290d41f5b, `Preprocessor` and `Lexer` are 
aware of the concept of scanning dependency directives. This makes it possible 
to scan for them on-demand rather than eagerly on the first filesystem 
operation (open, or even just stat).

This might improve performance, but is also necessary for the "PCH as module" 
mode. Some precompiled header sources use the ".pch" file extension, which 
means they were not getting scanned for dependency directives. This was okay 
when the PCH was the main input file in a separate scan step, because there we 
just lex the file in a scanning-specific frontend action. But when such source 
gets treated as a module implicitly loaded from a TU, it will get compiled as 
any other module - with Sema - which will result in compilation errors. (See 
attached test case.)
---
 .../DependencyScanningFilesystem.h| 20 +++---
 .../DependencyScanningFilesystem.cpp  | 63 +--
 .../DependencyScanningWorker.cpp  |  3 +-
 clang/test/ClangScanDeps/modules-extension.c  | 33 ++
 4 files changed, 60 insertions(+), 59 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/modules-extension.c

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 846fdc7253977f..9a522a3e2fe252 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -242,6 +242,8 @@ class EntryRef {
   /// The underlying cached entry.
   const CachedFileSystemEntry 
 
+  friend class DependencyScanningWorkerFilesystem;
+
 public:
   EntryRef(StringRef Name, const CachedFileSystemEntry )
   : Filename(Name), Entry(Entry) {}
@@ -300,14 +302,15 @@ class DependencyScanningWorkerFilesystem
   ///
   /// Attempts to use the local and shared caches first, then falls back to
   /// using the underlying filesystem.
-  llvm::ErrorOr
-  getOrCreateFileSystemEntry(StringRef Filename,
- bool DisableDirectivesScanning = false);
+  llvm::ErrorOr getOrCreateFileSystemEntry(StringRef Filename);
 
-private:
-  /// Check whether the file should be scanned for preprocessor directives.
-  bool shouldScanForDirectives(StringRef Filename);
+  /// Ensure the directive tokens are populated for this file entry.
+  ///
+  /// Returns true if the directive tokens are populated for this file entry,
+  /// false if not (i.e. this entry is not a file or its scan fails).
+  bool ensureDirectiveTokensArePopulated(EntryRef Entry);
 
+private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
   /// shared cache indexed by unique ID, or creates new entry from scratch.
@@ -317,11 +320,6 @@ class DependencyScanningWorkerFilesystem
   computeAndStoreResult(StringRef OriginalFilename,
 StringRef FilenameForLookup);
 
-  /// Scan for preprocessor directives for the given entry if necessary and
-  /// returns a wrapper object with reference semantics.
-  EntryRef scanForDirectivesIfNecessary(const CachedFileSystemEntry ,
-StringRef Filename, bool Disable);
-
   /// Represents a filesystem entry that has been stat-ed (and potentially 
read)
   /// and that's about to be inserted into the cache as 
`CachedFileSystemEntry`.
   struct TentativeEntry {
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 1b750cec41e1cc..9b7812a1adb9e3 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -41,24 +41,25 @@ DependencyScanningWorkerFilesystem::readFile(StringRef 
Filename) {
   return TentativeEntry(Stat, std::move(Buffer));
 }
 
-EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary(
-const CachedFileSystemEntry , StringRef Filename, bool Disable) {
-  if (Entry.isError() || Entry.isDirectory() || Disable ||
-  !shouldScanForDirectives(Filename))
-return EntryRef(Filename, Entry);
+bool DependencyScanningWorkerFilesystem::ensureDirectiveTokensArePopulated(
+EntryRef Ref) {
+  auto  = Ref.Entry;
+
+  if (Entry.isError() || Entry.isDirectory())
+return false;
 
   CachedFileContents *Contents = Entry.getCachedContents();
   assert(Contents && "contents not initialized");
 
   // Double-checked locking.
   if 

[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [clang][deps] Lazy dependency directives (PR #86347)

2024-03-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/86347

Since b4c83a13f664582015ea22924b9a0c6290d41f5b, `Preprocessor` and `Lexer` are 
aware of the concept of scanning dependency directives. This makes it possible 
to scan for them on-demand rather than eagerly on the first filesystem 
operation (open, or even just stat).

This might improve performance, but is also necessary for the "PCH as module" 
mode. Some precompiled header sources use the ".pch" file extension, which 
means they were not getting scanned for dependency directives. This was okay 
when the PCH was the main input file in a separate scan step, because there we 
just lex the file in a scanning-specific frontend action. But when such source 
gets treated as a module implicitly loaded from a TU, it will get compiled as 
any other module - with Sema - which will result in compilation errors. (See 
attached test case.)

>From 4bf2dd2d760e79464f25e9cc97487ddbebf0ceba Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Fri, 22 Mar 2024 13:29:43 -0700
Subject: [PATCH] [clang][deps] Lazy dependency directives

Since b4c83a13f664582015ea22924b9a0c6290d41f5b, `Preprocessor` and `Lexer` are 
aware of the concept of scanning dependency directives. This makes it possible 
to scan for them on-demand rather than eagerly on the first filesystem 
operation (open, or even just stat).

This might improve performance, but is also necessary for the "PCH as module" 
mode. Some precompiled header sources use the ".pch" file extension, which 
means they were not getting scanned for dependency directives. This was okay 
when the PCH was the main input file in a separate scan step, because there we 
just lex the file in a scanning-specific frontend action. But when such source 
gets treated as a module implicitly loaded from a TU, it will get compiled as 
any other module - with Sema - which will result in compilation errors. (See 
attached test case.)
---
 .../DependencyScanningFilesystem.h| 18 +++---
 .../DependencyScanningFilesystem.cpp  | 62 +--
 .../DependencyScanningWorker.cpp  |  4 +-
 clang/test/ClangScanDeps/modules-extension.c  | 33 ++
 4 files changed, 58 insertions(+), 59 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/modules-extension.c

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index 846fdc7253977f..870ef8b2f45bb0 100644
--- 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -242,6 +242,8 @@ class EntryRef {
   /// The underlying cached entry.
   const CachedFileSystemEntry 
 
+  friend class DependencyScanningWorkerFilesystem;
+
 public:
   EntryRef(StringRef Name, const CachedFileSystemEntry )
   : Filename(Name), Entry(Entry) {}
@@ -300,14 +302,13 @@ class DependencyScanningWorkerFilesystem
   ///
   /// Attempts to use the local and shared caches first, then falls back to
   /// using the underlying filesystem.
-  llvm::ErrorOr
-  getOrCreateFileSystemEntry(StringRef Filename,
- bool DisableDirectivesScanning = false);
+  llvm::ErrorOr getOrCreateFileSystemEntry(StringRef Filename);
 
-private:
-  /// Check whether the file should be scanned for preprocessor directives.
-  bool shouldScanForDirectives(StringRef Filename);
+  /// Scan for preprocessor directives for the given entry if necessary and
+  /// returns a wrapper object with reference semantics.
+  bool scanForDirectives(EntryRef Entry);
 
+private:
   /// For a filename that's not yet associated with any entry in the caches,
   /// uses the underlying filesystem to either look up the entry based in the
   /// shared cache indexed by unique ID, or creates new entry from scratch.
@@ -317,11 +318,6 @@ class DependencyScanningWorkerFilesystem
   computeAndStoreResult(StringRef OriginalFilename,
 StringRef FilenameForLookup);
 
-  /// Scan for preprocessor directives for the given entry if necessary and
-  /// returns a wrapper object with reference semantics.
-  EntryRef scanForDirectivesIfNecessary(const CachedFileSystemEntry ,
-StringRef Filename, bool Disable);
-
   /// Represents a filesystem entry that has been stat-ed (and potentially 
read)
   /// and that's about to be inserted into the cache as 
`CachedFileSystemEntry`.
   struct TentativeEntry {
diff --git 
a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 1b750cec41e1cc..8fd1990440bbb2 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -41,24 +41,24 @@ 

[clang-tools-extra] Add clang-tidy check readability-math-missing-parentheses (PR #84481)

2024-03-22 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,68 @@
+//===--- MathMissingParenthesesCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MathMissingParenthesesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
+hasDescendant(binaryOperator()))
+ .bind("binOp"),
+ this);
+}
+
+void addParantheses(
+const BinaryOperator *BinOp, const BinaryOperator *ParentBinOp,
+bool ,
+std::vector>
+) {
+  if (!BinOp)
+return;
+
+  if (ParentBinOp != nullptr &&
+  ParentBinOp->getOpcode() != BinOp->getOpcode()) {
+NeedToDiagnose = true;
+  }
+  const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
+  const clang::SourceLocation EndLoc = BinOp->getEndLoc().getLocWithOffset(1);
+  Insertions.push_back({StartLoc, EndLoc});
+  addParantheses(dyn_cast(BinOp->getLHS()->IgnoreImpCasts()),
+ BinOp, NeedToDiagnose, Insertions);
+  addParantheses(dyn_cast(BinOp->getRHS()->IgnoreImpCasts()),
+ BinOp, NeedToDiagnose, Insertions);
+}
+
+void MathMissingParenthesesCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *BinOp = Result.Nodes.getNodeAs("binOp");
+  bool NeedToDiagnose = false;
+  std::vector>
+  Insertions;
+  addParantheses(BinOp, nullptr, NeedToDiagnose, Insertions);
+  const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
+  const clang::SourceLocation EndLoc = BinOp->getEndLoc().getLocWithOffset(1);
+  const clang::SourceRange range(StartLoc, EndLoc);

5chmidti wrote:

`range` and `EndLoc` are unused

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-03-22 Thread John McCall via cfe-commits

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

Okay.  Thanks for putting up with such a protracted review!  I really like 
where we've ended up.

LGTM.  Please wait a few days before merging to give other reviewers a chance 
to give final feedback.

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 3b3de48fd84b8269d5f45ee0a9dc6b7448368424 
ab7d280abf053b67b716e0723e2e70876e639810 -- clang/lib/AST/TypePrinter.cpp 
clang/unittests/AST/DeclPrinterTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index f0e360f9ca..a7d8212249 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1390,20 +1390,18 @@ TEST(DeclPrinter, TestCXXRecordDecl17) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
   "Z A;",
-  "A",
-  "Z A"));
+  "A", "Z A"));
   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
 }
 
 TEST(DeclPrinter, TestCXXRecordDecl18) {
   ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
   "struct X {};"
-  "Z A;" 
+  "Z A;"
   "template "
   "struct Y{};"
   "Y, 2> B;",
-  "B", 
-  "Y, 2> B"));
+  "B", "Y, 2> B"));
   [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
 }
 

``




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


[clang] Fix printing of templated records. (PR #86339)

2024-03-22 Thread Zahira Ammarguellat via cfe-commits

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

None

>From ab7d280abf053b67b716e0723e2e70876e639810 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 22 Mar 2024 13:55:44 -0700
Subject: [PATCH] Fix printing of templated records.

---
 clang/lib/AST/TypePrinter.cpp   |  5 -
 clang/unittests/AST/DeclPrinterTest.cpp | 21 +
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 7032ff2f18468c..d9504f9dcb3899 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2303,11 +2303,6 @@ printTo(raw_ostream , ArrayRef Args, const 
PrintingPolicy ,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (!Policy.SuppressTagKeyword &&
-  Argument.getKind() == TemplateArgument::Type &&
-  isa(Argument.getAsType()))
-OS << Argument.getAsType().getAsString();
-  else
 // Tries to print the argument with location info if exists.
 printArgument(Arg, Policy, ArgOS,
   TemplateParameterList::shouldIncludeTypeForArgument(
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index e024c41e03b484..f0e360f9caf44a 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1386,6 +1386,27 @@ TEST(DeclPrinter, TestTemplateArgumentList16) {
   ASSERT_TRUE(PrintedDeclCXX11Matches(Code, "NT2", "int NT2 = 5"));
 }
 
+TEST(DeclPrinter, TestCXXRecordDecl17) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
+  "struct X {};"
+  "Z A;",
+  "A",
+  "Z A"));
+  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
+}
+
+TEST(DeclPrinter, TestCXXRecordDecl18) {
+  ASSERT_TRUE(PrintedDeclCXX98Matches("template struct Z {};"
+  "struct X {};"
+  "Z A;" 
+  "template "
+  "struct Y{};"
+  "Y, 2> B;",
+  "B", 
+  "Y, 2> B"));
+  [](PrintingPolicy ) { Policy.SuppressTagKeyword = false; };
+}
+
 TEST(DeclPrinter, TestFunctionParamUglified) {
   llvm::StringLiteral Code = R"cpp(
 class __c;

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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-22 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

My pleasure.

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-03-22 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

@rjmccall thanks, here is an update with those changes.  I've collapsed it to 
the 3 commits mentioned earlier

1) Tests marked up for the current behaviour
2) TargetInfo strict/flexible alignment load predicate
3) The new algorithm

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


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -109,9 +109,22 @@ int unused_with_implicit_default_def(void) { return 1; }
 int unused_with_implicit_forward_default_def(void) { return 0; }
 __attribute__((target_version("lse"))) int 
unused_with_implicit_forward_default_def(void) { return 1; }
 
-// This should generate a normal function.
+// This should generate a target version despite the default not being 
declared.
 __attribute__((target_version("rdm"))) int unused_without_default(void) { 
return 0; }
 
+// The following is guarded because in NOFMV we get errors for calling 
undeclared functions.
+#ifdef __HAVE_FUNCTION_MULTI_VERSIONING
+// This should generate a default declaration, two target versions and the 
resolver.
+__attribute__((target_version("jscvt"))) int 
used_def_without_default_decl(void) { return 1; }
+__attribute__((target_version("rdma"))) int 
used_def_without_default_decl(void) { return 2; }
+
+// This should generate a default declaration and the resolver.
+__attribute__((target_version("jscvt"))) int 
used_decl_without_default_decl(void);
+__attribute__((target_version("rdma"))) int 
used_decl_without_default_decl(void);
+
+int caller(void) { return used_def_without_default_decl() + 
used_decl_without_default_decl(); }

labrinea wrote:

Let me think about this a little more. The behavior is inconsistent when the 
order of declaration changes. If the default comes last then it is mangled and 
a resolver is generated. Perhaps this is preferable in case the other versions 
reside in another TU.

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


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-22 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

Yes it's expected that wasi-sdk will need changes to incorporate this PR. I'm 
waiting for this to be in an LLVM release before updating wasi-sdk.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [HLSL] Add validation for the -enable-16bit-types option (PR #85340)

2024-03-22 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/85340

>From 3cdcfa4e63550b9677c8ffe2f33eab85899b2c45 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 14 Mar 2024 17:04:12 -0700
Subject: [PATCH 1/9] add test

---
 .../clang/Basic/DiagnosticDriverKinds.td  |  3 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 86 ---
 2 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index e33a1f4c45b949..fae9132bd0a9c9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -753,7 +753,8 @@ def err_drv_hlsl_unsupported_target : Error<
   "HLSL code generation is unsupported for target '%0'">;
 def err_drv_hlsl_bad_shader_required_in_target : Error<
   "%select{shader model|Vulkan environment|shader stage}0 is required as 
%select{OS|environment}1 in target '%2' for HLSL code generation">;
-
+def err_drv_hlsl_enable_16bit_types_option_invalid: Error<
+  "enable_16bit_types option only valid when target shader model [-T] is >= 
6.2 and Hlsl Version [-HV] is >= 2021">;
 def err_drv_hlsl_bad_shader_unsupported : Error<
   "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' 
is invalid for HLSL code generation">;
 def warn_drv_dxc_missing_dxv : Warning<"dxv not found. "
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 05aac9caa7fb29..bf8fc42a27816c 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -66,15 +66,48 @@ bool isLegalShaderModel(Triple ) {
   return false;
 }
 
-std::optional tryParseProfile(StringRef Profile) {
-  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+struct ShaderModel {
+  StringRef TargetKind;
+  unsigned Major;
+  unsigned Minor;
+  bool OfflineLibMinor = false;
+};
+
+std::optional GetShaderModelFromString(StringRef Profile) {
   SmallVector Parts;
   Profile.split(Parts, "_");
   if (Parts.size() != 3)
 return std::nullopt;
 
+  unsigned long long Major = 0;
+  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
+return std::nullopt;
+
+  unsigned long long Minor = 0;
+  bool isOfflineLibMinor = false;
+  if (Parts[0] == "lib" && Parts[2] == "x")
+isOfflineLibMinor = true;
+  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
+return std::nullopt;
+
+  ShaderModel ret;
+  ret.TargetKind = Parts[0];
+  ret.Major = Major;
+  ret.Minor = Minor;
+  ret.OfflineLibMinor = isOfflineLibMinor;
+
+  return ret;
+}
+
+std::optional tryParseProfile(StringRef Profile) {
+  std::optional SM = GetShaderModelFromString(Profile);
+  if (!SM.has_value()) {
+return std::nullopt;
+  }
+  // [ps|vs|gs|hs|ds|cs|ms|as]_[major]_[minor]
+
   Triple::EnvironmentType Kind =
-  StringSwitch(Parts[0])
+  StringSwitch(SM.value().TargetKind)
   .Case("ps", Triple::EnvironmentType::Pixel)
   .Case("vs", Triple::EnvironmentType::Vertex)
   .Case("gs", Triple::EnvironmentType::Geometry)
@@ -88,21 +121,11 @@ std::optional tryParseProfile(StringRef 
Profile) {
   if (Kind == Triple::EnvironmentType::UnknownEnvironment)
 return std::nullopt;
 
-  unsigned long long Major = 0;
-  if (llvm::getAsUnsignedInteger(Parts[1], 0, Major))
-return std::nullopt;
-
-  unsigned long long Minor = 0;
-  if (Parts[2] == "x" && Kind == Triple::EnvironmentType::Library)
-Minor = OfflineLibMinor;
-  else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
-return std::nullopt;
-
   // dxil-unknown-shadermodel-hull
   llvm::Triple T;
   T.setArch(Triple::ArchType::dxil);
   T.setOSName(Triple::getOSTypeName(Triple::OSType::ShaderModel).str() +
-  VersionTuple(Major, Minor).getAsString());
+  VersionTuple(SM.value().Major, SM.value().Minor).getAsString());
   T.setEnvironment(Kind);
   if (isLegalShaderModel(T))
 return T.getTriple();
@@ -258,6 +281,41 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , 
StringRef BoundArch,
   // FIXME: add validation for enable_16bit_types should be after HLSL 2018 and
   // shader model 6.2.
   // See: https://github.com/llvm/llvm-project/issues/57876
+  if (DAL->hasArg(options::OPT_fnative_half_type)) {
+
+bool HVArgIsValid = true;
+bool TPArgIsValid = true;
+
+const StringRef HVArg =
+DAL->getLastArgValue(options::OPT_std_EQ, "hlsl2021");
+
+const StringRef TPArg =
+DAL->getLastArgValue(options::OPT_target_profile, "");
+std::optional parsedTargetProfile =
+GetShaderModelFromString(TPArg);
+
+unsigned long long HV_year;
+StringRef HV_year_str = HVArg.drop_front(4);
+if (HV_year_str != "202x") {
+  llvm::getAsUnsignedInteger(HV_year_str, 0, HV_year);
+  if (HV_year < 2021)
+HVArgIsValid = false;
+}
+
+if (!parsedTargetProfile.has_value())
+  return DAL;
+else {
+  if 

[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-22 Thread Reid Kleckner via cfe-commits

rnk wrote:

> As a data point, I've been setting core.autocrlf=true on Windows for years. 

If that's the case, my information is stale, which I accept.

> To be clear, this may do nothing on checkout if a user has set a config 
> option. 

That addresses my concerns.


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


[clang] [CMake][HLSL] Add SPIRV to target list for build (PR #86323)

2024-03-22 Thread Xiang Li via cfe-commits

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


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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the C/C++ code 
formatter.

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


[clang] [llvm] AMDGPU: Rename intrinsics and remove f16/bf16 versions for load transpose (PR #86313)

2024-03-22 Thread Changpeng Fang via cfe-commits

changpeng wrote:

> There is no issue in changing the names in principle. Curious, what is the 
> rationale to use more demangled names?

more user friendly.

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-22 Thread Alex Voicu via cfe-commits


@@ -1318,16 +1318,16 @@ define void @instructions.va_arg(i8* %v, ...) {
   %ap2 = bitcast i8** %ap to i8*
 
   call void @llvm.va_start(i8* %ap2)
-  ; CHECK: call void @llvm.va_start(ptr %ap2)
+  ; CHECK: call void @llvm.va_start.p0(ptr %ap2)
 
   va_arg i8* %ap2, i32
   ; CHECK: va_arg ptr %ap2, i32
-
+s

AlexVlx wrote:

Done.

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


[clang] [X86_32] Teach X86_32 va_arg to ignore empty structs. (PR #86075)

2024-03-22 Thread Eli Friedman via cfe-commits


@@ -1069,6 +1069,10 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction ,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  // Empty records are ignored for parameter passing purposes on non-Windows.
+  if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true))
+return CGF.CreateMemTemp(Ty);

efriedma-quic wrote:

If it doesn't work with the code as-is, please refactor to the code to make it 
work.  Scattered checks like this are hard to maintain.

The simplest thing here would be to just construct a CCState here, I think?  Or 
if that doesn't work for some reason, make the CCState parameter to 
classifyArgumentType optional.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits

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

>From 4e10b2c4dfed3fb59ee03c716852f7fb45de081a Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 18 Mar 2024 10:45:20 -0700
Subject: [PATCH] Check if Coroutine await_suspend type returns the right type

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Sema/SemaCoroutine.cpp  | 119 +-
 clang/test/SemaCXX/coroutines.cpp |  28 -
 4 files changed, 111 insertions(+), 41 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6e179ca9d6904..40d791a616b8a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -339,6 +339,9 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- Clang now emits errors for coroutine `await_suspend` functions whose return 
type is not
+  one of `void`, `bool`, or `std::coroutine_handle`.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fc727cef9cd835..796b3d9d5e1190 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11707,7 +11707,7 @@ def err_coroutine_promise_new_requires_nothrow : Error<
 def note_coroutine_promise_call_implicitly_required : Note<
   "call to %0 implicitly required by coroutine function here">;
 def err_await_suspend_invalid_return_type : Error<
-  "return type of 'await_suspend' is required to be 'void' or 'bool' (have %0)"
+  "return type of 'await_suspend' is required to be 'void', 'bool', or 
'std::coroutine_handle' (have %0)"
 >;
 def note_await_ready_no_bool_conversion : Note<
   "return type of 'await_ready' is required to be contextually convertible to 
'bool'"
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 736632857efc36..2e81a83b62df51 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -137,12 +137,8 @@ static QualType lookupPromiseType(Sema , const 
FunctionDecl *FD,
   return PromiseType;
 }
 
-/// Look up the std::coroutine_handle.
-static QualType lookupCoroutineHandleType(Sema , QualType PromiseType,
-  SourceLocation Loc) {
-  if (PromiseType.isNull())
-return QualType();
-
+static ClassTemplateDecl *lookupCoroutineHandleTemplate(Sema ,
+SourceLocation Loc) {
   NamespaceDecl *CoroNamespace = S.getStdNamespace();
   assert(CoroNamespace && "Should already be diagnosed");
 
@@ -151,18 +147,32 @@ static QualType lookupCoroutineHandleType(Sema , 
QualType PromiseType,
   if (!S.LookupQualifiedName(Result, CoroNamespace)) {
 S.Diag(Loc, diag::err_implied_coroutine_type_not_found)
 << "std::coroutine_handle";
-return QualType();
+return nullptr;
   }
 
-  ClassTemplateDecl *CoroHandle = Result.getAsSingle();
+  auto *CoroHandle = Result.getAsSingle();
+
   if (!CoroHandle) {
 Result.suppressDiagnostics();
 // We found something weird. Complain about the first thing we found.
 NamedDecl *Found = *Result.begin();
 S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle);
-return QualType();
+return nullptr;
   }
 
+  return CoroHandle;
+}
+
+/// Look up the std::coroutine_handle.
+static QualType lookupCoroutineHandleType(Sema , QualType PromiseType,
+  SourceLocation Loc) {
+  if (PromiseType.isNull())
+return QualType();
+
+  ClassTemplateDecl *CoroHandle = lookupCoroutineHandleTemplate(S, Loc);
+  if (!CoroHandle)
+return QualType();
+
   // Form template argument list for coroutine_handle.
   TemplateArgumentListInfo Args(Loc, Loc);
   Args.addArgument(TemplateArgumentLoc(
@@ -331,16 +341,12 @@ static ExprResult buildMemberCall(Sema , Expr *Base, 
SourceLocation Loc,
 // coroutine.
 static Expr *maybeTailCall(Sema , QualType RetType, Expr *E,
SourceLocation Loc) {
-  if (RetType->isReferenceType())
-return nullptr;
+  assert(!RetType->isReferenceType() &&
+ "Should have diagnosed reference types.");
   Type const *T = RetType.getTypePtr();
   if (!T->isClassType() && !T->isStructureType())
 return nullptr;
 
-  // FIXME: Add convertability check to coroutine_handle<>. Possibly via
-  // EvaluateBinaryTypeTrait(BTT_IsConvertible, ...) which is at the moment
-  // a private function in SemaExprCXX.cpp
-
   ExprResult AddressExpr = buildMemberCall(S, E, Loc, "address", std::nullopt);
   if (AddressExpr.isInvalid())
 return nullptr;
@@ -358,6 +364,30 @@ static Expr *maybeTailCall(Sema , QualType RetType, Expr 
*E,
   return S.MaybeCreateExprWithCleanups(JustAddress);
 }
 

[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits

yuxuanchen1997 wrote:

@ChuanqiXu9 

I have updated the patch to check for `std::coroutine_handle` and does not 
rely on `SemaExprCXX` changes. Please let me know what you think. 

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


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits


@@ -68,13 +68,15 @@ int __attribute__((target_version(""))) unsup1(void) { 
return 1; }
 void __attribute__((target_version("crc32"))) unsup2(void) {}
 
 void __attribute__((target_version("default+fp16"))) koo(void) {}
+//expected-error@-1 {{function multiversioning doesn't support feature 
'default'}}
 void __attribute__((target_version("default+default+default"))) loo(void) {}
+//expected-error@-1 {{function multiversioning doesn't support feature 
'default'}}

labrinea wrote:

This diagnostic is unrelated to the patch. I believe it deserves a separate PR 
if at all. I am not confused by the message itself to be honest as the ACLE is 
clear that the attribute string is eather "default" or a list of features with 
'+' in between. What bothers me is the inconsistency with `target_clones`, 
where "default+fp16" is treated as a warning and "default" is ignored. Both 
attributes should either warn or error.

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-22 Thread via cfe-commits

ldrumm wrote:

> So, is there a way to do CRLF -> LF on checkin, but do nothing on checkout?

To be clear, this *may* do nothing on checkout if a user has set a config 
option. The point of the present policy is not to control local preferences as 
far as the filetype isn't *reqired* to have a specific format; we only control 
what ends up in history.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

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


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-22 Thread Cheng Shao via cfe-commits

TerrorJack wrote:

@alexcrichton This is breaking `wasi-sdk` build with:

```
/workspace/wasi-sdk/build/install/opt/wasi-sdk/bin/clang --target=wasm32-wasip2 
-nodefaultlibs -shared 
--sysroot=/workspace/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot \
-o 
/workspace/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasip2/libc.so
 -Wl,--whole-archive build/wasm32-wasip2/libc.so.a -Wl,--no-whole-archive 
/workspace/wasi-sdk/build/install/opt/wasi-sdk/lib/clang/19/lib/wasi/libclang_rt.builtins-wasm32.a
error: unexpected argument '--entry' found

  tip: a similar argument exists: '--no-entry'

Usage: wasm-component-ld -o  --wasm-ld-path  <--export 
|-z 
|--stack-first|--allow-undefined|--fatal-warnings|--no-demangle|--gc-sections|-O
 |-L |-l |--no-entry|-m 
|--strip-all|OBJECTS>

For more information, try '--help'.
clang: error: linker command failed with exit code 2 (use -v to see invocation)
make[1]: *** [Makefile:569: 
/workspace/wasi-sdk/build/install/opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasip2/libc.so]
 Error 2
make[1]: Leaving directory '/workspace/wasi-sdk/src/wasi-libc'
make: *** [Makefile:142: build/wasi-libc.BUILT] Error 2
```

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

2024-03-22 Thread Yuxuan Chen via cfe-commits

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

>From 6887adae7500c4791a8620fa5b558e195e2c64cc Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 18 Mar 2024 10:45:20 -0700
Subject: [PATCH] Check if Coroutine await_suspend type returns the right type

---
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Sema/SemaCoroutine.cpp  | 119 +-
 clang/test/SemaCXX/coroutines.cpp |  28 -
 3 files changed, 108 insertions(+), 41 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fc727cef9cd835..796b3d9d5e1190 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11707,7 +11707,7 @@ def err_coroutine_promise_new_requires_nothrow : Error<
 def note_coroutine_promise_call_implicitly_required : Note<
   "call to %0 implicitly required by coroutine function here">;
 def err_await_suspend_invalid_return_type : Error<
-  "return type of 'await_suspend' is required to be 'void' or 'bool' (have %0)"
+  "return type of 'await_suspend' is required to be 'void', 'bool', or 
'std::coroutine_handle' (have %0)"
 >;
 def note_await_ready_no_bool_conversion : Note<
   "return type of 'await_ready' is required to be contextually convertible to 
'bool'"
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 736632857efc36..2e81a83b62df51 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -137,12 +137,8 @@ static QualType lookupPromiseType(Sema , const 
FunctionDecl *FD,
   return PromiseType;
 }
 
-/// Look up the std::coroutine_handle.
-static QualType lookupCoroutineHandleType(Sema , QualType PromiseType,
-  SourceLocation Loc) {
-  if (PromiseType.isNull())
-return QualType();
-
+static ClassTemplateDecl *lookupCoroutineHandleTemplate(Sema ,
+SourceLocation Loc) {
   NamespaceDecl *CoroNamespace = S.getStdNamespace();
   assert(CoroNamespace && "Should already be diagnosed");
 
@@ -151,18 +147,32 @@ static QualType lookupCoroutineHandleType(Sema , 
QualType PromiseType,
   if (!S.LookupQualifiedName(Result, CoroNamespace)) {
 S.Diag(Loc, diag::err_implied_coroutine_type_not_found)
 << "std::coroutine_handle";
-return QualType();
+return nullptr;
   }
 
-  ClassTemplateDecl *CoroHandle = Result.getAsSingle();
+  auto *CoroHandle = Result.getAsSingle();
+
   if (!CoroHandle) {
 Result.suppressDiagnostics();
 // We found something weird. Complain about the first thing we found.
 NamedDecl *Found = *Result.begin();
 S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle);
-return QualType();
+return nullptr;
   }
 
+  return CoroHandle;
+}
+
+/// Look up the std::coroutine_handle.
+static QualType lookupCoroutineHandleType(Sema , QualType PromiseType,
+  SourceLocation Loc) {
+  if (PromiseType.isNull())
+return QualType();
+
+  ClassTemplateDecl *CoroHandle = lookupCoroutineHandleTemplate(S, Loc);
+  if (!CoroHandle)
+return QualType();
+
   // Form template argument list for coroutine_handle.
   TemplateArgumentListInfo Args(Loc, Loc);
   Args.addArgument(TemplateArgumentLoc(
@@ -331,16 +341,12 @@ static ExprResult buildMemberCall(Sema , Expr *Base, 
SourceLocation Loc,
 // coroutine.
 static Expr *maybeTailCall(Sema , QualType RetType, Expr *E,
SourceLocation Loc) {
-  if (RetType->isReferenceType())
-return nullptr;
+  assert(!RetType->isReferenceType() &&
+ "Should have diagnosed reference types.");
   Type const *T = RetType.getTypePtr();
   if (!T->isClassType() && !T->isStructureType())
 return nullptr;
 
-  // FIXME: Add convertability check to coroutine_handle<>. Possibly via
-  // EvaluateBinaryTypeTrait(BTT_IsConvertible, ...) which is at the moment
-  // a private function in SemaExprCXX.cpp
-
   ExprResult AddressExpr = buildMemberCall(S, E, Loc, "address", std::nullopt);
   if (AddressExpr.isInvalid())
 return nullptr;
@@ -358,6 +364,30 @@ static Expr *maybeTailCall(Sema , QualType RetType, Expr 
*E,
   return S.MaybeCreateExprWithCleanups(JustAddress);
 }
 
+static bool isSpecializationOfCoroutineHandle(Sema , QualType Ty,
+  SourceLocation Loc) {
+  auto *CoroutineHandleClassTemplateDecl =
+  lookupCoroutineHandleTemplate(S, Loc);
+
+  if (!CoroutineHandleClassTemplateDecl)
+return false;
+
+  auto *RecordTy = Ty->getAs();
+  if (!RecordTy)
+return false;
+
+  auto *D = RecordTy->getDecl();
+  if (!D)
+return false;
+
+  auto *SpecializationDecl = dyn_cast(D);
+  if (!SpecializationDecl)
+return false;
+
+  return CoroutineHandleClassTemplateDecl->getCanonicalDecl() ==
+ 

[clang] [llvm] AMDGPU: Rename intrinsics and remove f16/bf16 versions for load transpose (PR #86313)

2024-03-22 Thread Sirish Pande via cfe-commits

srpande wrote:

There is no issue in changing the names in principle. Curious, what is the 
rationale to use more demangled names?

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [lld] [lldb] [llvm] [mlir] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)

2024-03-22 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

As a data point, I've been setting `core.autocrlf=true` on Windows for years. 
I've been trained to make sure _new_ files have LF endings (usually I copy an 
existing file instead of creating a new file) but both Notepad and the Visual 
Studio editor are willing to preserve the line-ending mode of the file as they 
found it. (This was not always true, but is these days.)

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


[clang] [CMake][HLSL] Add SPIRV to target list for build (PR #86323)

2024-03-22 Thread Cooper Partin via cfe-commits

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

SPIRV in the house!

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


[clang] [CMake][HLSL] Add SPIRV to target list for build (PR #86323)

2024-03-22 Thread Joshua Batista via cfe-commits

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


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


  1   2   3   >