[clang] [clang] Restrict use of scalar types in vector builtins (PR #119423)

2025-01-05 Thread Matt Arsenault via cfe-commits


@@ -68,15 +66,18 @@ void test_builtin_elementwise_add_sat(float f1, float f2, 
double d1, double d2,
   long long int i2, si8 vi1, si8 vi2,
   unsigned u1, unsigned u2, u4 vu1, u4 vu2,
   _BitInt(31) bi1, _BitInt(31) bi2,
-  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2) {
+  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2,
+  char c1, char c2, unsigned char uc1,
+  unsigned char uc2, short s1, short s2,
+  unsigned short us1, unsigned short us2) {
   // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
   // CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
   // CHECK-NEXT: call i64 @llvm.sadd.sat.i64(i64 [[I1]], i64 [[I2]])
   i1 = __builtin_elementwise_add_sat(i1, i2);
 
   // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
   // CHECK-NEXT: call i64 @llvm.sadd.sat.i64(i64 [[I1]], i64 10)
-  i1 = __builtin_elementwise_add_sat(i1, 10);
+  i1 = __builtin_elementwise_add_sat(i1, (long long int)10);

arsenm wrote:

If you were using int64_t, should use ll if using long long 

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


[clang] [clang-repl] Implement value printing of custom types (PR #84769)

2025-01-05 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

Hey @vgvassilev 

Just curious to know as to what work is left here and if any help is needed for 
the same ?



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


[clang] [Clang][Driver][Test] Created test for unsupported driver options (PR #120900)

2025-01-05 Thread via cfe-commits

https://github.com/GeorgeKA updated 
https://github.com/llvm/llvm-project/pull/120900

>From faf8597dbb58a08991e11e9c4b9a0aad2f0b4234 Mon Sep 17 00:00:00 2001
From: GeorgeKA 
Date: Sun, 22 Dec 2024 09:42:36 -0500
Subject: [PATCH 1/3] [Clang][Driver][Test] Created test for unsupported driver
 options

Created generate_unsupported_in_drivermode.py which generates a Lit
regression test file that validates that options are only exposed to
intended driver modes.

The options and driver modes are parsed from Options.td, whose path
should be provided on the command line. See
clang/include/clang/Driver/Options.td

The path to the TableGen executable can optionally be provided.
Otherwise, the script will search for it.
---
 .../generate_unsupported_in_drivermode.py | 249 ++
 1 file changed, 249 insertions(+)
 create mode 100644 clang/utils/generate_unsupported_in_drivermode.py

diff --git a/clang/utils/generate_unsupported_in_drivermode.py 
b/clang/utils/generate_unsupported_in_drivermode.py
new file mode 100644
index 00..f32c2c7c5a0d7c
--- /dev/null
+++ b/clang/utils/generate_unsupported_in_drivermode.py
@@ -0,0 +1,249 @@
+#!/usr/bin/env python3
+
+""" generate_unsupported_in_drivermode.py
+
+usage: python generate_unsupported_in_drivermode.py /Options.td 
[/llvm-tblgen]
+
+This script generates a Lit regression test file that validates that options
+are only exposed to intended driver modes.
+
+The options and driver modes are parsed from Options.td, whose path should be
+provided on the command line. See clang/include/clang/Driver/Options.td
+
+The path to the TableGen executable can optionally be provided. Otherwise, the
+script will search for it.
+
+Logic:
+1) For each option, (records of class "Option"), and for each driver, (records 
of class "OptionVisibility")
+a. if the option's "Visibility" field includes the driver flavour, skip 
processing this option for this driver
+b. if the option is part of an option group, (the record has the "Group" 
property),
+   and the group's "Visibility" field includes the driver flavor, skip 
processing this option for this driver
+c. otherwise this option is not supported by this driver flavor, and this 
pairing is saved for testing
+2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to 
parse for expected output. Ex: "error: unknown argument"
+"""
+
+import sys
+import shutil
+import os
+import json
+import subprocess
+from pathlib import Path
+
+LLVM_TABLEGEN = "llvm-tblgen"
+LIT_TEST_PATH = "../test/Driver/Inputs/unsupported-driver-options-check.ll"
+INCLUDE_PATH = "../../llvm/include"
+PREFIX = "CHECK-"
+
+# Strings used in Options.td for various driver flavours
+OPTION_CC1AS = "CC1AsOption"
+OPTION_CC1 = "CC1Option"
+OPTION_CL = "CLOption"
+OPTION_DXC = "DXCOption"
+OPTION_DEFAULT = "DefaultVis"
+OPTION_FC1 = "FC1Option"
+OPTION_FLANG = "FlangOption"
+
+# Error messages output from each driver
+ERROR_MSG_CC1AS = ": error: unknown argument"
+ERROR_MSG_CC1 = "error: unknown argument"
+ERROR_MSG_CL = "" # TODO
+ERROR_MSG_DXC = "" # TODO
+ERROR_MSG_DEFAULT = "clang: error: unknown argument"
+ERROR_MSG_FC1 = "error: unknown argument"
+ERROR_MSG_FLANG = "flang: error: unknown argument"
+
+# Lit CHECK prefixes
+CHECK_PREFIX_CC1AS = PREFIX + OPTION_CC1AS
+CHECK_PREFIX_CC1 = PREFIX + OPTION_CC1
+CHECK_PREFIX_CL = PREFIX + OPTION_CL
+CHECK_PREFIX_DXC = PREFIX + OPTION_DXC
+CHECK_PREFIX_DEFAULT = PREFIX + OPTION_DEFAULT
+CHECK_PREFIX_FC1 = PREFIX + OPTION_FC1
+CHECK_PREFIX_FLANG = PREFIX + OPTION_FLANG
+
+LIT_TEST_NOTE = ("; NOTE: This lit test was automatically generated to 
validate " +
+ "unintentionally exposed arguments to various driver 
flavours.\n"
+ "; NOTE: To make changes, see " + 
Path(__file__).resolve().as_posix()
+ + " from which it was generated.\n\n")
+
+def print_usage():
+""" Print valid usage of this script
+"""
+sys.exit( "usage: python " + sys.argv[0] + " /Options.td 
[/llvm-tblgen]" )
+
+def find_file(file_name, search_path):
+""" Find the given file name under a search path
+"""
+result = []
+
+for root, dir, files in os.walk(search_path):
+if file_name in files:
+result.append(os.path.join(root, file_name))
+return result
+
+def is_valid_file(path, expected_name):
+""" Is a file valid
+Check if a given path is to a file, and if it matches the expected file 
name
+"""
+if path.is_file() and path.name == expected_name:
+return True
+else:
+return False
+
+def find_tablegen():
+""" Validate the TableGen executable
+"""
+result = shutil.which(LLVM_TABLEGEN)
+if result is None:
+sys.exit("Unable to find " + LLVM_TABLEGEN + ".\nExiting")
+else:
+print("TableGen found: " + result)
+return result
+
+def find_groups(group_sequence, options_json, option):
+""" Find the groups for a given option
+Note that

[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/10] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Nathan Ridge via cfe-commits


@@ -2235,6 +2235,24 @@ TEST_P(ASTMatchersTest, 
ArgumentCountIs_CXXConstructExpr) {
  Constructor1Arg));
 }
 
+TEST_P(ASTMatchersTest, HasDependentName_DependentScopeDeclRefExpr) {
+  if (!GetParam().isCXX() || GetParam().hasDelayedTemplateParsing()) {
+// FIXME: Fix this test to work with delayed template parsing.
+return;
+  }
+
+  EXPECT_TRUE(matches("template  class X : T { void f() { T::v; } };",
+  dependentScopeDeclRefExpr(hasDependentName("v";
+
+  EXPECT_TRUE(matches("template  struct S { static T Foo; };"
+  "template  void x() { (void)S::Foo; }",
+  dependentScopeDeclRefExpr(hasDependentName("Foo";
+
+  EXPECT_TRUE(matches("template  struct S { static T foo(); };"
+  "template  void x() { S::foo; }",

HighCommander4 wrote:

nit: it would make the example more realistic if the function is actually 
called, as in `S::foo();`

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


[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Nathan Ridge via cfe-commits

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

Thanks! The update looks good, I have one more minor suggestion for a change 
which I'll just go ahead and make before merging.

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


[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Nathan Ridge via cfe-commits

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


[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-05 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-05 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

Oh, previously we didn't allow `-fallow-pcm-with-compiler-errors` so we didn't 
meet such problems. Out of curiosity (not a blocking issue), why do you want 
this feature for C++20 modules?

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


[clang] [clang] Do not serialize function definitions without a body (PR #121550)

2025-01-05 Thread Chuanqi Xu via cfe-commits


@@ -6227,8 +6227,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext 
&Context,
 // Add a trailing update record, if any. These must go last because we
 // lazily load their attached statement.
 if (!GeneratingReducedBMI || !CanElideDeclDef(D)) {
-  if (HasUpdatedBody) {
-const auto *Def = cast(D);
+  assert(!(HasUpdatedBody && HasAddedVarDefinition) &&
+ "Declaration can not be both a FunctionDecl and a VarDecl");
+  if (const auto *Def = dyn_cast(D);
+  HasUpdatedBody && Def->doesThisDeclarationHaveABody()) {

ChuanqiXu9 wrote:

Logically, it looks better to not set `HasUpdatedBody` if the declaration 
doesn't have a body.

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


[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/121656

>From 4cd48886384570e0e5bb0b712f4fd45f8decd27e Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 4 Jan 2025 17:36:05 +0100
Subject: [PATCH 1/4] [Clang][ASTMatcher] Add a matcher for the name of a
 DependentScopeDeclRefExpr

---
 clang/docs/LibASTMatchersReference.html   | 13 +
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h | 11 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  | 15 +++
 5 files changed, 42 insertions(+)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fc557888013254..6a03aeb5eec2a1 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3449,6 +3449,19 @@ Narrowing Matchers
 
 
 
+MatcherDependentScopeDeclRefExpr>hasDependentNamestd::string 
N
+Matches the 
dependent name of a dependent scope decl ref expr.
+
+Matches the dependent name of a dependent scope decl ref expr
+
+Given:
+
+  template CXXDependentScopeMemberExpr>memberHasSameNameAsBoundNodestd::string
 BindingID
 Matches template-dependent, but known, 
member names against an already-bound
 node
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e75fc447636e0..4ef69ca4c743ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1116,6 +1116,8 @@ AST Matchers
 
 - Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
 
+- Add ``hasDependentName`` matcher to match the dependent name of a dependent 
scope decl ref expr.
+
 clang-format
 
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index dd0fedb2cda2d4..6828fc6da1d5cf 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3257,6 +3257,17 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, 
memberHasSameNameAsBoundNode,
   });
 }
 
+/// Matches the dependent name of a dependent scope decl ref expr
+///
+/// Given:
+/// \code
+///  template  class X : T { void f() { T::v; } };
+/// \endcode
+/// \c dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`
+AST_MATCHER_P(DependentScopeDeclRefExpr, hasDependentName, std::string, N) {
+  return Node.getDeclName().getAsString() == N;
+}
+
 /// Matches C++ classes that are directly or indirectly derived from a class
 /// matching \c Base, or Objective-C classes that directly or indirectly
 /// subclass a class matching \c Base.
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 97e6bbc093fe46..336d3a14f79559 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -314,6 +314,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasDeducedType);
   REGISTER_MATCHER(hasDefaultArgument);
   REGISTER_MATCHER(hasDefinition);
+  REGISTER_MATCHER(hasDependentName);
   REGISTER_MATCHER(hasDescendant);
   REGISTER_MATCHER(hasDestinationType);
   REGISTER_MATCHER(hasDirectBase);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 056b7c7b571ef4..4278e3d4fe5959 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2235,6 +2235,21 @@ TEST_P(ASTMatchersTest, 
ArgumentCountIs_CXXConstructExpr) {
  Constructor1Arg));
 }
 
+TEST_P(ASTMatchersTest, hasDependentName_DependentScopeDeclRefExpr) {
+  if (!GetParam().isCXX() || GetParam().hasDelayedTemplateParsing()) {
+// FIXME: Fix this test to work with delayed template parsing.
+return;
+  }
+
+  EXPECT_TRUE(matches("template  class X : T { void f() { T::v; } };",
+  dependentScopeDeclRefExpr(hasDependentName("v";
+
+  EXPECT_TRUE(
+  matches("template  struct S { static T Foo; };"
+  "template  void declToImport() { (void)S::Foo; }",
+  dependentScopeDeclRefExpr(hasDependentName("Foo";
+}
+
 TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
 
   // Member functions:

>From e653a695260143304b71af662f98b1826082d2f6 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 5 Jan 2025 13:42:55 +0100
Subject: [PATCH 2/4] Address code review comments

---
 clang/docs/LibASTMatchersReference.html |  4 ++--
 clang/include/clang/ASTMatchers/ASTMatchers.h  

[clang] [C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2025-01-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

It looks nice to backport this if we're still in the release circle for 19.x

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


[clang] [C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2025-01-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

/cherry-pick 9f1e9f682d0a85ea013ccbce6a3ec4ac1be8335

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


[clang] [C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2025-01-05 Thread Chuanqi Xu via cfe-commits

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


[clang] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-01-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > Why is this submitted against the release/19.x branch? Is this a backport? 
> > If so, please indicate which commit it backports.
> 
> Not a backport but a new commit. I have now re-submitted it against `main`, 
> but I'd like it back-ported to `19.x` if possible.

It is better to fix the test failures (or announce they are not relevant with 
your pr)

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


[clang] [C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2025-01-05 Thread via cfe-commits

llvmbot wrote:


Failed to cherry-pick: 9f1e9f682d0a85ea013ccbce6a3ec4ac1be8335

https://github.com/llvm/llvm-project/actions/runs/12625144536

Please manually backport the fix and push it to your github fork.  Once this is 
done, please create a [pull 
request](https://github.com/llvm/llvm-project/compare)

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


[clang] [compiler-rt] [llvm] LLVMCoverage: Unify getCoverageForFile and getCoverageForFunction. NFC (PR #120842)

2025-01-05 Thread NAKAMURA Takumi via cfe-commits

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


[clang] f3590c1 - [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (#121656)

2025-01-05 Thread via cfe-commits

Author: Amr Hesham
Date: 2025-01-05T21:17:06-05:00
New Revision: f3590c16da9e6bb5c3b22f4593ef794a43dc8b5d

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

LOG: [Clang][ASTMatcher] Add a matcher for the name of a 
DependentScopeDeclRefExpr (#121656)

Add the `hasDependentName` matcher to match the name of
`DependentScopeDeclRefExpr`

Fixes https://github.com/llvm/llvm-project/issues/121610

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fc557888013254..18f9e7d6c0ea06 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3449,6 +3449,19 @@ Narrowing Matchers
 
 
 
+MatcherDependentScopeDeclRefExpr>hasDependentNamestd::string 
N
+Matches the 
dependent name of a DependentScopeDeclRefExpr.
+
+Matches the dependent name of a DependentScopeDeclRefExpr
+
+Given:
+
+  template CXXDependentScopeMemberExpr>memberHasSameNameAsBoundNodestd::string
 BindingID
 Matches template-dependent, but known, 
member names against an already-bound
 node

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e75fc447636e0..f2b27893b7a9db 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1116,6 +1116,8 @@ AST Matchers
 
 - Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
 
+- Add ``hasDependentName`` matcher to match the dependent name of a 
DependentScopeDeclRefExpr.
+
 clang-format
 
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index dd0fedb2cda2d4..f10135d7a901f1 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3257,6 +3257,17 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, 
memberHasSameNameAsBoundNode,
   });
 }
 
+/// Matches the dependent name of a DependentScopeDeclRefExpr
+///
+/// Given:
+/// \code
+///  template  class X : T { void f() { T::v; } };
+/// \endcode
+/// \c dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`
+AST_MATCHER_P(DependentScopeDeclRefExpr, hasDependentName, std::string, N) {
+  return Node.getDeclName().getAsString() == N;
+}
+
 /// Matches C++ classes that are directly or indirectly derived from a class
 /// matching \c Base, or Objective-C classes that directly or indirectly
 /// subclass a class matching \c Base.

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 97e6bbc093fe46..336d3a14f79559 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -314,6 +314,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasDeducedType);
   REGISTER_MATCHER(hasDefaultArgument);
   REGISTER_MATCHER(hasDefinition);
+  REGISTER_MATCHER(hasDependentName);
   REGISTER_MATCHER(hasDescendant);
   REGISTER_MATCHER(hasDestinationType);
   REGISTER_MATCHER(hasDirectBase);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 056b7c7b571ef4..f3d953454173ca 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2235,6 +2235,24 @@ TEST_P(ASTMatchersTest, 
ArgumentCountIs_CXXConstructExpr) {
  Constructor1Arg));
 }
 
+TEST_P(ASTMatchersTest, HasDependentName_DependentScopeDeclRefExpr) {
+  if (!GetParam().isCXX() || GetParam().hasDelayedTemplateParsing()) {
+// FIXME: Fix this test to work with delayed template parsing.
+return;
+  }
+
+  EXPECT_TRUE(matches("template  class X : T { void f() { T::v; } };",
+  dependentScopeDeclRefExpr(hasDependentName("v";
+
+  EXPECT_TRUE(matches("template  struct S { static T Foo; };"
+  "template  void x() { (void)S::Foo; }",
+  dependentScopeDeclRefExpr(hasDependentName("Foo";
+
+  EXPECT_TRUE(matches("template  struct S { static T foo(); };"
+  "template  void x() { S::foo(); }",
+  dependentScopeDeclRefExpr(hasDependentName("foo";
+}

[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 closed 
https://github.com/llvm/llvm-project/pull/121656
___
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 incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-05 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/121323

>From 896db4495ff2c29c2e623d92e004ef64f49c8dd0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 30 Dec 2024 16:38:29 +0800
Subject: [PATCH] [clang-tidy] fix incorrect configuration file path resolving
 when file paths contain `..`

`makeAbsolute` will not normalize path. When getting parent folder, `..` will 
go into the subfolder instead of the parent folder.
---
 .../clang-tidy/ClangTidyOptions.cpp   | 32 ---
 .../clang-tidy/ClangTidyOptions.h |  4 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++
 .../Inputs/normalized-path/code.cpp   |  0
 .../normalized-path/error-config/.clang-tidy  |  1 +
 .../infrastructure/normalized-path.test   |  3 ++
 6 files changed, 32 insertions(+), 11 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/code.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/error-config/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/normalized-path.test

diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 445c7f85c900c6..1ad278e5d9a795 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
@@ -298,12 +299,11 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef 
FileName) {
   if (ConfigOptions.InheritParentConfig.value_or(false)) {
 LLVM_DEBUG(llvm::dbgs()
<< "Getting options for file " << FileName << "...\n");
-assert(FS && "FS must be set.");
 
-llvm::SmallString<128> AbsoluteFilePath(FileName);
-
-if (!FS->makeAbsolute(AbsoluteFilePath)) {
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+llvm::ErrorOr> AbsoluteFilePath =
+getNormalizedAbsolutePath(FileName);
+if (AbsoluteFilePath) {
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
 }
   }
   RawOptions.emplace_back(ConfigOptions,
@@ -334,6 +334,17 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
   OverrideOptions(std::move(OverrideOptions)),
   ConfigHandlers(std::move(ConfigHandlers)) {}
 
+llvm::ErrorOr>
+FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
+  assert(FS && "FS must be set.");
+  llvm::SmallString<128> NormalizedAbsolutePath = {Path};
+  std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+  if (Err)
+return Err;
+  llvm::sys::path::remove_dots(NormalizedAbsolutePath, 
/*remove_dot_dot=*/true);
+  return NormalizedAbsolutePath;
+}
+
 void FileOptionsBaseProvider::addRawFileOptions(
 llvm::StringRef AbsolutePath, std::vector &CurOptions) {
   auto CurSize = CurOptions.size();
@@ -396,16 +407,15 @@ std::vector
 FileOptionsProvider::getRawOptions(StringRef FileName) {
   LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
   << "...\n");
-  assert(FS && "FS must be set.");
-
-  llvm::SmallString<128> AbsoluteFilePath(FileName);
 
-  if (FS->makeAbsolute(AbsoluteFilePath))
+  llvm::ErrorOr> AbsoluteFilePath =
+  getNormalizedAbsolutePath(FileName);
+  if (!AbsoluteFilePath)
 return {};
 
   std::vector RawOptions =
-  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 85d5a02ebbc1bc..95abe932d56ccf 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
 
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -237,6 +238,9 @@ class FileOptionsBaseProvider : public 
DefaultOptionsProvider {
   void addRawFileOptions(llvm::StringRef AbsolutePath,
  std::vector &CurOptions);
 
+  llvm::ErrorOr>
+  getNormalizedAbsolutePath(llvm::StringRef AbsolutePath);
+
   /// Try to read configuration files from \p Directory using registered
   /// \c ConfigHandlers.
   std::optional tryReadConfigFile(llvm::StringRef Directory);
diff --git a/clang-tools-extra/docs/

[clang-tools-extra] [clang-tidy][NFC] optimize cache for config option (PR #121406)

2025-01-05 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/121406

>From 8f8e8c5141fcb6b6d468c80cf3ceb4fdd88eecca Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 1 Jan 2025 01:11:36 +0800
Subject: [PATCH] [clang-tidy][NFC] optimize cache for config option

Current implement will cache ConfigOptions for each path, it will create lots 
of copy of options when project have deep nested folder structure.
New implement use vector to store options and only cache the index to reduce 
memory usage and avoid meanless copy
---
 .../clang-tidy/ClangTidyOptions.cpp   | 47 ++-
 .../clang-tidy/ClangTidyOptions.h |  5 +-
 2 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 445c7f85c900c6..9ecb255d916e9b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -337,33 +337,34 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
 void FileOptionsBaseProvider::addRawFileOptions(
 llvm::StringRef AbsolutePath, std::vector &CurOptions) {
   auto CurSize = CurOptions.size();
-
   // Look for a suitable configuration file in all parent directories of the
   // file. Start with the immediate parent directory and move up.
-  StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
-  for (StringRef CurrentPath = Path; !CurrentPath.empty();
-   CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
-std::optional Result;
-
-auto Iter = CachedOptions.find(CurrentPath);
-if (Iter != CachedOptions.end())
-  Result = Iter->second;
-
-if (!Result)
-  Result = tryReadConfigFile(CurrentPath);
-
-if (Result) {
-  // Store cached value for all intermediate directories.
-  while (Path != CurrentPath) {
+  StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
+  auto MemorizedConfigFile =
+  [this, &RootPath](StringRef CurrentPath) -> std::optional 
{
+auto Iter = CachedOptions.Memorized.find(CurrentPath);
+if (Iter != CachedOptions.Memorized.end())
+  return CachedOptions.Storage[Iter->second];
+std::optional OptionsSource = 
tryReadConfigFile(CurrentPath);
+if (OptionsSource) {
+  const size_t Index = CachedOptions.Storage.size();
+  CachedOptions.Storage.emplace_back(OptionsSource.value());
+  while (RootPath != CurrentPath) {
 LLVM_DEBUG(llvm::dbgs()
-   << "Caching configuration for path " << Path << ".\n");
-if (!CachedOptions.count(Path))
-  CachedOptions[Path] = *Result;
-Path = llvm::sys::path::parent_path(Path);
+   << "Caching configuration for path " << RootPath << ".\n");
+CachedOptions.Memorized[RootPath] = Index;
+RootPath = llvm::sys::path::parent_path(RootPath);
   }
-  CachedOptions[Path] = *Result;
-
-  CurOptions.push_back(*Result);
+  CachedOptions.Memorized[CurrentPath] = Index;
+  RootPath = llvm::sys::path::parent_path(CurrentPath);
+}
+return OptionsSource;
+  };
+  for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
+   CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
+if (std::optional Result =
+MemorizedConfigFile(CurrentPath)) {
+  CurOptions.emplace_back(Result.value());
   if (!Result->first.InheritParentConfig.value_or(false))
 break;
 }
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 85d5a02ebbc1bc..568f60cf98b21f 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -241,7 +241,10 @@ class FileOptionsBaseProvider : public 
DefaultOptionsProvider {
   /// \c ConfigHandlers.
   std::optional tryReadConfigFile(llvm::StringRef Directory);
 
-  llvm::StringMap CachedOptions;
+  struct OptionsCache {
+llvm::StringMap Memorized;
+llvm::SmallVector Storage;
+  } CachedOptions;
   ClangTidyOptions OverrideOptions;
   ConfigFileHandlers ConfigHandlers;
   llvm::IntrusiveRefCntPtr FS;

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


[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/121313

>From d5403c8f7dcdf15409febf1851bd8dc19b2babab Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 6 Oct 2024 00:41:48 -0400
Subject: [PATCH] [clangd] Add a unit test suite for HeuristicResolver

Fixes https://github.com/clangd/clangd/issues/2154
---
 clang-tools-extra/clangd/HeuristicResolver.h  |   5 +-
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../unittests/HeuristicResolverTests.cpp  | 540 ++
 3 files changed, 544 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp

diff --git a/clang-tools-extra/clangd/HeuristicResolver.h 
b/clang-tools-extra/clangd/HeuristicResolver.h
index dcc063bbc4adc0..c130e0677e86dd 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.h
+++ b/clang-tools-extra/clangd/HeuristicResolver.h
@@ -26,13 +26,14 @@ class UnresolvedUsingValueDecl;
 
 namespace clangd {
 
-// This class heuristic resolution of declarations and types in template code.
+// This class handles heuristic resolution of declarations and types in 
template
+// code.
 //
 // As a compiler, clang only needs to perform certain types of processing on
 // template code (such as resolving dependent names to declarations, or
 // resolving the type of a dependent expression) after instantiation. Indeed,
 // C++ language features such as template specialization mean such resolution
-// cannot be done accurately before instantiation
+// cannot be done accurately before instantiation.
 //
 // However, template code is written and read in uninstantiated form, and 
clangd
 // would like to provide editor features like go-to-definition in template code
diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index dffdcd5d014ca9..8dba8088908d5e 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -64,6 +64,7 @@ add_unittest(ClangdUnitTests ClangdTests
   GlobalCompilationDatabaseTests.cpp
   HeadersTests.cpp
   HeaderSourceSwitchTests.cpp
+  HeuristicResolverTests.cpp
   HoverTests.cpp
   IncludeCleanerTests.cpp
   IndexActionTests.cpp
diff --git a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp 
b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
new file mode 100644
index 00..42fc46f85b7a4e
--- /dev/null
+++ b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
@@ -0,0 +1,540 @@
+//===-- HeuristicResolverTests.cpp --*- 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
+//
+//===--===//
+#include "HeuristicResolver.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest.h"
+
+using namespace clang::ast_matchers;
+using clang::clangd::HeuristicResolver;
+using testing::ElementsAre;
+
+namespace clang {
+namespace {
+
+// Helper for matching a sequence of elements with a variadic list of matchers.
+// Usage: `ElementsAre(matchAdapter(Vs, MatchFunction)...)`, where `Vs...` is
+//a variadic list of matchers.
+// For each `V` in `Vs`, this will match the corresponding element `E` if
+// `MatchFunction(V, E)` is true.
+MATCHER_P2(matchAdapter, MatcherForElement, MatchFunction, "matchAdapter") {
+  return MatchFunction(MatcherForElement, arg);
+}
+
+template 
+using ResolveFnT = std::function(
+const HeuristicResolver *, const InputNode *)>;
+
+// Test heuristic resolution on `Code` using the resolution procedure
+// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
+// `InputNode` and returns a `std::vector`.
+// `InputMatcher` should be an AST matcher that matches a single node to pass 
as
+// input to `ResolveFn`, bound to the ID "input". `OutputMatchers` should be 
AST
+// matchers that each match a single node, bound to the ID "output".
+template 
+void expectResolution(llvm::StringRef Code, ResolveFnT ResolveFn,
+  const InputMatcher &IM, const OutputMatchers &...OMS) {
+  auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
+  auto &Ctx = TU->getASTContext();
+  auto InputMatches = match(IM, Ctx);
+  ASSERT_EQ(1u, InputMatches.size());
+  const auto *Input = InputMatches[0].template getNodeAs("input");
+  ASSERT_TRUE(Input);
+
+  auto OutputNodeMatches = [&](auto &OutputMatcher, auto &Actual) {
+auto OutputMatches = match(OutputMatcher, Ctx);
+if (OutputMatches.size() != 1u)
+  return false;
+const auto *ExpectedOutput =
+OutputMatches[0].template getNodeAs("output");
+

[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

In the latest update, matchers for the `DependentNameType` cases are revised to 
be more specific. Here, the approach I took was to match the context in which 
the types appear.

@hokein I believe your comment about using more specific matchers should be 
fully addressed now :)

https://github.com/llvm/llvm-project/pull/121313
___
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 modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-05 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 commented:

Please update release note.
I agree to enable this feature by default if adding an option.

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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2025-01-05 Thread via cfe-commits


@@ -174,6 +177,8 @@ struct OMPContext {
 
   BitVector ActiveTraits = BitVector(unsigned(TraitProperty::Last) + 1);
   SmallVector ConstructTraits;
+  static int DeviceNum;
+  static StringRef DeviceNumID;

Ritanya-B-Bharadwaj wrote:

Agreed. I have made it non-static. 

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/15] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang] [C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)

2025-01-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@jijjijj automated backport failed. You can create a PR to release/19.x 
manually to backport it.

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


[clang] [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (PR #112724)

2025-01-05 Thread NAKAMURA Takumi via cfe-commits


@@ -101,6 +101,25 @@ enum ForDefinition_t : bool {
   ForDefinition = true
 };
 
+class CounterPair : public std::pair {

chapuni wrote:

Added comments, and refactored more.
- Introduce the subclass `ValueOpt` and move mask operations into it.
- Name the pair as `Executed` and `Skipped`. (I prefer `std::pair` though...)

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


[clang] [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (PR #112724)

2025-01-05 Thread NAKAMURA Takumi via cfe-commits


@@ -122,6 +123,18 @@ class CodeGenPGO {
 Address MCDCCondBitmapAddr, llvm::Value *Val,
 CodeGenFunction &CGF);
 
+  void markStmtAsUsed(bool Skipped, const Stmt *S) {
+// Do nothing.
+  }
+
+  void markStmtMaybeUsed(const Stmt *S) {
+// Do nothing.
+  }
+
+  void verifyCounterMap() {

chapuni wrote:

Done.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/12] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),

ccotter wrote:

I updated the check to use `areStatementsIdentical` and `HasSideEffects`

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/12] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread via cfe-commits


@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "SprintfArgumentOverlapCheck.h"

EugeneZelenko wrote:

Please keep alphabetical order. Same in other list-like places.

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


[clang] [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (PR #112724)

2025-01-05 Thread NAKAMURA Takumi via cfe-commits


@@ -1869,7 +1871,10 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
   // If we are at an unreachable point, we don't need to emit the initializer
   // unless it contains a label.
   if (!HaveInsertPoint()) {
-if (!Init || !ContainsLabel(Init)) return;
+if (!Init || !ContainsLabel(Init)) {
+  PGO.markStmtMaybeUsed(Init);

chapuni wrote:

It should be compiled as an empty body and will be pruned. I will introduce 
debug facility that is enabled only in +Asserts.

I prioritized implementing the debug facility as low.

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


[clang] [clang-format] Add an option to control indentation of `export { ... }` (PR #110381)

2025-01-05 Thread Owen Pan via cfe-commits

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


[clang] [Coverage] Introduce `getBranchCounterPair()`. NFC. (PR #112702)

2025-01-05 Thread NAKAMURA Takumi via cfe-commits


@@ -941,6 +941,19 @@ struct CounterCoverageMappingBuilder
 return Counter::getCounter(CounterMap[S]);
   }
 
+  std::pair getBranchCounterPair(const Stmt *S,

chapuni wrote:

Done but I am still dubious namings would be appropriate. Not all users expect 
`[Exec, Skip]`, but `[Exec, Exit]` or similar. Do you have a better idea to 
resolve namings (not by structural assignments but by name)?

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   FirstArg->getBeginLoc(), FirstArg->getEndLoc()),
+   *Result.SourceManager, getLangOpts());
+
+  diag(OverlappingArg->getLocation(),
+   "argument '%0' overlaps the first argument "
+   "in %1, which is undefined behavior")
+  << FirstArgText << FnDecl;

ccotter wrote:

Now, the tool emits

```
7 |   sprintf(buf, "", buf,1,2,3);
  |   ~~~  ^~~
```

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/13] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/121313

>From dfde3a11f9e90e75ba5118959b0ad101b6369734 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 6 Oct 2024 00:41:48 -0400
Subject: [PATCH] [clangd] Add a unit test suite for HeuristicResolver

Fixes https://github.com/clangd/clangd/issues/2154
---
 clang-tools-extra/clangd/HeuristicResolver.h  |   5 +-
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../unittests/HeuristicResolverTests.cpp  | 535 ++
 3 files changed, 539 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp

diff --git a/clang-tools-extra/clangd/HeuristicResolver.h 
b/clang-tools-extra/clangd/HeuristicResolver.h
index dcc063bbc4adc0..c130e0677e86dd 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.h
+++ b/clang-tools-extra/clangd/HeuristicResolver.h
@@ -26,13 +26,14 @@ class UnresolvedUsingValueDecl;
 
 namespace clangd {
 
-// This class heuristic resolution of declarations and types in template code.
+// This class handles heuristic resolution of declarations and types in 
template
+// code.
 //
 // As a compiler, clang only needs to perform certain types of processing on
 // template code (such as resolving dependent names to declarations, or
 // resolving the type of a dependent expression) after instantiation. Indeed,
 // C++ language features such as template specialization mean such resolution
-// cannot be done accurately before instantiation
+// cannot be done accurately before instantiation.
 //
 // However, template code is written and read in uninstantiated form, and 
clangd
 // would like to provide editor features like go-to-definition in template code
diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index dffdcd5d014ca9..8dba8088908d5e 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -64,6 +64,7 @@ add_unittest(ClangdUnitTests ClangdTests
   GlobalCompilationDatabaseTests.cpp
   HeadersTests.cpp
   HeaderSourceSwitchTests.cpp
+  HeuristicResolverTests.cpp
   HoverTests.cpp
   IncludeCleanerTests.cpp
   IndexActionTests.cpp
diff --git a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp 
b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
new file mode 100644
index 00..1655b4066f69ac
--- /dev/null
+++ b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
@@ -0,0 +1,535 @@
+//===-- HeuristicResolverTests.cpp --*- 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
+//
+//===--===//
+#include "HeuristicResolver.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest.h"
+
+using namespace clang::ast_matchers;
+using clang::clangd::HeuristicResolver;
+using testing::ElementsAre;
+
+namespace clang {
+namespace {
+
+// Helper for matching a sequence of elements with a variadic list of matchers.
+// Usage: `ElementsAre(matchAdapter(Vs, MatchFunction)...)`, where `Vs...` is
+//a variadic list of matchers.
+// For each `V` in `Vs`, this will match the corresponding element `E` if
+// `MatchFunction(V, E)` is true.
+MATCHER_P2(matchAdapter, MatcherForElement, MatchFunction, "matchAdapter") {
+  return MatchFunction(MatcherForElement, arg);
+}
+
+template 
+using ResolveFnT = std::function(
+const HeuristicResolver *, const InputNode *)>;
+
+// Test heuristic resolution on `Code` using the resolution procedure
+// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
+// `InputNode` and returns a `std::vector`.
+// `InputMatcher` should be an AST matcher that matches a single node to pass 
as
+// input to `ResolveFn`, bound to the ID "input". `OutputMatchers` should be 
AST
+// matchers that each match a single node, bound to the ID "output".
+template 
+void expectResolution(llvm::StringRef Code, ResolveFnT ResolveFn,
+  const InputMatcher &IM, const OutputMatchers &...OMS) {
+  auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
+  auto &Ctx = TU->getASTContext();
+  auto InputMatches = match(IM, Ctx);
+  ASSERT_EQ(1u, InputMatches.size());
+  const auto *Input = InputMatches[0].template getNodeAs("input");
+  ASSERT_TRUE(Input);
+
+  auto OutputNodeMatches = [&](auto &OutputMatcher, auto &Actual) {
+auto OutputMatches = match(OutputMatcher, Ctx);
+if (OutputMatches.size() != 1u)
+  return false;
+const auto *ExpectedOutput =
+OutputMatches[0].template getNodeAs("output");
+

[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

(Rebased)

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


[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/121313

>From 63d9512fb376ee9bb837bad3f3d107969e561371 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 6 Oct 2024 00:41:48 -0400
Subject: [PATCH] [clangd] Add a unit test suite for HeuristicResolver

Fixes https://github.com/clangd/clangd/issues/2154
---
 clang-tools-extra/clangd/HeuristicResolver.h  |   5 +-
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../unittests/HeuristicResolverTests.cpp  | 540 ++
 3 files changed, 544 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp

diff --git a/clang-tools-extra/clangd/HeuristicResolver.h 
b/clang-tools-extra/clangd/HeuristicResolver.h
index dcc063bbc4adc0..c130e0677e86dd 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.h
+++ b/clang-tools-extra/clangd/HeuristicResolver.h
@@ -26,13 +26,14 @@ class UnresolvedUsingValueDecl;
 
 namespace clangd {
 
-// This class heuristic resolution of declarations and types in template code.
+// This class handles heuristic resolution of declarations and types in 
template
+// code.
 //
 // As a compiler, clang only needs to perform certain types of processing on
 // template code (such as resolving dependent names to declarations, or
 // resolving the type of a dependent expression) after instantiation. Indeed,
 // C++ language features such as template specialization mean such resolution
-// cannot be done accurately before instantiation
+// cannot be done accurately before instantiation.
 //
 // However, template code is written and read in uninstantiated form, and 
clangd
 // would like to provide editor features like go-to-definition in template code
diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index dffdcd5d014ca9..8dba8088908d5e 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -64,6 +64,7 @@ add_unittest(ClangdUnitTests ClangdTests
   GlobalCompilationDatabaseTests.cpp
   HeadersTests.cpp
   HeaderSourceSwitchTests.cpp
+  HeuristicResolverTests.cpp
   HoverTests.cpp
   IncludeCleanerTests.cpp
   IndexActionTests.cpp
diff --git a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp 
b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
new file mode 100644
index 00..8a2270521d622c
--- /dev/null
+++ b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
@@ -0,0 +1,540 @@
+//===-- HeuristicResolverTests.cpp --*- 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
+//
+//===--===//
+#include "HeuristicResolver.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest.h"
+
+using namespace clang::ast_matchers;
+using clang::clangd::HeuristicResolver;
+using testing::ElementsAre;
+
+namespace clang {
+namespace {
+
+// Helper for matching a sequence of elements with a variadic list of matchers.
+// Usage: `ElementsAre(matchAdapter(Vs, MatchFunction)...)`, where `Vs...` is
+//a variadic list of matchers.
+// For each `V` in `Vs`, this will match the corresponding element `E` if
+// `MatchFunction(V, E)` is true.
+MATCHER_P2(matchAdapter, MatcherForElement, MatchFunction, "matchAdapter") {
+  return MatchFunction(MatcherForElement, arg);
+}
+
+template 
+using ResolveFnT = std::function(
+const HeuristicResolver *, const InputNode *)>;
+
+// Test heuristic resolution on `Code` using the resolution procedure
+// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type
+// `InputNode` and returns a `std::vector`.
+// `InputMatcher` should be an AST matcher that matches a single node to pass 
as
+// input to `ResolveFn`, bound to the ID "input". `OutputMatchers` should be 
AST
+// matchers that each match a single node, bound to the ID "output".
+template 
+void expectResolution(llvm::StringRef Code, ResolveFnT ResolveFn,
+  const InputMatcher &IM, const OutputMatchers &...OMS) {
+  auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"});
+  auto &Ctx = TU->getASTContext();
+  auto InputMatches = match(IM, Ctx);
+  ASSERT_EQ(1u, InputMatches.size());
+  const auto *Input = InputMatches[0].template getNodeAs("input");
+  ASSERT_TRUE(Input);
+
+  auto OutputNodeMatches = [&](auto &OutputMatcher, auto &Actual) {
+auto OutputMatches = match(OutputMatcher, Ctx);
+if (OutputMatches.size() != 1u)
+  return false;
+const auto *ExpectedOutput =
+OutputMatches[0].template getNodeAs("output");
+

[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-ppc64le-linux-multistage` running on `ppc64le-clang-multistage-test` 
while building `clang` at step 5 "ninja check 1".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/76/builds/5845


Here is the relevant piece of the build log for the reference

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-mc
 -triple=x86_64-unknown-linux -position-independent  -filetype=obj -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.1.o
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-mc
 -triple=x86_64-unknown-linux -position-independent -filetype=obj -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.1.o
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
RUN: at line 4: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-jitlink
 -noexec 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.1.o
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-jitlink
 -noexec 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.1.o
RUN: at line 7: 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-mc
 -triple=x86_64-unknown-linux -position-independent --defsym=OVERFLOW=1  
-filetype=obj -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.2.o
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-mc
 -triple=x86_64-unknown-linux -position-independent --defsym=OVERFLOW=1 
-filetype=obj -o 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.2.o
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
RUN: at line 9: not 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-jitlink
 -noexec 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.2.o
 2>&1 | 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/FileCheck
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s
+ not 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/llvm-jitlink
 -noexec 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/test/ExecutionEngine/JITLink/x86-64/Output/ELF_R_X86_64_SIZE.s.tmp.2.o
+ 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/bin/FileCheck
 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/llvm/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_SIZE.s

--




```



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

[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121313)

2025-01-05 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

In the latest update, I use the new `hasDependentName()` matcher added in 
https://github.com/llvm/llvm-project/issues/121610 to make the matchers using 
`dependentScopeDeclRefExpr()` more specific.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread via cfe-commits


@@ -83,6 +83,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  SprintfArgumentOverlapCheck.cpp

EugeneZelenko wrote:

Ditto.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread via cfe-commits


@@ -154,6 +154,7 @@ Clang-Tidy Checks
:doc:`bugprone-too-small-loop-variable `,
:doc:`bugprone-unchecked-optional-access 
`,
:doc:`bugprone-undefined-memory-manipulation 
`,
+   :doc:`bugprone-sprintf-argument-overlap 
`,

EugeneZelenko wrote:

Ditto.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread via cfe-commits


@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(

EugeneZelenko wrote:

Alphabetical order, please.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/16] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2025-01-05 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj updated 
https://github.com/llvm/llvm-project/pull/118471

>From cb3bfb497c6f65bc185dc4fe7b8d9c5dbd92c4f0 Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Tue, 3 Dec 2024 03:58:40 -0600
Subject: [PATCH 1/3] Initial parsing/sema support for target_device selector
 set

---
 clang/include/clang/Sema/SemaOpenMP.h |   3 +
 clang/lib/AST/OpenMPClause.cpp|   5 +-
 clang/lib/Parse/ParseOpenMP.cpp   |  27 ++-
 clang/lib/Sema/SemaOpenMP.cpp |  29 +++
 .../OpenMP/begin_declare_variant_messages.c   |  22 +-
 clang/test/OpenMP/declare_variant_ast_print.c |   4 +
 .../OpenMP/declare_variant_bind_to_decl.cpp   |   2 +-
 clang/test/OpenMP/declare_variant_messages.c  |  57 +++---
 .../test/OpenMP/declare_variant_messages.cpp  |  28 +--
 clang/test/OpenMP/metadirective_messages.cpp  |   2 +-
 .../nvptx_declare_variant_name_mangling.cpp   |   8 +-
 .../include/llvm/Frontend/OpenMP/OMPContext.h |   9 +-
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  36 
 llvm/lib/Frontend/OpenMP/OMPContext.cpp   | 192 +-
 llvm/unittests/Frontend/OpenMPContextTest.cpp |  26 ++-
 15 files changed, 320 insertions(+), 130 deletions(-)

diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10f..4b9c930db26b5d 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,9 @@ class SemaOpenMP : public SemaBase {
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
+  /// Handle device_num selector.
+  void ActOnOpenMPDeviceNum(Expr *DeviceNumExpr);
+
   OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
  SourceLocation StartLoc,
  SourceLocation LParenLoc,
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4246ba95d827f1..870c4224c323bd 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2903,7 +2903,10 @@ TargetOMPContext::TargetOMPContext(
 const FunctionDecl *CurrentFunctionDecl,
 ArrayRef ConstructTraits)
 : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice,
- ASTCtx.getTargetInfo().getTriple()),
+ ASTCtx.getTargetInfo().getTriple(),
+ ASTCtx.getLangOpts().OMPTargetTriples.empty()
+ ? llvm::Triple()
+ : ASTCtx.getLangOpts().OMPTargetTriples[0]),
   FeatureValidityCheck([&](StringRef FeatureName) {
 return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName);
   }),
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b91928063169ee..84f1fcdb6e83f2 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -888,7 +888,18 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   TIProperty.Kind = TraitProperty::invalid;
 
   SourceLocation NameLoc = Tok.getLocation();
-  StringRef Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
+  StringRef Name;
+  if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
+Name = "number";
+TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
+ExprResult DeviceNumExprResult = ParseExpression();
+if (!DeviceNumExprResult.isInvalid()) {
+  Expr *DeviceNumExpr = DeviceNumExprResult.get();
+  Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
+}
+return;
+  }
+  Name = getNameFromIdOrString(*this, Tok, CONTEXT_TRAIT_LVL);
   if (Name.empty()) {
 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(Set, 
Selector);
@@ -918,7 +929,8 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
 << "()";
 return;
   }
-  TraitSelector SelectorForName = getOpenMPContextTraitSelectorKind(Name);
+  TraitSelector SelectorForName =
+  getOpenMPContextTraitSelectorKind(Name, SetForName);
   if (SelectorForName != TraitSelector::invalid) {
 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
@@ -935,7 +947,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty 
&TIProperty,
   }
   for (const auto &PotentialSet :
{TraitSet::construct, TraitSet::user, TraitSet::implementation,
-TraitSet::device}) {
+TraitSet::device, TraitSet::target_device}) {
 TraitProperty PropertyForName =
 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
 if (PropertyForName == TraitProperty::invalid)
@@ -1062,7 +1074,7 @@ void Parser::parseOMPTraitSelectorKind(OMPTraitSelector 
&TISelector,
 return;
   }
 
-  TISelector.Kind = getOpenMPContextTraitSelectorKind(Name);
+  TISelector.Kin

[clang] [llvm] [RISCV][VLS] Support RISCV VLS calling convention (PR #100346)

2025-01-05 Thread Brandon Wu via cfe-commits

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


[clang] [llvm] [RISCV][VLS] Support RISCV VLS calling convention (PR #100346)

2025-01-05 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Update:
1. Handle struct of fixed-length vectors
2. Remove `-mriscv-abi-vlen=N` option

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


[clang] [llvm] [RISCV][VLS] Support RISCV VLS calling convention (PR #100346)

2025-01-05 Thread Kito Cheng via cfe-commits


@@ -1953,7 +1953,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 /// Extra information which affects how the function is called, like
 /// regparm and the calling convention.
 LLVM_PREFERRED_TYPE(CallingConv)
-unsigned ExtInfo : 13;
+unsigned ExtInfo : 18;

kito-cheng wrote:

I incline don't touch FunctionTypeBitfields here, because it's RISC-V only.

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


[clang] [llvm] [RISCV][VLS] Support RISCV VLS calling convention (PR #100346)

2025-01-05 Thread Kito Cheng via cfe-commits


@@ -3013,6 +3013,7 @@ enum CXCallingConv {
   CXCallingConv_M68kRTD = 19,
   CXCallingConv_PreserveNone = 20,
   CXCallingConv_RISCVVectorCall = 21,
+  CXCallingConv_RISCVVLSCall = 22,

kito-cheng wrote:

Just use different calling convention to distinguish, then it would be easier 
to know the ABI_VLEN in the LLVM IR level, also can prevent the change in Type.h
```
CXCallingConv_RISCVVLSCall_32,
CXCallingConv_RISCVVLSCall_64,
...
CXCallingConv_RISCVVLSCall_65536,
```

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2025-01-05 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/114244

>From fd914cc82688b122654d2d7ada72007541b197c0 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 30 Oct 2024 10:54:49 -0400
Subject: [PATCH 01/17] Add bugprone-sprintf-overlap

---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/UndefinedSprintfOverlapCheck.cpp | 93 +++
 .../bugprone/UndefinedSprintfOverlapCheck.h   | 36 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../bugprone/undefined-sprintf-overlap.rst| 23 +
 .../docs/clang-tidy/checks/list.rst   |  3 +-
 .../bugprone/undefined-sprintf-overlap.cpp| 59 
 8 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 33ac65e715ce81..ac3a08c80d7ae6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -86,6 +86,7 @@
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
+#include "UndefinedSprintfOverlapCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
@@ -248,6 +249,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unchecked-optional-access");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
+CheckFactories.registerCheck(
+"bugprone-undefined-sprintf-overlap");
 CheckFactories.registerCheck(
 "bugprone-undelegated-constructor");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b0a2318acc0597..2403ed665fd5c7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
+  UndefinedSprintfOverlapCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
   UnhandledSelfAssignmentCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
new file mode 100644
index 00..301b6bce0dbbad
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp
@@ -0,0 +1,93 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(CallExpr, hasAnyOtherArgument,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : llvm::drop_begin(Node.arguments())) {
+ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+if (InnerMatcher.matches(*Arg, Finder, &Result)) {
+  *Builder = std::move(Result);
+  return true;
+}
+  }
+  return false;
+}
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const auto &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArg")));
+  auto OtherRefToArg = declRefExpr(to(varDecl(equalsBoundNode("firstArg"
+   .bind("overlappingArg");
+  Finder->ad

[clang] f53abc2 - [clang][NFC] Refactor expected directives in CWG2881 test

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T21:29:32+03:00
New Revision: f53abc2db07abfa38af9365bc15572112adbe040

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

LOG: [clang][NFC] Refactor expected directives in CWG2881 test

Added: 


Modified: 
clang/test/CXX/drs/cwg28xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index b0c46ee2d493a2..2cad2814cd6861 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -174,9 +174,7 @@ void g() {
 } // namespace cwg2877
 
 namespace cwg2881 { // cwg2881: 19
-
 #if __cplusplus >= 202302L
-
 template  struct A : T {};
 template  struct B : T {};
 template  struct C : virtual T { C(T t) : T(t) {} };
@@ -188,12 +186,12 @@ struct O1 : A, B {
   using B::operator();
 };
 
-template  struct O2 : protected Ts { // expected-note {{declared 
protected here}}
+template  struct O2 : protected Ts { // #cwg2881-O2
   using Ts::operator();
   O2(Ts ts) : Ts(ts) {}
 };
 
-template  struct O3 : private Ts { // expected-note {{declared 
private here}}
+template  struct O3 : private Ts { // #cwg2881-O3
   using Ts::operator();
   O3(Ts ts) : Ts(ts) {}
 };
@@ -217,7 +215,7 @@ struct O5 : private C, D {
 
 // This is only invalid if we call T's call operator.
 template 
-struct O6 : private T, U { // expected-note {{declared private here}}
+struct O6 : private T, U { // #cwg2881-O6
   using T::operator();
   using U::operator();
   O6(T t, U u) : T(t), U(u) {}
@@ -227,14 +225,26 @@ void f() {
   int x;
   auto L1 = [=](this auto&& self) { (void) &x; };
   auto L2 = [&](this auto&& self) { (void) &x; };
-  O1{L1, L1}(); // expected-error {{inaccessible due to 
ambiguity}}
-  O1{L2, L2}(); // expected-error {{inaccessible due to 
ambiguity}}
-  O2{L1}(); // expected-error {{must derive publicly from the lambda}}
-  O3{L1}(); // expected-error {{must derive publicly from the lambda}}
+  O1{L1, L1}();
+  /* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:
+struct cwg2881::O1 -> A<(lambda at {{.+}})> -> 
class (lambda at {{.+}})
+struct cwg2881::O1 -> B<(lambda at {{.+}})> -> 
class (lambda at {{.+}})}}*/
+  O1{L2, L2}();
+  /* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:
+struct cwg2881::O1 -> A<(lambda at {{.+}})> -> 
class (lambda at {{.+}})
+struct cwg2881::O1 -> B<(lambda at {{.+}})> -> 
class (lambda at {{.+}})}}*/
+  O2{L1}();
+  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 
'cwg2881::O2<(lambda at {{.+}})>' in lambda with capture; the type must derive 
publicly from the lambda}}
+  //   since-cxx23-note@#cwg2881-O2 {{declared protected here}}
+  O3{L1}();
+  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 
'cwg2881::O3<(lambda at {{.+}})>' in lambda with capture; the type must derive 
publicly from the lambda}}
+  //   since-cxx23-note@#cwg2881-O3 {{declared private here}}
   O4{L1}();
   O5{L1}();
   O6 o{L1, L2};
-  o.decltype(L1)::operator()(); // expected-error {{must derive publicly from 
the lambda}}
+  o.decltype(L1)::operator()();
+  // since-cxx23-error-re@-1 {{invalid explicit object parameter type 
'cwg2881::O6<(lambda at {{.+}}), (lambda at {{.+}})>' in lambda with capture; 
the type must derive publicly from the lambda}}
+  //   since-cxx23-note@#cwg2881-O6 {{declared private here}}
   o.decltype(L1)::operator()(); // No error here because we've already 
diagnosed this method.
   o.decltype(L2)::operator()();
 }
@@ -243,12 +253,14 @@ void f2() {
   int x = 0;
   auto lambda = [x] (this auto self) { return x; };
   using Lambda = decltype(lambda);
-  struct D : private Lambda { // expected-note {{declared private here}}
+  struct D : private Lambda { // #cwg2881-D
 D(Lambda l) : Lambda(l) {}
 using Lambda::operator();
 friend Lambda;
   } d(lambda);
-  d(); // expected-error {{must derive publicly from the lambda}}
+  d();
+  // since-cxx23-error@-1 {{invalid explicit object parameter type 'D' in 
lambda with capture; the type must derive publicly from the lambda}}
+  //   since-cxx23-note@#cwg2881-D {{declared private here}}
 }
 
 template 
@@ -263,18 +275,20 @@ struct Indirect : T {
 };
 
 template
-struct Ambiguous : Indirect, T { // expected-warning {{is inaccessible due 
to ambiguity}}
+struct Ambiguous : Indirect, T {
+/* since-cxx23-warning-re@-1 {{direct base '(lambda at {{.+}})' is 
inaccessible due to ambiguity:
+struct cwg2881::Ambiguous -> Indirect<(lambda at 
{{.+}})> -> class (lambda at {{.+}})
+struct cwg2881::Ambiguous -> class (lambda at 
{{.+}})}}*/
+//   since-cxx23-note-re@#cwg2881-f4 {{in instantiation of template class 
'cwg2881::Ambiguous<(lambda at {{.+}})>' requested here}}
+//   since-cxx34-note-re@#cwg2881-f4-call {{while substituting deduc

[clang] [clang][WebAssembly] Support the `-m(no-)red-zone` flag. (PR #119997)

2025-01-05 Thread Alex Rønne Petersen via cfe-commits

alexrp wrote:

ping

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


[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)

2025-01-05 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> > @dyung -- Ok, my latest attempt to work around these MSVC issues is now 
> > pushed to this PR. It also contains a commit of specifically debugging 
> > hacks to try and extract more information from any failure here. If you 
> > could try doing another build with the latest commit 
> > ([2ec750d](https://github.com/llvm/llvm-project/pull/120534/commits/2ec750d0105e1d4d52791f85293d16d28f6ccbd8))
> >  in this PR, would be very interested in how it works.
> 
> ```
> fatal error: error in backend: Name for __nvvm_vote_all is: ''!!!
> ```
> I don't see any instances of the `__builtin_ia32_packsswb128` from a quick 
> search of the test log.

This is awesome news!

It seems the last change was enough and gives me a strong guess as to the bug.

It does mean MSVC is miscompiling long string literals, so when you can 
upgrade, I would. And we should try to exclude these MSVC versions when we can.

But I may be able to work around more of these, stay tuned for some more 
updates.

> 
> Here is a compressed copy of the test log file:
> [log_test.2ec750d0105e1d4d52791f85293d16d28f6ccbd8.zip](https://www.dropbox.com/scl/fi/60gizuhvi85lz8jxw44t9/log_test.2ec750d0105e1d4d52791f85293d16d28f6ccbd8.zip?rlkey=esic3xnyg4i11rjzuc9i0cr2a&dl=0)



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


[clang] [clang] Add test for CWG192 "Name lookup in parameters" (PR #121679)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] fbc198c - [clang] Add test for CWG192 "Name lookup in parameters" (#121679)

2025-01-05 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T13:15:08+04:00
New Revision: fbc198c548cf21bb2be29509a46913a57f95e610

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

LOG: [clang] Add test for CWG192 "Name lookup in parameters" (#121679)

This patch adds a rather simple test for
[CWG192](https://cplusplus.github.io/CWG/issues/192.html). Parameter
declarations of member functions are not complete-class contexts (unlike
default arguments), so the example in the issue is ill-formed. Changes
in [CWG1352](https://cplusplus.github.io/CWG/issues/1352.html) which
resolved the issue, are superseded by the notion of complete-class
context (https://eel.is/c++draft/class.mem#def:complete-class_context).

Added: 


Modified: 
clang/test/CXX/drs/cwg1xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 939de6dee06d38..9eeca4cb2a681a 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -1364,6 +1364,14 @@ namespace cwg191 { // cwg191: yes
   }
 }
 
+namespace cwg192 { // cwg192: 2.7
+struct S {
+  void f(I i) { }
+  // expected-error@-1 {{unknown type name 'I'}}
+  typedef int I;
+};
+} // namespace cwg192
+
 // cwg193 is in cwg193.cpp
 
 namespace cwg194 { // cwg194: yes

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 335442c6e605f8..239c05e7823846 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1197,7 +1197,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/192.html";>192
 NAD
 Name lookup in parameters
-Unknown
+Clang 2.7
   
   
 https://cplusplus.github.io/CWG/issues/193.html";>193



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


[clang] [clang] Add test for CWG794 "Base-derived conversion in member type of pointer-to-member conversion" (PR #121660)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 3321c2d - [clang] Add test for CWG794 "Base-derived conversion in member type of pointer-to-member conversion" (#121660)

2025-01-05 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T13:17:15+04:00
New Revision: 3321c2d72ab7757dbdd38bdd99a76d89293dac8a

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

LOG: [clang] Add test for CWG794 "Base-derived conversion in member type of 
pointer-to-member conversion" (#121660)

This patch adds a test for
[CWG794](https://cplusplus.github.io/CWG/issues/794.html), which is an
NB comment closed as NAD. Author was asked to bring a paper to
Evolution, which never happened. So we test for the absence of
base-derived conversion in pointer-to-member conversion.

Added: 


Modified: 
clang/test/CXX/drs/cwg7xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/cwg7xx.cpp b/clang/test/CXX/drs/cwg7xx.cpp
index 507eb8fb714350..842d172d379005 100644
--- a/clang/test/CXX/drs/cwg7xx.cpp
+++ b/clang/test/CXX/drs/cwg7xx.cpp
@@ -337,3 +337,15 @@ template 
 void h(int i = 0, T ...args, int j = 1) {}
 #endif
 }
+
+namespace cwg794 { // cwg794: 2.7
+struct B {};
+struct D : B {};
+struct X {
+  D d;
+};
+struct Y : X {};
+B Y::*pm = &X::d;
+// expected-error@-1 {{cannot initialize a variable of type 'B Y::*' with an 
rvalue of type 'D cwg794::X::*': 
diff erent classes ('Y' vs 'cwg794::X')}}
+// FIXME: why diagnostic says just `Y` and not `cwg794::Y`, like `cwg794::X`?
+} // namespace cwg794

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 239c05e7823846..d767d2973b57ef 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -4775,7 +4775,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/794.html";>794
 NAD
 Base-derived conversion in member type of pointer-to-member 
conversion
-Unknown
+Clang 2.7
   
   
 https://cplusplus.github.io/CWG/issues/795.html";>795



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


[clang] [clang] Add test for CWG794 "Base-derived conversion in member type of pointer-to-member conversion" (PR #121660)

2025-01-05 Thread via cfe-commits


@@ -337,3 +337,15 @@ template 
 void h(int i = 0, T ...args, int j = 1) {}
 #endif
 }
+
+namespace cwg794 { // cwg794: 2.7
+struct B {};
+struct D : B {};
+struct X {
+  D d;
+};
+struct Y : X {};
+B Y::*pm = &X::d;
+// expected-error@-1 {{cannot initialize a variable of type 'B Y::*' with an 
rvalue of type 'D cwg794::X::*': different classes ('Y' vs 'cwg794::X')}}
+// FIXME: why diagnostic says just `Y` and not `cwg794::Y`, like `cwg794::X`?

cor3ntin wrote:

That seems to occur in `HandleFunctionTypeMismatch` - my best guess is that one 
is a canonical type and the other isn't? Not sure though

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


[clang] [clang] Add test for CWG203 "Type of address-of-member expression" (PR #121687)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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

This patch adds test for 
[CWG203](https://cplusplus.github.io/CWG/issues/203.html). Author was asking to 
change the type of pointer-to-member expression to be closer to how it's 
written as opposed to where the resulting member belongs to, but was turned 
down due to backwards compatibility concerns, so we're testing the status quo.

There are a total of 6 examples in the filing, so I decided to just throw all 
of them into the test. I had to turn example 2 into `constexpr` test that 
unfortunately requires C++20. Outcomes in example 5 that Tomasz expected are 
not in line with implementation behavior and my reading of the Standard. I 
think he got confused by the fact that unlike regular pointers, 
pointers-to-members can be implicitly _downcasted_, but not upcasted. I left 
comments in the example.

>From bca2bfe17b71faeebf65eba11adcb70927f878fd Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Jan 2025 13:58:16 +0300
Subject: [PATCH] [clang] Add test for CWG203 "Type of address-of-member
 expression"

---
 clang/test/CXX/drs/cwg2xx.cpp | 138 +-
 clang/www/cxx_dr_status.html  |   2 +-
 2 files changed, 137 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index ec37b420880e28..6a1dfcf2774779 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -2,8 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s 
-verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s 
-verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 // FIXME: diagnostic above is emitted only on Windows platforms
 // PR13819 -- __SIZE_TYPE__ is incompatible.
@@ -41,6 +42,139 @@ namespace cwg202 { // cwg202: 3.1
   template struct X;
 }
 
+namespace cwg203 { // cwg203: 2.8
+namespace ex1 {
+struct B {
+  int i;
+};
+struct D1 : B {};
+struct D2 : B {};
+
+int(D1::*pmD1) = &D2::i;
+} // namespace ex1
+
+#if __cplusplus >= 202002L
+namespace ex2 {
+struct A {
+  int i;
+  virtual void f() = 0; // #cwg203-ex2-A-f
+};
+
+struct B : A {
+  int j;
+  constexpr B() : j(5) {}
+  virtual void f();
+};
+
+struct C : B {
+  constexpr C() { j = 10; }
+};
+
+template 
+constexpr int DefaultValue(int(T::*m)) {
+  return T().*m;
+  // since-cxx20-error@-1 {{allocating an object of abstract class type 
'cwg203::ex2::A'}}
+  //   since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template 
specialization 'cwg203::ex2::DefaultValue' requested here}}
+  //   since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 
'f' in 'A'}}
+} // #cwg203-ex2-DefaultValue
+
+int a = DefaultValue(&B::i); // #cwg203-ex2-a
+static_assert(DefaultValue(&C::j) == 5, "");
+} // namespace ex2
+#endif
+
+namespace ex3 {
+class Base {
+public:
+  int func() const;
+};
+
+class Derived : public Base {};
+
+template  class Templ { // #cwg203-ex3-Templ
+public:
+  template  Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor
+};
+
+void foo() { Templ x(&Derived::func); }
+// expected-error@-1 {{:46:29: error: no matching constructor for 
initialization of 'Templ'}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
copy constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'const Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
move constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could 
not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}}
+} // namespace ex3
+
+namespace ex4 {
+struct Very_base {
+  int a;
+};
+struct Base1 : Very_base {};
+struct Base2 : Very_base {};
+struct Derived : Base1, Base2 {
+};
+
+int f() {
+  Derived d;
+  int Derived::*a_ptr = &Derived::Base1::a;
+  /* expected-error@-1
+  {{ambiguous c

[clang] [clang] Add test for CWG156 "Name lookup for conversion functions" (PR #121654)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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

>From dcd29ca8c77e24c532ca8300a7e46f5498ffebbb Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 4 Jan 2025 19:37:46 +0300
Subject: [PATCH 1/2] [clang] Add test for CWG156 "Name lookup for conversion
 functions"

---
 clang/test/CXX/drs/cwg1xx.cpp | 43 +++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 6aec8b65c91f12..eddad2e6a87b00 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -922,6 +922,49 @@ namespace cwg155 { // cwg155: dup 632
   // expected-warning@-1 {{braces around scalar initializer}}
 }
 
+namespace cwg156 { // cwg156: partial
+namespace ex1 {
+struct A {
+  operator int();
+} a;
+void foo() {
+  typedef int T;
+  a.operator T(); // T is found using unqualified lookup
+  // after qualified lookup in A fails.
+}
+} // namespace ex1
+
+namespace ex2 {
+struct A {
+  typedef int T;
+  operator T();
+};
+struct B : A {
+  operator T();
+} b;
+void foo() {
+  b.A::operator T(); // FIXME: qualified lookup should find T in A.
+  // expected-error@-1 {{unknown type name 'T'}}
+}
+} // namespace ex2
+
+namespace ex3 {
+template  struct A {
+  operator T1();
+};
+template  struct B : A {
+  operator T2();
+  void foo() {
+// In both cases, during instantiation, qualified lookup for T2 wouldn't 
be able
+// to find anything, so T2 has to be found by unqualified lookup.
+// After that, 'operator T2()' is found in A by qualfied lookup.
+T2 a = A::operator T2();
+T2 b = ((A *)this)->operator T2();
+  }
+};
+} // namespace ex3
+} // namespace cwg156
+
 // cwg158 is in cwg158.cpp
 
 namespace cwg159 { // cwg159: 3.5
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c069e155fd547c..bbdca49aad0533 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -981,7 +981,7 @@ C++ defect report implementation status
 https://cplusplus.github.io/CWG/issues/156.html";>156
 NAD
 Name lookup for conversion functions
-Unknown
+Partial
   
   
 https://cplusplus.github.io/CWG/issues/157.html";>157

>From 1904c0963739e68660aab410702dea7355f746c6 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Jan 2025 14:13:20 +0300
Subject: [PATCH 2/2] Merge CWG156 test into CWG111 test, and downgrade CWG
 to partial

---
 clang/test/CXX/drs/cwg11xx.cpp | 44 +-
 clang/test/CXX/drs/cwg1xx.cpp  | 44 +-
 clang/www/cxx_dr_status.html   |  4 ++--
 3 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index 8d187041400a60..d33ff060d2d39e 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -19,7 +19,7 @@ decltype(return_T>())* b;
 #endif
 } // namespace cwg1110
 
-namespace cwg { // cwg: 3.2
+namespace cwg { // cwg: partial
 namespace example1 {
 template  struct set; // #cwg-struct-set
 
@@ -57,6 +57,48 @@ void baz() {
   a.operator A();
 }
 } // namespace example2
+
+namespace example3 {
+struct A {
+  operator int();
+} a;
+void foo() {
+  typedef int T;
+  a.operator T(); // T is found using unqualified lookup
+  // after qualified lookup in A fails.
+}
+} // namespace example3
+
+namespace example4 {
+struct A {
+  typedef int T; // #cwg-A-T
+  operator T();
+};
+struct B : A {
+  operator T();
+} b;
+void foo() {
+  b.A::operator T(); // FIXME: qualified lookup should find T in A.
+  // expected-error@-1 {{unknown type name 'T'}}
+  //   expected-note@#cwg-A-T {{'A::T' declared here}}
+}
+} // namespace example4
+
+namespace example5 {
+template  struct A {
+  operator T1();
+};
+template  struct B : A {
+  operator T2();
+  void foo() {
+// In both cases, during instantiation, qualified lookup for T2 wouldn't 
be able
+// to find anything, so T2 has to be found by unqualified lookup.
+// After that, 'operator T2()' is found in A by qualfied lookup.
+T2 a = A::operator T2();
+T2 b = ((A *)this)->operator T2();
+  }
+};
+} // namespace example5
 } // namespace cwg
 
 namespace cwg1113 { // cwg1113: partial
diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index eddad2e6a87b00..6a26857bb80285 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -922,49 +922,7 @@ namespace cwg155 { // cwg155: dup 632
   // expected-warning@-1 {{braces around scalar initializer}}
 }
 
-namespace cwg156 { // cwg156: partial
-namespace ex1 {
-struct A {
-  operator int();
-} a;
-void foo() {
-  typedef int T;
-  a.operator T(); // T is found using unqualified lookup
-  // after qualified lookup in A fails.
-}
-} // namespace ex1
-
-namespace ex2 {

[clang] [clang] Add test for CWG203 "Type of address-of-member expression" (PR #121687)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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

>From bca2bfe17b71faeebf65eba11adcb70927f878fd Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Jan 2025 13:58:16 +0300
Subject: [PATCH 1/2] [clang] Add test for CWG203 "Type of address-of-member
 expression"

---
 clang/test/CXX/drs/cwg2xx.cpp | 138 +-
 clang/www/cxx_dr_status.html  |   2 +-
 2 files changed, 137 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index ec37b420880e28..6a1dfcf2774779 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -2,8 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s 
-verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s 
-verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 // FIXME: diagnostic above is emitted only on Windows platforms
 // PR13819 -- __SIZE_TYPE__ is incompatible.
@@ -41,6 +42,139 @@ namespace cwg202 { // cwg202: 3.1
   template struct X;
 }
 
+namespace cwg203 { // cwg203: 2.8
+namespace ex1 {
+struct B {
+  int i;
+};
+struct D1 : B {};
+struct D2 : B {};
+
+int(D1::*pmD1) = &D2::i;
+} // namespace ex1
+
+#if __cplusplus >= 202002L
+namespace ex2 {
+struct A {
+  int i;
+  virtual void f() = 0; // #cwg203-ex2-A-f
+};
+
+struct B : A {
+  int j;
+  constexpr B() : j(5) {}
+  virtual void f();
+};
+
+struct C : B {
+  constexpr C() { j = 10; }
+};
+
+template 
+constexpr int DefaultValue(int(T::*m)) {
+  return T().*m;
+  // since-cxx20-error@-1 {{allocating an object of abstract class type 
'cwg203::ex2::A'}}
+  //   since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template 
specialization 'cwg203::ex2::DefaultValue' requested here}}
+  //   since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 
'f' in 'A'}}
+} // #cwg203-ex2-DefaultValue
+
+int a = DefaultValue(&B::i); // #cwg203-ex2-a
+static_assert(DefaultValue(&C::j) == 5, "");
+} // namespace ex2
+#endif
+
+namespace ex3 {
+class Base {
+public:
+  int func() const;
+};
+
+class Derived : public Base {};
+
+template  class Templ { // #cwg203-ex3-Templ
+public:
+  template  Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor
+};
+
+void foo() { Templ x(&Derived::func); }
+// expected-error@-1 {{:46:29: error: no matching constructor for 
initialization of 'Templ'}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
copy constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'const Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
move constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could 
not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}}
+} // namespace ex3
+
+namespace ex4 {
+struct Very_base {
+  int a;
+};
+struct Base1 : Very_base {};
+struct Base2 : Very_base {};
+struct Derived : Base1, Base2 {
+};
+
+int f() {
+  Derived d;
+  int Derived::*a_ptr = &Derived::Base1::a;
+  /* expected-error@-1
+  {{ambiguous conversion from pointer to member of base class 
'cwg203::ex4::Very_base' to pointer to member of derived class 
'cwg203::ex4::Derived':
+struct cwg203::ex4::Derived -> Base1 -> Very_base
+struct cwg203::ex4::Derived -> Base2 -> Very_base}}*/
+};
+} // namespace ex4
+
+namespace ex5 {
+struct Base {
+  int a;
+};
+struct Derived : Base {
+  int b;
+};
+
+template 
+Member_type get(Class &c) {
+  return c.*ptr;
+}
+
+void call(int (*f)(Derived &)); // #cwg203-ex5-call
+
+int main() {
+  // ill-formed, contrary to Core issue filing:
+  // `&Derived::b` yields `int Derived::*`, which can't initialize NTTP of 
type `int Base::*`,
+  // because (implicit) pointer-to-member conversion doesn't upcast.
+  call(&get);
+  // expected-error@-1 {{no matching function for call to 'call'}}
+  //   expected-

[clang] [clang][NFC] Make all C++ DR tests run in full range of language modes (PR #121688)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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

This patch plugs holes in RUN lines in C++ DR tests, making sure they are run 
in C++98 through C++26, with the exception of C++03, which in Clang is 
synonymous to C++98.

>From d6e8b78f2209c4bc29d47b8d196ec9ec9000b4cb Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 5 Jan 2025 14:38:13 +0300
Subject: [PATCH] [clang][NFC] Make all C++ DR tests run in full range of
 language modes

---
 clang/test/CXX/drs/cwg0xx.cpp |  1 +
 clang/test/CXX/drs/cwg10xx.cpp|  1 +
 clang/test/CXX/drs/cwg118.cpp |  6 -
 clang/test/CXX/drs/cwg11xx.cpp|  4 +++-
 clang/test/CXX/drs/cwg12xx.cpp|  1 +
 clang/test/CXX/drs/cwg158.cpp |  5 -
 clang/test/CXX/drs/cwg1748.cpp|  5 -
 clang/test/CXX/drs/cwg177x.cpp|  5 -
 clang/test/CXX/drs/cwg1xx.cpp |  1 +
 clang/test/CXX/drs/cwg2771.cpp| 22 ---
 clang/test/CXX/drs/cwg2xx.cpp |  1 +
 clang/test/CXX/drs/cwg3xx.cpp | 11 +-
 .../test/CXX/drs/{cwgr593.cpp => cwg593.cpp}  |  0
 clang/test/CXX/drs/cwg6xx.cpp |  1 +
 clang/test/CXX/drs/cwg7xx.cpp |  4 +++-
 clang/test/CXX/drs/cwg9xx.cpp |  1 +
 16 files changed, 50 insertions(+), 19 deletions(-)
 rename clang/test/CXX/drs/{cwgr593.cpp => cwg593.cpp} (100%)

diff --git a/clang/test/CXX/drs/cwg0xx.cpp b/clang/test/CXX/drs/cwg0xx.cpp
index 993b6f29238593..8f7bd6532ae6d5 100644
--- a/clang/test/CXX/drs/cwg0xx.cpp
+++ b/clang/test/CXX/drs/cwg0xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 
 #if __cplusplus == 199711L
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
diff --git a/clang/test/CXX/drs/cwg10xx.cpp b/clang/test/CXX/drs/cwg10xx.cpp
index 58d552942c77cc..01de13238a6ae2 100644
--- a/clang/test/CXX/drs/cwg10xx.cpp
+++ b/clang/test/CXX/drs/cwg10xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
diff --git a/clang/test/CXX/drs/cwg118.cpp b/clang/test/CXX/drs/cwg118.cpp
index 04e19ce050788c..c7685fdb4f5b17 100644
--- a/clang/test/CXX/drs/cwg118.cpp
+++ b/clang/test/CXX/drs/cwg118.cpp
@@ -1,7 +1,11 @@
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++98 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++11 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
-// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++17 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++20 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++23 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++2c %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+
 
 // cwg118: yes
 
diff --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index 8d187041400a60..6493e23cf03eff 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -2,7 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2a %s -verify

[clang] [clang][NFC] Make all C++ DR tests run in full range of language modes (PR #121688)

2025-01-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch plugs holes in RUN lines in C++ DR tests, making sure they are run 
in C++98 through C++26, with the exception of C++03, which in Clang is 
synonymous to C++98.

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


16 Files Affected:

- (modified) clang/test/CXX/drs/cwg0xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg10xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg118.cpp (+5-1) 
- (modified) clang/test/CXX/drs/cwg11xx.cpp (+3-1) 
- (modified) clang/test/CXX/drs/cwg12xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg158.cpp (+4-1) 
- (modified) clang/test/CXX/drs/cwg1748.cpp (+4-1) 
- (modified) clang/test/CXX/drs/cwg177x.cpp (+4-1) 
- (modified) clang/test/CXX/drs/cwg1xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg2771.cpp (+14-8) 
- (modified) clang/test/CXX/drs/cwg2xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg3xx.cpp (+6-5) 
- (renamed) clang/test/CXX/drs/cwg593.cpp () 
- (modified) clang/test/CXX/drs/cwg6xx.cpp (+1) 
- (modified) clang/test/CXX/drs/cwg7xx.cpp (+3-1) 
- (modified) clang/test/CXX/drs/cwg9xx.cpp (+1) 


``diff
diff --git a/clang/test/CXX/drs/cwg0xx.cpp b/clang/test/CXX/drs/cwg0xx.cpp
index 993b6f29238593..8f7bd6532ae6d5 100644
--- a/clang/test/CXX/drs/cwg0xx.cpp
+++ b/clang/test/CXX/drs/cwg0xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 
 #if __cplusplus == 199711L
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
diff --git a/clang/test/CXX/drs/cwg10xx.cpp b/clang/test/CXX/drs/cwg10xx.cpp
index 58d552942c77cc..01de13238a6ae2 100644
--- a/clang/test/CXX/drs/cwg10xx.cpp
+++ b/clang/test/CXX/drs/cwg10xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
diff --git a/clang/test/CXX/drs/cwg118.cpp b/clang/test/CXX/drs/cwg118.cpp
index 04e19ce050788c..c7685fdb4f5b17 100644
--- a/clang/test/CXX/drs/cwg118.cpp
+++ b/clang/test/CXX/drs/cwg118.cpp
@@ -1,7 +1,11 @@
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++98 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++11 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
-// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++17 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++20 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++23 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++2c %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+
 
 // cwg118: yes
 
diff --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index 8d187041400a60..6493e23cf03eff 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -2,7 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected -fexceptions 
-fcxx-exceptio

[clang] [clang] Add test for CWG156 "Name lookup for conversion functions" (PR #121654)

2025-01-05 Thread via cfe-commits

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


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


[clang] [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (PR #121654)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (PR #121654)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 64e8d5b - [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (#121654)

2025-01-05 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T15:49:55+04:00
New Revision: 64e8d5b1baaa478c40931d290bf30687a6c93dac

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

LOG: [clang] Add tests from CWG156 to CWG (dual-scope lookup for 
conversion-function-ids) (#121654)

This patch adds test from
[CWG156](https://cplusplus.github.io/CWG/issues/156.html) to
[CWG](https://cplusplus.github.io/CWG/issues/.html) test, and
downgrades the latter to partial availability. The most relevant piece
of current wording is
[[basic.lookup.unqual]/5](https://eel.is/c++draft/basic.lookup#unqual-5):
> An unqualified name that is a component name
([[expr.prim.id.unqual]](https://eel.is/c++draft/expr.prim.id.unqual))
of a
[type-specifier](https://eel.is/c++draft/dcl.type.general#nt:type-specifier)
or
[ptr-operator](https://eel.is/c++draft/dcl.decl.general#nt:ptr-operator)
of a
[conversion-type-id](https://eel.is/c++draft/class.conv.fct#nt:conversion-type-id)
is looked up in the same fashion as the
[conversion-function-id](https://eel.is/c++draft/class.conv.fct#nt:conversion-function-id)
in which it
appears[.](https://eel.is/c++draft/basic.lookup#unqual-5.sentence-1)
If that lookup finds nothing, it undergoes unqualified name lookup; in
each case, only names that denote types or templates whose
specializations are types are
considered[.](https://eel.is/c++draft/basic.lookup#unqual-5.sentence-2)

Per resolution of
[CWG](https://cplusplus.github.io/CWG/issues/.html), additional
lookup in the context of the entire postfix-expression, which originally
was intended to cross-check lookup in the context of object-expression,
was effectively turned into a fallback for it.

Check out "Calling a conversion function" example in
[P1787R6](https://wg21.link/p1787r6) for step-by-step explanation of the
current lookup mechanics for conversion functions.

Clang rejects one of the well-formed examples, hence partial status.
Clang is the only implementation which rejects it:
https://godbolt.org/z/ohhbx8Mfs

Added: 


Modified: 
clang/test/CXX/drs/cwg11xx.cpp
clang/test/CXX/drs/cwg1xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index 8d187041400a60..d33ff060d2d39e 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -19,7 +19,7 @@ decltype(return_T>())* b;
 #endif
 } // namespace cwg1110
 
-namespace cwg { // cwg: 3.2
+namespace cwg { // cwg: partial
 namespace example1 {
 template  struct set; // #cwg-struct-set
 
@@ -57,6 +57,48 @@ void baz() {
   a.operator A();
 }
 } // namespace example2
+
+namespace example3 {
+struct A {
+  operator int();
+} a;
+void foo() {
+  typedef int T;
+  a.operator T(); // T is found using unqualified lookup
+  // after qualified lookup in A fails.
+}
+} // namespace example3
+
+namespace example4 {
+struct A {
+  typedef int T; // #cwg-A-T
+  operator T();
+};
+struct B : A {
+  operator T();
+} b;
+void foo() {
+  b.A::operator T(); // FIXME: qualified lookup should find T in A.
+  // expected-error@-1 {{unknown type name 'T'}}
+  //   expected-note@#cwg-A-T {{'A::T' declared here}}
+}
+} // namespace example4
+
+namespace example5 {
+template  struct A {
+  operator T1();
+};
+template  struct B : A {
+  operator T2();
+  void foo() {
+// In both cases, during instantiation, qualified lookup for T2 wouldn't 
be able
+// to find anything, so T2 has to be found by unqualified lookup.
+// After that, 'operator T2()' is found in A by qualfied lookup.
+T2 a = A::operator T2();
+T2 b = ((A *)this)->operator T2();
+  }
+};
+} // namespace example5
 } // namespace cwg
 
 namespace cwg1113 { // cwg1113: partial

diff  --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 9eeca4cb2a681a..e8fe3fff43a575 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -922,6 +922,7 @@ namespace cwg155 { // cwg155: dup 632
   // expected-warning@-1 {{braces around scalar initializer}}
 }
 
+// cwg156: sup 
 // cwg158 is in cwg158.cpp
 
 namespace cwg159 { // cwg159: 3.5

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index d767d2973b57ef..6ed5e3d37bae79 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -981,7 +981,7 @@ C++ defect report implementation status
 https://cplusplus.github.io/CWG/issues/156.html";>156
 NAD
 Name lookup for conversion functions
-Unknown
+Superseded by 
   
   
 https://cplusplus.github.io/CWG/issues/157.html";>157
@@ -6485,7 +6485,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/.html";>
 C++

[clang] [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (PR #121654)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-05 Thread via cfe-commits
=?utf-8?q?André?= Brand 
Message-ID:
In-Reply-To: 


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


[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

2025-01-05 Thread Luke Lau via cfe-commits

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

Apologies for the delay on this again. However I tried it out locally and it 
now seems to work on macOS, thanks for fixing that! 

I really can't speak much for the elisp, but we don't have many reviewers for 
the emacs stuff and this feature would be really handy to have.

So LGTM, if it needs more review I think it can be done post-commit :)

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


[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)

2025-01-05 Thread via cfe-commits

dyung wrote:

> @dyung -- Ok, my latest attempt to work around these MSVC issues is now 
> pushed to this PR. It also contains a commit of specifically debugging hacks 
> to try and extract more information from any failure here. If you could try 
> doing another build with the latest commit 
> ([2ec750d](https://github.com/llvm/llvm-project/pull/120534/commits/2ec750d0105e1d4d52791f85293d16d28f6ccbd8))
>  in this PR, would be very interested in how it works.

```
fatal error: error in backend: Name for __nvvm_vote_all is: ''!!!
```
I don't see any instances of the `__builtin_ia32_packsswb128` from a quick 
search of the test log.

Here is a compressed copy of the test log file:
[log_test.2ec750d0105e1d4d52791f85293d16d28f6ccbd8.zip](https://www.dropbox.com/scl/fi/60gizuhvi85lz8jxw44t9/log_test.2ec750d0105e1d4d52791f85293d16d28f6ccbd8.zip?rlkey=esic3xnyg4i11rjzuc9i0cr2a&dl=0)

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


[clang] 743c84b - [clang][NFC] Move CWG2353 test to its own file

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T20:46:23+03:00
New Revision: 743c84bb9b79ed70d9bed926c2a173db3b30f587

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

LOG: [clang][NFC] Move CWG2353 test to its own file

Added: 
clang/test/CXX/drs/cwg2353.cpp

Modified: 
clang/test/CXX/drs/cwg23xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/cwg2353.cpp b/clang/test/CXX/drs/cwg2353.cpp
new file mode 100644
index 00..31dd5bdc9dd71f
--- /dev/null
+++ b/clang/test/CXX/drs/cwg2353.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s 
-verify=expected -fexceptions -fcxx-exceptions -pedantic-errors -ast-dump | 
FileCheck %s
+
+// expected-no-diagnostics
+
+namespace cwg2353 { // cwg2353: 9
+  struct X {
+static const int n = 0;
+  };
+
+  // CHECK: FunctionDecl {{.*}} use
+  int use(X x) {
+// CHECK: MemberExpr {{.*}} .n
+// CHECK-NOT: non_odr_use
+// CHECK: DeclRefExpr {{.*}} 'x'
+// CHECK-NOT: non_odr_use
+return *&x.n;
+  }
+#pragma clang __debug dump use
+
+  // CHECK: FunctionDecl {{.*}} not_use
+  int not_use(X x) {
+// CHECK: MemberExpr {{.*}} .n {{.*}} non_odr_use_constant
+// CHECK: DeclRefExpr {{.*}} 'x'
+return x.n;
+  }
+#pragma clang __debug dump not_use
+
+  // CHECK: FunctionDecl {{.*}} not_use_2
+  int not_use_2(X *x) {
+// CHECK: MemberExpr {{.*}} ->n {{.*}} non_odr_use_constant
+// CHECK: DeclRefExpr {{.*}} 'x'
+return x->n;
+  }
+#pragma clang __debug dump not_use_2
+} // namespace cwg2353

diff  --git a/clang/test/CXX/drs/cwg23xx.cpp b/clang/test/CXX/drs/cwg23xx.cpp
index ded0219398334c..0169d9c2a0332b 100644
--- a/clang/test/CXX/drs/cwg23xx.cpp
+++ b/clang/test/CXX/drs/cwg23xx.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions 
-fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-14,since-cxx11 
-fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++14 %s 
-verify=expected,cxx11-14,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions 
-pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++17 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -std=c++2c %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-14,since-cxx11 
-fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 %s 
-verify=expected,cxx11-14,since-cxx11,since-cxx14 -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
@@ -284,39 

[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-05 Thread via cfe-commits
=?utf-8?q?André?= Brand 
Message-ID:
In-Reply-To: 


thebrandre wrote:

@cor3ntin I hope there is no misunderstanding here. If so, I apologize,

I strongly agree with you that some refactoring should be applied because, as I 
mentioned, the diagnostics get duplicated in certain cases as shown here on 
Compiler Explorer: 
[https://godbolt.org/z/473Eezhjn](https://godbolt.org/z/473Eezhjn).
But I would prefer opening another pull request for it keeping it separate from 
the fix making it easier to cherry-pick.
My understanding is that all commits get squashed before being applied to main?

If there is still something wrong with the commit message, I would gladly give 
it another try if you could be more specific. 

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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121614

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH 1/4] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

>From b8bf77687644c035683ae64a0a2a8e788ad74a83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 5 Jan 2025 12:07:40 +0200
Subject: [PATCH 2/4] change param name from TrailingAttrs to
 Che

[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121614

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH 1/3] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

>From b8bf77687644c035683ae64a0a2a8e788ad74a83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 5 Jan 2025 12:07:40 +0200
Subject: [PATCH 2/3] change param name from TrailingAttrs to
 Che

[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121614

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH 1/3] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

>From b8bf77687644c035683ae64a0a2a8e788ad74a83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 5 Jan 2025 12:07:40 +0200
Subject: [PATCH 2/3] change param name from TrailingAttrs to
 Che

[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread via cfe-commits

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

LGTM, thanks!

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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121614

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH 1/4] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

>From b8bf77687644c035683ae64a0a2a8e788ad74a83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 5 Jan 2025 12:07:40 +0200
Subject: [PATCH 2/4] change param name from TrailingAttrs to
 Che

[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits


@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);

a-tarasyuk wrote:

@cor3ntin is it acceptable to use `DiagnoseAndSkipCXX11Attributes` to reduce 
errors list?

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


[clang] [Clang][MIPS] Send correct architecture for MinGW toolchains (PR #121042)

2025-01-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-ubuntu` 
running on `as-builder-9` while building `clang` at step 16 
"test-check-lldb-api".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/195/builds/3042


Here is the relevant piece of the build log for the reference

```
Step 16 (test-check-lldb-api) failure: Test just built components: 
check-lldb-api completed (failure)
...
PASS: lldb-api :: types/TestIntegerType.py (1209 of 1218)
PASS: lldb-api :: types/TestIntegerTypeExpr.py (1210 of 1218)
PASS: lldb-api :: types/TestRecursiveTypes.py (1211 of 1218)
PASS: lldb-api :: types/TestShortType.py (1212 of 1218)
PASS: lldb-api :: types/TestLongTypes.py (1213 of 1218)
PASS: lldb-api :: types/TestShortTypeExpr.py (1214 of 1218)
PASS: lldb-api :: types/TestLongTypesExpr.py (1215 of 1218)
PASS: lldb-api :: tools/lldb-server/TestNonStop.py (1216 of 1218)
PASS: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (1217 of 1218)
TIMEOUT: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py (1218 
of 1218)
 TEST 'lldb-api :: 
python_api/process/cancel_attach/TestCancelAttach.py' FAILED 

Script:
--
/usr/bin/python3.12 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib
 --env 
LLVM_INCLUDE_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include
 --env 
LLVM_TOOLS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin
 --libcxx-include-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/c++/v1
 --libcxx-include-target-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/aarch64-unknown-linux-gnu/c++/v1
 --libcxx-library-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib/aarch64-unknown-linux-gnu
 --arch aarch64 --build-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/lldb 
--compiler 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang 
--dsymutil 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/dsymutil
 --make /usr/bin/gmake --llvm-tools-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin 
--lldb-obj-root 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb 
--lldb-libs-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib 
--platform-url connect://jetson-agx-2198.lab.llvm.org:1234 
--platform-working-dir /home/ubuntu/lldb-tests --sysroot 
/mnt/fs/jetson-agx-ubuntu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name 
remote-linux 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/python_api/process/cancel_attach
 -p TestCancelAttach.py
--
Exit Code: -9
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
8267bea9a35c3c3f866b942a50c2b98ac462ce35)
  clang revision 8267bea9a35c3c3f866b942a50c2b98ac462ce35
  llvm revision 8267bea9a35c3c3f866b942a50c2b98ac462ce35

--
Command Output (stderr):
--
WARNING:root:Custom libc++ is not supported for remote runs: ignoring --libcxx 
arguments
FAIL: LLDB 
(/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang-aarch64)
 :: test_scripted_implementation 
(TestCancelAttach.AttachCancelTestCase.test_scripted_implementation)

--


Slowest Tests:
--
600.04s: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py
180.98s: lldb-api :: commands/command/script_alias/TestCommandScriptAlias.py
81.61s: lldb-api :: tools/lldb-server/TestLldbGdbServer.py
70.68s: lldb-api :: commands/process/attach/TestProcessAttach.py
40.50s: lldb-api :: 
functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
35.11s: lldb-api :: functionalities/completion/TestCompletion.py
34.30s: lldb-api :: 
functionalities/single-thread-step/TestSingleThreadStepTimeout.py
32.52s: lldb-api :: tools/lldb-server/TestNonStop.py
21.41s: lldb-api :: commands/statistics/basic/TestStats.py
20.68s: lldb-api :: functionalities/gdb_remote_client/TestPlatformClient.py
19.06s: lldb-api :: functionalities/thread/state/TestThreadStates.py
18.24s: lldb-api :: commands/dwim-print/TestDWIMPrint.py
17.03s: lldb-api

[clang] [clang] Add test for CWG203 "Type of address-of-member expression" (PR #121687)

2025-01-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch adds test for 
[CWG203](https://cplusplus.github.io/CWG/issues/203.html). Author was asking to 
change the type of pointer-to-member expression to be closer to how it's 
written as opposed to where the resulting member belongs to, but was turned 
down due to backwards compatibility concerns, so we're testing the status quo.

There are a total of 6 examples in the filing, so I decided to just throw all 
of them into the test. I had to turn example 2 into `constexpr` test that 
unfortunately requires C++20. Outcomes in example 5 that Tomasz expected are 
not in line with implementation behavior and my reading of the Standard. I 
think he got confused by the fact that unlike regular pointers, 
pointers-to-members can be implicitly _downcasted_, but not upcasted. I left 
comments in the example.

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


2 Files Affected:

- (modified) clang/test/CXX/drs/cwg2xx.cpp (+136-2) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index ec37b420880e28..6a1dfcf2774779 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -2,8 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s 
-verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s 
-verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s 
-verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 // FIXME: diagnostic above is emitted only on Windows platforms
 // PR13819 -- __SIZE_TYPE__ is incompatible.
@@ -41,6 +42,139 @@ namespace cwg202 { // cwg202: 3.1
   template struct X;
 }
 
+namespace cwg203 { // cwg203: 2.8
+namespace ex1 {
+struct B {
+  int i;
+};
+struct D1 : B {};
+struct D2 : B {};
+
+int(D1::*pmD1) = &D2::i;
+} // namespace ex1
+
+#if __cplusplus >= 202002L
+namespace ex2 {
+struct A {
+  int i;
+  virtual void f() = 0; // #cwg203-ex2-A-f
+};
+
+struct B : A {
+  int j;
+  constexpr B() : j(5) {}
+  virtual void f();
+};
+
+struct C : B {
+  constexpr C() { j = 10; }
+};
+
+template 
+constexpr int DefaultValue(int(T::*m)) {
+  return T().*m;
+  // since-cxx20-error@-1 {{allocating an object of abstract class type 
'cwg203::ex2::A'}}
+  //   since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template 
specialization 'cwg203::ex2::DefaultValue' requested here}}
+  //   since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 
'f' in 'A'}}
+} // #cwg203-ex2-DefaultValue
+
+int a = DefaultValue(&B::i); // #cwg203-ex2-a
+static_assert(DefaultValue(&C::j) == 5, "");
+} // namespace ex2
+#endif
+
+namespace ex3 {
+class Base {
+public:
+  int func() const;
+};
+
+class Derived : public Base {};
+
+template  class Templ { // #cwg203-ex3-Templ
+public:
+  template  Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor
+};
+
+void foo() { Templ x(&Derived::func); }
+// expected-error@-1 {{:46:29: error: no matching constructor for 
initialization of 'Templ'}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
copy constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'const Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit 
move constructor) not viable: no known conversion from 'int 
(cwg203::ex3::Base::*)() const' to 'Templ' for 1st argument}}
+//   expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could 
not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}}
+} // namespace ex3
+
+namespace ex4 {
+struct Very_base {
+  int a;
+};
+struct Base1 : Very_base {};
+struct Base2 : Very_base {};
+struct Derived : Base1, Base2 {
+};
+
+int f() {
+  Derived d;
+  int Derived::*a_ptr = &Derived::Base1::a;
+  /* expected-error@-1
+  {{ambiguous conversion from pointer to member of base class 
'cwg203::ex4::Very_base' to pointer to member of derived class 
'cwg203::ex4::Derived':
+struct cwg203::ex4::Derived ->

[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-05 Thread via cfe-commits
=?utf-8?q?André?= Brand 
Message-ID:
In-Reply-To: 


thebrandre wrote:

@cor3ntin Good news! I figured it out on my own! And I now have a fix that I am 
confident in. đŸ™‚
I analyzed the steps of the parser in **a lot**  of similar cases, for which I 
also added quite a few regression tests.

The attributes have already been handled correctly previously. But to make sure 
of it, I also added tests.

Putting the few lines for the fix there, seems fairly consistent to me. It 
repeats the logic in 
[`Sema::ActOnTag`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.6/clang/lib/Sema/SemaDecl.cpp#L17152-L17154)
 and 
[`Sema::ActOnEnumBody`](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.6/clang/lib/Sema/SemaDecl.cpp#L19917-L19922)
 (exact lines of code are linked). We would now repeat them a third time but 
this is unavoidable because `Sema::ActOnEnumBody` is called again during 
instantiation but `Sema::ActOnTag` is not.
Refactoring this is would be hard because it's not really specified what 
exactly the individual functions are supposed to do. And the repetition doesn't 
seem too bad to me.

As you suggested, I stepped through the code to check if anything else from 
`Sema::ActOnTag` might be missing. But this doesn't seem to be the case.
Some things seemed odd but non-relevant. For example for `enum E : int {};`  
`EnumDecl::NumPositiveBits` is set to 1, but it stays 0 for the opaque 
declaration `enum E : int;`. I also noticed that I can trigger a case where [a 
diagnostic gets reported twice](https://godbolt.org/z/473Eezhjn)). This, 
however, seems rather unrelated to me. I would rather open up a separate pull 
request for that.

Thanks again for your feedback @cor3ntin - it helped me to get a much cleaner 
solution and a better understanding of the issue even though my initial 
analysis might have been a little confusing ...
Well, I hope it's now ready for merging. đŸ™‚

I rebased my branch on the current main and also "rebased away" my prior fix to 
make the diff more concise.


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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-05 Thread via cfe-commits


@@ -951,28 +959,130 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+namespace {
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+bool CheckBindingsCount(Sema &S, DecompositionDecl *DD, QualType DecompType,
+ArrayRef Bindings,
+unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+TemplateTypeParmDecl *DummyTemplateParam = TemplateTypeParmDecl::Create(
+S.Context, S.Context.getTranslationUnitDecl(),
+/*KeyLoc*/ SourceLocation(), /*NameLoc*/ SourceLocation(),
+/*TemplateDepth*/ 0, /*AutoParameterPosition*/ 0,
+/*Identifier*/ nullptr, false, /*IsParameterPack*/ true);
+
+// create the pack expr and assign it to the binding
+unsigned PackSize = MemberCount - Bindings.size() + 1;
+QualType PackType = S.Context.getPackExpansionType(
+QualType(DummyTemplateParam->getTypeForDecl(), 0), PackSize);
+(*BindingWithPackItr)
+->setBinding(PackType,
+ ResolvedUnexpandedPackExpr::Create(
+ S.Context, DD->getBeginLoc(), DecompType, PackSize));
+  }
+
+  if (IsValid)
+return false;
+
+  S.Diag(DD->getLocation(), diag::err_decomp_decl_wrong_number_bindings)
+  << DecompType << (unsigned)Bindings.size() << MemberCount << MemberCount
+  << (MemberCount < Bindings.size());
+  return true;
+}
+
+// BindingInitWalker
+//  - This implements a forward iterating flattened view
+//of structured bindings that may have a nested pack.
+//It allows the user to set the init expr for either the
+//BindingDecl or its ResolvedUnexpandedPackExpr

cor3ntin wrote:

TrailingObjects are contiguous.
I am indeed wondering if we lose anything by creating Ns binding here, instead 
of one binding that wraps a `ResolvedUnexpandedPackExpr` that wraps a reference 
to a nested BindingDecl

(we would indeed most certainly have to track the pattern somewhere if we go 
that route)

I'm still thinking about it, maybe @zyn0217 and @erichkeane have opinionsd




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


[clang] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-01-05 Thread Sharadh Rajaraman via cfe-commits

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)

2025-01-05 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

We also need to export `std::ranges::concat_view` and 
`std::ranges::views::concat` in `main/libcxx/modules/std/ranges.inc`.

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)

2025-01-05 Thread A. Jiang via cfe-commits


@@ -0,0 +1,623 @@
+// -*- 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___RANGES_CONCAT_VIEW_H
+#define _LIBCPP___RANGES_CONCAT_VIEW_H
+
+#include <__algorithm/ranges_find_if.h>
+#include <__assert>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iter_swap.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/movable_box.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__ranges/zip_view.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_nothrow_constructible.h>
+#include <__type_traits/is_nothrow_convertible.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/make_unsigned.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+namespace ranges {
+
+template 
+struct __extract_last : __extract_last<_Tail...> {};

frederick-vs-ja wrote:

Perhaps we should add workaround for GCC 14 which hadn't implemented pack 
indexing.

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


[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-05 Thread via cfe-commits
=?utf-8?q?André?= Brand 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

> Thanks for the PR. Can you update the commit message to be more descriptive?
> 
> I'm not sure the fix is sufficient.
> I think most of the checks done in `ActOnEnumBody` should be (re) performed 
> on instantiation.
> 
> Maybe we should instead
> 
> - Add a new `BuildEnumBody` function, move most (all?) the implementation of  
> `ActOnEnumBody` to that
> - call `BuildEnumBody` from both `ActOnEnumBody` and `RebuildEnumType`
> 
> That would not only fix the crash but also the fact that we are seemingly 
> missing a lot of diagnostics
> https://godbolt.org/z/17dTW4dEe
> 

@erichkeane wdyt?

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)

2025-01-05 Thread A. Jiang via cfe-commits


@@ -0,0 +1,623 @@
+// -*- 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___RANGES_CONCAT_VIEW_H
+#define _LIBCPP___RANGES_CONCAT_VIEW_H
+
+#include <__algorithm/ranges_find_if.h>
+#include <__assert>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iter_swap.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/movable_box.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__ranges/zip_view.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_nothrow_constructible.h>
+#include <__type_traits/is_nothrow_convertible.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/make_unsigned.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+

frederick-vs-ja wrote:

I _guess_ some OS header is defining `move` as a macro, but I'm not sure.

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


[clang] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-01-05 Thread Sharadh Rajaraman via cfe-commits

sharadhr wrote:

> Why is this submitted against the release/19.x branch? Is this a backport? If 
> so, please indicate which commit it backports.

Not a backport but a fix. I have now re-submitted it against `main`, but I'd 
like it back-ported to `19.x` if possible.

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


[clang] [clang] Add test for CWG794 "Base-derived conversion in member type of pointer-to-member conversion" (PR #121660)

2025-01-05 Thread via cfe-commits

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


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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits


@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);

a-tarasyuk wrote:

@cor3ntin thanks for the review. I've changed param

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


[clang] [Clang] disallow attributes after namespace identifier (PR #121614)

2025-01-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121614

>From b8f6ffc0a98a0d3ac55fba4e6ee680f1edea4571 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 4 Jan 2025 02:24:26 +0200
Subject: [PATCH 1/2] [Clang] disallow attributes after namespace identifier

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |  9 ++---
 clang/test/Parser/namespace-attributes.cpp| 10 +-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..43a95fd022c070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -553,6 +553,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 86fcae209c40db..9d76376cd6b015 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -283,6 +283,8 @@ def err_unexpected_qualified_namespace_alias : Error<
   "namespace alias must be a single identifier">;
 def err_unexpected_nested_namespace_attribute : Error<
   "attributes cannot be specified on a nested namespace definition">;
+def err_attribute_after_namespace : Error<
+  "standard attributes cannot appear after the namespace name">;
 def err_inline_namespace_alias : Error<"namespace alias cannot be inline">;
 def err_namespace_nonnamespace_scope : Error<
   "namespaces can only be defined in global or namespace scope">;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f30603feb65c5d..ec87163ffb7cee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -81,7 +81,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 
   ParsedAttributes attrs(AttrFactory);
 
-  auto ReadAttributes = [&] {
+  auto ReadAttributes = [&](bool TrailingAttrs) {
 bool MoreToParse;
 do {
   MoreToParse = false;
@@ -90,6 +90,9 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 MoreToParse = true;
   }
   if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
+if (TrailingAttrs)
+  Diag(Tok.getLocation(), diag::err_attribute_after_namespace);
+
 Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
 ? diag::warn_cxx14_compat_ns_enum_attribute
 : diag::ext_ns_enum_attribute)
@@ -100,7 +103,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 } while (MoreToParse);
   };
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ false);
 
   if (Tok.is(tok::identifier)) {
 Ident = Tok.getIdentifierInfo();
@@ -126,7 +129,7 @@ Parser::DeclGroupPtrTy 
Parser::ParseNamespace(DeclaratorContext Context,
 }
   }
 
-  ReadAttributes();
+  ReadAttributes(/*TrailingAttrs*/ true);
 
   SourceLocation attrLoc = attrs.Range.getBegin();
 
diff --git a/clang/test/Parser/namespace-attributes.cpp 
b/clang/test/Parser/namespace-attributes.cpp
index 9f925b742dfebd..8a873c55c5d633 100644
--- a/clang/test/Parser/namespace-attributes.cpp
+++ b/clang/test/Parser/namespace-attributes.cpp
@@ -16,11 +16,11 @@ namespace [[]] __attribute__(()) A
 {
 }
 
-namespace A __attribute__(()) [[]]
+namespace A __attribute__(()) [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A [[]] __attribute__(())
+namespace A [[]] __attribute__(()) // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
@@ -28,14 +28,14 @@ namespace [[]] A __attribute__(())
 {
 }
 
-namespace __attribute__(()) A [[]]
+namespace __attribute__(()) A [[]] // expected-error {{standard attributes 
cannot appear after the namespace name}}
 {
 }
 
-namespace A::B __attribute__(()) // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace A::B __attribute__(()) // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }
 
-namespace __attribute__(()) A::B // expected-error{{attributes cannot be 
specified on a nested namespace definition}}
+namespace __attribute__(()) A::B // expected-error {{attributes cannot be 
specified on a nested namespace definition}}
 {
 }

>From b8bf77687644c035683ae64a0a2a8e788ad74a83 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 5 Jan 2025 12:07:40 +0200
Subject: [PATCH 2/2] change param name from TrailingAttrs to
 Che

[clang] [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (PR #121654)

2025-01-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `clang` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/59/builds/10583


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/1/3 (2054 of 2063)
PASS: lldb-unit :: Utility/./UtilityTests/1/8 (2055 of 2063)
PASS: lldb-unit :: Utility/./UtilityTests/4/8 (2056 of 2063)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/2/3 (2057 of 2063)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/0/2 (2058 of 2063)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/1/2 (2059 of 2063)
PASS: lldb-unit :: Target/./TargetTests/11/14 (2060 of 2063)
PASS: lldb-unit :: Host/./HostTests/2/13 (2061 of 2063)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests/8/9 (2062 of 2063)
UNRESOLVED: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (2063 of 2063)
 TEST 'lldb-api :: tools/lldb-server/TestLldbGdbServer.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-server
 -p TestLldbGdbServer.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
64e8d5b1baaa478c40931d290bf30687a6c93dac)
  clang revision 64e8d5b1baaa478c40931d290bf30687a6c93dac
  llvm revision 64e8d5b1baaa478c40931d290bf30687a6c93dac
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_another_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_minus_one_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_zero_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_writes_all_gpr_registers_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for 

[clang] [clang][NFC] Make all C++ DR tests run in full range of language modes (PR #121688)

2025-01-05 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 327e2b7 - [clang][NFC] Make all C++ DR tests run in full range of language modes (#121688)

2025-01-05 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2025-01-05T16:13:44+04:00
New Revision: 327e2b7c7659e2fff2e644850b767ca77234bef4

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

LOG: [clang][NFC] Make all C++ DR tests run in full range of language modes 
(#121688)

This patch plugs holes in RUN lines in C++ DR tests, making sure they
are run in C++98 through C++26, with the exception of C++03, which in
Clang is synonymous to C++98.

Added: 
clang/test/CXX/drs/cwg593.cpp

Modified: 
clang/test/CXX/drs/cwg0xx.cpp
clang/test/CXX/drs/cwg10xx.cpp
clang/test/CXX/drs/cwg118.cpp
clang/test/CXX/drs/cwg11xx.cpp
clang/test/CXX/drs/cwg12xx.cpp
clang/test/CXX/drs/cwg158.cpp
clang/test/CXX/drs/cwg1748.cpp
clang/test/CXX/drs/cwg177x.cpp
clang/test/CXX/drs/cwg1xx.cpp
clang/test/CXX/drs/cwg2771.cpp
clang/test/CXX/drs/cwg2xx.cpp
clang/test/CXX/drs/cwg3xx.cpp
clang/test/CXX/drs/cwg6xx.cpp
clang/test/CXX/drs/cwg7xx.cpp
clang/test/CXX/drs/cwg9xx.cpp

Removed: 
clang/test/CXX/drs/cwgr593.cpp



diff  --git a/clang/test/CXX/drs/cwg0xx.cpp b/clang/test/CXX/drs/cwg0xx.cpp
index 993b6f29238593..8f7bd6532ae6d5 100644
--- a/clang/test/CXX/drs/cwg0xx.cpp
+++ b/clang/test/CXX/drs/cwg0xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 
-fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
 
 #if __cplusplus == 199711L
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)

diff  --git a/clang/test/CXX/drs/cwg10xx.cpp b/clang/test/CXX/drs/cwg10xx.cpp
index 58d552942c77cc..01de13238a6ae2 100644
--- a/clang/test/CXX/drs/cwg10xx.cpp
+++ b/clang/test/CXX/drs/cwg10xx.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions 
-fcxx-exceptions -pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;

diff  --git a/clang/test/CXX/drs/cwg118.cpp b/clang/test/CXX/drs/cwg118.cpp
index 04e19ce050788c..c7685fdb4f5b17 100644
--- a/clang/test/CXX/drs/cwg118.cpp
+++ b/clang/test/CXX/drs/cwg118.cpp
@@ -1,7 +1,11 @@
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++98 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++11 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
 // RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
-// RUN: %clang_cc1 -triple x86_64-linux -std=c++1z %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++17 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++20 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++23 %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++2c %s -pedantic-errors 
-emit-llvm -o - | FileCheck %s --implicit-check-not " call "
+
 
 // cwg118: yes
 

diff  --git a/clang/test/CXX/drs/cwg11xx.cpp b/clang/test/CXX/drs/cwg11xx.cpp
index d33ff060d2d39e..dc024caa5075ba 100644
--- a/clang/test/CXX/drs/cwg11xx.cpp
+++ b/clang/test/CXX/drs/cwg11xx.cpp
@@ -2,7 +2,9 @@
 // RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify=expected -fexceptions 
-fcxx-exceptions -pedant

[clang] [clang] Add tests from CWG156 to CWG1111 (dual-scope lookup for conversion-function-ids) (PR #121654)

2025-01-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot12` 
while building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/55/builds/5080


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 85703 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 
FAIL: LLVM :: 
ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (52302 of 
85703)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc
 -filetype=obj -triple=x86_64-windows-msvc 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc
 -filetype=obj -triple=x86_64-windows-msvc 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
RUN: at line 2: not 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink
 -noexec 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
 2>&1 | 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
+ not 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink
 -noexec 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s

--


Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--
55.36s: Clang :: Driver/fsanitize.c
42.09s: Clang :: Preprocessor/riscv-target-features.c
39.19s: Clang :: Driver/arm-cortex-cpus-2.c
38.32s: Clang :: Driver/arm-cortex-cpus-1.c
35.46

[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-05 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/121656

>From 4cd48886384570e0e5bb0b712f4fd45f8decd27e Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 4 Jan 2025 17:36:05 +0100
Subject: [PATCH 1/2] [Clang][ASTMatcher] Add a matcher for the name of a
 DependentScopeDeclRefExpr

---
 clang/docs/LibASTMatchersReference.html   | 13 +
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h | 11 +++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 .../ASTMatchers/ASTMatchersNarrowingTest.cpp  | 15 +++
 5 files changed, 42 insertions(+)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index fc557888013254..6a03aeb5eec2a1 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3449,6 +3449,19 @@ Narrowing Matchers
 
 
 
+MatcherDependentScopeDeclRefExpr>hasDependentNamestd::string 
N
+Matches the 
dependent name of a dependent scope decl ref expr.
+
+Matches the dependent name of a dependent scope decl ref expr
+
+Given:
+
+  template CXXDependentScopeMemberExpr>memberHasSameNameAsBoundNodestd::string
 BindingID
 Matches template-dependent, but known, 
member names against an already-bound
 node
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e75fc447636e0..4ef69ca4c743ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1116,6 +1116,8 @@ AST Matchers
 
 - Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
 
+- Add ``hasDependentName`` matcher to match the dependent name of a dependent 
scope decl ref expr.
+
 clang-format
 
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index dd0fedb2cda2d4..6828fc6da1d5cf 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3257,6 +3257,17 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, 
memberHasSameNameAsBoundNode,
   });
 }
 
+/// Matches the dependent name of a dependent scope decl ref expr
+///
+/// Given:
+/// \code
+///  template  class X : T { void f() { T::v; } };
+/// \endcode
+/// \c dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`
+AST_MATCHER_P(DependentScopeDeclRefExpr, hasDependentName, std::string, N) {
+  return Node.getDeclName().getAsString() == N;
+}
+
 /// Matches C++ classes that are directly or indirectly derived from a class
 /// matching \c Base, or Objective-C classes that directly or indirectly
 /// subclass a class matching \c Base.
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 97e6bbc093fe46..336d3a14f79559 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -314,6 +314,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasDeducedType);
   REGISTER_MATCHER(hasDefaultArgument);
   REGISTER_MATCHER(hasDefinition);
+  REGISTER_MATCHER(hasDependentName);
   REGISTER_MATCHER(hasDescendant);
   REGISTER_MATCHER(hasDestinationType);
   REGISTER_MATCHER(hasDirectBase);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 056b7c7b571ef4..4278e3d4fe5959 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2235,6 +2235,21 @@ TEST_P(ASTMatchersTest, 
ArgumentCountIs_CXXConstructExpr) {
  Constructor1Arg));
 }
 
+TEST_P(ASTMatchersTest, hasDependentName_DependentScopeDeclRefExpr) {
+  if (!GetParam().isCXX() || GetParam().hasDelayedTemplateParsing()) {
+// FIXME: Fix this test to work with delayed template parsing.
+return;
+  }
+
+  EXPECT_TRUE(matches("template  class X : T { void f() { T::v; } };",
+  dependentScopeDeclRefExpr(hasDependentName("v";
+
+  EXPECT_TRUE(
+  matches("template  struct S { static T Foo; };"
+  "template  void declToImport() { (void)S::Foo; }",
+  dependentScopeDeclRefExpr(hasDependentName("Foo";
+}
+
 TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {
 
   // Member functions:

>From e653a695260143304b71af662f98b1826082d2f6 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 5 Jan 2025 13:42:55 +0100
Subject: [PATCH 2/2] Address code review comments

---
 clang/docs/LibASTMatchersReference.html |  4 ++--
 clang/include/clang/ASTMatchers/ASTMatchers.h   |

  1   2   >