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

2024-01-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL 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-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,97 @@
+//===--- UseStdMinMaxCheck.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 "UseStdMinMaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseStdMinMaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  ifStmt(
+  has(binaryOperator(
+  anyOf(hasOperatorName("<"), hasOperatorName(">"),
+hasOperatorName("<="), hasOperatorName(">=")),
+  hasLHS(expr().bind("lhsVar1")), hasRHS(expr().bind("rhsVar1",
+  hasThen(stmt(binaryOperator(hasOperatorName("="),
+  hasLHS(expr().bind("lhsVar2")),
+  hasRHS(expr().bind("rhsVar2"))
+  .bind("ifStmt"),
+  this);
+}
+
+void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const auto *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const auto *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const auto *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2");
+  const auto *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+  auto &Context = *Result.Context;
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const auto *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+  auto lhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto lhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  if (binaryOp->getOpcode() == BO_LT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::max(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::min` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::min(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+}
+  } else if (binaryOp->getOpcode() == BO_GT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::min` instead of `>`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::min(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `>`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::max(" +
+  lhsVar1Str.str() + ", " +

PiotrZSL wrote:

better would be to move text instead of doing a copy, to avoid conflicts 
between checks.

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-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,97 @@
+//===--- UseStdMinMaxCheck.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 "UseStdMinMaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseStdMinMaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  ifStmt(
+  has(binaryOperator(
+  anyOf(hasOperatorName("<"), hasOperatorName(">"),
+hasOperatorName("<="), hasOperatorName(">=")),
+  hasLHS(expr().bind("lhsVar1")), hasRHS(expr().bind("rhsVar1",
+  hasThen(stmt(binaryOperator(hasOperatorName("="),
+  hasLHS(expr().bind("lhsVar2")),
+  hasRHS(expr().bind("rhsVar2"))
+  .bind("ifStmt"),
+  this);
+}
+
+void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const auto *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const auto *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const auto *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2");
+  const auto *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+  auto &Context = *Result.Context;
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const auto *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+  auto lhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto lhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  if (binaryOp->getOpcode() == BO_LT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::max(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::min` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::min(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+}
+  } else if (binaryOp->getOpcode() == BO_GT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::min` instead of `>`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::min(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `>`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),

PiotrZSL wrote:

fixes are incomplete,  include should be added if missing, look into 
other checks how they do it

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-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,97 @@
+//===--- UseStdMinMaxCheck.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 "UseStdMinMaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseStdMinMaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  ifStmt(
+  has(binaryOperator(
+  anyOf(hasOperatorName("<"), hasOperatorName(">"),
+hasOperatorName("<="), hasOperatorName(">=")),
+  hasLHS(expr().bind("lhsVar1")), hasRHS(expr().bind("rhsVar1",
+  hasThen(stmt(binaryOperator(hasOperatorName("="),
+  hasLHS(expr().bind("lhsVar2")),
+  hasRHS(expr().bind("rhsVar2"))
+  .bind("ifStmt"),
+  this);
+}
+
+void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const auto *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const auto *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const auto *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2");
+  const auto *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+  auto &Context = *Result.Context;
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const auto *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+  auto lhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto lhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  if (binaryOp->getOpcode() == BO_LT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::max(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {

PiotrZSL wrote:

probably better would be to compare expressions (with 
clang::tidy::utils::areStatementsIdentical) instead of strings, and this could 
be done on matcher level with isStatementIdenticalToBoundNode matcher.
Simply because there can be some differences with formatting (new lines) or 
spaces, and strings wont be equal.

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-14 Thread Piotr Zegar via cfe-commits

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

I would say that few more nits and could be fine.
add tests for class members and some other tests.

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-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,38 @@
+//===--- UseStdMinMaxCheck.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_USESTDMINMAXCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USESTDMINMAXCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// replaces certain conditional statements with equivalent ``std::min`` or

PiotrZSL wrote:

Replaces

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-14 Thread Piotr Zegar via cfe-commits


@@ -336,6 +336,7 @@ Clang-Tidy Checks
:doc:`portability-restrict-system-includes 
`, "Yes"
:doc:`portability-simd-intrinsics `,
:doc:`portability-std-allocator-const `,
+   :doc:`readability-use-std-min-max `, "Yes"

PiotrZSL wrote:

i still thinking that this should be a modernize check.

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-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,97 @@
+//===--- UseStdMinMaxCheck.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 "UseStdMinMaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseStdMinMaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  ifStmt(
+  has(binaryOperator(
+  anyOf(hasOperatorName("<"), hasOperatorName(">"),
+hasOperatorName("<="), hasOperatorName(">=")),
+  hasLHS(expr().bind("lhsVar1")), hasRHS(expr().bind("rhsVar1",
+  hasThen(stmt(binaryOperator(hasOperatorName("="),
+  hasLHS(expr().bind("lhsVar2")),
+  hasRHS(expr().bind("rhsVar2"))
+  .bind("ifStmt"),
+  this);
+}
+
+void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const auto *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const auto *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const auto *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2");
+  const auto *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+  auto &Context = *Result.Context;
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const auto *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+  auto lhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto lhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(lhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar1Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar1->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  auto rhsVar2Str = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(rhsVar2->getSourceRange()),
+  Context.getSourceManager(), Context.getLangOpts());
+
+  if (binaryOp->getOpcode() == BO_LT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::max` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::max(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+} else if (lhsVar1Str == rhsVar2Str && rhsVar1Str == lhsVar2Str) {
+  diag(ifStmt->getIfLoc(), "use `std::min` instead of `<`")
+  << FixItHint::CreateReplacement(SourceRange(ifLocation, 
thenLocation),
+  lhsVar2Str.str() + " = std::min(" +
+  lhsVar1Str.str() + ", " +
+  rhsVar1Str.str() + ")");
+}
+  } else if (binaryOp->getOpcode() == BO_GT) {
+if (lhsVar1Str == lhsVar2Str && rhsVar1Str == rhsVar2Str) {

PiotrZSL wrote:

this diag looks same like that in line 73-78, consider merging.

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-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,58 @@
+// 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() {
+  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(value1` 
[readability-use-std-min-max]
+  if (value1 > myConstexprMax(value2, value3))
+value1 = myConstexprMax(value2, value3); // CHECK-FIXES: value1 = 
std::min(value1, myConstexprMax(value2, value3));
+  
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  if (value1 < bar(value2, value3))
+value1 = bar(value2, value3); // CHECK-FIXES: value1 = std::max(value1, 
bar(value2, value3));
+}

PiotrZSL wrote:

add tests for <= and >=

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] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,157 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  auto isStdMove = callee(functionDecl(hasName("::std::move")));
+
+  // Resolved type, direct move.
+  Finder->addMatcher(
+  callExpr(isStdMove, hasArgument(0, cxxOperatorCallExpr(
+ hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ 
SharedPointerClasses)))
+  .bind("call"),
+  this);
+
+  // Resolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(
+  isStdMove,
+  hasArgument(
+  0, unaryOperator(
+ hasOperatorName("*"),
+ hasUnaryOperand(cxxMemberCallExpr(callee(cxxMethodDecl(
+ hasName("get"), 
ofClass(matchers::matchesAnyListedName(
+ SharedPointerClasses)
+  .bind("get_call"),
+  this);

PiotrZSL wrote:

you can duplicate callExpr or expr, like `callExpr(anyOf(callExpr().bind("a"), 
callExpr().bind("b")))`
callExpr/expr will work like allOf

https://github.com/llvm/llvm-project/pull/67467
___
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-move-shared-pointer-contents check. (PR #67467)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,157 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  auto isStdMove = callee(functionDecl(hasName("::std::move")));
+
+  // Resolved type, direct move.
+  Finder->addMatcher(
+  callExpr(isStdMove, hasArgument(0, cxxOperatorCallExpr(
+ hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ 
SharedPointerClasses)))
+  .bind("call"),
+  this);
+
+  // Resolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(
+  isStdMove,
+  hasArgument(
+  0, unaryOperator(
+ hasOperatorName("*"),
+ hasUnaryOperand(cxxMemberCallExpr(callee(cxxMethodDecl(
+ hasName("get"), 
ofClass(matchers::matchesAnyListedName(
+ SharedPointerClasses)
+  .bind("get_call"),
+  this);
+
+  auto isStdMoveUnresolved = callee(unresolvedLookupExpr(
+  
hasAnyDeclaration(namedDecl(hasUnderlyingDecl(hasName("::std::move"));
+
+  // Unresolved type, direct move.
+  Finder->addMatcher(
+  callExpr(
+  isStdMoveUnresolved,
+  hasArgument(0, unaryOperator(hasOperatorName("*"),
+   hasUnaryOperand(declRefExpr(hasType(
+   
qualType().bind("unresolved_p")))
+  .bind("unresolved_call"),
+  this);
+  // Annoyingly, the declRefExpr in the unresolved-move-of-get() case
+  // is of  rather than shared_ptr, so we have to
+  // just fetch the variable. This does leave a gap where a temporary
+  // shared_ptr wouldn't be caught, but moving out of a temporary
+  // shared pointer is a truly wild thing to do so it should be okay.
+
+  // Unresolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(isStdMoveUnresolved,
+   hasArgument(
+   0, unaryOperator(hasOperatorName("*"),
+hasDescendant(cxxDependentScopeMemberExpr(
+hasMemberName("get"))),
+hasDescendant(declRefExpr(to(

PiotrZSL wrote:

issue could be if you would have call expression in call expression, like:
`x = std::move(getSomething(y).field)`
Would be good to check if there are no other calls as parent.

https://github.com/llvm/llvm-project/pull/67467
___
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-move-shared-pointer-contents check. (PR #67467)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -117,7 +117,8 @@ Clang-Tidy Checks
:doc:`bugprone-parent-virtual-call `, "Yes"
:doc:`bugprone-posix-return `, "Yes"
:doc:`bugprone-redundant-branch-condition 
`, "Yes"
-   :doc:`bugprone-reserved-identifier `, "Yes"
+   :doc:`bugprone-reserved-identifier `, "Yes",

PiotrZSL wrote:

remove , at the end

https://github.com/llvm/llvm-project/pull/67467
___
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-move-shared-pointer-contents check. (PR #67467)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,125 @@
+// RUN: %check_clang_tidy %s bugprone-move-shared-pointer-contents %t -- 
-config="{CheckOptions: 
{bugprone-move-shared-pointer-contents.SharedPointerClasses: 
'::std::shared_ptr;my::OtherSharedPtr;'}}"
+
+// Some dummy definitions we'll need.
+
+namespace std {
+
+using size_t = int;
+
+template  struct remove_reference;
+template  struct remove_reference { typedef _Tp type; };
+template  struct remove_reference<_Tp &> { typedef _Tp type; };
+template  struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
+  return static_cast::type &&>(__t);
+}
+
+template 
+struct shared_ptr {

PiotrZSL wrote:

try including this header: 
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/shared_ptr.h
 instead 

https://github.com/llvm/llvm-project/pull/67467
___
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-move-shared-pointer-contents check. (PR #67467)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,157 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  auto isStdMove = callee(functionDecl(hasName("::std::move")));
+
+  // Resolved type, direct move.
+  Finder->addMatcher(
+  callExpr(isStdMove, hasArgument(0, cxxOperatorCallExpr(
+ hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ 
SharedPointerClasses)))
+  .bind("call"),
+  this);
+
+  // Resolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(
+  isStdMove,
+  hasArgument(
+  0, unaryOperator(
+ hasOperatorName("*"),
+ hasUnaryOperand(cxxMemberCallExpr(callee(cxxMethodDecl(
+ hasName("get"), 
ofClass(matchers::matchesAnyListedName(
+ SharedPointerClasses)
+  .bind("get_call"),
+  this);
+
+  auto isStdMoveUnresolved = callee(unresolvedLookupExpr(
+  
hasAnyDeclaration(namedDecl(hasUnderlyingDecl(hasName("::std::move"));
+
+  // Unresolved type, direct move.
+  Finder->addMatcher(
+  callExpr(
+  isStdMoveUnresolved,
+  hasArgument(0, unaryOperator(hasOperatorName("*"),
+   hasUnaryOperand(declRefExpr(hasType(
+   
qualType().bind("unresolved_p")))
+  .bind("unresolved_call"),
+  this);
+  // Annoyingly, the declRefExpr in the unresolved-move-of-get() case
+  // is of  rather than shared_ptr, so we have to
+  // just fetch the variable. This does leave a gap where a temporary
+  // shared_ptr wouldn't be caught, but moving out of a temporary
+  // shared pointer is a truly wild thing to do so it should be okay.
+
+  // Unresolved type, move out of get().
+  Finder->addMatcher(
+  callExpr(isStdMoveUnresolved,
+   hasArgument(
+   0, unaryOperator(hasOperatorName("*"),
+hasDescendant(cxxDependentScopeMemberExpr(
+hasMemberName("get"))),
+hasDescendant(declRefExpr(to(
+
varDecl().bind("unresolved_get_p")))
+  .bind("unresolved_get_call"),
+  this);
+}
+
+bool MoveSharedPointerContentsCheck::isSharedPointerClass(
+const VarDecl *VD) const {
+  if (VD == nullptr) {
+return false;
+  }
+
+  const QualType QT = VD->getType();
+  return isSharedPointerClass(&QT);
+}
+
+bool MoveSharedPointerContentsCheck::isSharedPointerClass(
+const QualType *QT) const {
+  if (QT == nullptr) {
+return false;
+  }
+  // We want the qualified name without template parameters,
+  // const/volatile, or reference/pointer qualifiers so we can look
+  // it up in SharedPointerClasses. This is a bit messy, but gets us
+  // to the underlying type without template parameters (eg
+  // std::shared_ptr) or const/volatile qualifiers even in the face of
+  // typedefs.
+
+  bool found = false;
+  const auto *Template = llvm::dyn_cast(
+  QT->getSplitDesugaredType().Ty);
+  if (Template != nullptr) {
+const std::string TypeName = Template->getTemplateName()
+ .getAsTemplateDecl()
+ ->getQualifiedNameAsString();
+for (const llvm::StringRef SharedPointer : SharedPointerClasses) {
+  // SharedPointer entries may or may not have leading ::, but TypeName
+  // definitely won't.
+  if (SharedPointer == TypeName || SharedPointer.substr(2) == TypeName) {

PiotrZSL wrote:

getAsTemplateDecl returns NamedDecl, all you need to do is just move lines 
83-109 into AST_MATCHER_P with extra InnerMatcher that would be used

[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

2024-01-14 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/78088

>From d040754092faa2106dc0b63af5e8bc7d7e1e47c2 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 14 Jan 2024 15:07:26 +0800
Subject: [PATCH] [Clang][Sema] fix crash of attribute transform

---
 clang/include/clang/AST/TypeLoc.h   |  4 
 clang/lib/Sema/TreeTransform.h  | 11 ---
 clang/test/Sema/attr-lifetimebound-no-crash.cpp | 17 +
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-lifetimebound-no-crash.cpp

diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 471deb14aba51f..04780fdeae3bc1 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -884,6 +884,10 @@ class AttributedTypeLoc : public 
ConcreteTypeLocgetEquivalentType(), getNonLocalData());
+  }
+
   /// The type attribute.
   const Attr *getAttr() const {
 return getLocalData()->TypeAttr;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1a1bc87d2b3203..be5ba2000de197 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6124,7 +6124,11 @@ QualType 
TreeTransform::TransformFunctionProtoType(
   //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
   //   and the end of the function-definition, member-declarator, or
   //   declarator.
-  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
+  auto *RD =
+  dyn_cast_or_null(SemaRef.getCurLexicalContext());
+  Sema::CXXThisScopeRAII ThisScope(
+  SemaRef, ThisContext == nullptr && nullptr != RD ? RD : ThisContext,
+  ThisTypeQuals);
 
   ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
   if (ResultType.isNull())
@@ -7083,8 +7087,9 @@ QualType TreeTransform::TransformAttributedType(
   modifiedType != oldType->getModifiedType()) {
 // TODO: this is really lame; we should really be rebuilding the
 // equivalent type from first principles.
-QualType equivalentType
-  = getDerived().TransformType(oldType->getEquivalentType());
+TypeLocBuilder AuxiliaryTLB;
+QualType equivalentType =
+getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
 if (equivalentType.isNull())
   return QualType();
 
diff --git a/clang/test/Sema/attr-lifetimebound-no-crash.cpp 
b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
new file mode 100644
index 00..5b873fa30c6ff2
--- /dev/null
+++ b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+template
+struct Bar {
+int* data;
+
+auto operator[](const int index) const [[clang::lifetimebound]] -> 
decltype(data[index]) {
+return data[index];
+}
+};
+
+int main() {
+Bar b;
+(void)b[2];
+}
\ No newline at end of file

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


[llvm] [clang-tools-extra] [clang] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

2024-01-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/76117

>From 97eeda4684804229d9faad19ea7b7888dcd91786 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 21 Dec 2023 02:30:34 +
Subject: [PATCH 1/6] Fix #75686: add iter_swap and iter_move to the matched
 name

---
 .../bugprone/ExceptionEscapeCheck.cpp   | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 90bf523ffb00b6..18cd7150185a20 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -58,14 +58,15 @@ void 
ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()),
- isMain(), hasName("swap")),
-   unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+  functionDecl(
+  isDefinition(),
+  anyOf(isNoThrow(),
+allOf(anyOf(cxxDestructorDecl(),
+cxxConstructorDecl(isMoveConstructor()),
+cxxMethodDecl(isMoveAssignmentOperator()), 
isMain(),
+hasAnyName("swap", "iter_swap", "iter_move")),
+  unless(isExplicitThrow())),
+isEnabled(FunctionsThatShouldNotThrow)))
   .bind("thrower"),
   this);
 }

>From c7cbf4c9bebbf450410c2679af188672257895aa Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 28 Dec 2023 01:30:35 +
Subject: [PATCH 2/6] [clang-tidy] Update documentation, release notes and
 tests for bugprone-exception-escape

---
 clang-tools-extra/docs/ReleaseNotes.rst|  4 
 .../clang-tidy/checks/bugprone/exception-escape.rst|  2 ++
 .../clang-tidy/checkers/bugprone/exception-escape.cpp  | 10 ++
 3 files changed, 16 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..967597cbba11b1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -242,6 +242,10 @@ Changes in existing checks
   casting during type conversions at variable initialization, now with improved
   compatibility for C++17 and later versions.
 
+- Improved :doc:`bugprone-exception-escape
+  ` check by extending the default
+  check function names to include ``iter_swap`` and ``iter_move``.
+
 - Improved :doc:`bugprone-lambda-function-name
   ` check by adding option
   `IgnoreMacros` to ignore warnings in macros.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
index e6aa8e001492a6..182fade7f47a03 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -11,6 +11,8 @@ should not. The functions which should not throw exceptions 
are the following:
 * Move assignment operators
 * The ``main()`` functions
 * ``swap()`` functions
+* ``iter_swap()`` functions
+* ``iter_move()`` functions
 * Functions marked with ``throw()`` or ``noexcept``
 * Other functions given as option
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
index 4a7149e81ce7e5..e20aa267392f55 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -586,6 +586,16 @@ void swap(int&, int&) {
   throw 1;
 }
 
+void iter_swap(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_swap' which should not throw exceptions
+  throw 1;
+}
+
+void iter_move(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_move' which should not throw exceptions
+  throw 1;
+}
+
 namespace std {
 class bad_alloc {};
 }

>From 0accdc7d74eda5719a1415588e704e2f8dff58c4 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 7 Jan 2024 02:25:47 +
Subject: [PATCH 3/6] [clang-tidy] exception-escape test: iter_move function
 should have only one parameter

---
 .../test/clang-tidy/checkers/bugprone/exception-escape.cpp  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clan

[clang] [Clang][Sema] Extract ellipsis location from CXXFoldExpr for reattaching constraints on NTTPs (PR #78080)

2024-01-14 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/78080

>From 7c0b5ffe4b377f198308b976eb726138837145c4 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 14 Jan 2024 12:21:33 +0800
Subject: [PATCH 1/2] [Clang][Sema] Extract ellipsis location from CXXFoldExpr
 for reattaching constraints on NTTPs

We build up a CXXFoldExpr for immediately declared constraints as
per C++20 [temp.param]/4. This is done by
`formImmediatelyDeclaredConstraint` where an EllipsisLoc is essential
to determine whether this is a pack.

On the other hand, when attempting to instantiate a class template,
member templates might not be instantiated immediately, so we leave
them intact. For function templates with NTTPs,  we reattach
constraints if possible so that they can be evaluated later. To
properly form that, we attempted to extract an ellipsis location if
the param per se was a parameter pack. Unfortunately, for the following
NTTP case, we seemingly failed to handle:

```cpp
template 
void member();
```

The NTTPD Pack is neither an ExpandedParameterPack nor a PackExpansion
(its type does not expand anything). As a result, we end up losing
track of the constraints on packs, although we have them inside the
associated CXXFoldExpr.

This patch fixes that by extracting the ellipsis location out of the
previous constraint expression. This closes
https://github.com/llvm/llvm-project/issues/63837.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 21 ---
 clang/test/SemaTemplate/concepts.cpp  | 21 +++
 3 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 154412144ef97a..04b2fac2c74713 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,9 @@ Bug Fixes to C++ Support
   (`#64607 `_)
   (`#64086 `_)
 
+- Fixed a crash where we lost uninstantiated constraints on placeholder NTTP 
packs. Fixes:
+  (`#63837 `_)
+
 - Fixed a regression where clang forgets how to substitute into constraints on 
template-template
   parameters. Fixes: 
   (`#57410 `_) and
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c09..208a7b120c419b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3056,16 +3056,21 @@ Decl 
*TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
 D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), DI);
 
   if (AutoTypeLoc AutoLoc = DI->getTypeLoc().getContainedAutoTypeLoc())
-if (AutoLoc.isConstrained())
+if (AutoLoc.isConstrained()) {
+  SourceLocation EllipsisLoc;
+  if (IsExpandedParameterPack)
+EllipsisLoc =
+DI->getTypeLoc().getAs().getEllipsisLoc();
+  else if (auto *Constraint = dyn_cast_if_present(
+   D->getPlaceholderTypeConstraint()))
+EllipsisLoc = Constraint->getEllipsisLoc();
   // Note: We attach the uninstantiated constriant here, so that it can be
-  // instantiated relative to the top level, like all our other 
constraints.
-  if (SemaRef.AttachTypeConstraint(
-  AutoLoc, Param, D,
-  IsExpandedParameterPack
-? DI->getTypeLoc().getAs()
-.getEllipsisLoc()
-: SourceLocation()))
+  // instantiated relative to the top level, like all our other
+  // constraints.
+  if (SemaRef.AttachTypeConstraint(AutoLoc, /*NewConstrainedParm=*/Param,
+   /*OrigConstrainedParm=*/D, EllipsisLoc))
 Invalid = true;
+}
 
   Param->setAccess(AS_public);
   Param->setImplicit(D->isImplicit());
diff --git a/clang/test/SemaTemplate/concepts.cpp 
b/clang/test/SemaTemplate/concepts.cpp
index e98ebcc9203a43..bac209a28da912 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1064,3 +1064,24 @@ void cand(T t)
 
 void test() { cand(42); }
 }
+
+namespace GH63837 {
+
+template concept IsFoo = true;
+
+template struct Struct {
+  template
+  void foo() {}
+
+  template requires (... && IsFoo)
+  void bar() {}
+
+  template
+  static inline int field = 0;
+};
+
+template void Struct::foo<>();
+template void Struct::bar<>();
+template int Struct::field<1, 2>;
+
+}

>From 5f1d090f414bcb42a931fde557844ddfd37c375d Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 14 Jan 2024 16:44:41 +0800
Subject: [PATCH 2/2] Remove trailing whitespaces

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
inde

[clang-tools-extra] [clang] [clangd] Handle an expanded token range that ends in the `eof` token in TokenBuffer::spelledForExpanded() (PR #78092)

2024-01-14 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/78092

Such ranges can legitimately arise in the case of invalid code, such as a 
declaration missing an ending brace.

>From 26a11f5fa7e79c85bac5cf92048194212b957b0a Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Tue, 9 Jan 2024 18:56:10 -0500
Subject: [PATCH] [clangd] Handle an expanded token range that ends in the
 `eof` token in TokenBuffer::spelledForExpanded()

Such ranges can legitimately arise in the case of invalid code,
such as a declaration missing an ending brace.
---
 clang-tools-extra/clangd/unittests/DumpASTTests.cpp | 11 +++
 clang/lib/Tooling/Syntax/Tokens.cpp |  6 ++
 clang/unittests/Tooling/Syntax/TokensTest.cpp   | 12 
 3 files changed, 29 insertions(+)

diff --git a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp 
b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
index d1b8f21b82c65a..304682118c871d 100644
--- a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
@@ -186,6 +186,17 @@ TEST(DumpASTTests, Arcana) {
   EXPECT_THAT(Node.children.front().arcana, testing::StartsWith("QualType "));
 }
 
+TEST(DumpASTTests, UnbalancedBraces) {
+  // Test that we don't crash while trying to compute a source range for the
+  // node whose ending brace is missing, and also that the source range is
+  // not empty.
+  Annotations Case("/*error-ok*/ $func[[int main() {]]");
+  ParsedAST AST = TestTU::withCode(Case.code()).build();
+  auto Node = dumpAST(DynTypedNode::create(findDecl(AST, "main")),
+  AST.getTokens(), AST.getASTContext());
+  ASSERT_EQ(Node.range, Case.range("func"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 2f28b9cf286a63..8d32c45a4a70cf 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -401,6 +401,12 @@ std::string TokenBuffer::Mapping::str() const {
 
 std::optional>
 TokenBuffer::spelledForExpanded(llvm::ArrayRef Expanded) const {
+  // In cases of invalid code, AST nodes can have source ranges that include
+  // the `eof` token. As there's no spelling for this token, exclude it from
+  // the range.
+  if (!Expanded.empty() && Expanded.back().kind() == tok::eof) {
+Expanded = Expanded.drop_back();
+  }
   // Mapping an empty range is ambiguous in case of empty mappings at either 
end
   // of the range, bail out in that case.
   if (Expanded.empty())
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 0c08318a637c0b..45b2f0de4eabc1 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -816,6 +816,18 @@ TEST_F(TokenBufferTest, SpelledByExpanded) {
   EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("prev good")), 
std::nullopt);
 }
 
+TEST_F(TokenBufferTest, NoCrashForEofToken) {
+  recordTokens(R"cpp(
+int main() {
+  )cpp");
+  // Calling spelledForExpanded() on the entire range of expanded tokens (which
+  // includes the `eof` token at the end) produces the range of all the spelled
+  // tokens (the `eof` is ignored).
+  EXPECT_THAT(
+  Buffer.spelledForExpanded(Buffer.expandedTokens()),
+  ValueIs(SameRange(Buffer.spelledTokens(SourceMgr->getMainFileID();
+}
+
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {
   recordTokens(R"cpp(
 #define SIGN(X) X##_washere

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


[clang-tools-extra] [clang] [clangd] Handle an expanded token range that ends in the `eof` token in TokenBuffer::spelledForExpanded() (PR #78092)

2024-01-14 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Based on previous discussion and analysis in 
https://github.com/llvm/llvm-project/pull/69849

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


[clang-tools-extra] [clang] [clangd] Handle an expanded token range that ends in the `eof` token in TokenBuffer::spelledForExpanded() (PR #78092)

2024-01-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)


Changes

Such ranges can legitimately arise in the case of invalid code, such as a 
declaration missing an ending brace.

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/unittests/DumpASTTests.cpp (+11) 
- (modified) clang/lib/Tooling/Syntax/Tokens.cpp (+6) 
- (modified) clang/unittests/Tooling/Syntax/TokensTest.cpp (+12) 


``diff
diff --git a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp 
b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
index d1b8f21b82c65a..304682118c871d 100644
--- a/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DumpASTTests.cpp
@@ -186,6 +186,17 @@ TEST(DumpASTTests, Arcana) {
   EXPECT_THAT(Node.children.front().arcana, testing::StartsWith("QualType "));
 }
 
+TEST(DumpASTTests, UnbalancedBraces) {
+  // Test that we don't crash while trying to compute a source range for the
+  // node whose ending brace is missing, and also that the source range is
+  // not empty.
+  Annotations Case("/*error-ok*/ $func[[int main() {]]");
+  ParsedAST AST = TestTU::withCode(Case.code()).build();
+  auto Node = dumpAST(DynTypedNode::create(findDecl(AST, "main")),
+  AST.getTokens(), AST.getASTContext());
+  ASSERT_EQ(Node.range, Case.range("func"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 2f28b9cf286a63..8d32c45a4a70cf 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -401,6 +401,12 @@ std::string TokenBuffer::Mapping::str() const {
 
 std::optional>
 TokenBuffer::spelledForExpanded(llvm::ArrayRef Expanded) const {
+  // In cases of invalid code, AST nodes can have source ranges that include
+  // the `eof` token. As there's no spelling for this token, exclude it from
+  // the range.
+  if (!Expanded.empty() && Expanded.back().kind() == tok::eof) {
+Expanded = Expanded.drop_back();
+  }
   // Mapping an empty range is ambiguous in case of empty mappings at either 
end
   // of the range, bail out in that case.
   if (Expanded.empty())
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 0c08318a637c0b..45b2f0de4eabc1 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -816,6 +816,18 @@ TEST_F(TokenBufferTest, SpelledByExpanded) {
   EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("prev good")), 
std::nullopt);
 }
 
+TEST_F(TokenBufferTest, NoCrashForEofToken) {
+  recordTokens(R"cpp(
+int main() {
+  )cpp");
+  // Calling spelledForExpanded() on the entire range of expanded tokens (which
+  // includes the `eof` token at the end) produces the range of all the spelled
+  // tokens (the `eof` is ignored).
+  EXPECT_THAT(
+  Buffer.spelledForExpanded(Buffer.expandedTokens()),
+  ValueIs(SameRange(Buffer.spelledTokens(SourceMgr->getMainFileID();
+}
+
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {
   recordTokens(R"cpp(
 #define SIGN(X) X##_washere

``




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


[clang] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2024-01-14 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> What do you think about this as an alternative: if `spelledForExpanded` 
> receives as input an expanded token range `[firstExpanded, lastExpanded]` 
> where `lastExpanded` is the `eof` token, return the spelled tokens 
> corresponding to `[firstExpanded, lastExpanded - 1]` instead? (In the case 
> where the `eof` token is the only one in the range, we could return nullopt.)
> 
> This would have the advantage of gracefully handling AST nodes like this one 
> whose end location is the `eof`, and return all the spelled tokens actually 
> making up the node.

I wrote this up at https://github.com/llvm/llvm-project/pull/78092

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


[libc] [lldb] [mlir] [clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [libcxx] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-14 Thread Fangrui Song via cfe-commits


@@ -1418,6 +1418,14 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'O':
 Info.setRequiresImmediate(0, 127);
 return true;
+  case 'W':
+switch (*++Name) {
+default:
+  return false;
+case 's':
+  Info.setAllowsRegister();

MaskRay wrote:

`setAllowsRegister` is somewhat confusing but its use is correct here (also 
used by aarch64/riscv `S`).

`setAllowsMemory` seems to not add extra checks.

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


[compiler-rt] [clang] [clang-tools-extra] [lldb] [libc] [flang] [llvm] [libcxx] [mlir] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-14 Thread Fangrui Song via cfe-commits


@@ -130,3 +130,7 @@ void pr40890(void) {
   __asm__ __volatile__("\n#define BEEF abcd%0\n" : : 
"n"((int*)0xdeadbeef));
 #endif
 }
+
+void test_W(int i) {
+  asm("" : : "Wd"(test_W)); // expected-error{{invalid input constraint 'Wd' 
in asm}}

MaskRay wrote:

The codegen tests  `asm("// %p0 %p1 %p2" :: "Ws"(&var), "Ws"(&arr[3]), 
"Ws"(test_Ws));` (and a struct test I am adding) provide positive tests:)

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


[compiler-rt] [clang] [clang-tools-extra] [lldb] [libc] [lld] [flang] [llvm] [libcxx] [mlir] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-14 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/77886

>From f5a33f9e6893250e3584a77630b771ee76693c20 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 11 Jan 2024 23:42:38 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/Basic/Targets/X86.cpp   | 11 ++
 .../test/CodeGen/X86/inline-asm-constraints.c |  8 +
 clang/test/Sema/inline-asm-validate-x86.c |  4 +++
 llvm/docs/LangRef.rst |  2 ++
 llvm/lib/Target/X86/X86AsmPrinter.cpp |  8 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   | 20 ---
 .../X86/inline-asm-Ws-constraint-error.ll |  9 +
 .../CodeGen/X86/inline-asm-Ws-constraint.ll   | 34 +++
 8 files changed, 91 insertions(+), 5 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-Ws-constraint-error.ll
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-Ws-constraint.ll

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 64e281b888a95f..a68b662d9401aa 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1418,6 +1418,14 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'O':
 Info.setRequiresImmediate(0, 127);
 return true;
+  case 'W':
+switch (*++Name) {
+default:
+  return false;
+case 's':
+  Info.setAllowsRegister();
+  return true;
+}
   // Register constraints.
   case 'Y': // 'Y' is the first character for several 2-character constraints.
 // Shift the pointer to the second character of the constraint.
@@ -1715,6 +1723,9 @@ std::string X86TargetInfo::convertConstraint(const char 
*&Constraint) const {
 return std::string("{st}");
   case 'u':// second from top of floating point stack.
 return std::string("{st(1)}"); // second from top of floating point stack.
+  case 'W':
+assert(Constraint[1] == 's');
+return '^' + std::string(Constraint++, 2);
   case 'Y':
 switch (Constraint[1]) {
 default:
diff --git a/clang/test/CodeGen/X86/inline-asm-constraints.c 
b/clang/test/CodeGen/X86/inline-asm-constraints.c
index b75a84d7a7bcbf..bfcbbca7c4f6bf 100644
--- a/clang/test/CodeGen/X86/inline-asm-constraints.c
+++ b/clang/test/CodeGen/X86/inline-asm-constraints.c
@@ -53,3 +53,11 @@ __m512 testZMM0(void) {
 #endif
   return zmm0;
 }
+
+extern int var;
+
+// CHECK-LABEL: test_Ws(
+// CHECK: call void asm sideeffect "// ${0:p} ${1:p}", 
"^Ws,^Ws,~{dirflag},~{fpsr},~{flags}"(ptr @var, ptr @test_Ws)
+void test_Ws(void) {
+  asm("// %p0 %p1" :: "Ws"(&var), "Ws"(test_Ws));
+}
diff --git a/clang/test/Sema/inline-asm-validate-x86.c 
b/clang/test/Sema/inline-asm-validate-x86.c
index 87b60a0955301a..032d76477c4ae6 100644
--- a/clang/test/Sema/inline-asm-validate-x86.c
+++ b/clang/test/Sema/inline-asm-validate-x86.c
@@ -130,3 +130,7 @@ void pr40890(void) {
   __asm__ __volatile__("\n#define BEEF abcd%0\n" : : 
"n"((int*)0xdeadbeef));
 #endif
 }
+
+void test_W() {
+  asm("" : : "Wd"(test_W)); // expected-error{{invalid input constraint 'Wd' 
in asm}}
+}
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d881deb30049a2..076029976ffc5d 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -5336,6 +5336,7 @@ X86:
   operand in a SSE register. If AVX is also enabled, can also be a 256-bit
   vector operand in an AVX register. If AVX-512 is also enabled, can also be a
   512-bit vector operand in an AVX512 register. Otherwise, an error.
+- ``Ws``: A symbolic reference or label reference.
 - ``x``: The same as ``v``, except that when AVX-512 is enabled, the ``x`` code
   only allocates into the first 16 AVX-512 registers, while the ``v`` code
   allocates into any of the 32 AVX-512 registers.
@@ -5518,6 +5519,7 @@ X86:
   the operand. (The behavior for relocatable symbol expressions is a
   target-specific behavior for this typically target-independent modifier)
 - ``H``: Print a memory reference with additional offset +8.
+- ``p``: Print a raw symbol name (without syntax-specific prefixes).
 - ``P``: Print a memory reference used as the argument of a call instruction or
   used with explicit base reg and index reg as its offset. So it can not use
   additional regs to present the memory reference. (E.g. omit ``(rip)``, even
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp 
b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 15cfd247f125ca..9f0fd4d0938e97 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -774,6 +774,14 @@ bool X86AsmPrinter::PrintAsmOperand(const MachineInstr 
*MI, unsigned OpNo,
   PrintOperand(MI, OpNo, O);
   return false;
 
+case 'p': {
+  const MachineOperand &MO = MI->getOperand(OpNo);
+  if (MO.getType() != MachineOperand:

[llvm] [clang] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2024-01-14 Thread David Green via cfe-commits

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

https://github.com/ARM-software/acle/pull/279 was committed recently, where I 
think this lines up with the final version of it. I think this LGTM in that 
case.

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


[clang-tools-extra] [clang] [clangd] Handle an expanded token range that ends in the `eof` token in TokenBuffer::spelledForExpanded() (PR #78092)

2024-01-14 Thread Nathan Ridge via cfe-commits

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


[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

2024-01-14 Thread Qizhi Hu via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [clang] Add test for CWG472 (PR #67948)

2024-01-14 Thread via cfe-commits


@@ -2871,7 +2871,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/472.html";>472
 drafting
 Casting across protected inheritance
-Not resolved
+No

cor3ntin wrote:

> For `"no drafting" status, can we say something different here? I think 
> something like "Not resolved, probably no" would be better, given that we 
> don't actually know what the resolution will be, and if it ends up resolved 
> NAD then we actually do implement it correctly :-)

I think that would make sense. Any opinion @AaronBallman ?

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


[clang] [Clang][Sema] improve sema check of clang::musttail attribute (PR #77727)

2024-01-14 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77727

>From 537228ee1a223cd89e87daa4402d3aa183d38980 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be159437..c2b9fbbeda4f57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -753,6 +753,9 @@ Bug Fixes in This Version
 - Fix an issue where clang cannot find conversion function with template
   parameter when instantiation of template class.
   Fixes (`#77583 `_)
+- Fix assertion failure when call noreturn-attribute function with musttail
+  attribute.
+  Fixes (`#76631 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..1006e7d65dd868 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA;
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[clang] [Clang][Sema] improve sema check of clang::musttail attribute (PR #77727)

2024-01-14 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> Just needs a release note, else LGTM.

Release note has been added.

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


[clang] d3ac676 - [clang-format][NFC] Use FileCheck for clang-format-ignore lit test (#77977)

2024-01-14 Thread via cfe-commits

Author: Owen Pan
Date: 2024-01-14T01:41:14-08:00
New Revision: d3ac676ea4d87142ff43f5a64cda1ad181b3ad47

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

LOG: [clang-format][NFC] Use FileCheck for clang-format-ignore lit test (#77977)

Added: 


Modified: 
clang/test/Format/clang-format-ignore.cpp

Removed: 




diff  --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
index 3e09fe59fa2120..b4e526463000ae 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -7,41 +7,45 @@
 // RUN: echo "level*/*.c*" >> .clang-format-ignore
 // RUN: echo "*/*2/foo.*" >> .clang-format-ignore
 // RUN: touch foo.cc
-// RUN: clang-format -verbose .clang-format-ignore foo.cc 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose .clang-format-ignore foo.cc 2>&1 \
+// RUN:   | FileCheck %s -allow-empty
 
 // RUN: cd level1
 // RUN: touch bar.cc baz.c
-// RUN: clang-format -verbose bar.cc baz.c 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose bar.cc baz.c 2>&1 | FileCheck %s -allow-empty
 
 // RUN: cd level2
 // RUN: touch foo.c foo.js
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 | FileCheck %s -allow-empty
+
+// CHECK-NOT: Formatting
 
 // RUN: touch .clang-format-ignore
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
-// RUN: grep -Fx "Formatting [2/2] foo.js" %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK2 -match-full-lines
+// CHECK2: Formatting [1/2] foo.c
+// CHECK2-NEXT: Formatting [2/2] foo.js
 
 // RUN: echo "*.js" > .clang-format-ignore
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK3 -match-full-lines
+// CHECK3: Formatting [1/2] foo.c
+// CHECK3-NOT: foo.js
 
 // RUN: cd ../..
-// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
-// RUN: grep -x "Formatting \[1/5] .*foo\.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK4 -match-full-lines
+// CHECK4: {{Formatting \[1/5] .*foo\.c}}
+// CHECK4-NOT: foo.js
 
 // RUN: rm .clang-format-ignore
-// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
-// RUN: grep -x "Formatting \[1/5] .*foo\.cc" %t.stderr
-// RUN: grep -x "Formatting \[2/5] .*bar\.cc" %t.stderr
-// RUN: grep -x "Formatting \[3/5] .*baz\.c" %t.stderr
-// RUN: grep -x "Formatting \[4/5] .*foo\.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK5 -match-full-lines
+// CHECK5: {{Formatting \[1/5] .*foo\.cc}}
+// CHECK5-NEXT: {{Formatting \[2/5] .*bar\.cc}}
+// CHECK5-NEXT: {{Formatting \[3/5] .*baz\.c}}
+// CHECK5-NEXT: {{Formatting \[4/5] .*foo\.c}}
+// CHECK5-NOT: foo.js
 
 // RUN: cd ..
 // RUN: rm -r %t.dir



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


[clang] [clang-format][NFC] Use FileCheck for clang-format-ignore lit test (PR #77977)

2024-01-14 Thread Owen Pan via cfe-commits

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


[clang-tools-extra] 356c2c2 - Fix #75686: add iter_swap and iter_move to the matched name (#76117)

2024-01-14 Thread via cfe-commits

Author: Da-Viper
Date: 2024-01-14T10:48:47+01:00
New Revision: 356c2c2399e1041439af817e3e179aa35361502e

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

LOG: Fix #75686: add iter_swap and iter_move to the matched name (#76117)

Added support for iter_swap, iter_move in bugprone-exception-escape 
and performance-noexcept-swap checks.

Fixes  #75686

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 90bf523ffb00b6..620a57194acb8e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -28,6 +28,10 @@ AST_MATCHER(FunctionDecl, isExplicitThrow) {
  Node.getExceptionSpecSourceRange().isValid();
 }
 
+AST_MATCHER(FunctionDecl, hasAtLeastOneParameter) {
+  return Node.getNumParams() > 0;
+}
+
 } // namespace
 
 ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
@@ -58,14 +62,16 @@ void 
ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()),
- isMain(), hasName("swap")),
-   unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+  functionDecl(
+  isDefinition(),
+  anyOf(isNoThrow(),
+allOf(anyOf(cxxDestructorDecl(),
+cxxConstructorDecl(isMoveConstructor()),
+cxxMethodDecl(isMoveAssignmentOperator()), 
isMain(),
+allOf(hasAnyName("swap", "iter_swap", "iter_move"),
+  hasAtLeastOneParameter())),
+  unless(isExplicitThrow())),
+isEnabled(FunctionsThatShouldNotThrow)))
   .bind("thrower"),
   this);
 }

diff  --git a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
index 25a58af74f7ee8..e7cba6e54e86a9 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -39,7 +39,8 @@ void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) 
{
  .bind("type"),
   hasParameter(1, hasType(qualType(hasCanonicalType(
   qualType(equalsBoundNode("type")));
-  Finder->addMatcher(functionDecl(unless(isDeleted()), hasName("swap"),
+  Finder->addMatcher(functionDecl(unless(isDeleted()),
+  hasAnyName("swap", "iter_swap"),
   anyOf(MethodMatcher, FunctionMatcher))
  .bind(BindFuncDeclName),
  this);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 07d788851f8d13..0144bf44c04792 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -260,6 +260,10 @@ Changes in existing checks
   casting during type conversions at variable initialization, now with improved
   compatibility for C++17 and later versions.
 
+- Improved :doc:`bugprone-exception-escape
+  ` check by extending the default
+  check function names to include ``iter_swap`` and ``iter_move``.
+
 - Improved :doc:`bugprone-implicit-widening-of-multiplication-result
   ` 
check
   to correctly emit fixes.
@@ -445,7 +449,8 @@ Changes in existing checks
 - Improved :doc:`performance-noexcept-swap
   ` check to enforce a stricter
   match with the swap function signature and better handling of condition
-  noexcept expressions, eliminating false-positives.
+  noexcept expressions, eliminating false-positives. ``iter_swap`` function 
name
+  is checked by default.
 
 - Improved :doc:`readability-braces-around-statements
   `

[clang-tools-extra] [clang] [llvm] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

2024-01-14 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] db17a3f - [clang-tidy][DOC] Fix some speling mistakes in release notes

2024-01-14 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2024-01-14T09:53:20Z
New Revision: db17a3f69fab16d45d08243b3e711940b6ae3b0d

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

LOG: [clang-tidy][DOC] Fix some speling mistakes in release notes

Reorder checks & fix some formating.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0144bf44c04792..05190b56728549 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,18 +224,18 @@ New checks
   Recommends the smallest possible underlying type for an ``enum`` or ``enum``
   class based on the range of its enumerators.
 
-- New :doc:`readability-reference-to-constructed-temporary
-  ` check.
-
-  Detects C++ code where a reference variable is used to extend the lifetime
-  of a temporary object that has just been constructed.
-
 - New :doc:`readability-avoid-return-with-void-value
   ` check.
 
   Finds return statements with ``void`` values used within functions with
   ``void`` result types.
 
+- New :doc:`readability-reference-to-constructed-temporary
+  ` check.
+
+  Detects C++ code where a reference variable is used to extend the lifetime
+  of a temporary object that has just been constructed.
+
 New check aliases
 ^
 
@@ -395,7 +395,7 @@ Changes in existing checks
 
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
-  using in elaborated type and only check cpp files.
+  using in elaborated type and only check C++ files.
 
 - Improved :doc:`modernize-avoid-bind
   ` check to
@@ -435,8 +435,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly. Added option `IgnoreExternC` to 
ignore ``typedef``
-  declaration in ``extern "C"`` scope.
+  forward declared ``typedef`` correctly. Added option `IgnoreExternC` to 
ignore
+  ``typedef`` declaration in ``extern "C"`` scope.
 
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
@@ -444,25 +444,25 @@ Changes in existing checks
 
 - Improved :doc:`performance-noexcept-move-constructor
   ` to better handle
-  conditional noexcept expressions, eliminating false-positives.
+  conditional ``noexcept`` expressions, eliminating false-positives.
 
 - Improved :doc:`performance-noexcept-swap
   ` check to enforce a stricter
   match with the swap function signature and better handling of condition
-  noexcept expressions, eliminating false-positives. ``iter_swap`` function 
name
-  is checked by default.
+  ``noexcept`` expressions, eliminating false-positives. ``iter_swap`` function
+  name is checked by default.
 
 - Improved :doc:`readability-braces-around-statements
   ` check to
   ignore false-positive for ``if constexpr`` in lambda expression.
 
 - Improved :doc:`readability-avoid-const-params-in-decls
-  ` diagnositics to
-  highlight the const location
+  ` diagnostics to
+  highlight the ``const`` location
 
 - Improved :doc:`readability-container-contains
   ` to correctly handle
-  interger literals with suffixes in fix-its.
+  integer literals with suffixes in fix-its.
 
 - Improved :doc:`readability-container-size-empty
   ` check to
@@ -485,7 +485,7 @@ Changes in existing checks
   ``camel_Snake_Case`` now detect more invalid identifier names. Fields in
   anonymous records (i.e. anonymous structs and unions) now can be checked with
   the naming rules associated with their enclosing scopes rather than the 
naming
-  rules of public struct/union members.
+  rules of public ``struct``/``union`` members.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take



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


[compiler-rt] [clang] [libcxx] [llvm] [clang-tools-extra] [mlir] [lldb] [flang] [lld] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/77967

>From 48c4463e8817c8ee0f00ffa7422e6fafbe838275 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Wed, 10 Jan 2024 13:46:19 +0200
Subject: [PATCH 01/12] [libc++][numeric] P0543R3: Saturation arithmetic

Implements: https://wg21.link/P0543R3
- https://eel.is/c++draft/numeric.sat

Additional notes:
- Division: https://eel.is/c++draft/expr.mul#4
- Arithmetic conversions: https://eel.is/c++draft/expr.arith.conv#1.5
- Clang builtins: 
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions
---
 libcxx/docs/FeatureTestMacroTable.rst |   2 +-
 libcxx/docs/ReleaseNotes/18.rst   |   7 +-
 libcxx/docs/Status/Cxx2cPapers.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 .../include/__numeric/saturation_arithmetic.h | 135 ++
 libcxx/include/module.modulemap.in|   1 +
 libcxx/include/numeric|  13 ++
 libcxx/include/version|   2 +-
 libcxx/modules/std/numeric.inc|  10 ++
 .../numeric.version.compile.pass.cpp  |  16 +--
 .../version.version.compile.pass.cpp  |  16 +--
 .../numeric.ops.sat/add_sat.pass.cpp  | 129 +
 .../numeric.ops.sat/add_sat.verify.cpp|  39 +
 .../numeric.ops.sat/div_sat.assert.pass.cpp   |  53 +++
 .../numeric.ops.sat/div_sat.pass.cpp  | 108 ++
 .../numeric.ops.sat/div_sat.verify.cpp|  39 +
 .../numeric.ops.sat/mul_sat.pass.cpp  | 119 +++
 .../numeric.ops.sat/mul_sat.verify.cpp|  39 +
 .../numeric.ops.sat/saturate_cast.pass.cpp| 132 +
 .../numeric.ops.sat/saturate_cast.verify.cpp  |  44 ++
 .../numeric.ops.sat/sub_sat.pass.cpp  | 107 ++
 .../numeric.ops.sat/sub_sat.verify.cpp|  39 +
 .../generate_feature_test_macro_components.py |   5 +-
 23 files changed, 1026 insertions(+), 32 deletions(-)
 create mode 100644 libcxx/include/__numeric/saturation_arithmetic.h
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.assert.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.verify.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 893a3b13ca06e0..9dd9c0c023bc8a 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -432,7 +432,7 @@ Status
 --- -
 ``__cpp_lib_rcu``   *unimplemented*
 --- -
-``__cpp_lib_saturation_arithmetic`` *unimplemented*
+``__cpp_lib_saturation_arithmetic`` ``202311L``
 --- -
 ``__cpp_lib_smart_ptr_owner_equality``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 6de7d07e454d34..877e387d9280fd 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -54,12 +54,13 @@ Implemented Papers
 - P2905R2 - Runtime format strings
 - P2918R2 - Runtime format strings II
 - P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
-- P2870R3 - Remove basic_string::reserve()
+- P2870R3 - Remove ``basic_string::reserve()``
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
-- P2821R5 - span.at()
-- P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P2821R5 - ``span.at()``
+- P0521R0 - Proposed Resolution for CA 14 (``shared_ptr`` ``use_count/unique``)
 - P1759R6 - Native handles and file streams
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P0543R3 - Saturation arithmetic
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status

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

2024-01-14 Thread via cfe-commits

Author: Jie Fu (傅杰)
Date: 2024-01-14T18:13:54+08:00
New Revision: 785167070982a75d1b123fbbf0917cc457846ec1

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

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

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

Co-authored-by: cor3ntin 

Added: 


Modified: 
clang/tools/libclang/linker-script-to-export-list.py

Removed: 




diff  --git a/clang/tools/libclang/linker-script-to-export-list.py 
b/clang/tools/libclang/linker-script-to-export-list.py
index 745996028d835f..9c7b6a98a34b55 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(r"^\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-14 Thread Jie Fu 傅杰 via cfe-commits

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


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

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

DamonFool wrote:

Thanks @MaskRay and @cor3ntin for the review.

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


[clang-tools-extra] [clang-tidy]fix readability-implicit-bool-conversion false-positives when comparison bool bitfield (PR #77878)

2024-01-14 Thread Piotr Zegar via cfe-commits

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

LGTM, but please note that I didn't get too deep into current ast matching, and 
movement of ExceptionCases higher looks a little bit suspicious. But I assume 
also that current tests cover this deeply.

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


[compiler-rt] [clang] [libcxx] [llvm] [clang-tools-extra] [mlir] [lldb] [flang] [lld] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/77967

>From 48c4463e8817c8ee0f00ffa7422e6fafbe838275 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Wed, 10 Jan 2024 13:46:19 +0200
Subject: [PATCH 01/13] [libc++][numeric] P0543R3: Saturation arithmetic

Implements: https://wg21.link/P0543R3
- https://eel.is/c++draft/numeric.sat

Additional notes:
- Division: https://eel.is/c++draft/expr.mul#4
- Arithmetic conversions: https://eel.is/c++draft/expr.arith.conv#1.5
- Clang builtins: 
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions
---
 libcxx/docs/FeatureTestMacroTable.rst |   2 +-
 libcxx/docs/ReleaseNotes/18.rst   |   7 +-
 libcxx/docs/Status/Cxx2cPapers.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 .../include/__numeric/saturation_arithmetic.h | 135 ++
 libcxx/include/module.modulemap.in|   1 +
 libcxx/include/numeric|  13 ++
 libcxx/include/version|   2 +-
 libcxx/modules/std/numeric.inc|  10 ++
 .../numeric.version.compile.pass.cpp  |  16 +--
 .../version.version.compile.pass.cpp  |  16 +--
 .../numeric.ops.sat/add_sat.pass.cpp  | 129 +
 .../numeric.ops.sat/add_sat.verify.cpp|  39 +
 .../numeric.ops.sat/div_sat.assert.pass.cpp   |  53 +++
 .../numeric.ops.sat/div_sat.pass.cpp  | 108 ++
 .../numeric.ops.sat/div_sat.verify.cpp|  39 +
 .../numeric.ops.sat/mul_sat.pass.cpp  | 119 +++
 .../numeric.ops.sat/mul_sat.verify.cpp|  39 +
 .../numeric.ops.sat/saturate_cast.pass.cpp| 132 +
 .../numeric.ops.sat/saturate_cast.verify.cpp  |  44 ++
 .../numeric.ops.sat/sub_sat.pass.cpp  | 107 ++
 .../numeric.ops.sat/sub_sat.verify.cpp|  39 +
 .../generate_feature_test_macro_components.py |   5 +-
 23 files changed, 1026 insertions(+), 32 deletions(-)
 create mode 100644 libcxx/include/__numeric/saturation_arithmetic.h
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.assert.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.verify.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 893a3b13ca06e0..9dd9c0c023bc8a 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -432,7 +432,7 @@ Status
 --- -
 ``__cpp_lib_rcu``   *unimplemented*
 --- -
-``__cpp_lib_saturation_arithmetic`` *unimplemented*
+``__cpp_lib_saturation_arithmetic`` ``202311L``
 --- -
 ``__cpp_lib_smart_ptr_owner_equality``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 6de7d07e454d34..877e387d9280fd 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -54,12 +54,13 @@ Implemented Papers
 - P2905R2 - Runtime format strings
 - P2918R2 - Runtime format strings II
 - P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
-- P2870R3 - Remove basic_string::reserve()
+- P2870R3 - Remove ``basic_string::reserve()``
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
-- P2821R5 - span.at()
-- P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P2821R5 - ``span.at()``
+- P0521R0 - Proposed Resolution for CA 14 (``shared_ptr`` ``use_count/unique``)
 - P1759R6 - Native handles and file streams
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P0543R3 - Saturation arithmetic
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status

[compiler-rt] [clang] [libcxx] [llvm] [clang-tools-extra] [mlir] [lldb] [flang] [lld] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/77967

>From 48c4463e8817c8ee0f00ffa7422e6fafbe838275 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Wed, 10 Jan 2024 13:46:19 +0200
Subject: [PATCH 01/13] [libc++][numeric] P0543R3: Saturation arithmetic

Implements: https://wg21.link/P0543R3
- https://eel.is/c++draft/numeric.sat

Additional notes:
- Division: https://eel.is/c++draft/expr.mul#4
- Arithmetic conversions: https://eel.is/c++draft/expr.arith.conv#1.5
- Clang builtins: 
https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions
---
 libcxx/docs/FeatureTestMacroTable.rst |   2 +-
 libcxx/docs/ReleaseNotes/18.rst   |   7 +-
 libcxx/docs/Status/Cxx2cPapers.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 .../include/__numeric/saturation_arithmetic.h | 135 ++
 libcxx/include/module.modulemap.in|   1 +
 libcxx/include/numeric|  13 ++
 libcxx/include/version|   2 +-
 libcxx/modules/std/numeric.inc|  10 ++
 .../numeric.version.compile.pass.cpp  |  16 +--
 .../version.version.compile.pass.cpp  |  16 +--
 .../numeric.ops.sat/add_sat.pass.cpp  | 129 +
 .../numeric.ops.sat/add_sat.verify.cpp|  39 +
 .../numeric.ops.sat/div_sat.assert.pass.cpp   |  53 +++
 .../numeric.ops.sat/div_sat.pass.cpp  | 108 ++
 .../numeric.ops.sat/div_sat.verify.cpp|  39 +
 .../numeric.ops.sat/mul_sat.pass.cpp  | 119 +++
 .../numeric.ops.sat/mul_sat.verify.cpp|  39 +
 .../numeric.ops.sat/saturate_cast.pass.cpp| 132 +
 .../numeric.ops.sat/saturate_cast.verify.cpp  |  44 ++
 .../numeric.ops.sat/sub_sat.pass.cpp  | 107 ++
 .../numeric.ops.sat/sub_sat.verify.cpp|  39 +
 .../generate_feature_test_macro_components.py |   5 +-
 23 files changed, 1026 insertions(+), 32 deletions(-)
 create mode 100644 libcxx/include/__numeric/saturation_arithmetic.h
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.assert.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.verify.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.verify.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 893a3b13ca06e0..9dd9c0c023bc8a 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -432,7 +432,7 @@ Status
 --- -
 ``__cpp_lib_rcu``   *unimplemented*
 --- -
-``__cpp_lib_saturation_arithmetic`` *unimplemented*
+``__cpp_lib_saturation_arithmetic`` ``202311L``
 --- -
 ``__cpp_lib_smart_ptr_owner_equality``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 6de7d07e454d34..877e387d9280fd 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -54,12 +54,13 @@ Implemented Papers
 - P2905R2 - Runtime format strings
 - P2918R2 - Runtime format strings II
 - P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
-- P2870R3 - Remove basic_string::reserve()
+- P2870R3 - Remove ``basic_string::reserve()``
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
-- P2821R5 - span.at()
-- P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P2821R5 - ``span.at()``
+- P0521R0 - Proposed Resolution for CA 14 (``shared_ptr`` ``use_count/unique``)
 - P1759R6 - Native handles and file streams
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P0543R3 - Saturation arithmetic
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status

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

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

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

>From c8d733479ee8d0fd7c75c4a623f8c1bc2f132c61 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..44fdef5ac57c86 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 O

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

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

davidchisnall wrote:

Formatting issues were introduced by running clang-format15, should now be 
fixed.

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


[clang] [clang] Remove outdated parts of documentation for #pragma diagnostic (PR #78095)

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

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

GCC has changed over the past decade.
Fixes #51472

>From 1aca1cd3be8209675b8aa3b79b2d626ad9f3c559 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Jan 2024 14:11:16 +0300
Subject: [PATCH] [clang] Remove outdated parts of documentation for #pragma
 diagnostic

GCC has changed over the past decade.
Fixes #51472
---
 clang/docs/UsersManual.rst | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c6a6b06fc04be7..22fbb6764e2f00 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1132,7 +1132,7 @@ Controlling Diagnostics via Pragmas
 Clang can also control what diagnostics are enabled through the use of
 pragmas in the source code. This is useful for turning off specific
 warnings in a section of source code. Clang supports GCC's pragma for
-compatibility with existing source code, as well as several extensions.
+compatibility with existing source code.
 
 The pragma may control any warning that can be used from the command
 line. Warnings may be set to ignored, warning, error, or fatal. The
@@ -1143,8 +1143,7 @@ warnings:
 
   #pragma GCC diagnostic ignored "-Wall"
 
-In addition to all of the functionality provided by GCC's pragma, Clang
-also allows you to push and pop the current warning state. This is
+Clang also allows you to push and pop the current warning state. This is
 particularly useful when writing a header file that will be compiled by
 other people, because you don't know what warning flags they build with.
 
@@ -1157,19 +1156,16 @@ existed.
   #if foo
   #endif foo // warning: extra tokens at end of #endif directive
 
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wextra-tokens"
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wextra-tokens"
 
   #if foo
   #endif foo // no warning
 
-  #pragma clang diagnostic pop
+  #pragma GCC diagnostic pop
 
 The push and pop pragmas will save and restore the full diagnostic state
-of the compiler, regardless of how it was set. That means that it is
-possible to use push and pop around GCC compatible diagnostics and Clang
-will push and pop them appropriately, while GCC will ignore the pushes
-and pops as unknown pragmas. It should be noted that while Clang
+of the compiler, regardless of how it was set. It should be noted that while 
Clang
 supports the GCC pragma, Clang and GCC do not support the exact same set
 of warnings, so even when using GCC compatible #pragmas there is no
 guarantee that they will have identical behaviour on both compilers.

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


[clang] [clang] Remove outdated parts of documentation for #pragma diagnostic (PR #78095)

2024-01-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

GCC has changed over the past decade.
Fixes #51472

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


1 Files Affected:

- (modified) clang/docs/UsersManual.rst (+6-10) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c6a6b06fc04be7..22fbb6764e2f00 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1132,7 +1132,7 @@ Controlling Diagnostics via Pragmas
 Clang can also control what diagnostics are enabled through the use of
 pragmas in the source code. This is useful for turning off specific
 warnings in a section of source code. Clang supports GCC's pragma for
-compatibility with existing source code, as well as several extensions.
+compatibility with existing source code.
 
 The pragma may control any warning that can be used from the command
 line. Warnings may be set to ignored, warning, error, or fatal. The
@@ -1143,8 +1143,7 @@ warnings:
 
   #pragma GCC diagnostic ignored "-Wall"
 
-In addition to all of the functionality provided by GCC's pragma, Clang
-also allows you to push and pop the current warning state. This is
+Clang also allows you to push and pop the current warning state. This is
 particularly useful when writing a header file that will be compiled by
 other people, because you don't know what warning flags they build with.
 
@@ -1157,19 +1156,16 @@ existed.
   #if foo
   #endif foo // warning: extra tokens at end of #endif directive
 
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wextra-tokens"
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wextra-tokens"
 
   #if foo
   #endif foo // no warning
 
-  #pragma clang diagnostic pop
+  #pragma GCC diagnostic pop
 
 The push and pop pragmas will save and restore the full diagnostic state
-of the compiler, regardless of how it was set. That means that it is
-possible to use push and pop around GCC compatible diagnostics and Clang
-will push and pop them appropriately, while GCC will ignore the pushes
-and pops as unknown pragmas. It should be noted that while Clang
+of the compiler, regardless of how it was set. It should be noted that while 
Clang
 supports the GCC pragma, Clang and GCC do not support the exact same set
 of warnings, so even when using GCC compatible #pragmas there is no
 guarantee that they will have identical behaviour on both compilers.

``




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


[mlir] [clang-tools-extra] [lld] [clang] [libcxx] [flang] [compiler-rt] [llvm] [lldb] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,119 @@
+// -*- 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 _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

philnik777 wrote:

Isn't that backwards from what we usually do? Unless it is shown that things 
improve the performance, we don't add optimizations. Also, FWIW: 
https://godbolt.org/z/7rasjdP7j

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


[lldb] [clang-tools-extra] [lld] [compiler-rt] [mlir] [llvm] [flang] [clang] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,119 @@
+// -*- 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 _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))

philnik777 wrote:

@mordante It sounded to me like you've asked for additional builtins for 
extended integer types instead of extending the existing one.

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


[flang] [clang-tools-extra] [lld] [clang] [libcxx] [lldb] [compiler-rt] [mlir] [llvm] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,130 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T div_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+#include "check_constexpr.h"
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{3}, 
IntegerT{4});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, minVal);
+assert(quot == (maxVal / minVal));
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, maxVal);
+assert(quot == (minVal / maxVal));
+  }
+
+  // Saturation - max only
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, 
IntegerT{-1});
+assert(quot == maxVal);
+  }
+
+  return true;
+}
+
+template 
+constexpr bool test_unsigned() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{3}, 
IntegerT{4});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, maxVal);
+assert(quot == (minVal / maxVal));
+  }
+
+  // Unsigned integer devision never overflow
+
+  return true;
+}
+
+template 
+void test_constexpr() {
+  TEST_EXPRESSION_CONSTEXPR(std::div_sat(IntegerT{90}, IntegerT{84}));
+  TEST_EXPRESSION_NOT_CONSTEXPR(std::div_sat(IntegerT{90}, IntegerT{0}));

philnik777 wrote:

We don't want to test the compiler in our tests. There is no need to check that 
division by zero results in an expression that's not constant AFAICT. The check 
for the `constexpr` expression can simply be tested by putting it into a scope 
that is forced to be constant evaluated.

https://github.com/llvm/llvm-project/pull/77967
___
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 support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread via cfe-commits


@@ -18,52 +19,80 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};

phyBrackets wrote:

So I was just curious if its fine to merge the above two if conditions into a 
single one, and then based on ternary operator returning the Range? If you 
think that's not a good idea for readability purpose then it's totally fine.

https://github.com/llvm/llvm-project/pull/77206
___
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 support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread Piotr Zegar via cfe-commits


@@ -18,52 +19,80 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};

PiotrZSL wrote:

No it would look ugly:
```
if (PrevToken.is(tok::unknown) || PrevToken.isNot(tok::equal))
   return {(PrevToken.is(tok::unknown) ? Range.getBegin() : 
PrevToken.getEndLoc()), Range.getEnd()};
```

It would require duplicating an condition. and those 2 conditions are not +- 
same.
First one is: we get invalid token, then let just return what we can (error 
case), second we found something else than =, so lets get that range.

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


[clang-tools-extra] [clang] [llvm] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/77206

>From 66e4026ff568fbd805ddd777596102381e4e0066 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 6 Jan 2024 18:04:57 +
Subject: [PATCH 1/2] [clang-tidy] Add support for in-class initializers in
 readability-redundant-member-init

Support detecting redundant in-class initializers.
Moved from https://reviews.llvm.org/D157262

Fixes: #62525
---
 .../readability/RedundantMemberInitCheck.cpp  | 73 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +-
 .../readability/redundant-member-init.rst |  3 +-
 .../readability/redundant-member-init.cpp | 52 +
 4 files changed, 110 insertions(+), 24 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult &Result) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getAnyMember()
-  << FixItHint::CreateRemoval(Init->getSourceRange());
-} else {
-  di

[llvm] [clang] [clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread via cfe-commits


@@ -18,52 +19,80 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};

phyBrackets wrote:

Yeah that's how I was thinking. Thanks for explaining!

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


[llvm] [clang] [clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread via cfe-commits

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


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


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

2024-01-14 Thread Shahid Iqbal via cfe-commits

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


[lldb] [llvm] [libcxx] [mlir] [clang-tools-extra] [compiler-rt] [lld] [flang] [clang] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

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


@@ -0,0 +1,119 @@
+// -*- 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 _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))

mordante wrote:

I asked both, extend `__builtin_add_overflow` for 128 bit, but typically there 
is a set like
`__builtin_[su]addl{0,2}_overflow` too, I think it would be good to keep that 
pattern from Clang's PoV. Having a new builtin also makes it easy for us to 
query whether `__builtin_add_overflow` has 128-bit support.

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


[clang] [libcxx] [mlir] [llvm] [lld] [compiler-rt] [clang-tools-extra] [flang] [lldb] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

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


@@ -0,0 +1,119 @@
+// -*- 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 _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

mordante wrote:

I don't think it's backwards, I'm quite sure we have used `if constexpr` to do 
optimizations. I see it only matters on `-O0`. Maybe add a comment the compiler 
can do this optimization.

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


[clang] [libcxx] [mlir] [llvm] [lld] [compiler-rt] [clang-tools-extra] [flang] [lldb] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,119 @@
+// -*- 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 _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

philnik777 wrote:

We've used `if constexpr` for optimizations, but generally you have to show 
that an optimization is actually an improvement. You basically requested that 
it's shown that your change isn't one.

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


[llvm] [clang-tools-extra] [clang] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-14 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 59e79f0 - [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (#77206)

2024-01-14 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-01-14T14:52:46+01:00
New Revision: 59e79f0de59d9e4576b6bf562de40a914702efd4

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

LOG: [clang-tidy] Add support for in-class initializers in 
readability-redundant-member-init (#77206)

Support detecting redundant in-class initializers. 
Moved from https://reviews.llvm.org/D157262

Fixes: #62525

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult &Result) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->

[clang-tools-extra] 7f1d757 - [clang-tidy] Fix false-positives in readability-container-size-empty (#74140)

2024-01-14 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-01-14T15:49:16+01:00
New Revision: 7f1d757fb40f06cc1c6b134d770987b340286996

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

LOG: [clang-tidy] Fix false-positives in readability-container-size-empty 
(#74140)

Added support for size-like method returning signed type, and corrected
false positive caused by always-false check for size bellow zero.

Closes #72619

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index f0357fb49eff33..19307b4cdcbe3c 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -291,10 +291,14 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
OpCode == BinaryOperatorKind::BO_NE))
   return;
 
-// Always true, no warnings for that.
-if ((OpCode == BinaryOperatorKind::BO_GE && Value == 0 && ContainerIsLHS) 
||
-(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))
-  return;
+// Always true/false, no warnings for that.
+if (Value == 0) {
+  if ((OpCode == BinaryOperatorKind::BO_GT && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LT && ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_LE && !ContainerIsLHS) ||
+  (OpCode == BinaryOperatorKind::BO_GE && ContainerIsLHS))
+return;
+}
 
 // Do not warn for size > 1, 1 < size, size <= 1, 1 >= size.
 if (Value == 1) {
@@ -306,12 +310,32 @@ void ContainerSizeEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 }
 
+// Do not warn for size < 1, 1 > size, size <= 0, 0 >= size for non signed
+// types
+if ((OpCode == BinaryOperatorKind::BO_GT && Value == 1 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LT && Value == 1 && ContainerIsLHS) 
||
+(OpCode == BinaryOperatorKind::BO_GE && Value == 0 &&
+ !ContainerIsLHS) ||
+(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && ContainerIsLHS)) 
{
+  const Expr *Container = ContainerIsLHS
+  ? BinaryOp->getLHS()->IgnoreImpCasts()
+  : BinaryOp->getRHS()->IgnoreImpCasts();
+  if (Container->getType()
+  .getCanonicalType()
+  .getNonReferenceType()
+  ->isSignedIntegerType())
+return;
+}
+
 if (OpCode == BinaryOperatorKind::BO_NE && Value == 0)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_GT ||
  OpCode == BinaryOperatorKind::BO_GE) &&
 ContainerIsLHS)
   Negation = true;
+
 if ((OpCode == BinaryOperatorKind::BO_LT ||
  OpCode == BinaryOperatorKind::BO_LE) &&
 !ContainerIsLHS)

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 562cb0d9e99ef0..b7007a71d94c0e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -467,7 +467,9 @@ Changes in existing checks
 - Improved :doc:`readability-container-size-empty
   ` check to
   detect comparison between string and empty string literals and support
-  ``length()`` method as an alternative to ``size()``.
+  ``length()`` method as an alternative to ``size()``. Resolved false positives
+  tied to negative values from size-like methods, and one triggered by size
+  checks below zero.
 
 - Improved :doc:`readability-function-size
   ` check configuration to use

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index 3b9e0608418305..84bdbd58b85e96 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -33,7 +33,7 @@ class TemplatedContainer {
 public:
   bool operator==(const TemplatedContainer& other) const;
   bool operator!=(const TemplatedContainer& other) const;
-  int size() const;
+  unsigned long size() const;
   bool empty() const;
 };
 
@@ -42,7 +42,7 @@ class PrivateEmpty {
 public:
   bool operator==(const PrivateEmpty& other) const;
   bool operator!=(const PrivateEmpty& other) const;
-  int size() const;
+  unsigned long size() const;
 private:
   bool empty() 

[clang-tools-extra] [clang-tidy] Fix false-positives in readability-container-size-empty (PR #74140)

2024-01-14 Thread Piotr Zegar via cfe-commits

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-01-14 Thread via cfe-commits

https://github.com/mydeveloperday created 
https://github.com/llvm/llvm-project/pull/78102

Not completely sure if we should handle this with a separate option or just 
treat [[attribute]] the same as __attribute((attribute)) 

This was raised by #77310

>From f95a9a43eff1a2c4cc01cc701e12a306a6d80d6d Mon Sep 17 00:00:00 2001
From: mydeveloperday 
Date: Sun, 14 Jan 2024 16:31:42 +
Subject: [PATCH] [clang-format] BreakAfterAttributes did not take into account
 gnu based attributes

---
 clang/lib/Format/TokenAnnotator.cpp   |  5 
 clang/unittests/Format/FormatTest.cpp | 25 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 18 +
 3 files changed, 48 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 24ce18a64348c1..ffe8428005b41d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -489,6 +489,10 @@ class AnnotatingParser {
 
 if (OpeningParen.is(TT_AttributeLParen))
   CurrentToken->setType(TT_AttributeRParen);
+if (CurrentToken->is(TT_AttributeRParen) && CurrentToken->Next &&
+!CurrentToken->Next->is(tok::kw___attribute)) {
+  CurrentToken->EndsCppAttributeGroup = true;
+}
 if (OpeningParen.is(TT_TypeDeclarationParen))
   CurrentToken->setType(TT_TypeDeclarationParen);
 if (OpeningParen.Previous &&
@@ -983,6 +987,7 @@ class AnnotatingParser {
 CurrentToken->MustBreakBefore = true;
   }
 }
+
 FormatToken *Tok = CurrentToken;
 next();
 // In Verilog primitives' state tables, `:`, `?`, and `-` aren't normal
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fb..2d85395d3c540f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int &i);",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__))\ninline int f(int 
&i);",
+   Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 92f57a77cdaf01..2b255e89307f23 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2381,11 +2381,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_AttributeRParen);
+  EXPECT_FALSE(Tokens[6]->EndsCppAttributeGroup);
+  EXPECT_TRUE(Tokens[7]->EndsCppAttributeGroup);
 
   Tokens = annotate("bool foo __declspec(dllimport);");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_AttributeLParen);
   EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TRUE(Tokens[5]->EndsCppAttributeGroup);
 
   Tokens = annotate("bool __attribute__((unused)) foo;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
@@ -2394,6 +2397,21 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
   EXPECT_TOKEN(Tokens[7], tok::identifier, TT_StartOfName);
+  EXPECT_TRUE(Tokens[6]->EndsCppAttributeGroup);
+
+  Tokens = annotate("bool __attribute__((unused)) __attribute__((const)) 
foo;");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[13], tok::identifier, TT_StartOfName);
+  EXPECT_FALSE(Tokens[8]->EndsCppAttributeGroup);
+  EXPECT_TRUE(Tokens[12]->EndsCppAttributeGroup);
 
   Tokens = a

[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-01-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: MyDeveloperDay (mydeveloperday)


Changes

Not completely sure if we should handle this with a separate option or just 
treat [[attribute]] the same as __attribute((attribute)) 

This was raised by #77310

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


3 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+5) 
- (modified) clang/unittests/Format/FormatTest.cpp (+25) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+18) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 24ce18a64348c1..ffe8428005b41d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -489,6 +489,10 @@ class AnnotatingParser {
 
 if (OpeningParen.is(TT_AttributeLParen))
   CurrentToken->setType(TT_AttributeRParen);
+if (CurrentToken->is(TT_AttributeRParen) && CurrentToken->Next &&
+!CurrentToken->Next->is(tok::kw___attribute)) {
+  CurrentToken->EndsCppAttributeGroup = true;
+}
 if (OpeningParen.is(TT_TypeDeclarationParen))
   CurrentToken->setType(TT_TypeDeclarationParen);
 if (OpeningParen.Previous &&
@@ -983,6 +987,7 @@ class AnnotatingParser {
 CurrentToken->MustBreakBefore = true;
   }
 }
+
 FormatToken *Tok = CurrentToken;
 next();
 // In Verilog primitives' state tables, `:`, `?`, and `-` aren't normal
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fb..2d85395d3c540f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26827,6 +26827,31 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
+TEST_F(FormatTest, BreakAfterGNUAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakAfterAttributes = FormatStyle::ABS_Never;
+
+  verifyFormat("__attribute__((__warn_unused_result__)) const int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__)) int j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__)) inline int f(int &i);",
+   Style);
+
+  Style.BreakAfterAttributes = FormatStyle::ABS_Always;
+  verifyFormat("__attribute__((__warn_unused_result__))\nconst int i;", Style);
+
+  verifyFormat(
+  "__attribute__((other)) __attribute__((__warn_unused_result__))\nint j;",
+  Style);
+
+  verifyFormat("__attribute__((__warn_unused_result__))\ninline int f(int 
&i);",
+   Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 92f57a77cdaf01..2b255e89307f23 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2381,11 +2381,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_AttributeRParen);
+  EXPECT_FALSE(Tokens[6]->EndsCppAttributeGroup);
+  EXPECT_TRUE(Tokens[7]->EndsCppAttributeGroup);
 
   Tokens = annotate("bool foo __declspec(dllimport);");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_AttributeLParen);
   EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TRUE(Tokens[5]->EndsCppAttributeGroup);
 
   Tokens = annotate("bool __attribute__((unused)) foo;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
@@ -2394,6 +2397,21 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
   EXPECT_TOKEN(Tokens[7], tok::identifier, TT_StartOfName);
+  EXPECT_TRUE(Tokens[6]->EndsCppAttributeGroup);
+
+  Tokens = annotate("bool __attribute__((unused)) __attribute__((const)) 
foo;");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[11], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[13], tok::identifier, TT_StartOfName);
+  EXPECT_FALSE(Tokens[8]->EndsCppAttributeGroup);
+  EXPECT_TRUE(Tokens[12]->EndsCppAttributeGroup);
 
   Tokens = annotate("void __attribute__((x)) Foo();");
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;

``




https://github.com/llvm/llvm-project/pull/78102

[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

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

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

C++14 introduced deduced return type for regular functions, but shortly after 
[CWG1878](https://wg21.link/cwg1878) was filed and resolved to disallow deduced 
return types in conversion function templates. So this patch diagnoses such 
usage of deduced return type in C++14 mode onwards.

Fixes #51776

>From 522c7dff31a6f63995877674f9f4282ae60f7aaa Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Jan 2024 19:45:04 +0300
Subject: [PATCH] [clang] Implement CWG1878 "`operator auto` template"

C++14 introduced deduced return type for regular functions, but shortly after 
[CWG1878](https://wg21.link/cwg1878) was filed and resolved to disallow deduced 
return types in conversion function templates. So this patch diagnoses such 
usage of deduced return type in C++14 mode onwards.
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +-
 clang/lib/Sema/SemaDeclCXX.cpp| 10 ++-
 clang/test/CXX/drs/dr18xx.cpp | 26 +
 .../SemaCXX/deduced-return-type-cxx14.cpp | 28 +++
 clang/www/cxx_dr_status.html  |  2 +-
 6 files changed, 57 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be159437..271e641a5ccce0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -560,6 +560,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses unexpanded packs within the template argument lists of 
function template specializations.
 - Clang now diagnoses attempts to bind a bitfield to an NTTP of a reference 
type as erroneous
   converted constant expression and not as a reference to subobject.
+- Clang now diagnoses ``auto`` and ``decltype(auto)`` in declarations of 
conversion function template
+  (`CWG1878: `_)
 
 
 Improvements to Clang's time-trace
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030a..de99d753a13a6c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2411,7 +2411,8 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration"
+  "|in declaration of conversion function template}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 36e53c684ac4dc..613dccbf445f91 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11323,8 +11323,16 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   }
 
   if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+= Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+<< 
Conversion->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc().getSourceRange()
+<< 
llvm::to_underlying(Conversion->getConversionType()->getAs()->getKeyword())
+<< /* in declaration of conversion function template */ 24;
+}
+
 return ConversionTemplate;
+  }
 
   return Conversion;
 }
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 175c39e8b73abb..8be94ed49e639d 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=

[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

C++14 introduced deduced return type for regular functions, but shortly after 
[CWG1878](https://wg21.link/cwg1878) was filed and resolved to disallow deduced 
return types in conversion function templates. So this patch diagnoses such 
usage of deduced return type in C++14 mode onwards.

Fixes #51776

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+9-1) 
- (modified) clang/test/CXX/drs/dr18xx.cpp (+21-5) 
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+22-6) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be1594376..271e641a5ccce0f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -560,6 +560,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses unexpanded packs within the template argument lists of 
function template specializations.
 - Clang now diagnoses attempts to bind a bitfield to an NTTP of a reference 
type as erroneous
   converted constant expression and not as a reference to subobject.
+- Clang now diagnoses ``auto`` and ``decltype(auto)`` in declarations of 
conversion function template
+  (`CWG1878: `_)
 
 
 Improvements to Clang's time-trace
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030ae..de99d753a13a6cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2411,7 +2411,8 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration"
+  "|in declaration of conversion function template}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 36e53c684ac4dc3..613dccbf445f91d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11323,8 +11323,16 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   }
 
   if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+= Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+<< 
Conversion->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc().getSourceRange()
+<< 
llvm::to_underlying(Conversion->getConversionType()->getAs()->getKeyword())
+<< /* in declaration of conversion function template */ 24;
+}
+
 return ConversionTemplate;
+  }
 
   return Conversion;
 }
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 175c39e8b73abbe..8be94ed49e639d2 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-veri

[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 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 fb2cc9b9fc5ae5a544e3009ae153f5ae83c5a89c 
522c7dff31a6f63995877674f9f4282ae60f7aaa -- clang/lib/Sema/SemaDeclCXX.cpp 
clang/test/CXX/drs/dr18xx.cpp clang/test/SemaCXX/deduced-return-type-cxx14.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 613dccbf44..0e7a43859c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11322,13 +11322,18 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   << ClassType << ConvType;
   }
 
-  if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate()) {
+  if (FunctionTemplateDecl *ConversionTemplate =
+  Conversion->getDescribedFunctionTemplate()) {
 if (ConvType->isUndeducedAutoType()) {
   Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
-<< 
Conversion->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc().getSourceRange()
-<< 
llvm::to_underlying(Conversion->getConversionType()->getAs()->getKeyword())
-<< /* in declaration of conversion function template */ 24;
+  << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()
+ .getSourceRange()
+  << llvm::to_underlying(Conversion->getConversionType()
+ ->getAs()
+ ->getKeyword())
+  << /* in declaration of conversion function template */ 24;
 }
 
 return ConversionTemplate;

``




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


[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

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

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

>From 522c7dff31a6f63995877674f9f4282ae60f7aaa Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Jan 2024 19:45:04 +0300
Subject: [PATCH 1/2] [clang] Implement CWG1878 "`operator auto` template"

C++14 introduced deduced return type for regular functions, but shortly after 
[CWG1878](https://wg21.link/cwg1878) was filed and resolved to disallow deduced 
return types in conversion function templates. So this patch diagnoses such 
usage of deduced return type in C++14 mode onwards.
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +-
 clang/lib/Sema/SemaDeclCXX.cpp| 10 ++-
 clang/test/CXX/drs/dr18xx.cpp | 26 +
 .../SemaCXX/deduced-return-type-cxx14.cpp | 28 +++
 clang/www/cxx_dr_status.html  |  2 +-
 6 files changed, 57 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cbce1be1594376..271e641a5ccce0f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -560,6 +560,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses unexpanded packs within the template argument lists of 
function template specializations.
 - Clang now diagnoses attempts to bind a bitfield to an NTTP of a reference 
type as erroneous
   converted constant expression and not as a reference to subobject.
+- Clang now diagnoses ``auto`` and ``decltype(auto)`` in declarations of 
conversion function template
+  (`CWG1878: `_)
 
 
 Improvements to Clang's time-trace
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030ae..de99d753a13a6cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2411,7 +2411,8 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration"
+  "|in declaration of conversion function template}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 36e53c684ac4dc3..613dccbf445f91d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11323,8 +11323,16 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   }
 
   if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+= Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+<< 
Conversion->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc().getSourceRange()
+<< 
llvm::to_underlying(Conversion->getConversionType()->getAs()->getKeyword())
+<< /* in declaration of conversion function template */ 24;
+}
+
 return ConversionTemplate;
+  }
 
   return Conversion;
 }
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 175c39e8b73abbe..8be94ed49e639d2 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,cxx11-17,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions 
-Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected,since-cxx17,since-cxx20,since-

[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits


@@ -686,3 +686,19 @@ auto f(auto x) { // cxx14-error {{'auto' not allowed in 
function prototype}}
 }
 
 }
+
+struct DeducedTargetTypeOfConversionFunction {
+  operator auto() const { return char(); }
+  operator const auto() const { return float(); }

cor3ntin wrote:

can you add tests with references?

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


[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits


@@ -11322,9 +11322,22 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   << ClassType << ConvType;
   }
 
-  if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+  if (FunctionTemplateDecl *ConversionTemplate =
+  Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+  << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()

cor3ntin wrote:

I think this is a slightly bigger hammer than it needs to be.
I think we should just use `->getTypeLoc().getSourceRange()` (yes, it would be 
the source range of the type + qualifiers, but i think that's as good, if not 
better

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


[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits


@@ -11322,9 +11322,22 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   << ClassType << ConvType;
   }
 
-  if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+  if (FunctionTemplateDecl *ConversionTemplate =
+  Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+  << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()
+ .getSourceRange()
+  << llvm::to_underlying(Conversion->getConversionType()
+ ->getAs()
+ ->getKeyword())

cor3ntin wrote:

You do not have to change it here, but this is kind of nasty.
`<< Conversion->getConversionType()` should just work, so this is an artifact 
of a weirdly constructed diagnostic.
I wonder if we should adapt the `err_auto_not_allowed` diagnostic.

We do this weird dance in 3 places
I also will not properly diagnose constrained return types

ie ```cpp
template 
concept C = true;

struct S {
operator C auto();
};```


Writing that iI think we should bite the bullet and change it

```cpp

def err_auto_not_allowed : Error<
  "%select{"use of "
  "%select{class template|function template|variable template|alias template|"
  "template template parameter|concept|template}3 %4 requires template "
  "arguments; argument deduction|%2}0 not allowed "
  "%select{in function prototype"
  "|in non-static struct member|in struct member"
  "|in non-static union member|in union member"
  "|in non-static class member|in interface member"
  "|in exception declaration|in template parameter until C++17|in block literal"
  "|in template argument|in typedef|in type alias|in function return type"
  "|in conversion function type|here|in lambda parameter"
  "|in type allocated by 'new'|in K&R-style function parameter"
  "|in template parameter|in friend declaration|in function prototype that is "
  "not a function declaration|in requires expression parameter"
  "|in array declaration"
  "|in declaration of conversion function template}1">;
```
Should work, we would have to change the 3 uses of err_auto_not_allowed

Can you add tests for constrained auto?



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


[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [libcxx] [mlir] [libc++][concepts] Implements concept helper `__libcpp_integer` (PR #78086)

2024-01-14 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/78086

>From f2008de694bc867efa9632df183f64e3ea194e4e Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sun, 14 Jan 2024 09:34:46 +0200
Subject: [PATCH 1/5] [libc++][concepts] Implements  concept helper
 `__libcpp_integer`

...and tests.
---
 libcxx/include/__concepts/arithmetic.h|   4 +
 .../arithmetic.compile.pass.cpp   | 117 ++
 2 files changed, 121 insertions(+)
 create mode 100644 
libcxx/test/libcxx/concepts/concepts.arithmetic/arithmetic.compile.pass.cpp

diff --git a/libcxx/include/__concepts/arithmetic.h 
b/libcxx/include/__concepts/arithmetic.h
index f41e4c9f2747cc3..0c44f117805f368 100644
--- a/libcxx/include/__concepts/arithmetic.h
+++ b/libcxx/include/__concepts/arithmetic.h
@@ -42,9 +42,13 @@ concept floating_point = is_floating_point_v<_Tp>;
 
 template 
 concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
+
 template 
 concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
 
+template 
+concept __libcpp_integer = __libcpp_unsigned_integer<_Tp> || 
__libcpp_signed_integer<_Tp>;
+
 #endif // _LIBCPP_STD_VER >= 20
 
 _LIBCPP_END_NAMESPACE_STD
diff --git 
a/libcxx/test/libcxx/concepts/concepts.arithmetic/arithmetic.compile.pass.cpp 
b/libcxx/test/libcxx/concepts/concepts.arithmetic/arithmetic.compile.pass.cpp
new file mode 100644
index 000..aefe21d852df52b
--- /dev/null
+++ 
b/libcxx/test/libcxx/concepts/concepts.arithmetic/arithmetic.compile.pass.cpp
@@ -0,0 +1,117 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+#include 
+
+struct SomeObject {};
+
+// Concept helpers for the internal type traits for the fundamental types.
+
+// template 
+// concept __libcpp_unsigned_integer;
+
+// Unsigned
+static_assert(std::__libcpp_unsigned_integer);
+static_assert(std::__libcpp_unsigned_integer);
+static_assert(std::__libcpp_unsigned_integer);
+static_assert(std::__libcpp_unsigned_integer);
+static_assert(std::__libcpp_unsigned_integer);
+static_assert(std::__libcpp_unsigned_integer);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_unsigned_integer<__uint128_t>);
+#endif
+// Signed
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(!std::__libcpp_unsigned_integer<__int128_t>);
+#endif
+// Non-integer
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+static_assert(!std::__libcpp_unsigned_integer);
+
+// template 
+// concept __libcpp_signed_integer;
+
+// Unsigned
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(!std::__libcpp_signed_integer<__uint128_t>);
+#endif
+// Signed
+static_assert(std::__libcpp_signed_integer);
+static_assert(std::__libcpp_signed_integer);
+static_assert(std::__libcpp_signed_integer);
+static_assert(std::__libcpp_signed_integer);
+static_assert(std::__libcpp_signed_integer);
+static_assert(std::__libcpp_signed_integer);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_signed_integer<__int128_t>);
+#endif
+// Non-integer
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+static_assert(!std::__libcpp_signed_integer);
+
+// template 
+// concept __libcpp_integer;
+
+// Unsigned
+static_assert(std::__libcpp_integer);
+static_assert(std::__libcpp_integer);
+static_assert(std::__libcpp_integer);
+static_assert(std::__libcpp_integer);
+static_assert(std::__libcpp_integer);
+static_assert(std::__libcpp_integer)

[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-14 Thread via cfe-commits

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


[clang] [clang-format] Extract utility functions outside of test fixture (PR #78108)

2024-01-14 Thread via cfe-commits

https://github.com/seranu created 
https://github.com/llvm/llvm-project/pull/78108

Extract utility functions outside of test fixture for 
DefinitionBlockSeparatorTest so that these functions can be used by other test 
fixtures. There are no functional changes.

This is a refactoring in preparation of the fix for #42112 

>From 952c782d7e7067fb1e33f24525fe1bcae67edf00 Mon Sep 17 00:00:00 2001
From: Serban Ungureanu 
Date: Sun, 14 Jan 2024 17:40:02 +0200
Subject: [PATCH] [clang-format] Extract utility functions outside of test
 fixture so that they can be used by other test fixtures in this file

---
 .../Format/DefinitionBlockSeparatorTest.cpp   | 119 +-
 1 file changed, 59 insertions(+), 60 deletions(-)

diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp 
b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index f5489498a93b9e..3939f856638545 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -17,73 +17,72 @@
 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 {
-protected:
-  static 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;
-  }
-
-  static std::string
-  separateDefinitionBlocks(llvm::StringRef Code,
-   const FormatStyle &Style = getLLVMStyle()) {
-return separateDefinitionBlocks(
-Code,
-/*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
+std::string removeEmptyLines(llvm::StringRef Code) {
+  std::string Result = "";
+  for (auto Char : Code.str()) {
+if (Result.size()) {
+  auto LastChar = Result.back();
+  if ((Char == '\n' && LastChar == '\n') ||
+  (Char == '\r' && (LastChar == '\r' || LastChar == '\n'))) {
+continue;
+  }
+}
+Result.push_back(Char);
   }
+  return Result;
+}
 
-  static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
-const FormatStyle &Style = getLLVMStyle(),
-llvm::StringRef ExpectedCode = "",
-bool Inverse = true) {
-::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-bool HasOriginalCode = true;
-if (ExpectedCode == "") {
-  ExpectedCode = Code;
-  HasOriginalCode = false;
-}
+std::string
+separateDefinitionBlocks(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+  return separateDefinitionBlocks(
+  Code,
+  /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
+}
 
-EXPECT_EQ(ExpectedCode, separateDefinitionBlocks(ExpectedCode, Style))
-<< "Expected code is not stable";
-if (Inverse) {
-  FormatStyle InverseStyle = Style;
-  if (Style.SeparateDefinitionBlocks == FormatStyle::SDS_Always)
-InverseStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Never;
-  else
-InverseStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
-  EXPECT_NE(ExpectedCode,
-separateDefinitionBlocks(ExpectedCode, InverseStyle))
-  << "Inverse formatting makes no difference";
-}
-std::string CodeToFormat =
-HasOriginalCode ? Code.str() : removeEmptyLines(Code);
-std::string Result = separateDefinitionBlocks(CodeToFormat, Style);
-EXPECT_EQ(ExpectedCode, Result) << "Test failed. Formatted:\n" << Result;
+void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle(),
+   llvm::StringRef ExpectedCode = "", bool Inverse = true) {
+  ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+  bool HasOriginalCode = true;
+  if (ExpectedCode == "") {
+ExpectedCode = Code;
+HasOriginalCode = false;
   }
 
-  static std::string removeEmptyLines(llvm::StringRef Code) {
-std::string Result = "";
-for (auto Char : Code.str()) {
-  if (Res

[clang] [clang-format] Extract utility functions outside of test fixture (PR #78108)

2024-01-14 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang-format] Extract utility functions outside of test fixture (PR #78108)

2024-01-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: serbanu (seranu)


Changes

Extract utility functions outside of test fixture for 
DefinitionBlockSeparatorTest so that these functions can be used by other test 
fixtures. There are no functional changes.

This is a refactoring in preparation of the fix for #42112 

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


1 Files Affected:

- (modified) clang/unittests/Format/DefinitionBlockSeparatorTest.cpp (+59-60) 


``diff
diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp 
b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index f5489498a93b9e..3939f856638545 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -17,73 +17,72 @@
 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 {
-protected:
-  static 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;
-  }
-
-  static std::string
-  separateDefinitionBlocks(llvm::StringRef Code,
-   const FormatStyle &Style = getLLVMStyle()) {
-return separateDefinitionBlocks(
-Code,
-/*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
+std::string removeEmptyLines(llvm::StringRef Code) {
+  std::string Result = "";
+  for (auto Char : Code.str()) {
+if (Result.size()) {
+  auto LastChar = Result.back();
+  if ((Char == '\n' && LastChar == '\n') ||
+  (Char == '\r' && (LastChar == '\r' || LastChar == '\n'))) {
+continue;
+  }
+}
+Result.push_back(Char);
   }
+  return Result;
+}
 
-  static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
-const FormatStyle &Style = getLLVMStyle(),
-llvm::StringRef ExpectedCode = "",
-bool Inverse = true) {
-::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-bool HasOriginalCode = true;
-if (ExpectedCode == "") {
-  ExpectedCode = Code;
-  HasOriginalCode = false;
-}
+std::string
+separateDefinitionBlocks(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+  return separateDefinitionBlocks(
+  Code,
+  /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
+}
 
-EXPECT_EQ(ExpectedCode, separateDefinitionBlocks(ExpectedCode, Style))
-<< "Expected code is not stable";
-if (Inverse) {
-  FormatStyle InverseStyle = Style;
-  if (Style.SeparateDefinitionBlocks == FormatStyle::SDS_Always)
-InverseStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Never;
-  else
-InverseStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
-  EXPECT_NE(ExpectedCode,
-separateDefinitionBlocks(ExpectedCode, InverseStyle))
-  << "Inverse formatting makes no difference";
-}
-std::string CodeToFormat =
-HasOriginalCode ? Code.str() : removeEmptyLines(Code);
-std::string Result = separateDefinitionBlocks(CodeToFormat, Style);
-EXPECT_EQ(ExpectedCode, Result) << "Test failed. Formatted:\n" << Result;
+void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle(),
+   llvm::StringRef ExpectedCode = "", bool Inverse = true) {
+  ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+  bool HasOriginalCode = true;
+  if (ExpectedCode == "") {
+ExpectedCode = Code;
+HasOriginalCode = false;
   }
 
-  static std::string removeEmptyLines(llvm::StringRef Code) {
-std::string Result = "";
-for (auto Char : Code.str()) {
-  if (Result.size()) {
-auto LastChar = Result.back();
-if ((Char == '\n' && LastChar == '\n') ||
-(Char == '\r' && (LastChar == '\r' || LastChar == '\n'))) {
-  continue;
-}
- 

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

2024-01-14 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 this change in a separate PR at 
https://github.com/llvm/llvm-project/pull/78108.

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][Sema] Print more static_assert exprs (PR #74852)

2024-01-14 Thread via cfe-commits

https://github.com/sethp updated https://github.com/llvm/llvm-project/pull/74852

>From f281d34a51f662c934f158e4770774b0dc3588a2 Mon Sep 17 00:00:00 2001
From: Seth Pellegrino 
Date: Thu, 7 Dec 2023 08:45:51 -0800
Subject: [PATCH 1/9] [Clang][Sema] Print more static_assert exprs

This change introspects more values involved in a static_assert, and
extends the supported set of operators for introspection to include
binary operator method calls.

It's intended to address the use-case where a small static_assert helper
looks something like this (via `constexpr-builtin-bit-cast.cpp`):

```c++
struct int_splicer {
  unsigned x;
  unsigned y;

  constexpr bool operator==(const int_splicer &other) const {
return other.x == x && other.y == y;
  }
};
```

When used like so:

```c++
constexpr int_splicer got{1, 2};
constexpr int_splicer want{3, 4};
static_assert(got == want);
```

Then we'd expect to get the error:

```
Static assertion failed due to requirement 'got == want'
```

And this change adds the helpful note:

```
Expression evaluates to '{1, 2} == {3, 4}'
```
---
 clang/lib/Sema/SemaDeclCXX.cpp| 31 ++-
 .../CXX/class/class.compare/class.eq/p3.cpp   | 20 ++--
 .../CXX/class/class.compare/class.rel/p2.cpp  | 10 +++---
 .../over.match.oper/p9-2a.cpp |  2 +-
 clang/test/SemaCXX/static-assert-cxx17.cpp|  2 +-
 5 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecec..e3d46c3140741b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,6 +17219,13 @@ static bool ConvertAPValueToString(const APValue &V, 
QualType T,
 OS << "i)";
   } break;
 
+  case APValue::ValueKind::Array:
+  case APValue::ValueKind::Vector:
+  case APValue::ValueKind::Struct: {
+llvm::raw_svector_ostream OS(Str);
+V.printPretty(OS, Context, T);
+  } break;
+
   default:
 return false;
   }
@@ -17256,11 +17263,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E);
-  Op && Op->getOpcode() != BO_LOr) {
-const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
-const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
-
+  const auto Diagnose = [&](const Expr *LHS, const Expr *RHS,
+const llvm::StringRef &OpStr) {
+LHS = LHS->IgnoreParenImpCasts();
+RHS = RHS->IgnoreParenImpCasts();
 // Ignore comparisons of boolean expressions with a boolean literal.
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
@@ -17287,10 +17293,19 @@ void Sema::DiagnoseStaticAssertDetails(const Expr *E) 
{
  DiagSide[I].ValueString, Context);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  Diag(E->getExprLoc(), diag::note_expr_evaluates_to)
+  << DiagSide[0].ValueString << OpStr << DiagSide[1].ValueString
+  << E->getSourceRange();
 }
+  };
+
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
+Diagnose(Op->getLHS(), Op->getRHS(), Op->getOpcodeStr());
+  } else if (const auto *Op = dyn_cast(E);
+ Op && Op->isInfixBinaryOp()) {
+Diagnose(Op->getArg(0), Op->getArg(1),
+ getOperatorSpelling(Op->getOperator()));
   }
 }
 
diff --git a/clang/test/CXX/class/class.compare/class.eq/p3.cpp 
b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
index 04db022fe73021..53c4dda133301b 100644
--- a/clang/test/CXX/class/class.compare/class.eq/p3.cpp
+++ b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
@@ -6,11 +6,11 @@ struct A {
 };
 
 static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 5});
-static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 0}); // expected-error 
{{failed}}
+static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3,

[clang] [libc] [Libc] Give more functions restrict qualifiers (PR #78061)

2024-01-14 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/78061

>From 5dd1e619ca89d326650894bb2983e21616e765eb Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Sat, 13 Jan 2024 14:09:17 -0500
Subject: [PATCH] [Libc] Give more functions restrict qualifiers

strsep has restrict qualifiers, as well as strtok_r.
Add the restrict qualifiers to them.

Source: https://man7.org/linux/man-pages/man3/strsep.3.html
---
 clang/lib/Headers/llvm_libc_wrappers/string.h| 4 ++--
 clang/test/Analysis/Inputs/system-header-simulator.h | 6 +++---
 clang/test/Analysis/string.c | 4 ++--
 libc/spec/bsd_ext.td | 4 ++--
 libc/src/string/strsep.cpp   | 3 ++-
 libc/src/string/strsep.h | 2 +-
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Headers/llvm_libc_wrappers/string.h 
b/clang/lib/Headers/llvm_libc_wrappers/string.h
index b4fbf17c7e421f7..0ea49cb137606c7 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/string.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/string.h
@@ -51,13 +51,13 @@ char *strcpy(char *__restrict, const char *__restrict) 
__LIBC_ATTRS;
 size_t strcspn(const char *, const char *) __LIBC_ATTRS;
 char *strdup(const char *) __LIBC_ATTRS;
 size_t strlen(const char *) __LIBC_ATTRS;
-char *strncat(char *, const char *, size_t) __LIBC_ATTRS;
+char *strncat(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
 int strncmp(const char *, const char *, size_t) __LIBC_ATTRS;
 char *strncpy(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
 char *strndup(const char *, size_t) __LIBC_ATTRS;
 size_t strnlen(const char *, size_t) __LIBC_ATTRS;
 size_t strspn(const char *, const char *) __LIBC_ATTRS;
-char *strtok(char *__restrict, const char *) __LIBC_ATTRS;
+char *strtok(char *__restrict, const char *__restrict) __LIBC_ATTRS;
 char *strtok_r(char *__restrict, const char *__restrict,
char **__restrict) __LIBC_ATTRS;
 size_t strxfrm(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index cd7ac616bcc67fa..5f969adfdd92cd5 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -71,9 +71,9 @@ int fflush(FILE *stream);
 size_t strlen(const char *);
 
 char *strcpy(char *restrict, const char *restrict);
-char *strncpy(char *dst, const char *src, size_t n);
-char *strsep(char **stringp, const char *delim);
-void *memcpy(void *dst, const void *src, size_t n);
+char *strncpy(char *restrict dst, const char * restrict src, size_t n);
+char *strsep(char ** restrict stringp, const char * restrict delim);
+void *memcpy(void * restrict dst, const void * restrict src, size_t n);
 void *memset(void *s, int c, size_t n);
 
 typedef unsigned long __darwin_pthread_key_t;
diff --git a/clang/test/Analysis/string.c b/clang/test/Analysis/string.c
index d47de9db8228e57..85232624160c062 100644
--- a/clang/test/Analysis/string.c
+++ b/clang/test/Analysis/string.c
@@ -71,7 +71,7 @@ void clang_analyzer_eval(int);
 int scanf(const char *restrict format, ...);
 void *malloc(size_t);
 void free(void *);
-void *memcpy(void *dest, const void *src, size_t n);
+void *memcpy(void *restrict dest, const void *restrict src, size_t n);
 
 //===--===
 // strlen()
@@ -1252,7 +1252,7 @@ int strncasecmp_null_argument(char *a, size_t n) {
 // strsep()
 //===--===
 
-char *strsep(char **stringp, const char *delim);
+char *strsep(char ** restrict stringp, const char * restrict delim);
 
 void strsep_null_delim(char *s) {
   strsep(&s, NULL); // expected-warning{{Null pointer passed as 2nd argument 
to strsep()}}
diff --git a/libc/spec/bsd_ext.td b/libc/spec/bsd_ext.td
index 3829e57e9765a96..c52d5bf10c80a88 100644
--- a/libc/spec/bsd_ext.td
+++ b/libc/spec/bsd_ext.td
@@ -8,12 +8,12 @@ def BsdExtensions : StandardSpec<"BSDExtensions"> {
 FunctionSpec<
 "strlcat",
 RetValSpec,
-[ArgSpec, ArgSpec, ArgSpec]
+[ArgSpec, ArgSpec, 
ArgSpec]
 >,
 FunctionSpec<
 "strlcpy",
 RetValSpec,
-[ArgSpec, ArgSpec, ArgSpec]
+[ArgSpec, ArgSpec, 
ArgSpec]
 >,
 FunctionSpec<
 "strsep",
diff --git a/libc/src/string/strsep.cpp b/libc/src/string/strsep.cpp
index edd2cf07e20a450..5ebf2550744c304 100644
--- a/libc/src/string/strsep.cpp
+++ b/libc/src/string/strsep.cpp
@@ -12,7 +12,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(char *, strsep, (char **stringp, const char *delim)) {
+LLVM_LIBC_FUNCTION(char *, strsep,
+   (char **__restrict stringp, c

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

2024-01-14 Thread via cfe-commits

seranu wrote:

> You'd have to create multiple pull requests. And if they build on each other 
> there is no nice way of doing this on github. You can of course use this one 
> for a change. You can also not split the work, but chances are it will take 
> longer for the changes to land.

I created a new PR for the test refactoring at 
https://github.com/llvm/llvm-project/pull/78108

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] Implement CWG1878 "`operator auto` template" (PR #78103)

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


@@ -11322,9 +11322,22 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   << ClassType << ConvType;
   }
 
-  if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+  if (FunctionTemplateDecl *ConversionTemplate =
+  Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+  << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()

Endilll wrote:

I went this way mostly because I didn't want `const` qualifier on the member 
function to be highlighted, as it's not relevant. But it's getting a bit worse 
than this if we go your way:
```
4 |   operator const auto() const { return 1.2; } // error: conversion 
function template
  |  ^~~~
6 |   operator decltype(auto)() const { return 1.2; } // error: 
conversion function template
  |^~
```

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


[clang] [llvm] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 commented:

Thanks, some comments.

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


[clang] [llvm] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,62 @@
+//===- OffloadWrapper.h --r-*- 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_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
+#define LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/Module.h"
+
+namespace llvm {
+namespace offloading {
+/// Class for embedding and registering offloading images and related objects 
in
+/// a Module.
+class OffloadWrapper {
+public:
+  using EntryArrayTy = std::pair;
+
+  OffloadWrapper(const Twine &Suffix = "", bool EmitSurfacesAndTextures = true)
+  : Suffix(Suffix.str()), EmitSurfacesAndTextures(EmitSurfacesAndTextures) 
{
+  }
+
+  /// Wraps the input device images into the module \p M as global symbols and
+  /// registers the images with the OpenMP Offloading runtime libomptarget.
+  /// \param EntryArray Optional pair pointing to the `__start` and `__stop`
+  /// symbols holding the `__tgt_offload_entry` array.
+  llvm::Error wrapOpenMPBinaries(
+  llvm::Module &M, llvm::ArrayRef> Images,
+  std::optional EntryArray = std::nullopt) const;
+
+  /// Wraps the input fatbinary image into the module \p M as global symbols 
and
+  /// registers the images with the CUDA runtime.
+  /// \param EntryArray Optional pair pointing to the `__start` and `__stop`
+  /// symbols holding the `__tgt_offload_entry` array.
+  llvm::Error
+  wrapCudaBinary(llvm::Module &M, llvm::ArrayRef Images,
+ std::optional EntryArray = std::nullopt) const;
+
+  /// Wraps the input bundled image into the module \p M as global symbols and
+  /// registers the images with the HIP runtime.
+  /// \param EntryArray Optional pair pointing to the `__start` and `__stop`
+  /// symbols holding the `__tgt_offload_entry` array.
+  llvm::Error
+  wrapHIPBinary(llvm::Module &M, llvm::ArrayRef Images,
+std::optional EntryArray = std::nullopt) const;
+
+protected:
+  /// Suffix used when emitting symbols. It defaults to the empty string.
+  std::string Suffix;
+
+  /// Whether to emit surface and textures registration code. It defaults to
+  /// false.
+  bool EmitSurfacesAndTextures;

jhuber6 wrote:

So, I wasn't sure about this either. I know that CUDA emits these 
`__cudaRegisterSurface` calls, but I can't seem to find them in any of the 
exported libraries. It caused linker errors due to that and I was too lazy to 
fix it. Wondering if they've been deprecated, maybe @tra knows.

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


[llvm] [clang] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits


@@ -568,32 +590,45 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
 
 } // namespace
 
-Error wrapOpenMPBinaries(Module &M, ArrayRef> Images) {
-  GlobalVariable *Desc = createBinDesc(M, Images);
+Error OffloadWrapper::wrapOpenMPBinaries(
+Module &M, ArrayRef> Images,
+std::optional EntryArray) const {
+  GlobalVariable *Desc = createBinDesc(
+  M, Images,
+  EntryArray
+  ? *EntryArray
+  : offloading::getOffloadEntryArray(M, "omp_offloading_entries"),

jhuber6 wrote:

Thinking that this argument shouldn't be default, it should be up to whoever 
calls it to create such an array. For the linker wrapper it would be getting 
the offloading utility first. Making these arrays is quite complicated for 
implicit default behavior if we're expecting other things to happen I feel.

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


[llvm] [clang] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits

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


[llvm] [clang] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits


@@ -568,32 +590,45 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
 
 } // namespace
 
-Error wrapOpenMPBinaries(Module &M, ArrayRef> Images) {
-  GlobalVariable *Desc = createBinDesc(M, Images);
+Error OffloadWrapper::wrapOpenMPBinaries(
+Module &M, ArrayRef> Images,
+std::optional EntryArray) const {
+  GlobalVariable *Desc = createBinDesc(
+  M, Images,
+  EntryArray
+  ? *EntryArray
+  : offloading::getOffloadEntryArray(M, "omp_offloading_entries"),
+  Suffix);
   if (!Desc)
 return createStringError(inconvertibleErrorCode(),
  "No binary descriptors created.");
-  createRegisterFunction(M, Desc);
-  createUnregisterFunction(M, Desc);
+  createRegisterFunction(M, Desc, Suffix);
+  createUnregisterFunction(M, Desc, Suffix);
   return Error::success();
 }
 
-Error wrapCudaBinary(Module &M, ArrayRef Image) {
-  GlobalVariable *Desc = createFatbinDesc(M, Image, /* IsHIP */ false);
+Error OffloadWrapper::wrapCudaBinary(
+Module &M, ArrayRef Image,
+std::optional EntryArray) const {
+  GlobalVariable *Desc = createFatbinDesc(M, Image, /* IsHIP */ false, Suffix);
   if (!Desc)
 return createStringError(inconvertibleErrorCode(),
  "No fatinbary section created.");
 
-  createRegisterFatbinFunction(M, Desc, /* IsHIP */ false);
+  createRegisterFatbinFunction(M, Desc, /* IsHIP */ false, EntryArray, Suffix,
+   EmitSurfacesAndTextures);
   return Error::success();
 }
 
-Error wrapHIPBinary(Module &M, ArrayRef Image) {
-  GlobalVariable *Desc = createFatbinDesc(M, Image, /* IsHIP */ true);
+Error OffloadWrapper::wrapHIPBinary(
+Module &M, ArrayRef Image,
+std::optional EntryArray) const {
+  GlobalVariable *Desc = createFatbinDesc(M, Image, /* IsHIP */ true, Suffix);
   if (!Desc)
 return createStringError(inconvertibleErrorCode(),
  "No fatinbary section created.");
 
-  createRegisterFatbinFunction(M, Desc, /* IsHIP */ true);
+  createRegisterFatbinFunction(M, Desc, /* IsHIP */ true, EntryArray, Suffix,

jhuber6 wrote:

Can you fix these comments while you're at it? LLVM inline comments should be 
`/*IsHIP=*/`

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


[llvm] [clang] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,62 @@
+//===- OffloadWrapper.h --r-*- 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_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
+#define LLVM_FRONTEND_OFFLOADING_OFFLOADWRAPPER_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/IR/Module.h"
+
+namespace llvm {
+namespace offloading {
+/// Class for embedding and registering offloading images and related objects 
in
+/// a Module.
+class OffloadWrapper {

jhuber6 wrote:

I feel like these should just be free functions and the extra two bits of state 
here are additional default arguments like you've done with `EntryArray`.

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


[clang] [llvm] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits


@@ -568,32 +590,45 @@ void createRegisterFatbinFunction(Module &M, 
GlobalVariable *FatbinDesc,
 
 } // namespace
 
-Error wrapOpenMPBinaries(Module &M, ArrayRef> Images) {
-  GlobalVariable *Desc = createBinDesc(M, Images);
+Error OffloadWrapper::wrapOpenMPBinaries(
+Module &M, ArrayRef> Images,
+std::optional EntryArray) const {
+  GlobalVariable *Desc = createBinDesc(
+  M, Images,
+  EntryArray
+  ? *EntryArray
+  : offloading::getOffloadEntryArray(M, "omp_offloading_entries"),
+  Suffix);
   if (!Desc)
 return createStringError(inconvertibleErrorCode(),
  "No binary descriptors created.");
-  createRegisterFunction(M, Desc);
-  createUnregisterFunction(M, Desc);
+  createRegisterFunction(M, Desc, Suffix);

jhuber6 wrote:

What is the Suffix  for exactly? It might be better just to give it some 
generic name, since the executed use currently it always `_cuda_` or `_omp_` as 
a name within some other stuff.

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


[clang] [llvm] [llvm][frontend][offloading] Move clang-linker-wrapper/OffloadWrapper.* to llvm/Frontend/Offloading (PR #78057)

2024-01-14 Thread Joseph Huber via cfe-commits

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-14 Thread via cfe-commits


@@ -0,0 +1,205 @@
+// RUN: %clang_cc1 -std=c++2a -verify -fsyntax-only -triple wasm32 %s
+// RUN: %clang_cc1 -std=c++2a -verify -fsyntax-only -triple 
aarch64_be-linux-gnu %s
+
+struct A {
+  int a, b[3], c;
+  bool operator==(const A&) const = default;
+};
+
+constexpr auto a0 = A{0, 0, 3, 4, 5};
+
+// expected-note@+1 {{evaluates to '(const A){0, {0, 3, 4}, 5} == A{1, {2, 3, 
4}, 5}'}}
+static_assert(a0 == A{1, {2, 3, 4}, 5}); // expected-error {{failed}}
+
+// `operator==` wrapper type
+struct _arr {
+  const int b[3];
+  constexpr bool operator==(const int rhs[3]) const {
+for (unsigned i = 0; i < sizeof(b) / sizeof(int); i++)
+  if (b[i] != rhs[i])
+return false;
+return true;
+  }
+};
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc99-extensions"
+static_assert(_arr{{2, 3, 4}} == (const int[3]){2, 3, 4});
+#pragma clang diagnostic pop
+
+// expected-note@+1 {{{evaluates to '_arr{{2, 3, 4}} == (const int[3]){0, 3, 
4}'}}}
+static_assert(_arr{2, 3, 4} == a0.b); // expected-error {{failed}}
+
+
+struct B {
+  int a, c; // named the same just to keep things fresh
+  bool operator==(const B&) const = default;
+};
+
+// expected-note@+1 {{evaluates to 'B{7, 6} == B{8, 6}'}}
+static_assert(B{7, 6} == B{8, 6}); // expected-error {{failed}}
+
+typedef int v4si __attribute__((__vector_size__(16)));
+
+struct C: A, B {
+  enum { E1, E2 } e;
+  bool operator==(const C&) const = default;
+};
+
+constexpr auto cc = C{A{1, {2, 3, 4}, 5}, B{7, 6}, C::E1};
+
+// expected-note@+1 {{{evaluates to '(const C){{1, {2, 3, 4}, 5}, {7, 6}, 
C::E1} == C{{0, {0, 3, 4}, 5}, {5, 0}, C::E2}'}}}
+static_assert(cc == C{a0, {5}, C::E2}); // expected-error {{failed}}
+
+enum E { numerator };
+constexpr E e = E::numerator;
+static_assert(numerator == ((E)0));
+static_assert(((E)0) == ((E)7)); // expected-error {{failed}}
+// expected-note@-1 {{{evaluates to 'numerator == (E)7'}}}
+
+typedef enum { something } MyEnum;
+static_assert(MyEnum::something == ((MyEnum)7)); // expected-error {{failed}}
+// expected-note@-1 {{{evaluates to 'something == (MyEnum)7'}}}
+
+// unnamed enums
+static_assert(C::E1 == (decltype(C::e))0);
+// expected-note@+1 {{{evaluates to 'C::E1 == C::E2'}}}
+static_assert(C::E1 == (decltype(C::e))1); // expected-error {{failed}}
+static_assert(C::E1 == (decltype(C::e))7); // expected-error {{failed}}
+// expected-note@-1 {{{evaluates to 'C::E1 == (decltype(C::e))7'}}}
+
+constexpr enum { declLocal } ee = declLocal;
+static_assert(((decltype(ee))0) == ee);
+static_assert(((decltype(ee))0) == ((decltype(ee))7)); // expected-error 
{{failed}}
+// expected-note@-1 {{{evaluates to 'declLocal == (decltype(ee))7'}}}
+
+struct TU {
+  enum { S, U } Tag;
+  union {
+signed int s;
+unsigned int u;
+  };
+  constexpr bool operator==(const TU& rhs) const {
+if (Tag != rhs.Tag) return false;
+switch (Tag) {
+  case S:
+return s == rhs.s;
+  case U:
+return u == rhs.u;
+}
+  };
+};
+static_assert(TU{TU::S, {7}} == TU{TU::S, {.s=7}});
+static_assert(TU{TU::U, {.u=9}} == TU{TU::U, {.u=9}});
+
+// expected-note@+1 {{{evaluates to 'TU{TU::S, {.s = 7}} == TU{TU::S, {.s = 
6}}'}}}
+static_assert(TU{TU::S, {.s=7}} == TU{TU::S, {.s=6}}); // expected-error 
{{failed}}
+static_assert(TU{TU::U, {.u=7}} == TU{TU::U, {.u=9}}); // expected-error 
{{failed}}
+// expected-note@-1 {{{evaluates to 'TU{TU::U, {.u = 7}} == TU{TU::U, {.u = 
9}}'}}}
+
+struct EnumArray {
+  const E nums[3];
+  constexpr bool operator==(const E rhs[3]) const {
+for (unsigned i = 0; i < sizeof(nums) / sizeof(E); i++)
+  if (nums[i] != rhs[i])
+return false;
+return true;
+
+  };
+};
+static_assert(EnumArray{} == (const E[3]){numerator});
+
+// expected-note@+1 {{{evaluates to 'EnumArray{{}} == (const E[3]){numerator, 
(const E)1, (const E)2}'}}}
+static_assert(EnumArray{} == (const E[3]){(E)0, (E)1, (E)2}); // 
expected-error {{failed}}
+
+// define `std::bit_cast`
+namespace std {
+template 
+constexpr To bit_cast(const From &from) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from);
+}
+} // namespace std
+
+namespace vector {
+typedef int v4si __attribute__((__vector_size__(16)));
+
+struct V {
+  v4si v;
+
+  // doesn't work
+  // vectors are not contextually convertable to `bool`, and
+  // `==` on vectors produces a vector of element-wise results
+  // bool operator==(const V&) const = default;
+
+  constexpr bool operator==(const V& rhs) const {
+// doesn't work
+// __builtin_reduce_and is not valid in a constant expression
+// return __builtin_reduce_and(b == rhs.b) && __builtin_reduce_and(v == 
rhs.v);
+
+// also doesn't work
+// surprisingly, b[0] is also not valid in a constant expression (nor v[0])
+// return b[0] == rhs.b[0] && ...
+
+// cmp an array of bytes that does element-wise comparisons that's the 
same size as v
+struct cmp {
+  unsigned char v [sizeof(v4s

[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-14 Thread Samuel Thibault via cfe-commits

https://github.com/sthibaul updated 
https://github.com/llvm/llvm-project/pull/78065

>From fefe6175fa21c668f58d69b0acc9abb89af981ab Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sun, 14 Jan 2024 19:01:52 +0100
Subject: [PATCH 1/3] hurd: Fix indent

---
 clang/test/Driver/hurd.cpp | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/test/Driver/hurd.cpp b/clang/test/Driver/hurd.cpp
index 1c4ba16af063d7e..8934997b107aed6 100644
--- a/clang/test/Driver/hurd.cpp
+++ b/clang/test/Driver/hurd.cpp
@@ -2,8 +2,8 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s
-// CHECK: "-cc1"
-// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK:  "-cc1"
+// CHECK:  "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../include/c++/10"
 /// Debian specific - the path component after 'include' is i386-gnu even
 /// though the installation is i686-gnu.
@@ -29,9 +29,9 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   --stdlib=platform -static 2>&1 | FileCheck 
--check-prefix=CHECK-STATIC %s
-// CHECK-STATIC: "-cc1"
-// CHECK-STATIC: "-static-define"
-// CHECK-STATIC: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-STATIC:  "-cc1"
+// CHECK-STATIC:  "-static-define"
+// CHECK-STATIC:  "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../include/c++/10"
 /// Debian specific - the path component after 'include' is i386-gnu even
 /// though the installation is i686-gnu.
@@ -57,9 +57,9 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   -shared 2>&1 | FileCheck --check-prefix=CHECK-SHARED %s
-// CHECK-SHARED: "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-SHARED: "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginS.o"
-// CHECK-SHARED: "-L
+// CHECK-SHARED:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-SHARED:  "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginS.o"
+// CHECK-SHARED:  "-L
 // CHECK-SHARED-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-gnu/10"
 // CHECK-SHARED-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../lib32"
 // CHECK-SHARED-SAME: {{^}} "-L[[SYSROOT]]/lib/i386-gnu"

>From 1f4e490c8160c36e0cba130f4587f8ab0b4cfecb Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sun, 14 Jan 2024 19:02:30 +0100
Subject: [PATCH 2/3] hurd: Strengthen test

---
 clang/test/Driver/hurd.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/hurd.cpp b/clang/test/Driver/hurd.cpp
index 8934997b107aed6..f76d2cd73a01662 100644
--- a/clang/test/Driver/hurd.cpp
+++ b/clang/test/Driver/hurd.cpp
@@ -43,7 +43,7 @@
 // CHECK-STATIC-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-STATIC-SAME: {{^}} "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include"
 // CHECK-STATIC:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-STATIC:  "-static"
+// CHECK-STATIC-SAME: "-static"
 // CHECK-STATIC:  "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginT.o"
 // CHECK-STATIC:  "-L
 // CHECK-STATIC-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-gnu/10"

>From 151e8d9325e68259bfbf227d148ed4b508125856 Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sat, 13 Jan 2024 20:16:03 +0100
Subject: [PATCH 3/3] Hurd: Add x86_64 support

---
 clang/lib/Basic/Targets.cpp   |  2 +
 clang/lib/Driver/ToolChains/Gnu.cpp   | 29 ++-
 clang/lib/Driver/ToolChains/Hurd.cpp  | 16 +++-
 .../usr/lib/gcc/x86_64-gnu/10/crtbegin.o  |  0
 .../usr/x86_64-gnu/bin/as |  0
 .../usr/x86_64-gnu/bin/ld |  0
 .../usr/x86_64-gnu/lib/.keep  |  0
 .../basic_hurd_tree/lib/x86_64-gnu/.keep  |  0
 .../Driver/Inputs/basic_hurd_tree/lib64/.keep |  0
 .../usr/include/x86_64-gnu/.keep  |  0
 .../usr/include/x86_64-gnu/c++/10/.keep   |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbegin.o  |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbeginS.o |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbeginT.o |  0
 .../basic_hurd_tree/usr/lib/x86_64-gnu/.keep  |  0
 .../Inputs/basic_hurd_tree/usr/lib64/.keep|  0
 clang/test/Driver/hurd.cpp| 79 +++
 llvm/unittests/TargetParser/TripleTest.cpp|  6 ++
 18 files changed, 129 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/lib/gcc/x86_64-gnu/10/crtbegin.o
 create mode 100755 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/bin/as
 create mode 100755 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_hurd_tree/

[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-14 Thread Samuel Thibault via cfe-commits


@@ -78,3 +78,82 @@
 // CHECK-CROSS: 
"{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/../../../../i686-gnu/bin/ld"
 {{.*}} "-m" "elf_i386"
 // CHECK-CROSS: 
"{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/crtbegin.o"
 // CHECK-CROSS: 
"-L{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/../../../../i686-gnu/lib"
+
+// RUN: %clang -### %s --target=x86_64-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
+// RUN:   --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK-64 %s
+// CHECK-64: "-cc1"
+// CHECK-64: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-64-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/c++/10"
+/// Debian specific - the path component after 'include' is x86_64-gnu even
+/// though the installation is x86_64-gnu.
+// CHECK-64-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/x86_64-gnu/c++/10"
+// CHECK-64-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/c++/10/backward"
+// CHECK-64-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-64:  "-internal-externc-isystem"
+// CHECK-64-SAME: {{^}} "[[SYSROOT]]/usr/include/x86_64-gnu"
+// CHECK-64-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-64-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// CHECK-64:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-64:  "-dynamic-linker" "/lib/ld-x86-64.so.1"
+// CHECK-64:  "{{.*}}/usr/lib/gcc/x86_64-gnu/10/crtbegin.o"
+// CHECK-64:  "-L
+// CHECK-64-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10"
+// CHECK-64-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../lib64"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/lib/x86_64-gnu"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/lib/../lib64"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/x86_64-gnu"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/../lib64"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/lib"
+// CHECK-64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+// RUN: %clang -### %s --target=x86_64-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
+// RUN:   --stdlib=platform -static 2>&1 | FileCheck 
--check-prefix=CHECK-64-STATIC %s
+// CHECK-64-STATIC: "-cc1"
+// CHECK-64-STATIC: "-static-define"
+// CHECK-64-STATIC: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-64-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/c++/10"
+/// Debian specific - the path component after 'include' is x86_64-gnu even
+/// though the installation is x86_64-gnu.
+// CHECK-64-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/x86_64-gnu/c++/10"
+// CHECK-64-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../include/c++/10/backward"
+// CHECK-64-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
+// CHECK-64-STATIC:  "-internal-externc-isystem"
+// CHECK-64-STATIC-SAME: {{^}} "[[SYSROOT]]/usr/include/x86_64-gnu"
+// CHECK-64-STATIC-SAME: {{^}} "-internal-externc-isystem" 
"[[SYSROOT]]/include"
+// CHECK-64-STATIC-SAME: {{^}} "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include"
+// CHECK-64-STATIC:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-64-STATIC:  "-static"
+// CHECK-64-STATIC:  "{{.*}}/usr/lib/gcc/x86_64-gnu/10/crtbeginT.o"
+// CHECK-64-STATIC:  "-L
+// CHECK-64-STATIC-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10"
+// CHECK-64-STATIC-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../lib64"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/lib/x86_64-gnu"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/lib/../lib64"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/x86_64-gnu"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/../lib64"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/lib"
+// CHECK-64-STATIC-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+// RUN: %clang -### %s --target=x86_64-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
+// RUN:   -shared 2>&1 | FileCheck --check-prefix=CHECK-64-SHARED %s
+// CHECK-64-SHARED: "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-64-SHARED: "{{.*}}/usr/lib/gcc/x86_64-gnu/10/crtbeginS.o"
+// CHECK-64-SHARED: "-L
+// CHECK-64-SHARED-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10"
+// CHECK-64-SHARED-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc/x86_64-gnu/10/../../../../lib64"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/lib/x86_64-gnu"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/lib/../lib64"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/x86_64-gnu"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/../lib64"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/lib"
+// CHECK-64-SHARED-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+// RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
+// RUN: --gcc-toolchain=%S/Inputs/basic_cross_hurd_tree/usr \
+// RUN

[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-14 Thread via cfe-commits

sethp wrote:

I think this change is useful enough on its own that I'd like us to consider 
merging it: to me, teaching the compiler to do additional diffing or further 
clarifying the structure of complicated sub-objects feel like they'd benefit 
from having this work as a fallback. We could then build up from concrete 
examples of "it would be nice if the compiler diff'd here", and rely on the 
much more capable (and domain-aware) programmers to use the complete evaluation 
result for solving the general case.

That said, I'm curious if there's an upper limit we ought to set here on the 
size of the string: copy & paste work fine for hundreds or even thousands of 
characters, but if someone `static_assert`s on a multi-GB `const char*`, they 
might be in for a bit of trouble.

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


[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-14 Thread Samuel Thibault via cfe-commits


@@ -2477,7 +2477,7 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
   "x86_64-slackware-linux", "x86_64-unknown-linux",
-  "x86_64-amazon-linux"};
+  "x86_64-amazon-linux","x86_64-gnu"};

sthibaul wrote:

That was it indeed, I have replaced with some code.

It's not debian that picked it up, but the GNU toolchains (GNU/Hurd was 
supposed to be the "pure GNU" system).

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


[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-14 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 270c6cbda2acf1f60891e10667af6d9741b62009 
151e8d9325e68259bfbf227d148ed4b508125856 -- clang/lib/Basic/Targets.cpp 
clang/lib/Driver/ToolChains/Gnu.cpp clang/lib/Driver/ToolChains/Hurd.cpp 
clang/test/Driver/hurd.cpp llvm/unittests/TargetParser/TripleTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 16da6c0425..891a0278af 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2659,11 +2659,9 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 switch (TargetTriple.getArch()) {
 case llvm::Triple::x86_64:
   LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
-  TripleAliases.append(begin(X86_64HurdTriples),
-   end(X86_64HurdTriples));
+  TripleAliases.append(begin(X86_64HurdTriples), end(X86_64HurdTriples));
   BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
-  BiarchTripleAliases.append(begin(X86HurdTriples),
- end(X86HurdTriples));
+  BiarchTripleAliases.append(begin(X86HurdTriples), end(X86HurdTriples));
   break;
 case llvm::Triple::x86:
   LibDirs.append(begin(X86LibDirs), end(X86LibDirs));

``




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


[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-14 Thread Samuel Thibault via cfe-commits

https://github.com/sthibaul updated 
https://github.com/llvm/llvm-project/pull/78065

>From fefe6175fa21c668f58d69b0acc9abb89af981ab Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sun, 14 Jan 2024 19:01:52 +0100
Subject: [PATCH 1/3] hurd: Fix indent

---
 clang/test/Driver/hurd.cpp | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/test/Driver/hurd.cpp b/clang/test/Driver/hurd.cpp
index 1c4ba16af063d7e..8934997b107aed6 100644
--- a/clang/test/Driver/hurd.cpp
+++ b/clang/test/Driver/hurd.cpp
@@ -2,8 +2,8 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   --stdlib=platform 2>&1 | FileCheck --check-prefix=CHECK %s
-// CHECK: "-cc1"
-// CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK:  "-cc1"
+// CHECK:  "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../include/c++/10"
 /// Debian specific - the path component after 'include' is i386-gnu even
 /// though the installation is i686-gnu.
@@ -29,9 +29,9 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   --stdlib=platform -static 2>&1 | FileCheck 
--check-prefix=CHECK-STATIC %s
-// CHECK-STATIC: "-cc1"
-// CHECK-STATIC: "-static-define"
-// CHECK-STATIC: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-STATIC:  "-cc1"
+// CHECK-STATIC:  "-static-define"
+// CHECK-STATIC:  "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-STATIC-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../include/c++/10"
 /// Debian specific - the path component after 'include' is i386-gnu even
 /// though the installation is i686-gnu.
@@ -57,9 +57,9 @@
 
 // RUN: %clang -### %s --target=i686-pc-hurd-gnu 
--sysroot=%S/Inputs/basic_hurd_tree \
 // RUN:   -shared 2>&1 | FileCheck --check-prefix=CHECK-SHARED %s
-// CHECK-SHARED: "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-SHARED: "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginS.o"
-// CHECK-SHARED: "-L
+// CHECK-SHARED:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-SHARED:  "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginS.o"
+// CHECK-SHARED:  "-L
 // CHECK-SHARED-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-gnu/10"
 // CHECK-SHARED-SAME: {{^}} 
"-L[[SYSROOT]]/usr/lib/gcc/i686-gnu/10/../../../../lib32"
 // CHECK-SHARED-SAME: {{^}} "-L[[SYSROOT]]/lib/i386-gnu"

>From 1f4e490c8160c36e0cba130f4587f8ab0b4cfecb Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sun, 14 Jan 2024 19:02:30 +0100
Subject: [PATCH 2/3] hurd: Strengthen test

---
 clang/test/Driver/hurd.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/hurd.cpp b/clang/test/Driver/hurd.cpp
index 8934997b107aed6..f76d2cd73a01662 100644
--- a/clang/test/Driver/hurd.cpp
+++ b/clang/test/Driver/hurd.cpp
@@ -43,7 +43,7 @@
 // CHECK-STATIC-SAME: {{^}} "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-STATIC-SAME: {{^}} "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include"
 // CHECK-STATIC:  "{{.*}}ld" "--sysroot=[[SYSROOT:[^"]+]]"
-// CHECK-STATIC:  "-static"
+// CHECK-STATIC-SAME: "-static"
 // CHECK-STATIC:  "{{.*}}/usr/lib/gcc/i686-gnu/10/crtbeginT.o"
 // CHECK-STATIC:  "-L
 // CHECK-STATIC-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-gnu/10"

>From 156ed9e34ba1cd6f6e83e485842a37d1c132450e Mon Sep 17 00:00:00 2001
From: Samuel Thibault 
Date: Sat, 13 Jan 2024 20:16:03 +0100
Subject: [PATCH 3/3] Hurd: Add x86_64 support

---
 clang/lib/Basic/Targets.cpp   |  2 +
 clang/lib/Driver/ToolChains/Gnu.cpp   | 27 ++-
 clang/lib/Driver/ToolChains/Hurd.cpp  | 16 +++-
 .../usr/lib/gcc/x86_64-gnu/10/crtbegin.o  |  0
 .../usr/x86_64-gnu/bin/as |  0
 .../usr/x86_64-gnu/bin/ld |  0
 .../usr/x86_64-gnu/lib/.keep  |  0
 .../basic_hurd_tree/lib/x86_64-gnu/.keep  |  0
 .../Driver/Inputs/basic_hurd_tree/lib64/.keep |  0
 .../usr/include/x86_64-gnu/.keep  |  0
 .../usr/include/x86_64-gnu/c++/10/.keep   |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbegin.o  |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbeginS.o |  0
 .../usr/lib/gcc/x86_64-gnu/10/crtbeginT.o |  0
 .../basic_hurd_tree/usr/lib/x86_64-gnu/.keep  |  0
 .../Inputs/basic_hurd_tree/usr/lib64/.keep|  0
 clang/test/Driver/hurd.cpp| 79 +++
 llvm/unittests/TargetParser/TripleTest.cpp|  6 ++
 18 files changed, 127 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/lib/gcc/x86_64-gnu/10/crtbegin.o
 create mode 100755 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/bin/as
 create mode 100755 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_cross_hurd_tree/usr/x86_64-gnu/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_hurd_tree/

[clang] [mlir] [libcxx] [llvm] [clang-tools-extra] [libc++][concepts] Implements concept helper `__libcpp_integer` (PR #78086)

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

mordante wrote:

> ```
> 86\test\std\utilities\format\format.functions\Output\formatted_size.pass.cpp.dir\t.tmp.exe'
> # .---command stderr
> # | Traceback (most recent call last):
> # |   File "C:\ws\src\libcxx\utils\run.py", line 72, in 
> # | exit(main())
> # |   File "C:\ws\src\libcxx\utils\run.py", line 68, in main
> # | return subprocess.call(commandLine, cwd=args.execdir, env=env, 
> shell=False)
> # |   File "c:\python39\lib\subprocess.py", line 349, in call
> # | with Popen(*popenargs, **kwargs) as p:
> # |   File "c:\python39\lib\subprocess.py", line 951, in __init__
> # | self._execute_child(args, executable, preexec_fn, close_fds,
> # |   File "c:\python39\lib\subprocess.py", line 1420, in _execute_child
> # | hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
> # | OSError: [WinError 225] Operation did not complete successfully because 
> the file contains a virus or potentially unwanted 
> ```

I've seen that happen before :-/ 

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


[clang] [mlir] [libcxx] [llvm] [clang-tools-extra] [libc++][concepts] Implements concept helper `__libcpp_integer` (PR #78086)

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

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

LGTM! Thanks! Please ping me when you've update your other patch with these 
changes.

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


[llvm] [mlir] [clang-tools-extra] [clang] [libcxx] [libc++][concepts] Implements concept helper `__libcpp_integer` (PR #78086)

2024-01-14 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

> LGTM! Thanks! Please ping me when you've update your other patch with these 
> changes.

Thank you! I'll ping you when I am ready with the other patch. I still need to 
implement additional tests.

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


  1   2   3   >