[clang-tools-extra] [clang-tidy]Add new check readability-avoid-nested-conditional-operator (PR #78022)

2024-01-13 Thread Congcong Cai via cfe-commits

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

Finds nested conditional operator.
Nested conditional operators lead code hard to understand, so they should be 
splited as several statement and stored in temporary varibale.

>From 0988bb25a35e5d50b44bf53d459098777280c3e5 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 13 Jan 2024 16:00:16 +0800
Subject: [PATCH] [clang-tidy]Add new check
 readability-avoid-nested-conditional-operator Finds nested conditional
 operator. Nested conditional operators lead code hard to understand, so they
 should be splited as several statement and stored in temporary varibale.

---
 .../AvoidNestedConditionalOperatorCheck.cpp   | 56 +++
 .../AvoidNestedConditionalOperatorCheck.h | 33 +++
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../avoid-nested-conditional-operator.rst | 20 +++
 .../avoid-nested-conditional-operator.cpp | 23 
 8 files changed, 142 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-nested-conditional-operator.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-nested-conditional-operator.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
new file mode 100644
index 00..a0278c3ae32fa7
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
@@ -0,0 +1,56 @@
+//===--- AvoidNestedConditionalOperatorCheck.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 "AvoidNestedConditionalOperatorCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/DiagnosticIDs.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+constexpr const char *Description = "don't use nested conditional operator";
+constexpr const char *OutSideConditionalOperatorNote =
+"outside conditional operator here";
+} // namespace
+
+void AvoidNestedConditionalOperatorCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  conditionalOperator(
+  anyOf(
+  hasCondition(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasTrueExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasFalseExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator")
+  .bind("conditional-operator"),
+  this);
+}
+
+void AvoidNestedConditionalOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *CO =
+  Result.Nodes.getNodeAs("conditional-operator");
+  const auto *NCO = Result.Nodes.getNodeAs(
+  "nested-conditional-operator");
+  assert(CO);
+  assert(NCO);
+
+  if (CO->getBeginLoc().isMacroID() || NCO->getBeginLoc().isMacroID())
+return;
+
+  diag(NCO->getBeginLoc(), Description);
+  diag(CO->getBeginLoc(), OutSideConditionalOperatorNote, DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
new file mode 100644
index 00..2f82ea86cd849d
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Fin

[clang-tools-extra] [clang-tidy]Add new check readability-avoid-nested-conditional-operator (PR #78022)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

Finds nested conditional operator.
Nested conditional operators lead code hard to understand, so they should be 
splited as several statement and stored in temporary varibale.

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


8 Files Affected:

- (added) 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 (+56) 
- (added) 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h 
(+33) 
- (modified) clang-tools-extra/clang-tidy/readability/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
(+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-nested-conditional-operator.rst
 (+20) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-nested-conditional-operator.cpp
 (+23) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
new file mode 100644
index 00..a0278c3ae32fa7
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
@@ -0,0 +1,56 @@
+//===--- AvoidNestedConditionalOperatorCheck.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 "AvoidNestedConditionalOperatorCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/DiagnosticIDs.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+constexpr const char *Description = "don't use nested conditional operator";
+constexpr const char *OutSideConditionalOperatorNote =
+"outside conditional operator here";
+} // namespace
+
+void AvoidNestedConditionalOperatorCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  conditionalOperator(
+  anyOf(
+  hasCondition(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasTrueExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasFalseExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator")
+  .bind("conditional-operator"),
+  this);
+}
+
+void AvoidNestedConditionalOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *CO =
+  Result.Nodes.getNodeAs("conditional-operator");
+  const auto *NCO = Result.Nodes.getNodeAs(
+  "nested-conditional-operator");
+  assert(CO);
+  assert(NCO);
+
+  if (CO->getBeginLoc().isMacroID() || NCO->getBeginLoc().isMacroID())
+return;
+
+  diag(NCO->getBeginLoc(), Description);
+  diag(CO->getBeginLoc(), OutSideConditionalOperatorNote, DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
new file mode 100644
index 00..2f82ea86cd849d
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Finds nested conditional operator.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-nested-conditional-operator.html
+class AvoidNestedConditionalOperatorCheck : public ClangTidyCheck {
+public:
+  AvoidNestedConditionalOperatorCheck(StringRef Name, ClangTidyContext 
*Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult 

[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-13 Thread Phoebe Wang via cfe-commits


@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;
+  }
+

phoebewang wrote:

Suggestion:
```
uint64_t SizeInBytes = 0;
if (!isEmptyRecord(CGF.getContext(), Ty, true))
  SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
```

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


[clang] [llvm] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-13 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 updated 
https://github.com/llvm/llvm-project/pull/76558

>From 590f4920ceb1a80d711d39624b0249cd9ff774d2 Mon Sep 17 00:00:00 2001
From: Trevor Gross 
Date: Fri, 11 Aug 2023 22:16:01 -0400
Subject: [PATCH 1/4] [IR] Add an xpassing test for `f128` intrinsic lowering

`f128` intrinsic functions lower to incorrect libc calls. Add a test
showing current behavior.
---
 .../CodeGen/Generic/f128-math-lowering.ll | 610 ++
 1 file changed, 610 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/f128-math-lowering.ll

diff --git a/llvm/test/CodeGen/Generic/f128-math-lowering.ll 
b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
new file mode 100644
index 00..8a70786d97fe67
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
@@ -0,0 +1,610 @@
+
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+;
+; RUN: llc < %s -mtriple=aarch64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-AARCH64
+; RUN: llc < %s -mtriple=riscv32-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-RISCV32
+; RUN: llc < %s -mtriple=s390x-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-S390X
+; RUN: llc < %s -mtriple=i686-unknown-unknown   -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X64
+;
+; Verify that fp128 intrinsics only lower to `long double` calls on platforms
+; where `f128` and `long double` have the same layout.
+;
+; We test on x86 and x64 which have 80-bit ld, as well as aarch64 (ld == f128),
+; riscv32 (ld == f64), and s380x (ld == f128 with different alignment from
+; x64/aarch64 f128).
+;
+; FIXME: these emit calls to long double functions but should emit f128 calls
+
+define fp128 @test_cbrtf128(fp128 %a) {
+; CHECK-LABEL:  test_cbrtf128:
+; CHECK-AARCH64:b llvm.cbrt.f128
+; CHECK-RISCV32:call llvm.cbrt.f128@plt
+; CHECK-S390X:  brasl {{%.*}} llvm.cbrt.f128@PLT
+; CHECK-X64:jmp llvm.cbrt.f128@PLT # TAILCALL
+; CHECK-X86:calll llvm.cbrt.f128@PLT
+start:
+  %0 = tail call fp128 @llvm.cbrt.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.cbrt.f128(fp128)
+
+
+define fp128 @test_ceilf128(fp128 %a) {
+; CHECK-LABEL:  test_ceilf128:
+; CHECK-AARCH64:b ceill
+; CHECK-RISCV32:call ceill@plt
+; CHECK-S390X:  brasl {{%.*}} ceill@PLT
+; CHECK-X64:jmp ceill@PLT
+; CHECK-X86:calll ceill
+start:
+  %0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.ceil.f128(fp128)
+
+
+define fp128 @test_copysignf128(fp128 %a, fp128 %b) {
+; No math library call here, so make sure the assembly does the correct thing.
+; This test is autogenerated
+; CHECK-LABEL:test_copysignf128:
+; CHECK-AARCH64-LABEL: test_copysignf128:
+; CHECK-AARCH64:   // %bb.0: // %start
+; CHECK-AARCH64-NEXT:stp q0, q1, [sp, #-32]!
+; CHECK-AARCH64-NEXT:.cfi_def_cfa_offset 32
+; CHECK-AARCH64-NEXT:ldrb w8, [sp, #15]
+; CHECK-AARCH64-NEXT:ldrb w9, [sp, #31]
+; CHECK-AARCH64-NEXT:bfxil w9, w8, #0, #7
+; CHECK-AARCH64-NEXT:strb w9, [sp, #15]
+; CHECK-AARCH64-NEXT:ldr q0, [sp], #32
+; CHECK-AARCH64-NEXT:ret
+;
+; CHECK-RISCV32-LABEL: test_copysignf128:
+; CHECK-RISCV32:   # %bb.0: # %start
+; CHECK-RISCV32-NEXT:lw a3, 0(a1)
+; CHECK-RISCV32-NEXT:lw a4, 4(a1)
+; CHECK-RISCV32-NEXT:lw a2, 12(a2)
+; CHECK-RISCV32-NEXT:lw a5, 12(a1)
+; CHECK-RISCV32-NEXT:lw a1, 8(a1)
+; CHECK-RISCV32-NEXT:lui a6, 524288
+; CHECK-RISCV32-NEXT:and a2, a2, a6
+; CHECK-RISCV32-NEXT:slli a5, a5, 1
+; CHECK-RISCV32-NEXT:srli a5, a5, 1
+; CHECK-RISCV32-NEXT:or a2, a5, a2
+; CHECK-RISCV32-NEXT:sw a1, 8(a0)
+; CHECK-RISCV32-NEXT:sw a4, 4(a0)
+; CHECK-RISCV32-NEXT:sw a3, 0(a0)
+; CHECK-RISCV32-NEXT:sw a2, 12(a0)
+; CHECK-RISCV32-NEXT:ret
+;
+; CHECK-S390X-LABEL: test_copysignf128:
+; CHECK-S390X:   # %bb.0: # %start
+; CHECK-S390X-NEXT:ld %f0, 0(%r3)
+; CHECK-S390X-NEXT:ld %f2, 8(%r3)
+; CHECK-S390X-NEXT:ld %f1, 0(%r4)
+; CHECK-S390X-NEXT:ld %f3, 8(%r4)
+; CHECK-S390X-NEXT:cpsdr %f0, %f1, %f0
+; CHECK-S390X-NEXT:std %f0, 0(%r2)
+; CHECK-S390X-NEXT:std %f2, 8(%r2)
+; CHECK-S390X-NEXT:br %r14
+;
+; CHECK-X86-LABEL: test_copysignf128:
+; CHECK-X86:   # %bb.0: # %start
+; CHECK-X86-NEXT:pushl %ebx
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 8
+; CHECK-X86-NEXT:pushl %edi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 12
+; CHECK-X86-NEXT:pushl %esi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 16
+; CHECK-X86-NEXT:.cfi_offset %esi, -16
+; CHECK-X86-NEXT:.cfi_offset %edi, -12
+; CHECK-X86-NEXT:.cfi_offset %ebx, -8
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-X86-N

[clang] [llvm] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-13 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 updated 
https://github.com/llvm/llvm-project/pull/76558

>From 946581e0c6a06be92b16d74199b58a72be4b76f3 Mon Sep 17 00:00:00 2001
From: Trevor Gross 
Date: Fri, 11 Aug 2023 22:16:01 -0400
Subject: [PATCH 1/4] [IR] Add an xpassing test for `f128` intrinsic lowering

`f128` intrinsic functions lower to incorrect libc calls. Add a test
showing current behavior.
---
 .../CodeGen/Generic/f128-math-lowering.ll | 610 ++
 1 file changed, 610 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/f128-math-lowering.ll

diff --git a/llvm/test/CodeGen/Generic/f128-math-lowering.ll 
b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
new file mode 100644
index 00..8a70786d97fe67
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
@@ -0,0 +1,610 @@
+
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+;
+; RUN: llc < %s -mtriple=aarch64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-AARCH64
+; RUN: llc < %s -mtriple=riscv32-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-RISCV32
+; RUN: llc < %s -mtriple=s390x-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-S390X
+; RUN: llc < %s -mtriple=i686-unknown-unknown   -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X64
+;
+; Verify that fp128 intrinsics only lower to `long double` calls on platforms
+; where `f128` and `long double` have the same layout.
+;
+; We test on x86 and x64 which have 80-bit ld, as well as aarch64 (ld == f128),
+; riscv32 (ld == f64), and s380x (ld == f128 with different alignment from
+; x64/aarch64 f128).
+;
+; FIXME: these emit calls to long double functions but should emit f128 calls
+
+define fp128 @test_cbrtf128(fp128 %a) {
+; CHECK-LABEL:  test_cbrtf128:
+; CHECK-AARCH64:b llvm.cbrt.f128
+; CHECK-RISCV32:call llvm.cbrt.f128@plt
+; CHECK-S390X:  brasl {{%.*}} llvm.cbrt.f128@PLT
+; CHECK-X64:jmp llvm.cbrt.f128@PLT # TAILCALL
+; CHECK-X86:calll llvm.cbrt.f128@PLT
+start:
+  %0 = tail call fp128 @llvm.cbrt.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.cbrt.f128(fp128)
+
+
+define fp128 @test_ceilf128(fp128 %a) {
+; CHECK-LABEL:  test_ceilf128:
+; CHECK-AARCH64:b ceill
+; CHECK-RISCV32:call ceill@plt
+; CHECK-S390X:  brasl {{%.*}} ceill@PLT
+; CHECK-X64:jmp ceill@PLT
+; CHECK-X86:calll ceill
+start:
+  %0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.ceil.f128(fp128)
+
+
+define fp128 @test_copysignf128(fp128 %a, fp128 %b) {
+; No math library call here, so make sure the assembly does the correct thing.
+; This test is autogenerated
+; CHECK-LABEL:test_copysignf128:
+; CHECK-AARCH64-LABEL: test_copysignf128:
+; CHECK-AARCH64:   // %bb.0: // %start
+; CHECK-AARCH64-NEXT:stp q0, q1, [sp, #-32]!
+; CHECK-AARCH64-NEXT:.cfi_def_cfa_offset 32
+; CHECK-AARCH64-NEXT:ldrb w8, [sp, #15]
+; CHECK-AARCH64-NEXT:ldrb w9, [sp, #31]
+; CHECK-AARCH64-NEXT:bfxil w9, w8, #0, #7
+; CHECK-AARCH64-NEXT:strb w9, [sp, #15]
+; CHECK-AARCH64-NEXT:ldr q0, [sp], #32
+; CHECK-AARCH64-NEXT:ret
+;
+; CHECK-RISCV32-LABEL: test_copysignf128:
+; CHECK-RISCV32:   # %bb.0: # %start
+; CHECK-RISCV32-NEXT:lw a3, 0(a1)
+; CHECK-RISCV32-NEXT:lw a4, 4(a1)
+; CHECK-RISCV32-NEXT:lw a2, 12(a2)
+; CHECK-RISCV32-NEXT:lw a5, 12(a1)
+; CHECK-RISCV32-NEXT:lw a1, 8(a1)
+; CHECK-RISCV32-NEXT:lui a6, 524288
+; CHECK-RISCV32-NEXT:and a2, a2, a6
+; CHECK-RISCV32-NEXT:slli a5, a5, 1
+; CHECK-RISCV32-NEXT:srli a5, a5, 1
+; CHECK-RISCV32-NEXT:or a2, a5, a2
+; CHECK-RISCV32-NEXT:sw a1, 8(a0)
+; CHECK-RISCV32-NEXT:sw a4, 4(a0)
+; CHECK-RISCV32-NEXT:sw a3, 0(a0)
+; CHECK-RISCV32-NEXT:sw a2, 12(a0)
+; CHECK-RISCV32-NEXT:ret
+;
+; CHECK-S390X-LABEL: test_copysignf128:
+; CHECK-S390X:   # %bb.0: # %start
+; CHECK-S390X-NEXT:ld %f0, 0(%r3)
+; CHECK-S390X-NEXT:ld %f2, 8(%r3)
+; CHECK-S390X-NEXT:ld %f1, 0(%r4)
+; CHECK-S390X-NEXT:ld %f3, 8(%r4)
+; CHECK-S390X-NEXT:cpsdr %f0, %f1, %f0
+; CHECK-S390X-NEXT:std %f0, 0(%r2)
+; CHECK-S390X-NEXT:std %f2, 8(%r2)
+; CHECK-S390X-NEXT:br %r14
+;
+; CHECK-X86-LABEL: test_copysignf128:
+; CHECK-X86:   # %bb.0: # %start
+; CHECK-X86-NEXT:pushl %ebx
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 8
+; CHECK-X86-NEXT:pushl %edi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 12
+; CHECK-X86-NEXT:pushl %esi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 16
+; CHECK-X86-NEXT:.cfi_offset %esi, -16
+; CHECK-X86-NEXT:.cfi_offset %edi, -12
+; CHECK-X86-NEXT:.cfi_offset %ebx, -8
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-X86-N

[clang] [clang-format] Add PenaltyBreakScopeResolution option. (PR #78015)

2024-01-13 Thread Emilia Kond via cfe-commits

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


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


[clang] [llvm] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-13 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 updated 
https://github.com/llvm/llvm-project/pull/76558

>From 90a465d0a7e9744a4a8043152016e500927a0d95 Mon Sep 17 00:00:00 2001
From: Trevor Gross 
Date: Fri, 11 Aug 2023 22:16:01 -0400
Subject: [PATCH 1/4] [IR] Add an xpassing test for `f128` intrinsic lowering

`f128` intrinsic functions lower to incorrect libc calls. Add a test
showing current behavior.
---
 .../CodeGen/Generic/f128-math-lowering.ll | 610 ++
 1 file changed, 610 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/f128-math-lowering.ll

diff --git a/llvm/test/CodeGen/Generic/f128-math-lowering.ll 
b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
new file mode 100644
index 00..8a70786d97fe67
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
@@ -0,0 +1,610 @@
+
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+;
+; RUN: llc < %s -mtriple=aarch64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-AARCH64
+; RUN: llc < %s -mtriple=riscv32-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-RISCV32
+; RUN: llc < %s -mtriple=s390x-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-S390X
+; RUN: llc < %s -mtriple=i686-unknown-unknown   -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X64
+;
+; Verify that fp128 intrinsics only lower to `long double` calls on platforms
+; where `f128` and `long double` have the same layout.
+;
+; We test on x86 and x64 which have 80-bit ld, as well as aarch64 (ld == f128),
+; riscv32 (ld == f64), and s380x (ld == f128 with different alignment from
+; x64/aarch64 f128).
+;
+; FIXME: these emit calls to long double functions but should emit f128 calls
+
+define fp128 @test_cbrtf128(fp128 %a) {
+; CHECK-LABEL:  test_cbrtf128:
+; CHECK-AARCH64:b llvm.cbrt.f128
+; CHECK-RISCV32:call llvm.cbrt.f128@plt
+; CHECK-S390X:  brasl {{%.*}} llvm.cbrt.f128@PLT
+; CHECK-X64:jmp llvm.cbrt.f128@PLT # TAILCALL
+; CHECK-X86:calll llvm.cbrt.f128@PLT
+start:
+  %0 = tail call fp128 @llvm.cbrt.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.cbrt.f128(fp128)
+
+
+define fp128 @test_ceilf128(fp128 %a) {
+; CHECK-LABEL:  test_ceilf128:
+; CHECK-AARCH64:b ceill
+; CHECK-RISCV32:call ceill@plt
+; CHECK-S390X:  brasl {{%.*}} ceill@PLT
+; CHECK-X64:jmp ceill@PLT
+; CHECK-X86:calll ceill
+start:
+  %0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.ceil.f128(fp128)
+
+
+define fp128 @test_copysignf128(fp128 %a, fp128 %b) {
+; No math library call here, so make sure the assembly does the correct thing.
+; This test is autogenerated
+; CHECK-LABEL:test_copysignf128:
+; CHECK-AARCH64-LABEL: test_copysignf128:
+; CHECK-AARCH64:   // %bb.0: // %start
+; CHECK-AARCH64-NEXT:stp q0, q1, [sp, #-32]!
+; CHECK-AARCH64-NEXT:.cfi_def_cfa_offset 32
+; CHECK-AARCH64-NEXT:ldrb w8, [sp, #15]
+; CHECK-AARCH64-NEXT:ldrb w9, [sp, #31]
+; CHECK-AARCH64-NEXT:bfxil w9, w8, #0, #7
+; CHECK-AARCH64-NEXT:strb w9, [sp, #15]
+; CHECK-AARCH64-NEXT:ldr q0, [sp], #32
+; CHECK-AARCH64-NEXT:ret
+;
+; CHECK-RISCV32-LABEL: test_copysignf128:
+; CHECK-RISCV32:   # %bb.0: # %start
+; CHECK-RISCV32-NEXT:lw a3, 0(a1)
+; CHECK-RISCV32-NEXT:lw a4, 4(a1)
+; CHECK-RISCV32-NEXT:lw a2, 12(a2)
+; CHECK-RISCV32-NEXT:lw a5, 12(a1)
+; CHECK-RISCV32-NEXT:lw a1, 8(a1)
+; CHECK-RISCV32-NEXT:lui a6, 524288
+; CHECK-RISCV32-NEXT:and a2, a2, a6
+; CHECK-RISCV32-NEXT:slli a5, a5, 1
+; CHECK-RISCV32-NEXT:srli a5, a5, 1
+; CHECK-RISCV32-NEXT:or a2, a5, a2
+; CHECK-RISCV32-NEXT:sw a1, 8(a0)
+; CHECK-RISCV32-NEXT:sw a4, 4(a0)
+; CHECK-RISCV32-NEXT:sw a3, 0(a0)
+; CHECK-RISCV32-NEXT:sw a2, 12(a0)
+; CHECK-RISCV32-NEXT:ret
+;
+; CHECK-S390X-LABEL: test_copysignf128:
+; CHECK-S390X:   # %bb.0: # %start
+; CHECK-S390X-NEXT:ld %f0, 0(%r3)
+; CHECK-S390X-NEXT:ld %f2, 8(%r3)
+; CHECK-S390X-NEXT:ld %f1, 0(%r4)
+; CHECK-S390X-NEXT:ld %f3, 8(%r4)
+; CHECK-S390X-NEXT:cpsdr %f0, %f1, %f0
+; CHECK-S390X-NEXT:std %f0, 0(%r2)
+; CHECK-S390X-NEXT:std %f2, 8(%r2)
+; CHECK-S390X-NEXT:br %r14
+;
+; CHECK-X86-LABEL: test_copysignf128:
+; CHECK-X86:   # %bb.0: # %start
+; CHECK-X86-NEXT:pushl %ebx
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 8
+; CHECK-X86-NEXT:pushl %edi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 12
+; CHECK-X86-NEXT:pushl %esi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 16
+; CHECK-X86-NEXT:.cfi_offset %esi, -16
+; CHECK-X86-NEXT:.cfi_offset %edi, -12
+; CHECK-X86-NEXT:.cfi_offset %ebx, -8
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-X86-N

[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)

2024-01-13 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/70594

>From 864bd0ef7b6bbb0bc1502ef5884ae3c261d3b156 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 29 Oct 2023 18:37:17 +0530
Subject: [PATCH] [clang] Fix a crash in debug mode

Resolves Issue #35603

This bug was caused due to the assertions being too strict,
loosened by stripping qualifiers from the base class but not
from the type of the initializer.

Added Release Notes for the same.
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/test/Sema/GH35603.cpp| 19 +++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/GH35603.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be159437..7183dc447b67fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -918,6 +918,9 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
+- Fix crash when inheriting from a cv-qualified type. Fixes:
+  (`#35603 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..3ad66604255924 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6417,7 +6417,7 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue &This,
   // Non-virtual base classes are initialized in the order in the class
   // definition. We have already checked for virtual base classes.
   assert(!BaseIt->isVirtual() && "virtual base for literal type");
-  assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+  assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
  "base class initializers not in expected order");
   ++BaseIt;
 #endif
diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp
new file mode 100644
index 00..853552108ec2b6
--- /dev/null
+++ b/clang/test/Sema/GH35603.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+  constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+  constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+  constexpr S3() : A() {}
+};

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


[llvm] [clang] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-13 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 updated 
https://github.com/llvm/llvm-project/pull/76558

>From 90a465d0a7e9744a4a8043152016e500927a0d95 Mon Sep 17 00:00:00 2001
From: Trevor Gross 
Date: Fri, 11 Aug 2023 22:16:01 -0400
Subject: [PATCH 1/4] [IR] Add an xpassing test for `f128` intrinsic lowering

`f128` intrinsic functions lower to incorrect libc calls. Add a test
showing current behavior.
---
 .../CodeGen/Generic/f128-math-lowering.ll | 610 ++
 1 file changed, 610 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/f128-math-lowering.ll

diff --git a/llvm/test/CodeGen/Generic/f128-math-lowering.ll 
b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
new file mode 100644
index 00..8a70786d97fe67
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
@@ -0,0 +1,610 @@
+
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+;
+; RUN: llc < %s -mtriple=aarch64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-AARCH64
+; RUN: llc < %s -mtriple=riscv32-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-RISCV32
+; RUN: llc < %s -mtriple=s390x-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-S390X
+; RUN: llc < %s -mtriple=i686-unknown-unknown   -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X64
+;
+; Verify that fp128 intrinsics only lower to `long double` calls on platforms
+; where `f128` and `long double` have the same layout.
+;
+; We test on x86 and x64 which have 80-bit ld, as well as aarch64 (ld == f128),
+; riscv32 (ld == f64), and s380x (ld == f128 with different alignment from
+; x64/aarch64 f128).
+;
+; FIXME: these emit calls to long double functions but should emit f128 calls
+
+define fp128 @test_cbrtf128(fp128 %a) {
+; CHECK-LABEL:  test_cbrtf128:
+; CHECK-AARCH64:b llvm.cbrt.f128
+; CHECK-RISCV32:call llvm.cbrt.f128@plt
+; CHECK-S390X:  brasl {{%.*}} llvm.cbrt.f128@PLT
+; CHECK-X64:jmp llvm.cbrt.f128@PLT # TAILCALL
+; CHECK-X86:calll llvm.cbrt.f128@PLT
+start:
+  %0 = tail call fp128 @llvm.cbrt.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.cbrt.f128(fp128)
+
+
+define fp128 @test_ceilf128(fp128 %a) {
+; CHECK-LABEL:  test_ceilf128:
+; CHECK-AARCH64:b ceill
+; CHECK-RISCV32:call ceill@plt
+; CHECK-S390X:  brasl {{%.*}} ceill@PLT
+; CHECK-X64:jmp ceill@PLT
+; CHECK-X86:calll ceill
+start:
+  %0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.ceil.f128(fp128)
+
+
+define fp128 @test_copysignf128(fp128 %a, fp128 %b) {
+; No math library call here, so make sure the assembly does the correct thing.
+; This test is autogenerated
+; CHECK-LABEL:test_copysignf128:
+; CHECK-AARCH64-LABEL: test_copysignf128:
+; CHECK-AARCH64:   // %bb.0: // %start
+; CHECK-AARCH64-NEXT:stp q0, q1, [sp, #-32]!
+; CHECK-AARCH64-NEXT:.cfi_def_cfa_offset 32
+; CHECK-AARCH64-NEXT:ldrb w8, [sp, #15]
+; CHECK-AARCH64-NEXT:ldrb w9, [sp, #31]
+; CHECK-AARCH64-NEXT:bfxil w9, w8, #0, #7
+; CHECK-AARCH64-NEXT:strb w9, [sp, #15]
+; CHECK-AARCH64-NEXT:ldr q0, [sp], #32
+; CHECK-AARCH64-NEXT:ret
+;
+; CHECK-RISCV32-LABEL: test_copysignf128:
+; CHECK-RISCV32:   # %bb.0: # %start
+; CHECK-RISCV32-NEXT:lw a3, 0(a1)
+; CHECK-RISCV32-NEXT:lw a4, 4(a1)
+; CHECK-RISCV32-NEXT:lw a2, 12(a2)
+; CHECK-RISCV32-NEXT:lw a5, 12(a1)
+; CHECK-RISCV32-NEXT:lw a1, 8(a1)
+; CHECK-RISCV32-NEXT:lui a6, 524288
+; CHECK-RISCV32-NEXT:and a2, a2, a6
+; CHECK-RISCV32-NEXT:slli a5, a5, 1
+; CHECK-RISCV32-NEXT:srli a5, a5, 1
+; CHECK-RISCV32-NEXT:or a2, a5, a2
+; CHECK-RISCV32-NEXT:sw a1, 8(a0)
+; CHECK-RISCV32-NEXT:sw a4, 4(a0)
+; CHECK-RISCV32-NEXT:sw a3, 0(a0)
+; CHECK-RISCV32-NEXT:sw a2, 12(a0)
+; CHECK-RISCV32-NEXT:ret
+;
+; CHECK-S390X-LABEL: test_copysignf128:
+; CHECK-S390X:   # %bb.0: # %start
+; CHECK-S390X-NEXT:ld %f0, 0(%r3)
+; CHECK-S390X-NEXT:ld %f2, 8(%r3)
+; CHECK-S390X-NEXT:ld %f1, 0(%r4)
+; CHECK-S390X-NEXT:ld %f3, 8(%r4)
+; CHECK-S390X-NEXT:cpsdr %f0, %f1, %f0
+; CHECK-S390X-NEXT:std %f0, 0(%r2)
+; CHECK-S390X-NEXT:std %f2, 8(%r2)
+; CHECK-S390X-NEXT:br %r14
+;
+; CHECK-X86-LABEL: test_copysignf128:
+; CHECK-X86:   # %bb.0: # %start
+; CHECK-X86-NEXT:pushl %ebx
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 8
+; CHECK-X86-NEXT:pushl %edi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 12
+; CHECK-X86-NEXT:pushl %esi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 16
+; CHECK-X86-NEXT:.cfi_offset %esi, -16
+; CHECK-X86-NEXT:.cfi_offset %edi, -12
+; CHECK-X86-NEXT:.cfi_offset %ebx, -8
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-X86-N

[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-13 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77907

>From e4cd3bd69cc8dbf9fb922cf92207d71946b03b72 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  5 -
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 16 
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/x86_64-vaarg.cpp

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..9f17287da99c50 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2988,7 +2988,10 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to
   // an 8 byte boundary.
 
-  uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+  uint64_t SizeInBytes = 0;
+  if (!isEmptyRecord(CGF.getContext(), Ty, true))
+SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
new file mode 100644
index 00..cbb9a47cf444fd
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -0,0 +1,16 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr %overflow_arg_area_p, 
align 8
+  __builtin_va_list l;
+  __builtin_va_start(l, a);
+  emptyvar = __builtin_va_arg(l, struct Empty);
+  __builtin_va_end(l);
+}

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


[clang] [llvm] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-13 Thread Trevor Gross via cfe-commits

https://github.com/tgross35 updated 
https://github.com/llvm/llvm-project/pull/76558

>From 90a465d0a7e9744a4a8043152016e500927a0d95 Mon Sep 17 00:00:00 2001
From: Trevor Gross 
Date: Fri, 11 Aug 2023 22:16:01 -0400
Subject: [PATCH 1/4] [IR] Add an xpassing test for `f128` intrinsic lowering

`f128` intrinsic functions lower to incorrect libc calls. Add a test
showing current behavior.
---
 .../CodeGen/Generic/f128-math-lowering.ll | 610 ++
 1 file changed, 610 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/f128-math-lowering.ll

diff --git a/llvm/test/CodeGen/Generic/f128-math-lowering.ll 
b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
new file mode 100644
index 00..8a70786d97fe67
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/f128-math-lowering.ll
@@ -0,0 +1,610 @@
+
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 2
+;
+; RUN: llc < %s -mtriple=aarch64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-AARCH64
+; RUN: llc < %s -mtriple=riscv32-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-RISCV32
+; RUN: llc < %s -mtriple=s390x-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-S390X
+; RUN: llc < %s -mtriple=i686-unknown-unknown   -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X86
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | 
FileCheck %s --check-prefix=CHECK-X64
+;
+; Verify that fp128 intrinsics only lower to `long double` calls on platforms
+; where `f128` and `long double` have the same layout.
+;
+; We test on x86 and x64 which have 80-bit ld, as well as aarch64 (ld == f128),
+; riscv32 (ld == f64), and s380x (ld == f128 with different alignment from
+; x64/aarch64 f128).
+;
+; FIXME: these emit calls to long double functions but should emit f128 calls
+
+define fp128 @test_cbrtf128(fp128 %a) {
+; CHECK-LABEL:  test_cbrtf128:
+; CHECK-AARCH64:b llvm.cbrt.f128
+; CHECK-RISCV32:call llvm.cbrt.f128@plt
+; CHECK-S390X:  brasl {{%.*}} llvm.cbrt.f128@PLT
+; CHECK-X64:jmp llvm.cbrt.f128@PLT # TAILCALL
+; CHECK-X86:calll llvm.cbrt.f128@PLT
+start:
+  %0 = tail call fp128 @llvm.cbrt.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.cbrt.f128(fp128)
+
+
+define fp128 @test_ceilf128(fp128 %a) {
+; CHECK-LABEL:  test_ceilf128:
+; CHECK-AARCH64:b ceill
+; CHECK-RISCV32:call ceill@plt
+; CHECK-S390X:  brasl {{%.*}} ceill@PLT
+; CHECK-X64:jmp ceill@PLT
+; CHECK-X86:calll ceill
+start:
+  %0 = tail call fp128 @llvm.ceil.f128(fp128 %a)
+  ret fp128 %0
+}
+
+declare fp128 @llvm.ceil.f128(fp128)
+
+
+define fp128 @test_copysignf128(fp128 %a, fp128 %b) {
+; No math library call here, so make sure the assembly does the correct thing.
+; This test is autogenerated
+; CHECK-LABEL:test_copysignf128:
+; CHECK-AARCH64-LABEL: test_copysignf128:
+; CHECK-AARCH64:   // %bb.0: // %start
+; CHECK-AARCH64-NEXT:stp q0, q1, [sp, #-32]!
+; CHECK-AARCH64-NEXT:.cfi_def_cfa_offset 32
+; CHECK-AARCH64-NEXT:ldrb w8, [sp, #15]
+; CHECK-AARCH64-NEXT:ldrb w9, [sp, #31]
+; CHECK-AARCH64-NEXT:bfxil w9, w8, #0, #7
+; CHECK-AARCH64-NEXT:strb w9, [sp, #15]
+; CHECK-AARCH64-NEXT:ldr q0, [sp], #32
+; CHECK-AARCH64-NEXT:ret
+;
+; CHECK-RISCV32-LABEL: test_copysignf128:
+; CHECK-RISCV32:   # %bb.0: # %start
+; CHECK-RISCV32-NEXT:lw a3, 0(a1)
+; CHECK-RISCV32-NEXT:lw a4, 4(a1)
+; CHECK-RISCV32-NEXT:lw a2, 12(a2)
+; CHECK-RISCV32-NEXT:lw a5, 12(a1)
+; CHECK-RISCV32-NEXT:lw a1, 8(a1)
+; CHECK-RISCV32-NEXT:lui a6, 524288
+; CHECK-RISCV32-NEXT:and a2, a2, a6
+; CHECK-RISCV32-NEXT:slli a5, a5, 1
+; CHECK-RISCV32-NEXT:srli a5, a5, 1
+; CHECK-RISCV32-NEXT:or a2, a5, a2
+; CHECK-RISCV32-NEXT:sw a1, 8(a0)
+; CHECK-RISCV32-NEXT:sw a4, 4(a0)
+; CHECK-RISCV32-NEXT:sw a3, 0(a0)
+; CHECK-RISCV32-NEXT:sw a2, 12(a0)
+; CHECK-RISCV32-NEXT:ret
+;
+; CHECK-S390X-LABEL: test_copysignf128:
+; CHECK-S390X:   # %bb.0: # %start
+; CHECK-S390X-NEXT:ld %f0, 0(%r3)
+; CHECK-S390X-NEXT:ld %f2, 8(%r3)
+; CHECK-S390X-NEXT:ld %f1, 0(%r4)
+; CHECK-S390X-NEXT:ld %f3, 8(%r4)
+; CHECK-S390X-NEXT:cpsdr %f0, %f1, %f0
+; CHECK-S390X-NEXT:std %f0, 0(%r2)
+; CHECK-S390X-NEXT:std %f2, 8(%r2)
+; CHECK-S390X-NEXT:br %r14
+;
+; CHECK-X86-LABEL: test_copysignf128:
+; CHECK-X86:   # %bb.0: # %start
+; CHECK-X86-NEXT:pushl %ebx
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 8
+; CHECK-X86-NEXT:pushl %edi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 12
+; CHECK-X86-NEXT:pushl %esi
+; CHECK-X86-NEXT:.cfi_def_cfa_offset 16
+; CHECK-X86-NEXT:.cfi_offset %esi, -16
+; CHECK-X86-NEXT:.cfi_offset %edi, -12
+; CHECK-X86-NEXT:.cfi_offset %ebx, -8
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; CHECK-X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-X86-N

[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-13 Thread Longsheng Mou via cfe-commits


@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;
+  }
+

CoTinker wrote:

done

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits


@@ -17,80 +17,97 @@
 namespace clang {
 namespace format {
 namespace {
+std::string
+separateDefinitionBlocks(llvm::StringRef Code,
+ const std::vector &Ranges,
+ const FormatStyle &Style = getLLVMStyle()) {
+  LLVM_DEBUG(llvm::errs() << "---\n");
+  LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+  tooling::Replacements Replaces = reformat(Style, Code, Ranges, "");
+  auto Result = applyAllReplacements(Code, Replaces);
+  EXPECT_TRUE(static_cast(Result));
+  LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+  return *Result;
+}
 
-class DefinitionBlockSeparatorTest : public ::testing::Test {

seranu wrote:

I extracted the utility functions around `_verifyFormat` in the anonymous 
namespace so that they can be used by other test fixtures.

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits

seranu wrote:

> Maybe first only handle #42112 for what I will be really grateful. 

#42112 requests separating both license text and include directives blocks.

> And then the stuff with the _license_, because I see discussion there. As far 
> as I can tell you just declare all comments on top of a file as license.

In my proposal, the license text is considered indeed to be a block of comments 
at the top of the source file, definitely up for discussion.

> I think you want too much in one change.

How do you suggest I should split the work?


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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits


@@ -586,7 +586,8 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::SeparateDefinitionStyle &Value) 
{
 IO.enumCase(Value, "Leave", FormatStyle::SDS_Leave);
-IO.enumCase(Value, "Always", FormatStyle::SDS_Always);
+IO.enumCase(Value, "One", FormatStyle::SDS_One);
+IO.enumCase(Value, "Two", FormatStyle::SDS_Two);
 IO.enumCase(Value, "Never", FormatStyle::SDS_Never);
   }

seranu wrote:

Does it need to be a spearate enum value or can it be handled as `SDS_One`?

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits


@@ -586,7 +586,8 @@ template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::SeparateDefinitionStyle &Value) 
{
 IO.enumCase(Value, "Leave", FormatStyle::SDS_Leave);
-IO.enumCase(Value, "Always", FormatStyle::SDS_Always);
+IO.enumCase(Value, "One", FormatStyle::SDS_One);
+IO.enumCase(Value, "Two", FormatStyle::SDS_Two);
 IO.enumCase(Value, "Never", FormatStyle::SDS_Never);
   }

seranu wrote:

There weren't any config parsing tests for SeparateDefinitionBlocks option. 
Will add.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-13 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

I checked it locally, the patch doesn't fix the reported problem:
```
$ clang pr77036.cpp && ./a.out
-nan
Fail
```

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits


@@ -65,18 +81,18 @@ void DefinitionBlockSeparator::separateBlocks(
 }
 return false;
   };
-  unsigned NewlineCount =
-  (Style.SeparateDefinitionBlocks == FormatStyle::SDS_Always ? 1 : 0) + 1;
+  unsigned NewlineCount = getNewlineCount(Style.SeparateDefinitionBlocks);
   WhitespaceManager Whitespaces(
   Env.getSourceManager(), Style,
   Style.LineEnding > FormatStyle::LE_CRLF
   ? WhitespaceManager::inputUsesCRLF(
 Env.getSourceManager().getBufferData(Env.getFileID()),
 Style.LineEnding == FormatStyle::LE_DeriveCRLF)
   : Style.LineEnding == FormatStyle::LE_CRLF);
+  std::optional inLicenseText{};

seranu wrote:

Changed

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits


@@ -171,6 +187,31 @@ void DefinitionBlockSeparator::separateBlocks(
   return false;
 };
 
+// Separate License text.
+const bool isComment = Lines[I]->isComment();

seranu wrote:

changed

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


[clang] [llvm] [AArch64] Make Armv8.3-a extension set +pauth by default (PR #78027)

2024-01-13 Thread Anatoly Trosinenko via cfe-commits

https://github.com/atrosinenko created 
https://github.com/llvm/llvm-project/pull/78027

Add AEK_PAUTH to ARMV8_3A in TargetParser and let it propagate to ARMV8R, as it 
aligns with GCC defaults.

After adding AEK_PAUTH, several tests from TargetParserTest.cpp crashed when 
trying to format an error message, thus update a format string in 
AssertSameExtensionFlags to account for bitmask being pre-formatted as 
std::string.

>From c960dacbdb58efbf2a2ef30eb4d0a9a640ce1071 Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Thu, 21 Dec 2023 19:34:12 +0300
Subject: [PATCH] [AArch64] Make Armv8.3-a extension set +pauth by default

Add AEK_PAUTH to ARMV8_3A in TargetParser and let it propagate to
ARMV8R, as it aligns with GCC defaults.

After adding AEK_PAUTH, several tests from TargetParserTest.cpp crashed
when trying to format an error message, thus update a format string in
AssertSameExtensionFlags to account for bitmask being pre-formatted
as std::string.
---
 clang/lib/Basic/Targets/AArch64.cpp   |  1 -
 clang/test/CodeGen/aarch64-targetattr.c   | 10 ++---
 .../Preprocessor/aarch64-target-features.c| 10 ++---
 .../llvm/TargetParser/AArch64TargetParser.h   |  2 +-
 .../TargetParser/TargetParserTest.cpp | 45 ++-
 5 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 9ebaf4d40cd7e5..346ba76f7c34d0 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -258,7 +258,6 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
-  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
 }
diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 5f557532a4b4a7..8a00feba0e952a 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -97,19 +97,19 @@ void minusarch() {}
 // CHECK: attributes #0 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #2 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
+// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
 // CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
 // CHECK: attributes #5 = { {{.*}} "tune-cpu"="cortex-a710" }
 // CHECK: attributes #6 = { {{.*}} "target-cpu"="generic" }
 // CHECK: attributes #7 = { {{.*}} "tune-cpu"="generic" }
 // CHECK: attributes #8 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
 // CHECK: attributes #9 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
+// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+pauth,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
+// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+pauth,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
 // CHECK: attributes #12 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
 // CHECK: attributes #13 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve,-sve2" }
 // CHECK: attributes #14 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ra

[llvm] [clang] [AArch64] Make Armv8.3-a extension set +pauth by default (PR #78027)

2024-01-13 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-clang

Author: Anatoly Trosinenko (atrosinenko)


Changes

Add AEK_PAUTH to ARMV8_3A in TargetParser and let it propagate to ARMV8R, as it 
aligns with GCC defaults.

After adding AEK_PAUTH, several tests from TargetParserTest.cpp crashed when 
trying to format an error message, thus update a format string in 
AssertSameExtensionFlags to account for bitmask being pre-formatted as 
std::string.

---

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


5 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (-1) 
- (modified) clang/test/CodeGen/aarch64-targetattr.c (+5-5) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (+5-5) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+1-1) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+24-21) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 9ebaf4d40cd7e5..346ba76f7c34d0 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -258,7 +258,6 @@ void AArch64TargetInfo::getTargetDefinesARMV83A(const 
LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
   Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
-  Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
 }
diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 5f557532a4b4a7..8a00feba0e952a 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -97,19 +97,19 @@ void minusarch() {}
 // CHECK: attributes #0 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #2 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
+// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
 // CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
 // CHECK: attributes #5 = { {{.*}} "tune-cpu"="cortex-a710" }
 // CHECK: attributes #6 = { {{.*}} "target-cpu"="generic" }
 // CHECK: attributes #7 = { {{.*}} "tune-cpu"="generic" }
 // CHECK: attributes #8 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
 // CHECK: attributes #9 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
+// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+pauth,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
+// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+pauth,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
 // CHECK: attributes #12 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
 // CHECK: attributes #13 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve,-sve2" }
 // CHECK: attributes #14 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" 
"guarded-control-stack"="true" {{.*}} 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.

[llvm] [clang] [AArch64] Make Armv8.3-a extension set +pauth by default (PR #78027)

2024-01-13 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 460ff58f62456a1f3ccf61ec9cf9d10781bd41bb 
c960dacbdb58efbf2a2ef30eb4d0a9a640ce1071 -- clang/lib/Basic/Targets/AArch64.cpp 
clang/test/CodeGen/aarch64-targetattr.c 
clang/test/Preprocessor/aarch64-target-features.c 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp 
b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 3d7158e0ae..722f0d88fd 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -127,14 +127,14 @@ template  struct 
AssertSameExtensionFlags {
 if (ExpectedFlags == GotFlags)
   return testing::AssertionSuccess();
 
-return testing::AssertionFailure() << llvm::formatv(
-   "CPU: {4}\n"
-   "Expected extension flags: {0} ({1})\n"
-   " Got extension flags: {2} ({3})\n",
-   FormatExtensionFlags(ExpectedFlags),
-   SerializeExtensionFlags(ExpectedFlags),
-   FormatExtensionFlags(GotFlags),
-   SerializeExtensionFlags(ExpectedFlags), CPUName);
+return testing::AssertionFailure()
+   << llvm::formatv("CPU: {4}\n"
+"Expected extension flags: {0} ({1})\n"
+" Got extension flags: {2} ({3})\n",
+FormatExtensionFlags(ExpectedFlags),
+SerializeExtensionFlags(ExpectedFlags),
+FormatExtensionFlags(GotFlags),
+SerializeExtensionFlags(ExpectedFlags), CPUName);
   }
 
 private:
@@ -1067,21 +1067,21 @@ INSTANTIATE_TEST_SUITE_P(
 ::testing::Values(
 ARMCPUTestParams(
 "cortex-a34", "armv8-a", "crypto-neon-fp-armv8",
-(AArch64::ExtensionBitset(
-{AArch64::AEK_CRC, AArch64::AEK_AES, AArch64::AEK_SHA2,
- AArch64::AEK_FP, AArch64::AEK_SIMD})),
+(AArch64::ExtensionBitset({AArch64::AEK_CRC, AArch64::AEK_AES,
+   AArch64::AEK_SHA2, AArch64::AEK_FP,
+   AArch64::AEK_SIMD})),
 "8-A"),
 ARMCPUTestParams(
 "cortex-a35", "armv8-a", "crypto-neon-fp-armv8",
-(AArch64::ExtensionBitset(
-{AArch64::AEK_CRC, AArch64::AEK_AES, AArch64::AEK_SHA2,
- AArch64::AEK_FP, AArch64::AEK_SIMD})),
+(AArch64::ExtensionBitset({AArch64::AEK_CRC, AArch64::AEK_AES,
+   AArch64::AEK_SHA2, AArch64::AEK_FP,
+   AArch64::AEK_SIMD})),
 "8-A"),
 ARMCPUTestParams(
 "cortex-a53", "armv8-a", "crypto-neon-fp-armv8",
-(AArch64::ExtensionBitset(
-{AArch64::AEK_CRC, AArch64::AEK_AES, AArch64::AEK_SHA2,
- AArch64::AEK_FP, AArch64::AEK_SIMD})),
+(AArch64::ExtensionBitset({AArch64::AEK_CRC, AArch64::AEK_AES,
+   AArch64::AEK_SHA2, AArch64::AEK_FP,
+   AArch64::AEK_SIMD})),
 "8-A"),
 ARMCPUTestParams(
 "cortex-a55", "armv8.2-a", "crypto-neon-fp-armv8",
@@ -1105,48 +1105,53 @@ INSTANTIATE_TEST_SUITE_P(
 ARMCPUTestParams(
 "cortex-a520", "armv9.2-a", "crypto-neon-fp-armv8",
 (AArch64::ExtensionBitset(
-{AArch64::AEK_BF16,  AArch64::AEK_I8MM,  AArch64::AEK_SVE,
- AArch64::AEK_SVE2,  AArch64::AEK_FP16,  AArch64::AEK_DOTPROD,
- AArch64::AEK_LSE,  AArch64::AEK_RDM,  AArch64::AEK_SIMD,
- AArch64::AEK_RCPC,  AArch64::AEK_RAS,  AArch64::AEK_CRC,
- AArch64::AEK_FP,  AArch64::AEK_SB,  AArch64::AEK_SSBS,
- AArch64::AEK_MTE,  AArch64::AEK_FP16FML,  AArch64::AEK_PAUTH,
- AArch64::AEK_SVE2BITPERM,  AArch64::AEK_FLAGM,
- AArch64::AEK_PERFMON, AArch64::AEK_PREDRES})),
+{AArch64::AEK_BF16,AArch64::AEK_I8MM,
+ AArch64::AEK_SVE, AArch64::AEK_SVE2,
+ AArch64::AEK_FP16,AArch64::AEK_DOTPROD,
+ AArch64::AEK_LSE, AArch64::AEK_RDM,
+ AArch64::AEK_SIMD,AArch64::AEK_RCPC,
+ AArch64::AEK_RAS, AArch64::AEK_CRC,
+ AArch64::AEK_FP,  AArch64::AEK_SB,
+ AArch64::AEK_SSBS,AArch64::AEK_MTE,
+ AArch64::AEK_FP16FML, AArch64::AEK_PAUTH,
+ AArch64::AEK_SVE2BITPERM, AArch64::AEK_FLAGM,
+

[clang] [openmp] [mlir] [llvm] [lld] [libcxx] [libc++] Deprecate the _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS macro (PR #77692)

2024-01-13 Thread Mark de Wever via cfe-commits

mordante wrote:

> > My suggestion on #69994 had been to stop implying 
> > `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS` from 
> > `_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES` in LLVM 18 at the same time as 
> > deprecating it. Did you intend to _not_ do that, or was it just missed?
> 
> We've also deprecated (or plan to?) `_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES`, 
> so there isn't really a point in changing anything there now.

I've created https://github.com/llvm/llvm-project/pull/77879 for that yesterday.

https://github.com/llvm/llvm-project/pull/77692
___
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 bugprone-eval-order (PR #78028)

2024-01-13 Thread via cfe-commits

https://github.com/maflcko created 
https://github.com/llvm/llvm-project/pull/78028

The evaluation order of function or constructor parameters is unspecified, 
which may be unknown to non-expert C++ developers, and can lead to bugs. Thus, 
add a clang-tidy check to catch presumed suspect code.

### Implementation

* The check prints a warning, when at least two parameters in a call are 
sourced from any method of a class, and at least one of those method calls is 
non-`const`. A fix is not offered.
* C++11 constructor list-initialization `[dcl.init.list]` has an evaluation 
order and can be used to silence this check.
* In case of false positives, the check can be suppressed, or disabled 
completely.
* `static` methods and global functions may also lead to issues, but they are 
not considered in this check, for now.

### Rationale

The check is limited to member functions, because presumably the most common 
issue in real code is some kind of reader object:

```cpp
struct Reader {
char buf[4]{};
int pos{};
char Pop() { return buf[pos++]; }
};

int Calc(char byte1, char byte2) { return byte1 > byte2; };

int main() {
Reader r{{1, 2, 3}};
return Calc(r.Pop(), r.Pop());  // May return 0 or 1
}
```

https://godbolt.org/z/rY5MMnPE3

>From e2a080eece7477be512d56b8e49e64060de3b526 Mon Sep 17 00:00:00 2001
From: MarcoFalke <*~=`'#}+{/-|&$^_...@721217.xyz>
Date: Fri, 12 Jan 2024 17:38:57 +0100
Subject: [PATCH] clang-tidy: Add bugprone-eval-order

---
 .../bugprone/BugproneTidyModule.cpp   |  2 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../clang-tidy/bugprone/EvalOrderCheck.cpp| 59 +++
 .../clang-tidy/bugprone/EvalOrderCheck.h  | 32 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../clang-tidy/checks/bugprone/eval-order.rst | 40 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/bugprone/eval-order.cpp  | 46 +++
 8 files changed, 186 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/eval-order.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/eval-order.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 435cb1e3fbcff3..3d84b6138ad635 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -23,6 +23,7 @@
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
+#include "EvalOrderCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -119,6 +120,7 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-easily-swappable-parameters");
 CheckFactories.registerCheck("bugprone-empty-catch");
+CheckFactories.registerCheck("bugprone-eval-order");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck("bugprone-fold-init-type");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 70e7fbc7ec0c14..624a4f5cd95fe4 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -18,6 +18,7 @@ add_clang_library(clangTidyBugproneModule
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
+  EvalOrderCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp
new file mode 100644
index 00..e9f1c0f3c3c7d0
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp
@@ -0,0 +1,59 @@
+//===--- EvalOrderCheck.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 "EvalOrderCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+using ::clang::ast_matchers::internal::Matcher;
+
+namespace clang::tidy::bugprone {
+
+EvalOrderCheck::EvalOrderCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidy

[clang-tools-extra] clang-tidy: Add bugprone-eval-order (PR #78028)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: None (maflcko)


Changes

The evaluation order of function or constructor parameters is unspecified, 
which may be unknown to non-expert C++ developers, and can lead to bugs. Thus, 
add a clang-tidy check to catch presumed suspect code.

### Implementation

* The check prints a warning, when at least two parameters in a call are 
sourced from any method of a class, and at least one of those method calls is 
non-`const`. A fix is not offered.
* C++11 constructor list-initialization `[dcl.init.list]` has an evaluation 
order and can be used to silence this check.
* In case of false positives, the check can be suppressed, or disabled 
completely.
* `static` methods and global functions may also lead to issues, but they are 
not considered in this check, for now.

### Rationale

The check is limited to member functions, because presumably the most common 
issue in real code is some kind of reader object:

```cpp
struct Reader {
char buf[4]{};
int pos{};
char Pop() { return buf[pos++]; }
};

int Calc(char byte1, char byte2) { return byte1 > byte2; };

int main() {
Reader r{{1, 2, 3}};
return Calc(r.Pop(), r.Pop());  // May return 0 or 1
}
```

https://godbolt.org/z/rY5MMnPE3

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+2) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp (+59) 
- (added) clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.h (+32) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (added) clang-tools-extra/docs/clang-tidy/checks/bugprone/eval-order.rst 
(+40) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) clang-tools-extra/test/clang-tidy/checkers/bugprone/eval-order.cpp 
(+46) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 435cb1e3fbcff3..3d84b6138ad635 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -23,6 +23,7 @@
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
+#include "EvalOrderCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -119,6 +120,7 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-easily-swappable-parameters");
 CheckFactories.registerCheck("bugprone-empty-catch");
+CheckFactories.registerCheck("bugprone-eval-order");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck("bugprone-fold-init-type");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 70e7fbc7ec0c14..624a4f5cd95fe4 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -18,6 +18,7 @@ add_clang_library(clangTidyBugproneModule
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
+  EvalOrderCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp
new file mode 100644
index 00..e9f1c0f3c3c7d0
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/EvalOrderCheck.cpp
@@ -0,0 +1,59 @@
+//===--- EvalOrderCheck.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 "EvalOrderCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+using ::clang::ast_matchers::internal::Matcher;
+
+namespace clang::tidy::bugprone {
+
+EvalOrderCheck::EvalOrderCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
+bool EvalOrderCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {
+  return LangOpts.CPlusPlus;
+}
+
+void EvalOrderCheck::registerMatchers(MatchFinder *Finder) {
+  auto Ctor = cxxConstructExpr(unless(isListInitialization())).bind("ctor");
+  auto Fun = callExpr().bind("fun");
+  auto Mut = unless(hasDeclaration

[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits

https://github.com/seranu updated 
https://github.com/llvm/llvm-project/pull/77918

>From 60a5851b40f03fb71b2a3d30972d51ba40244d68 Mon Sep 17 00:00:00 2001
From: Serban Ungureanu 
Date: Fri, 12 Jan 2024 14:33:32 +0200
Subject: [PATCH 1/2] [clang-format] Extend DefinitionBlockSeparatorStyle to
 separate license text, include blocks and to support two empty lines between
 blocks

---
 clang/include/clang/Format/Format.h   |  71 ++---
 clang/lib/Format/DefinitionBlockSeparator.cpp |  56 +++-
 clang/lib/Format/Format.cpp   |   3 +-
 clang/lib/Format/TokenAnnotator.h |   6 +
 .../Format/DefinitionBlockSeparatorTest.cpp   | 268 +-
 5 files changed, 292 insertions(+), 112 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 5ffd63ee73fc36..794817a26879d5 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3853,46 +3853,51 @@ struct FormatStyle {
 /// Leave definition blocks as they are.
 SDS_Leave,
 /// Insert an empty line between definition blocks.
-SDS_Always,
+SDS_One,
+/// Insert two empty lines between definition blocks.
+SDS_Two,
 /// Remove any empty line between definition blocks.
 SDS_Never
   };
 
   /// Specifies the use of empty lines to separate definition blocks, including
-  /// classes, structs, enums, and functions.
+  /// license text, includes, classes, structs, enums, and functions.
   /// \code
   ///Never  v.s. Always
-  ///#include   #include 
-  ///struct Foo {
-  ///  int a, b, c;  struct Foo {
-  ///};int a, b, c;
-  ///namespace Ns {  };
-  ///class Bar {
-  ///public: namespace Ns {
-  ///  struct Foobar {   class Bar {
-  ///int a;  public:
-  ///int b;struct Foobar {
-  ///  };int a;
-  ///private:int b;
-  ///  int t;  };
-  ///  int method1() {
-  ///// ...  private:
-  ///  }   int t;
-  ///  enum List {
-  ///ITEM1,int method1() {
-  ///ITEM2   // ...
-  ///  };  }
-  ///  template
-  ///  int method2(T x) {  enum List {
-  ///// ...  ITEM1,
-  ///  } ITEM2
-  ///  int i, j, k;};
-  ///  int method3(int par) {
-  ///// ...template
-  ///  }   int method2(T x) {
-  ///};  // ...
-  ///class C {};   }
-  ///}
+  ////* License text /* License text
+  ///   End license text */ End license text */
+  ///#include 
+  ///struct Foo {#include 
+  ///  int a, b, c;
+  ///};  struct Foo {
+  ///namespace Ns {int a, b, c;
+  ///class Bar { };
+  ///public:
+  ///  struct Foobar {   namespace Ns {
+  ///int a;  class Bar {
+  ///int b;  public:
+  ///  };  struct Foobar {
+  ///private:int a;
+  ///  int t;int b;
+  ///  int method1() { };
+  ///// ...
+  ///  } private:
+  ///  enum List { int t;
+  ///ITEM1,
+  ///ITEM2 int method1() {
+  ///  };// ...
+  ///  template}
+  ///  int method2(T x) {
+  ///// ...enum List {
+  ///  } ITEM1,
+  ///  int i, j, k;  ITEM2
+  ///  int method3(int par) {  };
+  ///// ...
+  ///  }   template
+  ///};int method2(T x) {
+  ///class C {}; // ...
+  ///} }
+  ///
   ///  int i, j, k;
   ///
   ///  int method3(int par) {
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..37d554fb678662 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -17,6 +17,22 @@
 #include "llvm/Support/Debug.h"
 #define DEBUG_TYPE "definit

[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 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 2798b72ae7e5caad793169b77cbac47fe2362d0f 
291c05994202393a858de1aafa8eeaf958223964 -- clang/include/clang/Format/Format.h 
clang/lib/Format/DefinitionBlockSeparator.cpp clang/lib/Format/Format.cpp 
clang/lib/Format/TokenAnnotator.h clang/unittests/Format/ConfigParseTest.cpp 
clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 0bed68f0e6..635adc1435 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -89,7 +89,7 @@ void DefinitionBlockSeparator::separateBlocks(
 Env.getSourceManager().getBufferData(Env.getFileID()),
 Style.LineEnding == FormatStyle::LE_DeriveCRLF)
   : Style.LineEnding == FormatStyle::LE_CRLF);
-  bool InLicenseText { true };
+  bool InLicenseText{true};
   for (unsigned I = 0; I < Lines.size(); ++I) {
 const auto &CurrentLine = Lines[I];
 if (CurrentLine->InMacroBody)
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 8c8581f11d..2f751ab0d8 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -996,11 +996,16 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   AllowBreakBeforeNoexceptSpecifier, FormatStyle::BBNSS_Never);
 
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Never;
-  CHECK_PARSE("SeparateDefinitionBlocks: One", SeparateDefinitionBlocks, 
FormatStyle::SDS_One);
-  CHECK_PARSE("SeparateDefinitionBlocks: Two", SeparateDefinitionBlocks, 
FormatStyle::SDS_Two);
-  CHECK_PARSE("SeparateDefinitionBlocks: Leave", SeparateDefinitionBlocks, 
FormatStyle::SDS_Leave);
-  CHECK_PARSE("SeparateDefinitionBlocks: Always", SeparateDefinitionBlocks, 
FormatStyle::SDS_One);
-  CHECK_PARSE("SeparateDefinitionBlocks: Never", SeparateDefinitionBlocks, 
FormatStyle::SDS_Never);
+  CHECK_PARSE("SeparateDefinitionBlocks: One", SeparateDefinitionBlocks,
+  FormatStyle::SDS_One);
+  CHECK_PARSE("SeparateDefinitionBlocks: Two", SeparateDefinitionBlocks,
+  FormatStyle::SDS_Two);
+  CHECK_PARSE("SeparateDefinitionBlocks: Leave", SeparateDefinitionBlocks,
+  FormatStyle::SDS_Leave);
+  CHECK_PARSE("SeparateDefinitionBlocks: Always", SeparateDefinitionBlocks,
+  FormatStyle::SDS_One);
+  CHECK_PARSE("SeparateDefinitionBlocks: Never", SeparateDefinitionBlocks,
+  FormatStyle::SDS_Never);
 }
 
 TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {

``




https://github.com/llvm/llvm-project/pull/77918
___
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 bugprone-eval-order (PR #78028)

2024-01-13 Thread via cfe-commits

maflcko wrote:

I guess this check has too many false-positives, so reading from a 
user-supplied list of class names as a config setting would make more sense?

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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-13 Thread via cfe-commits

https://github.com/seranu updated 
https://github.com/llvm/llvm-project/pull/77918

>From 60a5851b40f03fb71b2a3d30972d51ba40244d68 Mon Sep 17 00:00:00 2001
From: Serban Ungureanu 
Date: Fri, 12 Jan 2024 14:33:32 +0200
Subject: [PATCH 1/3] [clang-format] Extend DefinitionBlockSeparatorStyle to
 separate license text, include blocks and to support two empty lines between
 blocks

---
 clang/include/clang/Format/Format.h   |  71 ++---
 clang/lib/Format/DefinitionBlockSeparator.cpp |  56 +++-
 clang/lib/Format/Format.cpp   |   3 +-
 clang/lib/Format/TokenAnnotator.h |   6 +
 .../Format/DefinitionBlockSeparatorTest.cpp   | 268 +-
 5 files changed, 292 insertions(+), 112 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 5ffd63ee73fc36..794817a26879d5 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3853,46 +3853,51 @@ struct FormatStyle {
 /// Leave definition blocks as they are.
 SDS_Leave,
 /// Insert an empty line between definition blocks.
-SDS_Always,
+SDS_One,
+/// Insert two empty lines between definition blocks.
+SDS_Two,
 /// Remove any empty line between definition blocks.
 SDS_Never
   };
 
   /// Specifies the use of empty lines to separate definition blocks, including
-  /// classes, structs, enums, and functions.
+  /// license text, includes, classes, structs, enums, and functions.
   /// \code
   ///Never  v.s. Always
-  ///#include   #include 
-  ///struct Foo {
-  ///  int a, b, c;  struct Foo {
-  ///};int a, b, c;
-  ///namespace Ns {  };
-  ///class Bar {
-  ///public: namespace Ns {
-  ///  struct Foobar {   class Bar {
-  ///int a;  public:
-  ///int b;struct Foobar {
-  ///  };int a;
-  ///private:int b;
-  ///  int t;  };
-  ///  int method1() {
-  ///// ...  private:
-  ///  }   int t;
-  ///  enum List {
-  ///ITEM1,int method1() {
-  ///ITEM2   // ...
-  ///  };  }
-  ///  template
-  ///  int method2(T x) {  enum List {
-  ///// ...  ITEM1,
-  ///  } ITEM2
-  ///  int i, j, k;};
-  ///  int method3(int par) {
-  ///// ...template
-  ///  }   int method2(T x) {
-  ///};  // ...
-  ///class C {};   }
-  ///}
+  ////* License text /* License text
+  ///   End license text */ End license text */
+  ///#include 
+  ///struct Foo {#include 
+  ///  int a, b, c;
+  ///};  struct Foo {
+  ///namespace Ns {int a, b, c;
+  ///class Bar { };
+  ///public:
+  ///  struct Foobar {   namespace Ns {
+  ///int a;  class Bar {
+  ///int b;  public:
+  ///  };  struct Foobar {
+  ///private:int a;
+  ///  int t;int b;
+  ///  int method1() { };
+  ///// ...
+  ///  } private:
+  ///  enum List { int t;
+  ///ITEM1,
+  ///ITEM2 int method1() {
+  ///  };// ...
+  ///  template}
+  ///  int method2(T x) {
+  ///// ...enum List {
+  ///  } ITEM1,
+  ///  int i, j, k;  ITEM2
+  ///  int method3(int par) {  };
+  ///// ...
+  ///  }   template
+  ///};int method2(T x) {
+  ///class C {}; // ...
+  ///} }
+  ///
   ///  int i, j, k;
   ///
   ///  int method3(int par) {
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..37d554fb678662 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -17,6 +17,22 @@
 #include "llvm/Support/Debug.h"
 #define DEBUG_TYPE "definit

[clang] [clang-format] TableGen keywords support. (PR #77477)

2024-01-13 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!

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


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-13 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall created 
https://github.com/llvm/llvm-project/pull/78030

These will be supported in the upcoming 2.2 release and so are gated on that 
version.

Direct methods call `objc_send_initialize` if they are class methods that may 
not have called initialize.  This is guarded by checking for the class flag bit 
that is set on initialisation in the class.  This bit now forms part of the 
ABI, but it's been stable for 30+ years so that's fine as a contract going 
forwards.

>From b286b9b07d60a7b3243ad5e8e6959a4d7d7fda49 Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 204 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 
 3 files changed, 230 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..a71f42169fc3e6 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -926,6 +932,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1981,6 +1989,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 CGObjCGNUstep2(CodeGenModule &Mod) : CGObjCGNUstep(Mod, 10, 4, 2) {
   MsgLookupSuperFn.init(&CGM, "objc_msg_lookup_super", IMPTy,
 PtrToObjCSuperTy, SelectorTy);
+  SentInitializeFn.init(&CGM, "objc_send_initialize",
+

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Chisnall (davidchisnall)


Changes

These will be supported in the upcoming 2.2 release and so are gated on that 
version.

Direct methods call `objc_send_initialize` if they are class methods that may 
not have called initialize.  This is guarded by checking for the class flag bit 
that is set on initialisation in the class.  This bit now forms part of the 
ABI, but it's been stable for 30+ years so that's fine as a contract going 
forwards.

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


3 Files Affected:

- (modified) clang/include/clang/Basic/ObjCRuntime.h (+12-3) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+181-23) 
- (added) clang/test/CodeGenObjC/gnustep2-direct-method.m (+37) 


``diff
diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..a71f42169fc3e6 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -926,6 +932,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1981,6 +1989,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 CGObjCGNUstep2(CodeGenModule &Mod) : CGObjCGNUstep(Mod, 10, 4, 2) {
   MsgLookupSuperFn.init(&CGM, "objc_msg_lookup_super", IMPTy,
 PtrToObjCSuperTy, SelectorTy);
+  SentInitializeFn.init(&CGM, "objc_send_initialize",
+llvm::Type::getVoidTy(VMContext), IdTy);
   // struct objc_property
   // {
   //   const char *name;
@@ -1994,6 +2004,106 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 { PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty 
});
 }
 
+void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
+  const ObjCMethodDecl *OMD,
+  const ObjCContainerDecl *CD) override {
+  auto &Builder = CGF.Builder;
+  bool ReceiverCanBeNull = true;
+  auto selfAddr = CGF.GetAddrOfLocalVar

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-13 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 8f76f1816ea63b7cc28e150ba319ffbfe6351f9e 
b286b9b07d60a7b3243ad5e8e6959a4d7d7fda49 -- 
clang/include/clang/Basic/ObjCRuntime.h clang/lib/CodeGen/CGObjCGNU.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index a71f42169f..44fdef5ac5 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2030,78 +2030,78 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   // ...
 
   if (OMD->isClassMethod()) {
-  const ObjCInterfaceDecl *OID = cast(CD);
+const ObjCInterfaceDecl *OID = cast(CD);
 
-  // Nullable `Class` expressions cannot be messaged with a direct method
-  // so the only reason why the receive can be null would be because
-  // of weak linking.
-  ReceiverCanBeNull = isWeakLinkedClass(OID);
+// Nullable `Class` expressions cannot be messaged with a direct method
+// so the only reason why the receive can be null would be because
+// of weak linking.
+ReceiverCanBeNull = isWeakLinkedClass(OID);
   }
 
   if (ReceiverCanBeNull) {
-  llvm::BasicBlock *SelfIsNilBlock =
-  CGF.createBasicBlock("objc_direct_method.self_is_nil");
-  llvm::BasicBlock *ContBlock =
-  CGF.createBasicBlock("objc_direct_method.cont");
-
-  // if (self == nil) {
-  auto selfTy = cast(selfValue->getType());
-  auto Zero = llvm::ConstantPointerNull::get(selfTy);
-
-  llvm::MDBuilder MDHelper(CGM.getLLVMContext());
-  Builder.CreateCondBr(Builder.CreateICmpEQ(selfValue, Zero),
-   SelfIsNilBlock, ContBlock,
-   MDHelper.createBranchWeights(1, 1 << 20));
-
-  CGF.EmitBlock(SelfIsNilBlock);
-
-  //   return (ReturnType){ };
-  auto retTy = OMD->getReturnType();
-  Builder.SetInsertPoint(SelfIsNilBlock);
-  if (!retTy->isVoidType()) {
-CGF.EmitNullInitialization(CGF.ReturnValue, retTy);
-  }
-  CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
-  // }
+llvm::BasicBlock *SelfIsNilBlock =
+CGF.createBasicBlock("objc_direct_method.self_is_nil");
+llvm::BasicBlock *ContBlock =
+CGF.createBasicBlock("objc_direct_method.cont");
+
+// if (self == nil) {
+auto selfTy = cast(selfValue->getType());
+auto Zero = llvm::ConstantPointerNull::get(selfTy);
+
+llvm::MDBuilder MDHelper(CGM.getLLVMContext());
+Builder.CreateCondBr(Builder.CreateICmpEQ(selfValue, Zero),
+ SelfIsNilBlock, ContBlock,
+ MDHelper.createBranchWeights(1, 1 << 20));
+
+CGF.EmitBlock(SelfIsNilBlock);
+
+//   return (ReturnType){ };
+auto retTy = OMD->getReturnType();
+Builder.SetInsertPoint(SelfIsNilBlock);
+if (!retTy->isVoidType()) {
+  CGF.EmitNullInitialization(CGF.ReturnValue, retTy);
+}
+CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
+// }
 
-  // rest of the body
-  CGF.EmitBlock(ContBlock);
-  Builder.SetInsertPoint(ContBlock);
+// rest of the body
+CGF.EmitBlock(ContBlock);
+Builder.SetInsertPoint(ContBlock);
   }
 
   if (OMD->isClassMethod()) {
-  // Prefix of the class type.
-  auto *classStart =
-  llvm::StructType::get(PtrTy, PtrTy, PtrTy, LongTy, LongTy);
-  auto &astContext = CGM.getContext();
-  auto flags = Builder.CreateLoad(
-  Address{Builder.CreateStructGEP(classStart, selfValue, 4), LongTy,
-  CharUnits::fromQuantity(
-  astContext.getTypeAlign(astContext.UnsignedLongTy))});
-  auto isInitialized = Builder.CreateAnd(flags, (1 << 8));
-  llvm::BasicBlock *notInitializedBlock =
-  CGF.createBasicBlock("objc_direct_method.send_initialize");
-  llvm::BasicBlock *initializedBlock =
-  CGF.createBasicBlock("objc_direct_method.class_initialized");
-  llvm::MDBuilder MDHelper(CGM.getLLVMContext());
-  Builder.CreateCondBr(Builder.CreateICmpEQ(isInitialized, Zeros[0]),
-   notInitializedBlock, initializedBlock,
-   MDHelper.createBranchWeights(1, 1 << 20));
-  CGF.EmitBlock(notInitializedBlock);
-  Builder.SetInsertPoint(notInitializedBlock);
-  CGF.EmitRuntimeCall(SentInitializeFn, selfValue);
-  Builder.CreateBr(initializedBlock);
-  CGF.EmitBlock(initializedBlock);
-  Builder.SetInsertPoint(initializedBlock);
+// Prefix of the class type.
+auto *classStart =
+llvm::StructType::get(PtrTy, PtrTy, PtrTy, LongTy, LongTy);
+auto &astContext = CGM.getContext();
+auto 

[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-13 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 created 
https://github.com/llvm/llvm-project/pull/78032

Support the handling of TableGen's multiline string (code) literal.
That has the form,
[{ this is the string possibly with multi line... }]

This is a separated part from https://github.com/llvm/llvm-project/pull/76059.

>From d0767350f26215e86dee039427183630b3f02668 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 13 Jan 2024 21:44:34 +0900
Subject: [PATCH] [clang-format] TableGen multi line string support.

---
 clang/lib/Format/ContinuationIndenter.cpp |  3 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/FormatTokenLexer.cpp | 57 +++
 clang/lib/Format/FormatTokenLexer.h   |  3 +
 clang/lib/Format/TokenAnnotator.cpp   |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  5 ++
 6 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..e6eaaa9ab45706 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1591,6 +1591,9 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
 State.StartOfStringLiteral = State.Column + 1;
   if (Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column + 1;
+  } else if (Current.is(TT_TableGenMultiLineString) &&
+ State.StartOfStringLiteral == 0) {
+State.StartOfStringLiteral = State.Column + 1;
   } else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d5ef627f1348d3..dede89f2600150 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,7 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a1fd6dd6effe6c..1060009bdcf131 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -93,6 +93,8 @@ ArrayRef FormatTokenLexer::lex() {
   // string literals are correctly identified.
   handleCSharpVerbatimAndInterpolatedStrings();
 }
+if (Style.isTableGen())
+  handleTableGenMultilineString();
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
@@ -272,6 +274,14 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Multi line string starts with [{
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+  }
 }
 
 bool FormatTokenLexer::tryMergeNSStringLiteral() {
@@ -763,6 +773,53 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset + 1)));
 }
 
+void FormatTokenLexer::handleTableGenMultilineString() {
+  FormatToken *MultiLineString = Tokens.back();
+  if (MultiLineString->isNot(TT_TableGenMultiLineString))
+return;
+
+  bool PrevIsRBrace = false;
+  const char *FirstBreak = nullptr;
+  const char *LastBreak = nullptr;
+  const char *Begin = MultiLineString->TokenText.begin();
+  // Skip until }], the closer of multi line string found.
+  for (const char *Current = Begin, *End = Lex->getBuffer().end();
+   Current != End; ++Current) {
+if (PrevIsRBrace && *Current == ']') {
+  // }] is the end of multi line string.
+  if (!FirstBreak)
+FirstBreak = Current;
+  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
+  // ColumnWidth is only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  StringRef(Begin, FirstBreak - Begin + 1),
+  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  if (LastBreak) {
+// Set LastLineColumnWidth if multi line string has multiple lines.
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+StringRef(Last

[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Hirofumi Nakamura (hnakamura5)


Changes

Support the handling of TableGen's multiline string (code) literal.
That has the form,
[{ this is the string possibly with multi line... }]

This is a separated part from https://github.com/llvm/llvm-project/pull/76059.

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


6 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+3) 
- (modified) clang/lib/Format/FormatToken.h (+1) 
- (modified) clang/lib/Format/FormatTokenLexer.cpp (+57) 
- (modified) clang/lib/Format/FormatTokenLexer.h (+3) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..e6eaaa9ab45706 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1591,6 +1591,9 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
 State.StartOfStringLiteral = State.Column + 1;
   if (Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column + 1;
+  } else if (Current.is(TT_TableGenMultiLineString) &&
+ State.StartOfStringLiteral == 0) {
+State.StartOfStringLiteral = State.Column + 1;
   } else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d5ef627f1348d3..dede89f2600150 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,7 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a1fd6dd6effe6c..1060009bdcf131 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -93,6 +93,8 @@ ArrayRef FormatTokenLexer::lex() {
   // string literals are correctly identified.
   handleCSharpVerbatimAndInterpolatedStrings();
 }
+if (Style.isTableGen())
+  handleTableGenMultilineString();
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
@@ -272,6 +274,14 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Multi line string starts with [{
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+  }
 }
 
 bool FormatTokenLexer::tryMergeNSStringLiteral() {
@@ -763,6 +773,53 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset + 1)));
 }
 
+void FormatTokenLexer::handleTableGenMultilineString() {
+  FormatToken *MultiLineString = Tokens.back();
+  if (MultiLineString->isNot(TT_TableGenMultiLineString))
+return;
+
+  bool PrevIsRBrace = false;
+  const char *FirstBreak = nullptr;
+  const char *LastBreak = nullptr;
+  const char *Begin = MultiLineString->TokenText.begin();
+  // Skip until }], the closer of multi line string found.
+  for (const char *Current = Begin, *End = Lex->getBuffer().end();
+   Current != End; ++Current) {
+if (PrevIsRBrace && *Current == ']') {
+  // }] is the end of multi line string.
+  if (!FirstBreak)
+FirstBreak = Current;
+  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
+  // ColumnWidth is only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  StringRef(Begin, FirstBreak - Begin + 1),
+  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  if (LastBreak) {
+// Set LastLineColumnWidth if multi line string has multiple lines.
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+StringRef(LastBreak + 1, Current - LastBreak),
+MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  }
+  resetL

[clang] 1e51b35 - [RISCV] Change required features for Zvfhmin intrinsics from ZvfhminOrZvfh to Zvfhmin (#77866)

2024-01-13 Thread via cfe-commits

Author: Jim Lin
Date: 2024-01-13T07:11:15-06:00
New Revision: 1e51b35981063ea3408d3dab6c103a23f94c25e0

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

LOG: [RISCV] Change required features for Zvfhmin intrinsics from ZvfhminOrZvfh 
to Zvfhmin (#77866)

>From #75735, Zvfh implies Zvfhmin.

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Sema/SemaRISCVVectorLookup.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index e7d78b03511fe9..8bde081052505d 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -117,7 +117,7 @@ multiclass RVVIndexedLoad {
 defvar eew = eew_list[0];
 defvar eew_type = eew_list[1];
 let Name = op # eew # "_v", IRName = op, MaskedIRName = op # "_mask",
-RequiredFeatures = !if(!eq(type, "x"), ["ZvfhminOrZvfh"],
+RequiredFeatures = !if(!eq(type, "x"), ["Zvfhmin"],
[]) in {
   def: RVVOutOp1Builtin<"v", "vPCe" # eew_type # "Uv", type>;
 if !not(IsFloat.val) then {
@@ -128,7 +128,7 @@ multiclass RVVIndexedLoad {
   defvar eew64 = "64";
   defvar eew64_type = "(Log2EEW:6)";
   let Name = op # eew64 # "_v", IRName = op, MaskedIRName = op # "_mask",
-  RequiredFeatures = !if(!eq(type, "x"), ["ZvfhminOrZvfh", "RV64"],
+  RequiredFeatures = !if(!eq(type, "x"), ["Zvfhmin", "RV64"],
  ["RV64"]) in {
   def: RVVOutOp1Builtin<"v", "vPCe" # eew64_type # "Uv", type>;
 if !not(IsFloat.val) then {
@@ -222,7 +222,7 @@ multiclass RVVIndexedStore {
   defvar eew = eew_list[0];
   defvar eew_type = eew_list[1];
   let Name = op # eew  # "_v", IRName = op, MaskedIRName = op # 
"_mask",
-  RequiredFeatures = !if(!eq(type, "x"), ["ZvfhminOrZvfh"],
+  RequiredFeatures = !if(!eq(type, "x"), ["Zvfhmin"],
  []) in  {
 def : RVVBuiltin<"v", "0Pe" # eew_type # "Uvv", type>;
 if !not(IsFloat.val) then {
@@ -233,7 +233,7 @@ multiclass RVVIndexedStore {
 defvar eew64 = "64";
 defvar eew64_type = "(Log2EEW:6)";
 let Name = op # eew64  # "_v", IRName = op, MaskedIRName = op # 
"_mask",
-RequiredFeatures = !if(!eq(type, "x"), ["ZvfhminOrZvfh", "RV64"],
+RequiredFeatures = !if(!eq(type, "x"), ["Zvfhmin", "RV64"],
["RV64"]) in  {
   def : RVVBuiltin<"v", "0Pe" # eew64_type # "Uvv", type>;
   if !not(IsFloat.val) then {
@@ -681,7 +681,7 @@ let HasBuiltinAlias = false,
 def vlm: RVVVLEMaskBuiltin;
 defm vle8: RVVVLEBuiltin<["c"]>;
 defm vle16: RVVVLEBuiltin<["s"]>;
-let Name = "vle16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
+let Name = "vle16_v", RequiredFeatures = ["Zvfhmin"] in
   defm vle16_h: RVVVLEBuiltin<["x"]>;
 defm vle32: RVVVLEBuiltin<["i","f"]>;
 defm vle64: RVVVLEBuiltin<["l","d"]>;
@@ -689,7 +689,7 @@ defm vle64: RVVVLEBuiltin<["l","d"]>;
 def vsm : RVVVSEMaskBuiltin;
 defm vse8 : RVVVSEBuiltin<["c"]>;
 defm vse16: RVVVSEBuiltin<["s"]>;
-let Name = "vse16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
+let Name = "vse16_v", RequiredFeatures = ["Zvfhmin"] in
   defm vse16_h: RVVVSEBuiltin<["x"]>;
 defm vse32: RVVVSEBuiltin<["i","f"]>;
 defm vse64: RVVVSEBuiltin<["l","d"]>;
@@ -697,14 +697,14 @@ defm vse64: RVVVSEBuiltin<["l","d"]>;
 // 7.5. Vector Strided Instructions
 defm vlse8: RVVVLSEBuiltin<["c"]>;
 defm vlse16: RVVVLSEBuiltin<["s"]>;
-let Name = "vlse16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
+let Name = "vlse16_v", RequiredFeatures = ["Zvfhmin"] in
   defm vlse16_h: RVVVLSEBuiltin<["x"]>;
 defm vlse32: RVVVLSEBuiltin<["i","f"]>;
 defm vlse64: RVVVLSEBuiltin<["l","d"]>;
 
 defm vsse8 : RVVVSSEBuiltin<["c"]>;
 defm vsse16: RVVVSSEBuiltin<["s"]>;
-let Name = "vsse16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
+let Name = "vsse16_v", RequiredFeatures = ["Zvfhmin"] in
   defm vsse16_h: RVVVSSEBuiltin<["x"]>;
 defm vsse32: RVVVSSEBuiltin<["i","f"]>;
 defm vsse64: RVVVSSEBuiltin<["l","d"]>;
@@ -719,7 +719,7 @@ defm : RVVIndexedStore<"vsoxei">;
 // 7.7. Unit-stride Fault-Only-First Loads
 defm vle8ff: RVVVLEFFBuiltin<["c"]>;
 defm vle16ff: RVVVLEFFBuiltin<["s"]>;
-let Name = "vle16ff_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
+let Name = "vle16ff_v", RequiredFeatures = ["Zvfhmin"] in
   defm vle16ff: RVVVLEFFBuiltin<["x"]>;
 defm vle32ff: RVVVLEFFBuiltin<["i", "f"]>;
 defm vle64ff: RVVVLEFFBuiltin<["

[clang] [RISCV] Change required features for Zvfhmin intrinsics from ZvfhminOrZvfh to Zvfhmin (PR #77866)

2024-01-13 Thread Jim Lin via cfe-commits

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-01-13 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Multi line string part https://github.com/llvm/llvm-project/pull/78032

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot created 
https://github.com/llvm/llvm-project/pull/78033

`if constexpr` and `if consteval` conditional statements code coverage should 
behave more like a preprocesor `#if`-s than normal ConditionalStmt. This PR 
should fix that.

From 50856e444d4fd9dc92dab34ed8ad302671ce3716 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jan 2024 14:41:21 +0100
Subject: [PATCH] [coverage] skipping code coverage for 'if constexpr' and 'if
 consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 151 ++
 .../ProfileData/Coverage/CoverageMapping.cpp  |  12 +-
 2 files changed, 132 insertions(+), 31 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index b245abd16c3f4a..7e3d2b76b8646b 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,6 +119,10 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch)
+  bool SkippedRegion{false};
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
@@ -174,6 +178,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +476,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1252,6 +1264,29 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Emit a skip region between \p StartLoc and \p EndLoc with the given 
count.
+  void markSkipArea(SourceLocation StartLoc, SourceLocation EndLoc) {
+if (StartLoc == EndLoc)
+  return;
+assert(SpellingRegion(SM, StartLoc, EndLoc).isInSourceOrder());
+handleFileExit(StartLoc);
+size_t Index = pushRegion({}, StartLoc, EndLoc);
+getRegion().setSkipped(true);
+handleFileExit(EndLoc);
+popRegions(Index);
+  }
+
+  void findGapAreaBetweenAndMarkSkipArea(SourceLocation AfterLoc,
+ SourceLocation BeforeLoc) {
+// const std::optional Gap = findGapAreaBetween(AfterLoc,
+// BeforeLoc);
+//
+// if (Gap) {
+//   markSkipArea(Gap->getBegin(), Gap->getEnd());
+// }
+markSkipArea(AfterLoc, BeforeLoc);
+  }
+
   /// Keep counts of breaks and continues inside loops.
   struct BreakContinue {
 Counter BreakCount;
@@ -1701,43 +1736,106 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(), getStart(Then));
+  Visit(Then);
+
+  if (Else) {
+// ignore 'else '
+findGapAreaBetweenAndMarkSkipArea(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(),
+Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+Visit(Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (S->getInit()) {
+  // don't mark initialisation as ignored
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, 
getStart(S->getInit()));
+  Visit(S->getInit());
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(S->getInit());
+}
+
+if (isTrue) {
+  // ignore ')'
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, getStart(Then));
+  

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Hana Dusíková (hanickadot)


Changes

`if constexpr` and `if consteval` conditional statements code coverage should 
behave more like a preprocesor `#if`-s than normal ConditionalStmt. This PR 
should fix that.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+123-28) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+9-3) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index b245abd16c3f4a..7e3d2b76b8646b 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,6 +119,10 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch)
+  bool SkippedRegion{false};
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
@@ -174,6 +178,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +476,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1252,6 +1264,29 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Emit a skip region between \p StartLoc and \p EndLoc with the given 
count.
+  void markSkipArea(SourceLocation StartLoc, SourceLocation EndLoc) {
+if (StartLoc == EndLoc)
+  return;
+assert(SpellingRegion(SM, StartLoc, EndLoc).isInSourceOrder());
+handleFileExit(StartLoc);
+size_t Index = pushRegion({}, StartLoc, EndLoc);
+getRegion().setSkipped(true);
+handleFileExit(EndLoc);
+popRegions(Index);
+  }
+
+  void findGapAreaBetweenAndMarkSkipArea(SourceLocation AfterLoc,
+ SourceLocation BeforeLoc) {
+// const std::optional Gap = findGapAreaBetween(AfterLoc,
+// BeforeLoc);
+//
+// if (Gap) {
+//   markSkipArea(Gap->getBegin(), Gap->getEnd());
+// }
+markSkipArea(AfterLoc, BeforeLoc);
+  }
+
   /// Keep counts of breaks and continues inside loops.
   struct BreakContinue {
 Counter BreakCount;
@@ -1701,43 +1736,106 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(), getStart(Then));
+  Visit(Then);
+
+  if (Else) {
+// ignore 'else '
+findGapAreaBetweenAndMarkSkipArea(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(),
+Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+Visit(Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (S->getInit()) {
+  // don't mark initialisation as ignored
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, 
getStart(S->getInit()));
+  Visit(S->getInit());
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(S->getInit());
+}
+
+if (isTrue) {
+  // ignore ')'
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, getStart(Then));
+  Visit(Then);
+
+  if (Else)
+// ignore 'else '
+findGapAreaBetweenAndMarkSkipArea(getEnd(Then), getEnd(Else));
+} else {
+  // ignore ')  [else]'

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From 7e09f8a2dc9026047d34e0d6f4f55df9ab196fc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sat, 13 Jan 2024 14:54:21 +0100
Subject: [PATCH] [coverage] skipping code coverage for 'if constexpr' and 'if
 consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 154 ++
 .../ProfileData/Coverage/CoverageMapping.cpp  |  15 +-
 2 files changed, 138 insertions(+), 31 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index b245abd16c3f4a..c476ffa6305da2 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,6 +119,10 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch)
+  bool SkippedRegion{false};
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
@@ -174,6 +178,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +476,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1252,6 +1264,29 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Emit a skip region between \p StartLoc and \p EndLoc with the given 
count.
+  void markSkipArea(SourceLocation StartLoc, SourceLocation EndLoc) {
+if (StartLoc == EndLoc)
+  return;
+assert(SpellingRegion(SM, StartLoc, EndLoc).isInSourceOrder());
+handleFileExit(StartLoc);
+size_t Index = pushRegion({}, StartLoc, EndLoc);
+getRegion().setSkipped(true);
+handleFileExit(EndLoc);
+popRegions(Index);
+  }
+
+  void findGapAreaBetweenAndMarkSkipArea(SourceLocation AfterLoc,
+ SourceLocation BeforeLoc) {
+// const std::optional Gap = findGapAreaBetween(AfterLoc,
+// BeforeLoc);
+//
+// if (Gap) {
+//   markSkipArea(Gap->getBegin(), Gap->getEnd());
+// }
+markSkipArea(AfterLoc, BeforeLoc);
+  }
+
   /// Keep counts of breaks and continues inside loops.
   struct BreakContinue {
 Counter BreakCount;
@@ -1701,43 +1736,108 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(), getStart(Then));
+  Visit(Then);
+
+  if (Else) {
+// ignore 'else '
+findGapAreaBetweenAndMarkSkipArea(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  findGapAreaBetweenAndMarkSkipArea(S->getIfLoc(),
+Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+Visit(Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (S->getInit()) {
+  // don't mark initialisation as ignored
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, 
getStart(S->getInit()));
+  Visit(S->getInit());
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(S->getInit());
+}
+
+if (isTrue) {
+  // ignore ')'
+  findGapAreaBetweenAndMarkSkipArea(startOfSkipped, getStart(Then));
+  Visit(Then);
+
+  if (Else)
+// ignore 'else '
+findGapAreaBetweenAndMarkSkipArea(getEnd(Then), getEnd(Else));
+} else {
+  // ignore ')  [els

[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

![coverage-change-if-constexpr](https://github.com/llvm/llvm-project/assets/6557263/7c579d4f-0f14-4c7e-b9af-b0ec15b389ee)


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


[clang] [SemaCXX] Make __builtin_addressof more like std::addressof (PR #78035)

2024-01-13 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/78035

Fixes #77928

There are a few places which expect that, if for an expression 
`E->getType()->isBuiltinType(BuiltinType::Overload)`, then `E` must be an 
`OverloadExpr` or a `UnaryOperator` where `cast(E)->getOpcode() 
== UO_AddrOf`.

Because `__builtin_addressof` is implemented similarly to `&`: 
https://github.com/llvm/llvm-project/blob/8d817f6479a5df874028a8b40fd30aecd3479005/clang/lib/Sema/SemaExpr.cpp#L15041
 It can result in something with `OverloadTy` that isn't an `OverloadExpr` or a 
`UnaryOperator` (it's a `CallExpr`).

There are two things we can do to fix this: Either change those checks to 
accept both `&E` and `__builtin_addressof(E)`, or change it so 
`__builtin_addressof(E)` doesn't treat OverloadExprs differently.

This takes the latter approach, disabling 
`__builtin_addressof(name-of-overloaded-function)`.

It appears that GCC allows `__builtin_addressof(fn)` to be an overloaded 
function: . The problem with allowing it in 
Clang is too much code generically deals with `CallExpr`s and you would have to 
special case `__builtin_addressof` to not try to resolve the arguments. And 
also it would be so rarely used in the first place (the fix being replacing 
`__builtin_addressof` with `&`)

>From 7384e99c5fc1bcba1a304735243e49e9738691aa Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 13 Jan 2024 10:48:21 +
Subject: [PATCH] [SemaCXX] Make __builtin_addressof more like std::addressof

Properly disable __builtin_addressof(f) where f is an overloaded function and 
__builtin_addressof(temporary).

__builtin_addressof(E) should now only work if E is bindable to an lvalue 
reference with the same type.
---
 clang/include/clang/Sema/Sema.h |  3 ++-
 clang/lib/Sema/SemaChecking.cpp |  2 +-
 clang/lib/Sema/SemaExpr.cpp | 24 +++--
 clang/test/SemaCXX/builtins.cpp | 38 -
 4 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cf2d4fbe6d3ba1..9941cbaadf780a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5805,7 +5805,8 @@ class Sema final {
  const Expr *Op,
  const CXXMethodDecl *MD);
 
-  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
+  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc,
+ bool IsBuiltinAddressof = false);
 
   bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 74f8f626fb1637..e96436fd75bb68 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -242,7 +242,7 @@ static bool SemaBuiltinAddressof(Sema &S, CallExpr 
*TheCall) {
 return true;
 
   ExprResult Arg(TheCall->getArg(0));
-  QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc());
+  QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc(), 
true);
   if (ResultType.isNull())
 return true;
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2f48ea237cdfa4..518c51e77c7a99 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15038,9 +15038,15 @@ bool 
Sema::CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc,
 /// operator (C99 6.3.2.1p[2-4]), and its result is never an lvalue.
 /// In C++, the operand might be an overloaded function name, in which case
 /// we allow the '&' but retain the overloaded-function type.
-QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) 
{
+/// If IsBuiltinAddressof is true, this is spelt __builtin_addressof(E)
+/// instead of &E.
+QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc,
+ bool IsBuiltinAddressof) {
   if (const BuiltinType *PTy = 
OrigOp.get()->getType()->getAsPlaceholderType()){
 if (PTy->getKind() == BuiltinType::Overload) {
+  if (IsBuiltinAddressof)
+return QualType();
+
   Expr *E = OrigOp.get()->IgnoreParens();
   if (!isa(E)) {
 assert(cast(E)->getOpcode() == UO_AddrOf);
@@ -15094,7 +15100,7 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 }
   }
 
-  if (getLangOpts().C99) {
+  if (!IsBuiltinAddressof && getLangOpts().C99) {
 // Implement C99-only parts of addressof rules.
 if (UnaryOperator* uOp = dyn_cast(op)) {
   if (uOp->getOpcode() == UO_Deref)
@@ -15116,11 +15122,11 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
   unsigned AddressOfError = AO_No_Error;
 
   if (lval == Expr::LV_ClassTemporary || lval == Expr::LV_ArrayTemporary) {
-bool sfinae = (bool)isS

[clang] [SemaCXX] Make __builtin_addressof more like std::addressof (PR #78035)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

Fixes #77928

There are a few places which expect that, if for an expression 
`E->getType()->isBuiltinType(BuiltinType::Overload)`, then `E` must be an 
`OverloadExpr` or a `UnaryOperator` where 
`cast(E)->getOpcode() == UO_AddrOf`.

Because `__builtin_addressof` is implemented similarly to `&`: 
https://github.com/llvm/llvm-project/blob/8d817f6479a5df874028a8b40fd30aecd3479005/clang/lib/Sema/SemaExpr.cpp#L15041
 It can result in something with `OverloadTy` that isn't an `OverloadExpr` or a 
`UnaryOperator` (it's a `CallExpr`).

There are two things we can do to fix this: Either change those checks to 
accept both `&E` and `__builtin_addressof(E)`, or change it so 
`__builtin_addressof(E)` doesn't treat OverloadExprs differently.

This takes the latter approach, disabling 
`__builtin_addressof(name-of-overloaded-function)`.

It appears that GCC allows `__builtin_addressof(fn)` to be an overloaded 
function: ;. The problem with allowing it 
in Clang is too much code generically deals with `CallExpr`s and you would have 
to special case `__builtin_addressof` to not try to resolve the arguments. And 
also it would be so rarely used in the first place (the fix being replacing 
`__builtin_addressof` with `&`)

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


4 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+17-7) 
- (modified) clang/test/SemaCXX/builtins.cpp (+37-1) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cf2d4fbe6d3ba1..9941cbaadf780a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5805,7 +5805,8 @@ class Sema final {
  const Expr *Op,
  const CXXMethodDecl *MD);
 
-  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc);
+  QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc,
+ bool IsBuiltinAddressof = false);
 
   bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 74f8f626fb1637..e96436fd75bb68 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -242,7 +242,7 @@ static bool SemaBuiltinAddressof(Sema &S, CallExpr 
*TheCall) {
 return true;
 
   ExprResult Arg(TheCall->getArg(0));
-  QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc());
+  QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc(), 
true);
   if (ResultType.isNull())
 return true;
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2f48ea237cdfa4..518c51e77c7a99 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15038,9 +15038,15 @@ bool 
Sema::CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc,
 /// operator (C99 6.3.2.1p[2-4]), and its result is never an lvalue.
 /// In C++, the operand might be an overloaded function name, in which case
 /// we allow the '&' but retain the overloaded-function type.
-QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) 
{
+/// If IsBuiltinAddressof is true, this is spelt __builtin_addressof(E)
+/// instead of &E.
+QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc,
+ bool IsBuiltinAddressof) {
   if (const BuiltinType *PTy = 
OrigOp.get()->getType()->getAsPlaceholderType()){
 if (PTy->getKind() == BuiltinType::Overload) {
+  if (IsBuiltinAddressof)
+return QualType();
+
   Expr *E = OrigOp.get()->IgnoreParens();
   if (!isa(E)) {
 assert(cast(E)->getOpcode() == UO_AddrOf);
@@ -15094,7 +15100,7 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
 }
   }
 
-  if (getLangOpts().C99) {
+  if (!IsBuiltinAddressof && getLangOpts().C99) {
 // Implement C99-only parts of addressof rules.
 if (UnaryOperator* uOp = dyn_cast(op)) {
   if (uOp->getOpcode() == UO_Deref)
@@ -15116,11 +15122,11 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc) {
   unsigned AddressOfError = AO_No_Error;
 
   if (lval == Expr::LV_ClassTemporary || lval == Expr::LV_ArrayTemporary) {
-bool sfinae = (bool)isSFINAEContext();
-Diag(OpLoc, isSFINAEContext() ? diag::err_typecheck_addrof_temporary
-  : diag::ext_typecheck_addrof_temporary)
+bool AllowTemporaryAddress = !isSFINAEContext() && !IsBuiltinAddressof;
+Diag(OpLoc, AllowTemporaryAddress ? diag::ext_typecheck_addrof_temporary
+  : 

[clang] [SemaCXX] Make __builtin_addressof more like std::addressof (PR #78035)

2024-01-13 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 8d817f6479a5df874028a8b40fd30aecd3479005 
7384e99c5fc1bcba1a304735243e49e9738691aa -- clang/include/clang/Sema/Sema.h 
clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp 
clang/test/SemaCXX/builtins.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e96436fd75..ec574b9224 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -242,7 +242,8 @@ static bool SemaBuiltinAddressof(Sema &S, CallExpr 
*TheCall) {
 return true;
 
   ExprResult Arg(TheCall->getArg(0));
-  QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc(), 
true);
+  QualType ResultType =
+  S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc(), true);
   if (ResultType.isNull())
 return true;
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 518c51e77c..6587276220 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15125,7 +15125,7 @@ QualType Sema::CheckAddressOfOperand(ExprResult 
&OrigOp, SourceLocation OpLoc,
 bool AllowTemporaryAddress = !isSFINAEContext() && !IsBuiltinAddressof;
 Diag(OpLoc, AllowTemporaryAddress ? diag::ext_typecheck_addrof_temporary
   : diag::err_typecheck_addrof_temporary)
-  << op->getType() << op->getSourceRange();
+<< op->getType() << op->getSourceRange();
 if (!AllowTemporaryAddress)
   return QualType();
 // Materialize the temporary as an lvalue so that we can take its address.

``




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


[clang] [clang] SyntaxWarning: invalid escape sequence '\s' with Python3.12 (PR #78036)

2024-01-13 Thread Jie Fu 傅杰 via cfe-commits

https://github.com/DamonFool created 
https://github.com/llvm/llvm-project/pull/78036

The following SyntaxWarning was observed with Python3.12 .
```
llvm-project/clang/tools/libclang/linker-script-to-export-list.py:9: 
SyntaxWarning: invalid escape sequence '\s'
  m = re.search("^\s+(clang_[^;]+)", line)
```

Similar problem had been reported here 
https://stackoverflow.com/questions/57645829/why-am-i-getting-a-syntaxwarning-invalid-escape-sequence-s-warning
 .

It would be better to fix it.
Thanks.


>From 57fa67bf86bea09b9c6011b8c9ec6f69fe11852f Mon Sep 17 00:00:00 2001
From: Jie Fu 
Date: Sat, 13 Jan 2024 21:51:36 +0800
Subject: [PATCH] [clang] SyntaxWarning: invalid escape sequence '\s' with
 Python3.12

llvm-project/clang/tools/libclang/linker-script-to-export-list.py:9: 
SyntaxWarning: invalid escape sequence '\s'
  m = re.search("^\s+(clang_[^;]+)", line)
---
 clang/tools/libclang/linker-script-to-export-list.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/libclang/linker-script-to-export-list.py 
b/clang/tools/libclang/linker-script-to-export-list.py
index 745996028d835f..35bfa230be704a 100644
--- a/clang/tools/libclang/linker-script-to-export-list.py
+++ b/clang/tools/libclang/linker-script-to-export-list.py
@@ -6,6 +6,6 @@
 output_file = open(sys.argv[2], "w")
 
 for line in input_file:
-m = re.search("^\s+(clang_[^;]+)", line)
+m = re.search("^\\s+(clang_[^;]+)", line)
 if m:
 output_file.write(m.group(1) + "\n")

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


[clang] [clang] SyntaxWarning: invalid escape sequence '\s' with Python3.12 (PR #78036)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jie Fu (傅杰) (DamonFool)


Changes

The following SyntaxWarning was observed with Python3.12 .
```
llvm-project/clang/tools/libclang/linker-script-to-export-list.py:9: 
SyntaxWarning: invalid escape sequence '\s'
  m = re.search("^\s+(clang_[^;]+)", line)
```

Similar problem had been reported here 
https://stackoverflow.com/questions/57645829/why-am-i-getting-a-syntaxwarning-invalid-escape-sequence-s-warning
 .

It would be better to fix it.
Thanks.


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


1 Files Affected:

- (modified) clang/tools/libclang/linker-script-to-export-list.py (+1-1) 


``diff
diff --git a/clang/tools/libclang/linker-script-to-export-list.py 
b/clang/tools/libclang/linker-script-to-export-list.py
index 745996028d835f..35bfa230be704a 100644
--- a/clang/tools/libclang/linker-script-to-export-list.py
+++ b/clang/tools/libclang/linker-script-to-export-list.py
@@ -6,6 +6,6 @@
 output_file = open(sys.argv[2], "w")
 
 for line in input_file:
-m = re.search("^\s+(clang_[^;]+)", line)
+m = re.search("^\\s+(clang_[^;]+)", line)
 if m:
 output_file.write(m.group(1) + "\n")

``




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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

![coverage-change](https://github.com/llvm/llvm-project/assets/6557263/f4d8ea72-a197-4fe5-8f1e-254e44fde0c1)


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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' [WIP] (PR #78033)

2024-01-13 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

(still needs some polishing)
![coverage-compare](https://github.com/llvm/llvm-project/assets/6557263/b62fae27-ca7a-4f48-9d16-d04a25262ea6)


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


[clang] [SemaCXX] Make __builtin_addressof more like std::addressof (PR #78035)

2024-01-13 Thread via cfe-commits

cor3ntin wrote:

I think the approach makes sense but I'd like other folks to weight in 
@AaronBallman @erichkeane.

Note that even if we wanted in the long term to do the work to support 
overloaded expression (which i would agree is probably not a high priority), 
fixing the crash seems to be the first order of business.

I also wondered if we should have specific diagnostics but it also doesn't seem 
worth it.

I haven't done a full review yet - in any this will need a release note.

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


[libcxx] [clang] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-13 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/77768

>From 7b6bd8158ecc4645e26ec2f6fd6e7c5215bb038a Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 22 Jul 2023 20:07:00 +0100
Subject: [PATCH 1/2] [SemaCXX] Implement CWG2137 (list-initialization from
 objects of the same type)

Differential Revision: https://reviews.llvm.org/D156032
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaInit.cpp   | 14 +++---
 clang/lib/Sema/SemaOverload.cpp   | 38 +++-
 clang/test/CXX/drs/dr14xx.cpp | 10 -
 clang/test/CXX/drs/dr21xx.cpp | 45 +++
 clang/www/cxx_dr_status.html  |  2 +-
 .../pairs.pair/ctor.pair_U_V_move.pass.cpp| 21 -
 7 files changed, 103 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59732962caac652..a52fb805497756d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -199,6 +199,8 @@ C++2c Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `CWG2137 `_ which allows
+  list-initialization from objects of the same type.
 
 C Language Changes
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 408ee5f775804b6..a3a7486af093fb4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4199,7 +4199,7 @@ static OverloadingResult ResolveConstructorOverload(
 /// \param IsListInit Is this list-initialization?
 /// \param IsInitListCopy Is this non-list-initialization resulting from a
 ///   list-initialization from {x} where x is the same
-///   type as the entity?
+///   aggregate type as the entity?
 static void TryConstructorInitialization(Sema &S,
  const InitializedEntity &Entity,
  const InitializationKind &Kind,
@@ -4239,8 +4239,8 @@ static void TryConstructorInitialization(Sema &S,
   // ObjC++: Lambda captured by the block in the lambda to block conversion
   // should avoid copy elision.
   if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.
 Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
 if (ILE)
@@ -4571,9 +4571,9 @@ static void TryListInitialization(Sema &S,
 return;
   }
 
-  // C++11 [dcl.init.list]p3, per DR1467:
-  // - If T is a class type and the initializer list has a single element of
-  //   type cv U, where U is T or a class derived from T, the object is
+  // C++11 [dcl.init.list]p3, per DR1467 and DR2137:
+  // - If T is an aggregate class and the initializer list has a single element
+  //   of type cv U, where U is T or a class derived from T, the object is
   //   initialized from that element (by copy-initialization for
   //   copy-list-initialization, or by direct-initialization for
   //   direct-list-initialization).
@@ -4584,7 +4584,7 @@ static void TryListInitialization(Sema &S,
   // - Otherwise, if T is an aggregate, [...] (continue below).
   if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 &&
   !IsDesignatedInit) {
-if (DestType->isRecordType()) {
+if (DestType->isRecordType() && DestType->isAggregateType()) {
   QualType InitType = InitList->getInit(0)->getType();
   if (S.Context.hasSameUnqualifiedType(InitType, DestType) ||
   S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 64bc3851980272c..30bc2036cf781c2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1562,19 +1562,37 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType 
ToType,
 //   called for those cases.
 if (CXXConstructorDecl *Constructor
   = dyn_cast(ICS.UserDefined.ConversionFunction)) {
-  QualType FromCanon
-= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType FromType;
+  SourceLocation FromLoc;
+  // C++11 [over.ics.list]p6, per DR2137:
+  // C++17 [over.ics.list]p6:
+  //   If C is not an initializer-list constructor and the initializer list
+  //   has a single element of type cv U, where U is X or a class derived
+  //   from X, the implicit conversion sequence has Exact Match rank if U 
is
+  //   X, or Conversion rank if U is derived from X.
+  if (const auto *InitList = dyn_cast(From);
+  InitList && InitList->getN

[clang] [clang] Add test for CWG1350 (PR #78040)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/78040

Test is based on [P0136R1](https://wg21.link/p0136r1) wording instead of 
proposed resolution in the issue itself.

This patch also expands related CWG1573 test with an additional test case. 
Existing `3.9` status of 1573 is still relevant even with this new test case.

>From 62620337b64c64535d76c5003f9acd450ab527f7 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 13 Jan 2024 17:32:37 +0300
Subject: [PATCH] [clang] Add test for CWG1350

Test is based on [P0136R1](https://wg21.link/p0136r1) wording instead of 
proposed resolution in the issue itself.

This patch also expands related CWG1573 test with an additional test case. 
Existing `3.9` status of 1573 is still relevant even with this new test case.
---
 clang/test/CXX/drs/dr13xx.cpp | 42 +++
 clang/test/CXX/drs/dr15xx.cpp |  7 ++
 clang/www/cxx_dr_status.html  |  2 +-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 359c04b3e0f3d4..6a4a1f52383c04 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -379,6 +379,48 @@ namespace dr1347 { // dr1347: 3.1
 #endif
 }
 
+namespace dr1350 { // dr1350: 3.5
+#if __cplusplus >= 201103L
+struct NoexceptCtor {
+  NoexceptCtor(int) noexcept {}
+};
+
+struct ThrowingNSDMI : NoexceptCtor {
+  int a = []() noexcept(false) { return 0; }();
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDMI, int), "");
+
+struct ThrowingCtor {
+  ThrowingCtor() noexcept(false) {}
+};
+
+struct ThrowingNSDM : NoexceptCtor {
+  ThrowingCtor c;
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDM, int), "");
+
+struct D : NoexceptCtor, ThrowingCtor {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D, int), "");
+
+struct ThrowingDefaultArg {
+  ThrowingDefaultArg(ThrowingCtor = {}) {}
+};
+
+struct D2 : NoexceptCtor, ThrowingDefaultArg {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D2, int), "");
+#endif
+} // namespace dr1350
+
 namespace dr1358 { // dr1358: 3.1
 #if __cplusplus >= 201103L
   struct Lit { constexpr operator int() const { return 0; } };
diff --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 007b42c74affb1..3d4050a5713f92 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -390,6 +390,13 @@ namespace dr1573 { // dr1573: 3.9
   H h(0);
   // since-cxx11-error@-1 {{constructor inherited by 'H' from base class 'G' 
is implicitly deleted}}
   //   since-cxx11-note@#dr1573-H {{constructor inherited by 'H' is implicitly 
deleted because field 'g' has no default constructor}}
+
+  // deleted definition of constructor is inherited
+  struct I { I(int) = delete; }; // #dr1573-I
+  struct J : I { using I::I; };
+  J j(0);
+  // since-cxx11-error@-1 {{call to deleted constructor of 'J'}}
+  //   since-cxx11-note@#dr1573-I {{'I' has been explicitly marked deleted 
here}}
 #endif
 }
 
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4a3ed19161f9a5..5acc72dcf54b2d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7908,7 +7908,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1350.html";>1350
 CD3
 Incorrect exception specification for inherited constructors
-Unknown
+Clang 3.5
   
   
 https://cplusplus.github.io/CWG/issues/1351.html";>1351

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


[clang] [clang] Add test for CWG1350 (PR #78040)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

Test is based on [P0136R1](https://wg21.link/p0136r1) wording instead of 
proposed resolution in the issue itself.

This patch also expands related CWG1573 test with an additional test case. 
Existing `3.9` status of 1573 is still relevant even with this new test case.

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


3 Files Affected:

- (modified) clang/test/CXX/drs/dr13xx.cpp (+42) 
- (modified) clang/test/CXX/drs/dr15xx.cpp (+7) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 359c04b3e0f3d4..6a4a1f52383c04 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -379,6 +379,48 @@ namespace dr1347 { // dr1347: 3.1
 #endif
 }
 
+namespace dr1350 { // dr1350: 3.5
+#if __cplusplus >= 201103L
+struct NoexceptCtor {
+  NoexceptCtor(int) noexcept {}
+};
+
+struct ThrowingNSDMI : NoexceptCtor {
+  int a = []() noexcept(false) { return 0; }();
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDMI, int), "");
+
+struct ThrowingCtor {
+  ThrowingCtor() noexcept(false) {}
+};
+
+struct ThrowingNSDM : NoexceptCtor {
+  ThrowingCtor c;
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDM, int), "");
+
+struct D : NoexceptCtor, ThrowingCtor {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D, int), "");
+
+struct ThrowingDefaultArg {
+  ThrowingDefaultArg(ThrowingCtor = {}) {}
+};
+
+struct D2 : NoexceptCtor, ThrowingDefaultArg {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D2, int), "");
+#endif
+} // namespace dr1350
+
 namespace dr1358 { // dr1358: 3.1
 #if __cplusplus >= 201103L
   struct Lit { constexpr operator int() const { return 0; } };
diff --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 007b42c74affb1..3d4050a5713f92 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -390,6 +390,13 @@ namespace dr1573 { // dr1573: 3.9
   H h(0);
   // since-cxx11-error@-1 {{constructor inherited by 'H' from base class 'G' 
is implicitly deleted}}
   //   since-cxx11-note@#dr1573-H {{constructor inherited by 'H' is implicitly 
deleted because field 'g' has no default constructor}}
+
+  // deleted definition of constructor is inherited
+  struct I { I(int) = delete; }; // #dr1573-I
+  struct J : I { using I::I; };
+  J j(0);
+  // since-cxx11-error@-1 {{call to deleted constructor of 'J'}}
+  //   since-cxx11-note@#dr1573-I {{'I' has been explicitly marked deleted 
here}}
 #endif
 }
 
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4a3ed19161f9a5..5acc72dcf54b2d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7908,7 +7908,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1350.html";>1350
 CD3
 Incorrect exception specification for inherited constructors
-Unknown
+Clang 3.5
   
   
 https://cplusplus.github.io/CWG/issues/1351.html";>1351

``




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


[libcxx] [clang] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-13 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/77768

>From 344366c3f749c43376aca09c5bd563ec823b76f9 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 22 Jul 2023 20:07:00 +0100
Subject: [PATCH 1/2] [SemaCXX] Implement CWG2137 (list-initialization from
 objects of the same type)

Differential Revision: https://reviews.llvm.org/D156032
---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/SemaInit.cpp   | 14 +++---
 clang/lib/Sema/SemaOverload.cpp   | 38 +++-
 clang/test/CXX/drs/dr14xx.cpp | 10 -
 clang/test/CXX/drs/dr21xx.cpp | 45 +++
 clang/www/cxx_dr_status.html  |  2 +-
 .../pairs.pair/ctor.pair_U_V_move.pass.cpp| 21 -
 7 files changed, 103 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59732962caac652..a52fb805497756d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -199,6 +199,8 @@ C++2c Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `CWG2137 `_ which allows
+  list-initialization from objects of the same type.
 
 C Language Changes
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 408ee5f775804b6..a3a7486af093fb4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4199,7 +4199,7 @@ static OverloadingResult ResolveConstructorOverload(
 /// \param IsListInit Is this list-initialization?
 /// \param IsInitListCopy Is this non-list-initialization resulting from a
 ///   list-initialization from {x} where x is the same
-///   type as the entity?
+///   aggregate type as the entity?
 static void TryConstructorInitialization(Sema &S,
  const InitializedEntity &Entity,
  const InitializationKind &Kind,
@@ -4239,8 +4239,8 @@ static void TryConstructorInitialization(Sema &S,
   // ObjC++: Lambda captured by the block in the lambda to block conversion
   // should avoid copy elision.
   if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.
 Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
 if (ILE)
@@ -4571,9 +4571,9 @@ static void TryListInitialization(Sema &S,
 return;
   }
 
-  // C++11 [dcl.init.list]p3, per DR1467:
-  // - If T is a class type and the initializer list has a single element of
-  //   type cv U, where U is T or a class derived from T, the object is
+  // C++11 [dcl.init.list]p3, per DR1467 and DR2137:
+  // - If T is an aggregate class and the initializer list has a single element
+  //   of type cv U, where U is T or a class derived from T, the object is
   //   initialized from that element (by copy-initialization for
   //   copy-list-initialization, or by direct-initialization for
   //   direct-list-initialization).
@@ -4584,7 +4584,7 @@ static void TryListInitialization(Sema &S,
   // - Otherwise, if T is an aggregate, [...] (continue below).
   if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 &&
   !IsDesignatedInit) {
-if (DestType->isRecordType()) {
+if (DestType->isRecordType() && DestType->isAggregateType()) {
   QualType InitType = InitList->getInit(0)->getType();
   if (S.Context.hasSameUnqualifiedType(InitType, DestType) ||
   S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 64bc3851980272c..30bc2036cf781c2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1562,19 +1562,37 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType 
ToType,
 //   called for those cases.
 if (CXXConstructorDecl *Constructor
   = dyn_cast(ICS.UserDefined.ConversionFunction)) {
-  QualType FromCanon
-= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType FromType;
+  SourceLocation FromLoc;
+  // C++11 [over.ics.list]p6, per DR2137:
+  // C++17 [over.ics.list]p6:
+  //   If C is not an initializer-list constructor and the initializer list
+  //   has a single element of type cv U, where U is X or a class derived
+  //   from X, the implicit conversion sequence has Exact Match rank if U 
is
+  //   X, or Conversion rank if U is derived from X.
+  if (const auto *InitList = dyn_cast(From);
+  InitList && InitList->getN

[clang] [clang] Add test for CWG1350 (PR #78040)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I was way too deep into P0136R1 [Rewording inheriting constructors (core issue 
1941 et al)](https://wg21.link/p0136r1) when I realized Richard has written 
tests for all issues covered there long ago. So I decided to carry on and check 
whether those tests would benefit from additional test cases. That's how I came 
up with a new test case for CWG1573, and came about its related issue 1350, 
which was lacking a test.

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


[clang] [libcxx] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-13 Thread Mital Ashok via cfe-commits


@@ -132,6 +142,36 @@ namespace dr2126 { // dr2126: 12
 #endif
 }
 
+namespace dr2137 { // dr2137: 18
+#if __cplusplus >= 201103L
+  struct Q {
+Q();
+Q(Q&&);
+Q(std::initializer_list) = delete; // since-cxx11-note 2 {{has been 
explicitly marked deleted here}}
+  };
+
+  Q x = Q { Q() }; // since-cxx11-error {{call to deleted constructor}}
+
+  int f(Q); // since-cxx11-note {{passing argument to parameter here}}
+  int y = f({ Q() }); // since-cxx11-error {{call to deleted constructor}}

MitalAshok wrote:

@Endilll Is this good now? Thanks in advance

https://github.com/llvm/llvm-project/pull/77768/files#diff-3426b975672f064b9f32caf4ebab729b815f4f65aa3e76bda4b5bdee986e2e6fR130-R131

https://github.com/llvm/llvm-project/pull/77768/files#diff-8807231ab4d193692d6cecdc6428aaf3c55dfd96101cff8fe0eb7034654658fbR154-R161

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


[clang] [libcxx] [SemaCXX] Implement CWG2137 (list-initialization from objects of the same type) (PR #77768)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

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

Looks perfect to me now. Thank you!

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70217)

2024-01-13 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Will wait for the EWG to give final guidance.

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70217)

2024-01-13 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Add test for CWG1350 (PR #78040)

2024-01-13 Thread via cfe-commits

cor3ntin wrote:

For completeness, can you add a couple of tests covering the note (ie, template 
case?)
Otherwise, LGTM

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-lldb

Author: Andrey Ali Khan Bolshakov (bolshakov-a)


Changes

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and reverted 
because a dependency commit was reverted, then committed again as 
4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because "dependency 
commit" 5a391d38ac6c561ba908334d427f26124ed9132e was reverted. But it doesn't 
seem that 5a391d38ac6c was a real dependency for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and 
18e093faf726d15f210ab4917142beec51848258 by Richard Smith (@zygoloid), 
with some minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and member 
pointer handling branch in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted` parameter in 
`Sema::CheckTemplateArgument`;

- minor cleanup in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC ver. 19.35; 
toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when the 
corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates in `warn-bool-conversion` 
test; in C++17 and C++20 mode, array reference used as a template argument of 
pointer type produces template argument of UncommonValue type, and 
`BuildExpressionFromNonTypeTemplateArgumentValue` makes `OpaqueValueExpr` for 
it, and `DiagnoseAlwaysNonNullPointer` cannot see through it; despite of "These 
cases should not warn" comment, I'm not sure about correct behavior; I'd expect 
a suggestion to replace `if` by `if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.

---

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


47 Files Affected:

- (modified) clang-tools-extra/clangd/DumpAST.cpp (+1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (+1) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/ODRHash.h (+3) 
- (modified) clang/include/clang/AST/PropertiesBase.td (+14) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2) 
- (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (+2) 
- (modified) clang/include/clang/AST/TemplateBase.h (+55-31) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-5) 
- (modified) clang/include/clang/Sema/Sema.h (+2-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5) 
- (modified) clang/lib/AST/ASTImporter.cpp (+13) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+4) 
- (modified) clang/lib/AST/Decl.cpp (+4) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+37-2) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+62-16) 
- (modified) clang/lib/AST/ODRHash.cpp (+72) 
- (modified) clang/lib/AST/StmtProfile.cpp (+6) 
- (modified) clang/lib/AST/TemplateBase.cpp (+110-3) 
- (modified) clang/lib/AST/TypeLoc.cpp (+1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+10) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+12-3) 
- (modified) clang/lib/Index/USRGeneration.cpp (+10) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+9-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+130-88) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+46-18) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+6-8) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+2) 
- (modified) clang/lib/Sema/TreeTransform.h (+10-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1) 
- (modified) clang/test/CXX/drs/dr18xx.cpp (+2-2) 
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (+3-1) 
- (modified) clang/test/CodeGenCXX/mangle-ms-templates.cpp (+48) 
- (modified) clang/test/CodeGenCXX/mangle-template.cpp (+39-1) 
- (added) clang/test/CodeGenCXX/template-arguments.cpp (+113) 
- (added) clang/test/Index/USR/structural-value-tpl-arg.cpp (+23) 
- (modified) clang/test/Modules/odr_hash.cpp (+190-3) 
- (modified) clang/test/SemaCXX/warn-bool-conversion.cpp (+2) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+19-21) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+22-18) 
- (modified) clang/tools/libclang/CIndex.cpp (+5) 
- (modified) clang/tools/libclang/CXCursor.cpp (+3) 
- (modified) clang/www/cxx_status.html (+13-5) 
- (modified) lldb/include/lldb/lldb-enumerations.h (+1) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.c

[clang] [clang] SyntaxWarning: invalid escape sequence '\s' with Python3.12 (PR #78036)

2024-01-13 Thread via cfe-commits


@@ -6,6 +6,6 @@
 output_file = open(sys.argv[2], "w")
 
 for line in input_file:
-m = re.search("^\s+(clang_[^;]+)", line)
+m = re.search("^\\s+(clang_[^;]+)", line)

cor3ntin wrote:

```suggestion
m = re.search(r"^\s+(clang_[^;]+)", line)
```

Making it a raw string is a marginally cleaner fix

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -25,7 +25,7 @@ template  struct S {}; // #dr1801-S
 S V; // #dr1801-S-i
 // cxx98-14-error@-1 {{non-type template argument does not refer to any 
declaration}}
 //   cxx98-14-note@#dr1801-S {{template parameter is declared here}}
-// since-cxx17-error@#dr1801-S-i {{non-type template argument refers to 
subobject '.i'}}
+// cxx17-error@#dr1801-S-i {{non-type template argument refers to subobject 
'.i'}}

bolshakov-a wrote:

I'm not sure about this. 
[Here](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1801) it 
is stated that this should be ill-formed, with a reference to 
[N4268](https://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4268.html). But 
it seems that it is not actual after P1907R1.

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -5401,6 +5409,8 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 // feasible some day.
 return TA.getAsIntegral().getBitWidth() <= 64 &&
IsReconstitutableType(TA.getIntegralType());
+  case TemplateArgument::StructuralValue:
+return false;

bolshakov-a wrote:

@dwblaikie, could you verify please? Maybe, non-type template arguments of 
floating point types are reconstitutable though?

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


[clang-tools-extra] [lldb] [clang] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@cor3ntin, #78041.

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


[clang] [AVX10][Doc] Add documentation about AVX10 options and their attentions (PR #77925)

2024-01-13 Thread Evgenii Kudriashov via cfe-commits


@@ -3963,6 +3963,60 @@ implicitly included in later levels.
 - ``-march=x86-64-v3``: (close to Haswell) AVX, AVX2, BMI1, BMI2, F16C, FMA, 
LZCNT, MOVBE, XSAVE
 - ``-march=x86-64-v4``: AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL
 
+`Intel AVX10 ISA `_ is
+a major new vector ISA incorporating the modern vectorization aspects of
+Intel AVX-512. This ISA will be supported on all future Intel processor.
+Users are supposed to use the new options ``-mavx10.N`` and ``-mavx10.N-512``
+on these processors and should not use traditional AVX512 options anymore.
+
+The ``N`` in ``-mavx10.N`` represents a continuous integer number starting
+from ``1``. ``-mavx10.N`` is an alias of ``-mavx10.N-256``, which means to
+enable all instructions within AVX10 version N at a maximum vector length of
+256 bits. ``-mavx10.N-512`` enables all instructions at a maximum vector
+length of 512 bits, which is a superset of instructions ``-mavx10.N`` enabled.
+
+Current binaries built with AVX512 features can run on Intel AVX10/512 capable
+processor without re-compile, but cannot run on AVX10/256 capable processor.
+Users need to re-compile their code with ``-mavx10.N``, and maybe update some
+code that calling to 512-bit X86 specific intrinsics and passing or returning
+512-bit vector types in function call, if they want to run on AVX10/256 capable
+processor. Binaries built with ``-mavx10.N`` can run on both AVX10/256 and
+AVX10/512 capable processor.
+
+Users can add a ``-mno-evex512`` in the command line with AVX512 options if
+they want to run the binary on both legacy AVX512 and new AVX10/256 capable
+processors. The option has the same constraints as ``-mavx10.N``, i.e.,
+cannot call to 512-bit X86 specific intrinsics and pass or return 512-bit 
vector
+types in function call.
+
+Users should avoid using AVX512 features in function target attributes when
+developing code for AVX10. If they have to do so, they need to add an explicit
+``evex512`` or ``no-evex512`` together with AVX512 features for 512-bit or
+non-512-bit functions respectively to avoid unexpected code generation. Both
+command line option and target attribute of EVEX512 feature can only be used
+with AVX512. They don't affect vector size of AVX10.
+
+User should not mix the use AVX10 and AVX512 options together at any time,
+because the option combinations are conflicting sometimes. For example, a
+combination of ``-mavx512f -mavx10.1-256`` doesn't show a clear intention to
+compiler, since instructions in AVX512F and AVX10.1/256 intersect but do not
+overlap. In this case, compiler will emit warning for it, but the behavior
+is determined. It will generate the same code as option ``-mavx10.1-512``.
+A similar case is ``-mavx512f -mavx10.2-256``, which equals to
+``-mavx10.1-512 -mavx10.2-256``, because ``avx10.2-256`` implies 
``avx10.1-256``
+and ``-mavx512f -mavx10.1-256`` equals to ``-mavx10.1-512``.
+
+There are some new macros introduced with AVX10 support. ``-mavx10.1-256`` will
+enable ``__AVX10_1__`` and ``__EVEX256__``, while ``-mavx10.1-512`` enables
+``__AVX10_1__``, ``__EVEX256__``, ``__EVEX512__``  and ``__AVX10_1_512__``.
+Besides, both ``-mavx10.1-256`` and ``-mavx10.1-512`` will enable all AVX512
+feature specific macros. A AVX512 feature will enable both ``__EVEX256__``,
+``__EVEX512__`` and its own macro. So ``__EVEX512__`` can be used to guard code
+that can run on both legacy AVX512 and AVX10/512 capable processors but cannot
+run on AVX10/256, while a AVX512 macro like ``__AVX512F__`` cannot tell the
+difference among the three options. Users need to check additional macros
+``__AVX10_1__`` and ``__EVEX512__`` if they want to make distinction.

e-kud wrote:

My idea was about scenario when you've migrated your sources to avx10 (e.g. 
using EVEX512 instead of AVX512F) but still have CI with different compilers 
that does not support it. I thought that it may be useful to provide some 
guidance. But I'm OK to leave it up to users. Whether they decide to specify 
versions or avx10 support availability.

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


[clang] [AVX10][Doc] Add documentation about AVX10 options and their attentions (PR #77925)

2024-01-13 Thread Evgenii Kudriashov via cfe-commits

https://github.com/e-kud approved this pull request.

LGTM. Thanks!

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,31 @@
+.. title:: clang-tidy - readability-use-std-min-max
+
+readability-use-std-min-max
+===
+
+Replaces certain conditional statements with equivalent ``std::min`` or 
``std::max`` expressions, 
+improving readability and promoting the use of standard library functions.
+Note: this transformation may impact performance in performance-critical code 
due to potential 
+additional stores compared to the original if statement.
+
+Examples:
+
+Before:
+
+.. code-block:: c++
+
+  void foo() {
+int a, b;

EugeneZelenko wrote:

Shouldn't variable be initialized?

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,33 @@
+.. title:: clang-tidy - readability-use-std-min-max
+
+readability-use-std-min-max
+===
+
+Replaces certain conditional statements with equivalent ``std::min`` or 
``std::max`` expressions, 

EugeneZelenko wrote:

Line is still longer than 79 characters. Same below.

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy %s readability-use-std-min-max %t
+
+void foo() {
+  int value1,value2,value3;
+  short value4;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  if (value1 < value2)
+value1 = value2; // CHECK-FIXES: value1 = std::max(value1, value2);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::min` instead of `<` 
[readability-use-std-min-max]
+  if (value1 < value2)
+value2 = value1; // CHECK-FIXES: value2 = std::min(value1, value2);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::min` instead of `>` 
[readability-use-std-min-max]
+  if (value2 > value1)
+value2 = value1; // CHECK-FIXES: value2 = std::min(value2, value1);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `>` 
[readability-use-std-min-max
+  if (value2 > value1)
+value1 = value2; // CHECK-FIXES: value1 = std::max(value2, value1);
+
+  // No suggestion needed here
+  if (value1 == value2)
+value1 = value2;
+  
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  if(value1https://github.com/llvm/llvm-project/pull/77816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,31 @@
+.. title:: clang-tidy - readability-use-std-min-max
+
+readability-use-std-min-max
+===
+
+Replaces certain conditional statements with equivalent ``std::min`` or 
``std::max`` expressions, 
+improving readability and promoting the use of standard library functions.
+Note: this transformation may impact performance in performance-critical code 
due to potential 
+additional stores compared to the original if statement.
+
+Examples:
+
+Before:
+
+.. code-block:: c++
+
+  void foo() {
+int a, b;
+if (a < b)
+  a = b;
+  }
+
+
+After:
+
+.. code-block:: c++
+
+  void foo() {
+int a, b;

EugeneZelenko wrote:

Ditto.

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


[clang] [AVX10][Doc] Add documentation about AVX10 options and their attentions (PR #77925)

2024-01-13 Thread Evgenii Kudriashov via cfe-commits

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits

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


[clang] [clang] Add test for CWG1350 (PR #78040)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/78040

>From 62620337b64c64535d76c5003f9acd450ab527f7 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 13 Jan 2024 17:32:37 +0300
Subject: [PATCH 1/2] [clang] Add test for CWG1350

Test is based on [P0136R1](https://wg21.link/p0136r1) wording instead of 
proposed resolution in the issue itself.

This patch also expands related CWG1573 test with an additional test case. 
Existing `3.9` status of 1573 is still relevant even with this new test case.
---
 clang/test/CXX/drs/dr13xx.cpp | 42 +++
 clang/test/CXX/drs/dr15xx.cpp |  7 ++
 clang/www/cxx_dr_status.html  |  2 +-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 359c04b3e0f3d4..6a4a1f52383c04 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -379,6 +379,48 @@ namespace dr1347 { // dr1347: 3.1
 #endif
 }
 
+namespace dr1350 { // dr1350: 3.5
+#if __cplusplus >= 201103L
+struct NoexceptCtor {
+  NoexceptCtor(int) noexcept {}
+};
+
+struct ThrowingNSDMI : NoexceptCtor {
+  int a = []() noexcept(false) { return 0; }();
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDMI, int), "");
+
+struct ThrowingCtor {
+  ThrowingCtor() noexcept(false) {}
+};
+
+struct ThrowingNSDM : NoexceptCtor {
+  ThrowingCtor c;
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDM, int), "");
+
+struct D : NoexceptCtor, ThrowingCtor {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D, int), "");
+
+struct ThrowingDefaultArg {
+  ThrowingDefaultArg(ThrowingCtor = {}) {}
+};
+
+struct D2 : NoexceptCtor, ThrowingDefaultArg {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D2, int), "");
+#endif
+} // namespace dr1350
+
 namespace dr1358 { // dr1358: 3.1
 #if __cplusplus >= 201103L
   struct Lit { constexpr operator int() const { return 0; } };
diff --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 007b42c74affb1..3d4050a5713f92 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -390,6 +390,13 @@ namespace dr1573 { // dr1573: 3.9
   H h(0);
   // since-cxx11-error@-1 {{constructor inherited by 'H' from base class 'G' 
is implicitly deleted}}
   //   since-cxx11-note@#dr1573-H {{constructor inherited by 'H' is implicitly 
deleted because field 'g' has no default constructor}}
+
+  // deleted definition of constructor is inherited
+  struct I { I(int) = delete; }; // #dr1573-I
+  struct J : I { using I::I; };
+  J j(0);
+  // since-cxx11-error@-1 {{call to deleted constructor of 'J'}}
+  //   since-cxx11-note@#dr1573-I {{'I' has been explicitly marked deleted 
here}}
 #endif
 }
 
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 4a3ed19161f9a5..5acc72dcf54b2d 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7908,7 +7908,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1350.html";>1350
 CD3
 Incorrect exception specification for inherited constructors
-Unknown
+Clang 3.5
   
   
 https://cplusplus.github.io/CWG/issues/1351.html";>1351

>From 9e515cbad56833dbf2c69e385d3ef3ebe8336458 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 13 Jan 2024 18:18:56 +0300
Subject: [PATCH 2/2] Expant 1350 test with constructor templates

---
 clang/test/CXX/drs/dr13xx.cpp | 37 +++
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 6a4a1f52383c04..366f58d9358003 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -403,21 +403,50 @@ struct ThrowingNSDM : NoexceptCtor {
 
 static_assert(!__is_nothrow_constructible(ThrowingNSDM, int), "");
 
-struct D : NoexceptCtor, ThrowingCtor {
+struct ThrowingCtorTemplate {
+  template 
+  ThrowingCtorTemplate() noexcept(false) {}
+};
+
+struct ThrowingNSDM2 : NoexceptCtor {
+  ThrowingCtorTemplate c;
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(ThrowingNSDM2, int), "");
+
+struct D1 : NoexceptCtor, ThrowingCtor {
+  using NoexceptCtor::NoexceptCtor;
+};
+
+static_assert(!__is_nothrow_constructible(D1, int), "");
+
+struct D2 : NoexceptCtor, ThrowingCtorTemplate {
   using NoexceptCtor::NoexceptCtor;
 };
 
-static_assert(!__is_nothrow_constructible(D, int), "");
+static_assert(!__is_nothrow_constructible(D2, int), "");
 
 struct ThrowingDefaultArg {
   ThrowingDefaultArg(ThrowingCtor = {}) {}
 };
 
-struct D2 : NoexceptCtor, ThrowingDefaultArg {
+struct D3 : NoexceptCtor, ThrowingDefaultArg {
   using NoexceptCtor::NoexceptCtor;
 };
 
-static_assert(!__is_nothrow_constructible(D2, int), "");
+static

[lldb] [clang-tools-extra] [clang] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-13 Thread via cfe-commits

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


[clang-tools-extra] [clang] [lldb] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-13 Thread via cfe-commits

cor3ntin wrote:

Author opened #78041 - closing

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


[clang] [AVX10][Doc] Add documentation about AVX10 options and their attentions (PR #77925)

2024-01-13 Thread Evgenii Kudriashov via cfe-commits

https://github.com/e-kud edited https://github.com/llvm/llvm-project/pull/77925
___
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-avoid-nested-conditional-operator (PR #78022)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H

EugeneZelenko wrote:

All symbols should be uppercase.

https://github.com/llvm/llvm-project/pull/78022
___
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-avoid-nested-conditional-operator (PR #78022)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.h - clang-tidy --*- C++ -*-===//

EugeneZelenko wrote:

Please add `-`.

https://github.com/llvm/llvm-project/pull/78022
___
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-avoid-nested-conditional-operator (PR #78022)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,20 @@
+.. title:: clang-tidy - readability-avoid-nested-conditional-operator
+
+readability-avoid-nested-conditional-operator
+=

EugeneZelenko wrote:

Please adjust length.

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

C++ DR test changes look good to me.

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Vlad Serebrennikov via cfe-commits


@@ -25,7 +25,7 @@ template  struct S {}; // #dr1801-S
 S V; // #dr1801-S-i
 // cxx98-14-error@-1 {{non-type template argument does not refer to any 
declaration}}
 //   cxx98-14-note@#dr1801-S {{template parameter is declared here}}
-// since-cxx17-error@#dr1801-S-i {{non-type template argument refers to 
subobject '.i'}}
+// cxx17-error@#dr1801-S-i {{non-type template argument refers to subobject 
'.i'}}

Endilll wrote:

Quoting P1907R1 wording changes:
> For a non-type template-parameter of reference or pointer type <...> the 
> reference or pointer value shall not refer to or be the address of 
> (respectively):
> ~a subobject (6.7.2),~
> <...>
> a subobject (6.7.2) of one of the above.

My reading is that you indeed can reference subobjects in NTTP since 20, unless 
they fall into one of the narrow categories listed in that paragraph. The 
change you made is correct, unless P1907R1 was adopted as a DR.

Sorry I forgot to check current wording when I added the test.

https://github.com/llvm/llvm-project/pull/78041
___
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 bugprone-eval-order (PR #78028)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,40 @@
+.. title:: clang-tidy - bugprone-eval-order
+
+bugprone-eval-order
+===
+
+Order of evaluation is unspecified for function and constructor parameters,
+unless the constructor uses C++11 list-initialization.
+
+This may lead to issues in code that is written with the assumption of a
+specified evaluation order.
+
+This tidy rule will print a warning when at least two parameters in a call are

EugeneZelenko wrote:

`This check`.

https://github.com/llvm/llvm-project/pull/78028
___
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 bugprone-eval-order (PR #78028)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,40 @@
+.. title:: clang-tidy - bugprone-eval-order
+
+bugprone-eval-order
+===
+
+Order of evaluation is unspecified for function and constructor parameters,

EugeneZelenko wrote:

Please synchronize with statement in Release Notes.

https://github.com/llvm/llvm-project/pull/78028
___
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 option to ignore macros in `readability-simplify-boolean-expr` check (PR #78043)

2024-01-13 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/78043

None

From 7dadf5494bbe53048d01ec78d7facd91085b2198 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 13 Jan 2024 16:36:48 +0100
Subject: [PATCH] [clang-tidy] Add option to ignore macros in
 `readability-simplify-boolean-expr` check

---
 .../readability/SimplifyBooleanExprCheck.cpp  |  5 +
 .../readability/SimplifyBooleanExprCheck.h|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +++
 .../readability/simplify-boolean-expr.rst |  8 ++--
 .../simplify-boolean-expr-macros.cpp  | 20 +++
 5 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 26d9287f07049e..34a18325ce3173 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -277,6 +277,9 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   }
 
   bool dataTraverseStmtPre(Stmt *S) {
+if (Check->IgnoreMacros && S->getBeginLoc().isMacroID()) {
+  return false;
+}
 if (S && !shouldIgnore(S))
   StmtStack.push_back(S);
 return true;
@@ -583,6 +586,7 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.get("IgnoreMacros", false)),
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
@@ -671,6 +675,7 @@ void SimplifyBooleanExprCheck::reportBinOp(const ASTContext 
&Context,
 }
 
 void SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
   Options.store(Opts, "ChainedConditionalReturn", ChainedConditionalReturn);
   Options.store(Opts, "ChainedConditionalAssignment",
 ChainedConditionalAssignment);
diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index c4dad24ec39985..ccc6f3d879fc02 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -64,6 +64,7 @@ class SimplifyBooleanExprCheck : public ClangTidyCheck {
  StringRef Description, SourceRange ReplacementRange,
  StringRef Replacement);
 
+  const bool IgnoreMacros;
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3437b6cf9b59e9..3b556418238db5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -500,6 +500,9 @@ Changes in existing checks
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Added option `IgnoreMacros` to :doc:`readability-simplify-boolean-expr` 
check.
+  It makes the check ignore boolean expressions passed into macros.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
index 18ab84b26a2595..443bcadc9f12e6 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
@@ -82,6 +82,10 @@ Examples:
 Options
 ---
 
+.. option:: IgnoreMacros
+
+   If `true`, ignore boolean expressions passed into macros. Default is 
`false`.
+
 .. option:: ChainedConditionalReturn
 
If `true`, conditional boolean return statements at the end of an
@@ -99,8 +103,8 @@ Options
 
 .. option:: SimplifyDeMorganRelaxed
 
-   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
-   conjunctions and disjunctions where there is no negation on either operand. 
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated
+   conjunctions and disjunctions where there is no negation on either operand.
This option has no effect if :option:`SimplifyDeMorgan` is `false`.
Default is `false`.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
new file mode 10064

[clang-tools-extra] [clang-tidy] Add option to ignore macros in `readability-simplify-boolean-expr` check (PR #78043)

2024-01-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Danny Mösch (SimplyDanny)


Changes



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


5 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp (+5) 
- (modified) 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h (+1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst 
(+6-2) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
 (+20) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 26d9287f07049e..34a18325ce3173 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -277,6 +277,9 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   }
 
   bool dataTraverseStmtPre(Stmt *S) {
+if (Check->IgnoreMacros && S->getBeginLoc().isMacroID()) {
+  return false;
+}
 if (S && !shouldIgnore(S))
   StmtStack.push_back(S);
 return true;
@@ -583,6 +586,7 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.get("IgnoreMacros", false)),
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
@@ -671,6 +675,7 @@ void SimplifyBooleanExprCheck::reportBinOp(const ASTContext 
&Context,
 }
 
 void SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
   Options.store(Opts, "ChainedConditionalReturn", ChainedConditionalReturn);
   Options.store(Opts, "ChainedConditionalAssignment",
 ChainedConditionalAssignment);
diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index c4dad24ec39985..ccc6f3d879fc02 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -64,6 +64,7 @@ class SimplifyBooleanExprCheck : public ClangTidyCheck {
  StringRef Description, SourceRange ReplacementRange,
  StringRef Replacement);
 
+  const bool IgnoreMacros;
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3437b6cf9b59e9..3b556418238db5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -500,6 +500,9 @@ Changes in existing checks
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Added option `IgnoreMacros` to :doc:`readability-simplify-boolean-expr` 
check.
+  It makes the check ignore boolean expressions passed into macros.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
index 18ab84b26a2595..443bcadc9f12e6 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
@@ -82,6 +82,10 @@ Examples:
 Options
 ---
 
+.. option:: IgnoreMacros
+
+   If `true`, ignore boolean expressions passed into macros. Default is 
`false`.
+
 .. option:: ChainedConditionalReturn
 
If `true`, conditional boolean return statements at the end of an
@@ -99,8 +103,8 @@ Options
 
 .. option:: SimplifyDeMorganRelaxed
 
-   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
-   conjunctions and disjunctions where there is no negation on either operand. 
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated
+   conjunctions and disjunctions where there is no negation on either operand.
This option has no effect if :option:`SimplifyDeMorgan` is `false`.
Default is `false`.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
new file mode 100644
index 00..55f586c168beb9
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
@@ -0,0 +1,20 

[llvm] [clang-tools-extra] [clang] Add OpenSSF Best Practice Badge (PR #77398)

2024-01-13 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/77398

>From 71574d1f8b37747b2b7176fffee8483a53fee4be Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 8 Jan 2024 16:39:00 -0800
Subject: [PATCH] Add OpenSSF Best Practice Badge

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 4ae7eaf9b083a5..186cd310bfbb6b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
 # The LLVM Compiler Infrastructure
 
 [![OpenSSF 
Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
+[![OpenSSF Best 
Practices](https://www.bestpractices.dev/projects/8273/badge)](https://www.bestpractices.dev/projects/8273)
 
 Welcome to the LLVM project!
 

___
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 option to ignore macros in `readability-simplify-boolean-expr` check (PR #78043)

2024-01-13 Thread Danny Mösch via cfe-commits




SimplyDanny wrote:

@njames93: The test currently fails. You likely see immediately why. I don't 
have a clue at the moment. Feels like I tried everything already. 😶

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


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread via cfe-commits


@@ -25,7 +25,7 @@ template  struct S {}; // #dr1801-S
 S V; // #dr1801-S-i
 // cxx98-14-error@-1 {{non-type template argument does not refer to any 
declaration}}
 //   cxx98-14-note@#dr1801-S {{template parameter is declared here}}
-// since-cxx17-error@#dr1801-S-i {{non-type template argument refers to 
subobject '.i'}}
+// cxx17-error@#dr1801-S-i {{non-type template argument refers to subobject 
'.i'}}

cor3ntin wrote:

I agree that this restriction no longer exist in the current wording. @zygoloid 

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


[llvm] [clang-tools-extra] [clang] Add OpenSSF Best Practice Badge (PR #77398)

2024-01-13 Thread Tom Stellard via cfe-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/77398
___
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 option to ignore macros in `readability-simplify-boolean-expr` check (PR #78043)

2024-01-13 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/78043

From 55d278f3f33716b5b18d46048df7e664bcdfed6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 13 Jan 2024 16:36:48 +0100
Subject: [PATCH] [clang-tidy] Add option to ignore macros in
 `readability-simplify-boolean-expr` check

---
 .../readability/SimplifyBooleanExprCheck.cpp  |  5 +
 .../readability/SimplifyBooleanExprCheck.h|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../readability/simplify-boolean-expr.rst |  8 ++--
 .../simplify-boolean-expr-macros.cpp  | 20 +++
 5 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 26d9287f07049e..34a18325ce3173 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -277,6 +277,9 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
   }
 
   bool dataTraverseStmtPre(Stmt *S) {
+if (Check->IgnoreMacros && S->getBeginLoc().isMacroID()) {
+  return false;
+}
 if (S && !shouldIgnore(S))
   StmtStack.push_back(S);
 return true;
@@ -583,6 +586,7 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.get("IgnoreMacros", false)),
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", false)),
@@ -671,6 +675,7 @@ void SimplifyBooleanExprCheck::reportBinOp(const ASTContext 
&Context,
 }
 
 void SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
   Options.store(Opts, "ChainedConditionalReturn", ChainedConditionalReturn);
   Options.store(Opts, "ChainedConditionalAssignment",
 ChainedConditionalAssignment);
diff --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index c4dad24ec39985..ccc6f3d879fc02 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -64,6 +64,7 @@ class SimplifyBooleanExprCheck : public ClangTidyCheck {
  StringRef Description, SourceRange ReplacementRange,
  StringRef Replacement);
 
+  const bool IgnoreMacros;
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3437b6cf9b59e9..02cbc0bf07c4b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -500,6 +500,10 @@ Changes in existing checks
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Added option `IgnoreMacros` to :doc:`readability-simplify-boolean-expr
+  ` check.
+  It makes the check ignore boolean expressions passed into macros.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
index 18ab84b26a2595..443bcadc9f12e6 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-boolean-expr.rst
@@ -82,6 +82,10 @@ Examples:
 Options
 ---
 
+.. option:: IgnoreMacros
+
+   If `true`, ignore boolean expressions passed into macros. Default is 
`false`.
+
 .. option:: ChainedConditionalReturn
 
If `true`, conditional boolean return statements at the end of an
@@ -99,8 +103,8 @@ Options
 
 .. option:: SimplifyDeMorganRelaxed
 
-   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
-   conjunctions and disjunctions where there is no negation on either operand. 
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated
+   conjunctions and disjunctions where there is no negation on either operand.
This option has no effect if :option:`SimplifyDeMorgan` is `false`.
Default is `false`.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp
new file mode 100644

[clang-tools-extra] [clang-tidy] Add option to ignore macros in `readability-simplify-boolean-expr` check (PR #78043)

2024-01-13 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/77816

>From 1883d987b2f83adaef05fdb47ae25c7b06582a64 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Jan 2024 00:02:46 +0530
Subject: [PATCH 01/14] Add readability check to suggest replacement of
 conditional statement with std::min/std::max

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../ConditionaltostdminmaxCheck.cpp   | 86 +++
 .../readability/ConditionaltostdminmaxCheck.h | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/ConditionalToStdMinMax.rst| 29 +++
 .../readability/ConditionalToStdMinMax.cpp| 27 ++
 8 files changed, 183 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/ConditionalToStdMinMax.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/ConditionalToStdMinMax.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..4bc373bb69bb84 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangTidyReadabilityModule
   AvoidReturnWithVoidValueCheck.cpp
   AvoidUnconditionalPreprocessorIfCheck.cpp
   BracesAroundStatementsCheck.cpp
+  ConditionaltostdminmaxCheck.cpp
   ConstReturnTypeCheck.cpp
   ContainerContainsCheck.cpp
   ContainerDataPointerCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
new file mode 100644
index 00..fba8c68f737450
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
@@ -0,0 +1,86 @@
+//===--- ConditionaltostdminmaxCheck.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 "ConditionaltostdminmaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ConditionaltostdminmaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+ifStmt(
+  has(
+binaryOperator(
+  anyOf(hasOperatorName("<"),hasOperatorName(">")),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar1"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar1")))
+  )
+  )
+,
+hasThen(
+  stmt(
+binaryOperator(
+  hasOperatorName("="),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar2"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar2")))
+  )
+)
+  ) 
+).bind("ifStmt"),this);
+
+
+
+}
+
+void ConditionaltostdminmaxCheck::check(const MatchFinder::MatchResult 
&Result) {
+  const DeclRefExpr *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const DeclRefExpr *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const DeclRefExpr *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const DeclRefExpr *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2"); 
 
+  const IfStmt *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const BinaryOperator *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+  return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+
+  if(binaryOp->getOpcode() == BO_LT){
+if(lhsVar1->getDecl() == lhsVar2->getDecl() && rhsVar1->getDecl() == 
rhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::max instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+else if(lhsVar1->getDecl() == rhsVar2->getDecl() && rhsVar1->getDecl() == 
lhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::min instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+  }
+  else if(binaryOp->getOpcode() == BO_GT){
+if(lhsVar1->getDecl() == l

[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have added the initialisation of variables and also added tests involving 
constexpr,functions etc. 

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s readability-use-std-min-max %t
+
+constexpr int myConstexprMin(int a, int b) {
+  return a < b ? a : b;
+}
+
+constexpr int myConstexprMax(int a, int b) {
+  return a > b ? a : b;
+}
+
+int bar(int x, int y) {
+  return x < y ? x : y;
+}
+void foo() {

EugeneZelenko wrote:

Please separate with newline.

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-13 Thread via cfe-commits


@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy %s readability-use-std-min-max %t
+
+void foo() {
+  int value1,value2,value3;
+  short value4;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  if (value1 < value2)
+value1 = value2; // CHECK-FIXES: value1 = std::max(value1, value2);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::min` instead of `<` 
[readability-use-std-min-max]
+  if (value1 < value2)
+value2 = value1; // CHECK-FIXES: value2 = std::min(value1, value2);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::min` instead of `>` 
[readability-use-std-min-max]
+  if (value2 > value1)
+value2 = value1; // CHECK-FIXES: value2 = std::min(value2, value1);
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `>` 
[readability-use-std-min-max
+  if (value2 > value1)
+value1 = value2; // CHECK-FIXES: value1 = std::max(value2, value1);
+
+  // No suggestion needed here
+  if (value1 == value2)
+value1 = value2;
+  
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  if(value1https://github.com/llvm/llvm-project/pull/77816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] workflows: Refactor release-tasks.yml (PR #69523)

2024-01-13 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/69523

>From 6a7f298f403e0e454644f3d945242120f8b2b321 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Wed, 18 Oct 2023 04:56:28 -0700
Subject: [PATCH 1/4] workflows: Refactor release-tasks.yml

* Split out the lit release job and the documentation build jobs into their
own workflow files.  This makes it possible to manually run these jobs
via workflow_dispatch.

* Improve tag/user validation and ensure it gets run for each release
task.
---
 .github/workflows/release-binaries.yml|  51 ---
 .github/workflows/release-documentation.yml   |  84 +++
 .github/workflows/release-doxygen.yml |  62 
 .github/workflows/release-lit.yml |  74 +
 .github/workflows/release-tasks.yml   | 140 ++
 .../workflows/set-release-binary-outputs.sh   |  18 +--
 llvm/utils/release/github-upload-release.py   |  22 ++-
 7 files changed, 321 insertions(+), 130 deletions(-)
 create mode 100644 .github/workflows/release-documentation.yml
 create mode 100644 .github/workflows/release-doxygen.yml
 create mode 100644 .github/workflows/release-lit.yml

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index 75d4f419ab1fdc..d8b732413d2bf6 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -1,20 +1,29 @@
 name: Release Binaries
 
 on:
-  push:
-tags:
-  - 'llvmorg-*'
   workflow_dispatch:
 inputs:
+  release-version:
+description: 'Release Version'
+required: true
+type: string
   upload:
 description: 'Upload binaries to the release page'
 required: true
-default: true
+default: false
 type: boolean
-  tag:
-description: 'Tag to build'
+
+  workflow_call:
+inputs:
+  release-version:
+description: 'Release Version'
 required: true
 type: string
+  upload:
+description: 'Upload binaries to the release page'
+required: true
+default: false
+type: boolean
 
 permissions:
   contents: read # Default everything to read-only
@@ -23,21 +32,26 @@ jobs:
   prepare:
 name: Prepare to build binaries
 runs-on: ubuntu-22.04
-if: github.repository == 'llvm/llvm-project'
 outputs:
-  release-version: ${{ steps.validate-tag.outputs.release-version }}
-  release: ${{ steps.validate-tag.outputs.release }}
-  build-dir: ${{ steps.validate-tag.outputs.build-dir }}
-  rc-flags: ${{ steps.validate-tag.outputs.rc-flags }}
-  ref: ${{ steps.validate-tag.outputs.ref }}
-  upload: ${{ steps.validate-tag.outputs.upload }}
+  release-version: ${{ steps.vars.outputs.release-version }}
+  release: ${{ steps.vars.outputs.release }}
+  build-dir: ${{ steps.vars.outputs.build-dir }}
+  rc-flags: ${{ steps.vars.outputs.rc-flags }}
+  ref: ${{ steps.vars.outputs.ref }}
+  upload: ${{ steps.vars.outputs.upload }}
 
 steps:
 - name: Checkout LLVM
   uses: actions/checkout@v4
 
-- name: Validate and parse tag
-  id: validate-tag
+- name: Check Permissions
+  env:
+GITHUB_TOKEN: ${{ github.token }}
+  run: |
+./llvm/utils/release/./github-upload-release.py --token 
"$GITHUB_TOKEN" --user ${{ github.actor }} check-permissions
+
+- name: Collect Variables
+  id: vars
   # In order for the test-release.sh script to run correctly, the LLVM
   # source needs to be at the following location relative to the build dir:
   # | X.Y.Z-rcN | ./rcN/llvm-project
@@ -47,15 +61,12 @@ jobs:
   # | X.Y.Z-rcN | -rc N -test-asserts
   # | X.Y.Z | -final
   run: |
-tag="${{ github.ref_name }}"
-trimmed=$(echo ${{ inputs.tag }} | xargs)
-[[ "$trimmed" != "" ]] && tag="$trimmed"
 if [ -n "${{ inputs.upload }}" ]; then
   upload="${{ inputs.upload }}"
 else
-  upload="true"
+  upload="false"
 fi
-bash .github/workflows/set-release-binary-outputs.sh "${{ github.actor 
}}" "$tag" "$upload"
+bash .github/workflows/set-release-binary-outputs.sh "${{ 
inputs.release-version }}" "$upload"
 
   # Try to get around the 6 hour timeout by first running a job to fill
   # the build cache.
diff --git a/.github/workflows/release-documentation.yml 
b/.github/workflows/release-documentation.yml
new file mode 100644
index 00..832570ed6fe93f
--- /dev/null
+++ b/.github/workflows/release-documentation.yml
@@ -0,0 +1,84 @@
+name: Release Documentation
+
+permissions:
+  contents: read
+
+on:
+  workflow_dispatch:
+inputs:
+  release-version:
+description: 'Release Version'
+required: true
+type: string
+  upload:
+description: 'Upload documentation'
+required: false
+type: boolean
+
+  workflow_call:
+inp

  1   2   3   4   >