[clang] [webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis (PR #127309)

2025-02-15 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the timely review!

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


[clang] [webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis (PR #127309)

2025-02-15 Thread Ryosuke Niwa via cfe-commits

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


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-02-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Chris B (llvm-beanz)


Changes

This PR disallows virtual inheritance and virtual functions in HLSL.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+6-1) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+3) 
- (added) clang/test/SemaHLSL/Language/NoVirtual.hlsl (+14) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..bec3b5d48fd51 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,5 +1817,7 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function : Error<"virtual functions are unsupported in 
HLSL">;
+def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported 
in HLSL">;
 
 } // end of Parser diagnostics
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ae136af47391..dfa2dbf5ab61f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4411,7 +4411,12 @@ void Parser::ParseDeclarationSpecifiers(
 DiagID = diag::err_openclcxx_virtual_function;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
-  } else {
+  } else if (getLangOpts().HLSL) {
+DiagID = diag::err_hlsl_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
 isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
   }
   break;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 43db715ac6d70..dbc6d5f7c43a3 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2491,6 +2491,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
 IsVirtual = true;
   }
 
+  if (getLangOpts().HLSL && IsVirtual)
+Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
+
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
   // Parse the class-name.
diff --git a/clang/test/SemaHLSL/Language/NoVirtual.hlsl 
b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
new file mode 100644
index 0..8d61bde7d836e
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
+
+struct Base {
+  int X;
+  void MemberFunction();  // valid
+  virtual void MemberFunction2(); // expected-error{{virtual functions are 
unsupported in HLSL}}
+};
+
+struct Derived : virtual Base { // expected-error{{virtual inheritance is 
unsupported in HLSL}}
+  int Y;
+
+  void MemberFunction2() override; // expected-error{{only virtual member 
functions can be marked 'override'}}
+};
+

``




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


[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-02-15 Thread Fangrui Song via cfe-commits

MaskRay wrote:

CLANG_INSTALL_LIBDIR_BASENAME can be "lib" or "lib64". I think it should only 
be used for libraries outside of llvm-project, like how cuda/amdgpu libs are 
installed by system. For llvm-project installed libs, it's much better to stick 
with a uniform "lib", which is easy to test in clang/test/Driver `%clang -###` 
and avoid platform differences (the test will not break on a different 
installation just because CLANG_INSTALL_LIBDIR_BASENAME is different).

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


[clang] [FreeBSD] Support -stdlib=libstdc++ (PR #126302)

2025-02-15 Thread Alexander Richardson via cfe-commits

arichardson wrote:

ping, is this ok to merge?

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


[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-02-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Michał Górny (mgorny)


Changes

Fix `tools::addFortranRuntimeLibraryPath` to use
`CLANG_INSTALL_LIBDIR_BASENAME` rather than hardwired `lib` directory. This 
fixes flang being unable to find its runtime when installed into nonstandard 
directory on a system using `lib64` for 64-bit libraries. While technically 
flang runtime could be installed with a different libdir value than clang, it 
seems rather unlikely.

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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2d01943ca1ac4..47e6fd9dbf902 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1367,7 +1367,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);
-  llvm::sys::path::append(DefaultLibPath, "lib");
+  llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
   if (TC.getTriple().isKnownWindowsMSVCEnvironment())
 CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
   else

``




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


[clang] [HLSL] Implement HLSL intialization list support (PR #123141)

2025-02-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`ppc64le-lld-multistage-test` running on `ppc64le-lld-multistage-test` while 
building `clang` at step 12 "build-stage2-unified-tree".

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


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

```
Step 12 (build-stage2-unified-tree) failure: build (failure)
...
217.876 [899/780/4784] Linking CXX static library lib/libLLVMPowerPCAsmParser.a
217.881 [899/779/4785] Building CXX object 
tools/clang/unittests/Format/CMakeFiles/FormatTests.dir/SortImportsTestJava.cpp.o
217.885 [899/778/4786] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGCXX.cpp.o
217.936 [899/777/4787] Building CXX object 
lib/Target/PowerPC/CMakeFiles/LLVMPowerPCCodeGen.dir/PPCPreEmitPeephole.cpp.o
217.977 [899/776/4788] Building AMDGPUGenMCCodeEmitter.inc...
218.032 [899/775/4789] Building CXX object 
tools/clang/unittests/Format/CMakeFiles/FormatTests.dir/FormatTestTextProto.cpp.o
218.037 [899/774/4790] Building CXX object 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/TypePrinter.cpp.o
218.040 [899/773/4791] Building CXX object 
tools/clang/unittests/Format/CMakeFiles/FormatTests.dir/FormatTestSelective.cpp.o
218.067 [899/772/4792] Building CXX object 
lib/Target/XCore/CMakeFiles/LLVMXCoreCodeGen.dir/XCoreAsmPrinter.cpp.o
218.119 [899/771/4793] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o
FAILED: tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o 
ccache 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/install/stage1/bin/clang++
 -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -MF 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o.d -o 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Sema/SemaHLSL.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Sema/SemaHLSL.cpp:3226:17:
 error: variable 'RTy' set but not used [-Werror,-Wunused-but-set-variable]
 3226 |   if (auto *RTy = Ty->getAs())
  | ^
1 error generated.
218.192 [899/770/4794] Building CXX object 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/Stmt.cpp.o
218.248 [899/769/4795] Building CXX object 
unittests/Target/PowerPC/CMakeFiles/PowerPCTests.dir/AIXRelocModelTest.cpp.o
218.253 [899/768/4796] Building CXX object 
tools/clang/unittests/Lex/CMakeFiles/LexTests.dir/ModuleDeclStateTest.cpp.o
218.304 [899/767/4797] Building CXX object 
tools/clang/tools/clang-refactor/CMakeFiles/clang-refactor.dir/TestSupport.cpp.o
218.308 [899/766/4798] Building CXX object 
lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64AdvSIMDScalarPass.cpp.o
218.369 [899/765/4799] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/ABIInfoImpl.cpp.o
218.376 [899/764/4800] Building CXX object 
tools/clang/tools/clang-format/CMakeFiles/clang-format.dir/ClangFormat.cpp.o
218.502 [899/763/4801] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/ABIInfo.cpp.o
21

[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-02-15 Thread Michał Górny via cfe-commits

https://github.com/mgorny created 
https://github.com/llvm/llvm-project/pull/127345

Fix `tools::addFortranRuntimeLibraryPath` to use
`CLANG_INSTALL_LIBDIR_BASENAME` rather than hardwired `lib` directory. This 
fixes flang being unable to find its runtime when installed into nonstandard 
directory on a system using `lib64` for 64-bit libraries. While technically 
flang runtime could be installed with a different libdir value than clang, it 
seems rather unlikely.

From a41cebcc8f7887864de2a0447d64faa9c95e02b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Sat, 15 Feb 2025 21:00:16 +0100
Subject: [PATCH] [clang] [Driver] Fix respecting libdir when locating flang
 runtime

Fix `tools::addFortranRuntimeLibraryPath` to use
`CLANG_INSTALL_LIBDIR_BASENAME` rather than hardwired `lib` directory.
This fixes flang being unable to find its runtime when installed into
nonstandard directory on a system using `lib64` for 64-bit libraries.
While technically flang runtime could be installed with a different
libdir value than clang, it seems rather unlikely.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2d01943ca1ac4..47e6fd9dbf902 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1367,7 +1367,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
&TC,
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);
-  llvm::sys::path::append(DefaultLibPath, "lib");
+  llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
   if (TC.getTriple().isKnownWindowsMSVCEnvironment())
 CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
   else

___
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++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-15 Thread Nhat Nguyen via cfe-commits

https://github.com/changkhothuychung updated 
https://github.com/llvm/llvm-project/pull/120920

error: too big or took too long to generate
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement HLSL intialization list support (PR #123141)

2025-02-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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)
...
[3613/4131] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/SimplifyInstructions.cpp.o
[3614/4131] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/StripDebugInfo.cpp.o
[3615/4131] Building CXX object 
tools/llvm-rtdyld/CMakeFiles/llvm-rtdyld.dir/llvm-rtdyld.cpp.o
[3616/4131] Building CXX object 
tools/llvm-rust-demangle-fuzzer/CMakeFiles/llvm-rust-demangle-fuzzer.dir/DummyDemanglerFuzzer.cpp.o
[3617/4131] Building CXX object 
tools/llvm-stress/CMakeFiles/llvm-stress.dir/llvm-stress.cpp.o
[3618/4131] Building CXX object 
tools/llvm-tli-checker/CMakeFiles/llvm-tli-checker.dir/llvm-tli-checker.cpp.o
[3619/4131] Building CXX object 
tools/llvm-yaml-numeric-parser-fuzzer/CMakeFiles/llvm-yaml-numeric-parser-fuzzer.dir/yaml-numeric-parser-fuzzer.cpp.o
[3620/4131] Building CXX object 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParsePragma.cpp.o
[3621/4131] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaDeclObjC.cpp.o
[3622/4131] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o
FAILED: tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm_build0/bin/clang++
 -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/tools/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/tools/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/build_default/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -MF 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o.d -o 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/clang/lib/Sema/SemaHLSL.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/llvm-project/clang/lib/Sema/SemaHLSL.cpp:3226:17:
 error: variable 'RTy' set but not used [-Werror,-Wunused-but-set-variable]
 3226 |   if (auto *RTy = Ty->getAs())
  | ^
1 error generated.
[3623/4131] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaInit.cpp.o
[3624/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGCXX.cpp.o
[3625/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGCXXABI.cpp.o
[3626/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGObjCRuntime.cpp.o
[3627/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGOpenCLRuntime.cpp.o
[3628/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/Targets/CSKY.cpp.o
[3629/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/Targets/Lanai.cpp.o
[3630/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/Targets/M68k.cpp.o
[3631/4131] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/Targets/TCE.cpp.o
[3632/4131] Buildi

[clang] [HLSL] Implement HLSL intialization list support (PR #123141)

2025-02-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64le-rhel` 
running on `ppc64le-clang-rhel-test` while building `clang` at step 5 
"build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
42.413 [352/192/215] Creating library symlink lib/libclangdSupport.so
43.660 [351/192/216] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/DeclSpec.cpp.o
43.894 [350/192/217] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaSwift.cpp.o
44.019 [349/192/218] Linking CXX shared library 
lib/libclangdRemoteIndex.so.21.0git
44.041 [348/192/219] Creating library symlink lib/libclangdRemoteIndex.so
44.622 [347/192/220] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaFixItUtils.cpp.o
44.762 [346/192/221] Linking CXX executable bin/amdgpu-arch
44.924 [345/192/222] Linking CXX executable bin/nvptx-arch
45.049 [344/192/223] Linking CXX executable bin/lli-child-target
45.156 [343/192/224] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o
FAILED: tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.19.1.7/bin/clang++ 
--gcc-toolchain=/gcc-toolchain/usr -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/tools/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/clang/lib/Sema
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/tools/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -MF 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o.d -o 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaHLSL.cpp.o -c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/clang/lib/Sema/SemaHLSL.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/clang/lib/Sema/SemaHLSL.cpp:3226:17:
 error: variable 'RTy' set but not used [-Werror,-Wunused-but-set-variable]
 3226 |   if (auto *RTy = Ty->getAs())
  | ^
1 error generated.
45.181 [343/191/225] Linking CXX executable bin/llvm-as
45.285 [343/190/226] Building CXX object 
tools/clang/lib/Serialization/CMakeFiles/obj.clangSerialization.dir/GeneratePCH.cpp.o
46.324 [343/189/227] Building CXX object 
tools/clang/tools/diagtool/CMakeFiles/diagtool.dir/ListWarnings.cpp.o
46.341 [343/188/228] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaCXXScopeSpec.cpp.o
46.736 [343/187/229] Building CXX object 
tools/clang/tools/diagtool/CMakeFiles/diagtool.dir/FindDiagnosticID.cpp.o
46.787 [343/186/230] Building CXX object 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseAST.cpp.o
46.920 [343/185/231] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/CheckExprLifetime.cpp.o
47.348 [343/184/232] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaAccess.cpp.o
47.932 [343/183/233] Building CXX object 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/DeclCXX.cpp.o
48.009 [343/182/234] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/CodeCompleteConsumer.cpp.o
48.579 [343/181/235] Building CXX object 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseHLSL.cpp.o
48.750 [343/180/236] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaOpenACC.cpp.o
48.840 [343/179/237] Building CXX object 
tools/clang/lib/Parse/CMakeFiles

[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-02-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz created 
https://github.com/llvm/llvm-project/pull/127346

This PR disallows virtual inheritance and virtual functions in HLSL.

>From e62dc4bfc4f1cff2a624caf70fcc7bb0dc4a6236 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Sat, 15 Feb 2025 14:34:05 -0600
Subject: [PATCH] [HLSL] Disallow virtual inheritance and functions

This PR disallows virtual inheritance and virtual functions in HLSL.
---
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDecl.cpp |  7 ++-
 clang/lib/Parse/ParseDeclCXX.cpp  |  3 +++
 clang/test/SemaHLSL/Language/NoVirtual.hlsl   | 14 ++
 4 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaHLSL/Language/NoVirtual.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..bec3b5d48fd51 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,5 +1817,7 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function : Error<"virtual functions are unsupported in 
HLSL">;
+def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported 
in HLSL">;
 
 } // end of Parser diagnostics
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ae136af47391..dfa2dbf5ab61f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4411,7 +4411,12 @@ void Parser::ParseDeclarationSpecifiers(
 DiagID = diag::err_openclcxx_virtual_function;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
-  } else {
+  } else if (getLangOpts().HLSL) {
+DiagID = diag::err_hlsl_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
 isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
   }
   break;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 43db715ac6d70..dbc6d5f7c43a3 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2491,6 +2491,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
 IsVirtual = true;
   }
 
+  if (getLangOpts().HLSL && IsVirtual)
+Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
+
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
   // Parse the class-name.
diff --git a/clang/test/SemaHLSL/Language/NoVirtual.hlsl 
b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
new file mode 100644
index 0..8d61bde7d836e
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
+
+struct Base {
+  int X;
+  void MemberFunction();  // valid
+  virtual void MemberFunction2(); // expected-error{{virtual functions are 
unsupported in HLSL}}
+};
+
+struct Derived : virtual Base { // expected-error{{virtual inheritance is 
unsupported in HLSL}}
+  int Y;
+
+  void MemberFunction2() override; // expected-error{{only virtual member 
functions can be marked 'override'}}
+};
+

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


[clang] 50581ef - [NFC] Fix warning in recent commit

2025-02-15 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2025-02-15T14:19:31-06:00
New Revision: 50581ef1ee45815b9230043319de5ae93680d4ad

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

LOG: [NFC] Fix warning in recent commit

Added: 


Modified: 
clang/lib/Sema/SemaHLSL.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index be45761552290..957c3a0888438 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -3223,7 +3223,7 @@ bool SemaHLSL::TransformInitList(const InitializedEntity 
&Entity,
 Expr *E = Init->getInit(I);
 if (E->HasSideEffects(Ctx)) {
   QualType Ty = E->getType();
-  if (auto *RTy = Ty->getAs())
+  if (Ty->isRecordType())
 E = new (Ctx) MaterializeTemporaryExpr(Ty, E, E->isLValue());
   E = new (Ctx) OpaqueValueExpr(E->getBeginLoc(), Ty, E->getValueKind(),
 E->getObjectKind(), E);



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


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-02-15 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 50581ef1ee45815b9230043319de5ae93680d4ad 
e62dc4bfc4f1cff2a624caf70fcc7bb0dc4a6236 --extensions cpp -- 
clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index dfa2dbf5ab..eb72fb892b 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4415,8 +4415,7 @@ void Parser::ParseDeclarationSpecifiers(
 DiagID = diag::err_hlsl_virtual_function;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
-  }
-  else {
+  } else {
 isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
   }
   break;

``




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


[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

This PR reapply https://github.com/llvm/llvm-project/pull/117437.


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


10 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/AST/ParentMap.cpp (+17) 
- (modified) clang/lib/Analysis/CFG.cpp (+45-9) 
- (modified) clang/lib/Analysis/ReachableCode.cpp (+19-18) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+6-3) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+34-22) 
- (modified) clang/test/AST/ast-dump-recovery.cpp (+1-1) 
- (modified) clang/test/Analysis/lifetime-extended-regions.cpp (+3-4) 
- (modified) clang/test/SemaCXX/cxx2c-placeholder-vars.cpp (+4-4) 
- (modified) clang/test/SemaCXX/warn-unreachable.cpp (+75) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index efaacdf18d50a..6272f32fa845a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -270,6 +270,10 @@ Code Completion
 Static Analyzer
 ---
 
+- Clang currently support extending lifetime of object bound to 
+  reference members of aggregates in CFG and ExprEngine, that are
+  created from default member initializer.
+
 New features
 
 
diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index e62e71bf5a514..580613b2618fb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "llvm/ADT/DenseMap.h"
 
@@ -103,6 +104,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 3e144395cffc6..add673aa2e7ab 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,10 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default,
+   AddStmtChoice asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default,
+AddStmtChoice asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2263,16 +2267,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2442,6 +2440,44 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+
+  // We can't add the default argument if it's not rewritten because the
+  // expression inside a CXXDefaultArgExpr is owned by the called function's
+  // declaration, not by the caller, we could end up with the same expression
+  // appearing multiple times.
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
+  AddStmtChoice asc) {
+  if (Init->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Init)) {
+  autoCreateBlock();
+  appendStmt(Block, Init);
+  

[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread via cfe-commits

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


[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/127338

This PR reapply https://github.com/llvm/llvm-project/pull/117437.


>From 092af69607909859e9d352e51122d9569c050464 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 15 Feb 2025 17:03:32 +0800
Subject: [PATCH 1/2] [Analyzer][CFG] Correctly handle rebuilt default arg and
 default init expression

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/AST/ParentMap.cpp   | 17 ++
 clang/lib/Analysis/CFG.cpp| 50 ++---
 clang/lib/Analysis/ReachableCode.cpp  | 37 ++--
 clang/lib/Sema/SemaExpr.cpp   |  9 ++-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  | 56 +++
 clang/test/AST/ast-dump-recovery.cpp  |  2 +-
 .../Analysis/lifetime-extended-regions.cpp|  7 +--
 clang/test/SemaCXX/cxx2c-placeholder-vars.cpp |  8 +--
 clang/test/SemaCXX/warn-unreachable.cpp   | 39 +
 10 files changed, 168 insertions(+), 61 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index efaacdf18d50a..6272f32fa845a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -270,6 +270,10 @@ Code Completion
 Static Analyzer
 ---
 
+- Clang currently support extending lifetime of object bound to 
+  reference members of aggregates in CFG and ExprEngine, that are
+  created from default member initializer.
+
 New features
 
 
diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index e62e71bf5a514..580613b2618fb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "llvm/ADT/DenseMap.h"
 
@@ -103,6 +104,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 3e144395cffc6..eec014649d73e 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,10 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default,
+   AddStmtChoice asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default,
+AddStmtChoice asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2263,16 +2267,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2442,6 +2440,40 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+
+  // We can't add the default argument if it's not rewritten because the
+  // expression inside a CXXDefaultArgExpr is owned by the called function's
+  // declaration, not by the caller, we could end up with the same expression
+  // appearing multiple times.
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXD

[clang-tools-extra] [clang-tidy] Add support for `-ignore-insert-conflict` in `run-clang-tidy.py` (PR #127066)

2025-02-15 Thread Nicolas van Kempen via cfe-commits
Vicente Mataix =?utf-8?q?Ferrándiz?= ,
Vicente Mataix =?utf-8?q?Ferrándiz?= ,
Vicente Mataix =?utf-8?q?Ferrándiz?= 
Message-ID:
In-Reply-To: 



@@ -446,6 +448,12 @@ async def main() -> None:
 action="store_true",
 help="Allow empty enabled checks.",
 )
+parser.add_argument(
+"-ignore-insert-conflict",
+action="store_true",
+default=True,

nicovank wrote:

Shouldn't this be false by default and toggled to true when the option is 
present?

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


[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

2025-02-15 Thread Balazs Benics via cfe-commits


@@ -91,6 +91,12 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`performance-redundant-lookup
+  ` check.
+
+  This check warns about potential redundant container lookup operations within

steakhal wrote:

Dropped in c6a681c955fef8b933374a05a157f48ba4ead360

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


[clang] [webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis (PR #127309)

2025-02-15 Thread Rashmi Mudduluru via cfe-commits

https://github.com/t-rasmud approved this pull request.


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


[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

2025-02-15 Thread Balazs Benics via cfe-commits

steakhal wrote:

> @steakhal: Please fix documentation and Release Notes wording that I 
> mentioned already.

Thanks, fixed!
I'm actually more curious about the semantic requirements, and about what 
directions should I explore more.

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


[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread Balazs Benics via cfe-commits


@@ -2464,6 +2464,10 @@ CFGBlock 
*CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
   autoCreateBlock();
   appendStmt(Block, Init);
 }
+
+// Unlike CXXDefaultArgExpr::getExpr stripped off the top level FullExpr 
and
+// ConstantExpr, CXXDefaultInitExpr::getExpr does not do this, so we don't
+// need to ignore ParenExprs, because the top level will not be a 
ParenExpr.

steakhal wrote:

>From the PR summary, I was expecting a semantic fix to the reapplied commit.
This commit only adds some comments. Did I miss something?

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


[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/127338

>From 092af69607909859e9d352e51122d9569c050464 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 15 Feb 2025 17:03:32 +0800
Subject: [PATCH 1/2] [Analyzer][CFG] Correctly handle rebuilt default arg and
 default init expression

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/AST/ParentMap.cpp   | 17 ++
 clang/lib/Analysis/CFG.cpp| 50 ++---
 clang/lib/Analysis/ReachableCode.cpp  | 37 ++--
 clang/lib/Sema/SemaExpr.cpp   |  9 ++-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  | 56 +++
 clang/test/AST/ast-dump-recovery.cpp  |  2 +-
 .../Analysis/lifetime-extended-regions.cpp|  7 +--
 clang/test/SemaCXX/cxx2c-placeholder-vars.cpp |  8 +--
 clang/test/SemaCXX/warn-unreachable.cpp   | 39 +
 10 files changed, 168 insertions(+), 61 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index efaacdf18d50a..6272f32fa845a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -270,6 +270,10 @@ Code Completion
 Static Analyzer
 ---
 
+- Clang currently support extending lifetime of object bound to 
+  reference members of aggregates in CFG and ExprEngine, that are
+  created from default member initializer.
+
 New features
 
 
diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index e62e71bf5a514..580613b2618fb 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ParentMap.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "llvm/ADT/DenseMap.h"
 
@@ -103,6 +104,22 @@ static void BuildParentMap(MapTy& M, Stmt* S,
   BuildParentMap(M, SubStmt, OVMode);
 }
 break;
+  case Stmt::CXXDefaultArgExprClass:
+if (auto *Arg = dyn_cast(S)) {
+  if (Arg->hasRewrittenInit()) {
+M[Arg->getExpr()] = S;
+BuildParentMap(M, Arg->getExpr(), OVMode);
+  }
+}
+break;
+  case Stmt::CXXDefaultInitExprClass:
+if (auto *Init = dyn_cast(S)) {
+  if (Init->hasRewrittenInit()) {
+M[Init->getExpr()] = S;
+BuildParentMap(M, Init->getExpr(), OVMode);
+  }
+}
+break;
   default:
 for (Stmt *SubStmt : S->children()) {
   if (SubStmt) {
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 3e144395cffc6..eec014649d73e 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -556,6 +556,10 @@ class CFGBuilder {
 
 private:
   // Visitors to walk an AST and construct the CFG.
+  CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default,
+   AddStmtChoice asc);
+  CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default,
+AddStmtChoice asc);
   CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc);
   CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc);
   CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc);
@@ -2263,16 +2267,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
asc, ExternallyDestructed);
 
 case Stmt::CXXDefaultArgExprClass:
+  return VisitCXXDefaultArgExpr(cast(S), asc);
+
 case Stmt::CXXDefaultInitExprClass:
-  // FIXME: The expression inside a CXXDefaultArgExpr is owned by the
-  // called function's declaration, not by the caller. If we simply add
-  // this expression to the CFG, we could end up with the same Expr
-  // appearing multiple times (PR13385).
-  //
-  // It's likewise possible for multiple CXXDefaultInitExprs for the same
-  // expression to be used in the same function (through aggregate
-  // initialization).
-  return VisitStmt(S, asc);
+  return VisitCXXDefaultInitExpr(cast(S), asc);
 
 case Stmt::CXXBindTemporaryExprClass:
   return VisitCXXBindTemporaryExpr(cast(S), asc);
@@ -2442,6 +2440,40 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
+ AddStmtChoice asc) {
+  if (Arg->hasRewrittenInit()) {
+if (asc.alwaysAdd(*this, Arg)) {
+  autoCreateBlock();
+  appendStmt(Block, Arg);
+}
+return VisitStmt(Arg->getExpr(), asc);
+  }
+
+  // We can't add the default argument if it's not rewritten because the
+  // expression inside a CXXDefaultArgExpr is owned by the called function's
+  // declaration, not by the caller, we could end up with the same expression
+  // appearing multiple times.
+  return VisitStmt(Arg, asc);
+}
+
+CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
+  

[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2025-02-15 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> seeing breaks in downstream build of rocPRIM

Probably need to revert the downstream revert of the original problematic patch 

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


[clang] [clang] [Driver] Fix respecting libdir when locating flang runtime (PR #127345)

2025-02-15 Thread Michał Górny via cfe-commits

mgorny wrote:

But `lib` is used for 32-bit libraries, and `lib64` for 64-bit libraries.

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


[clang] [flang] [CMake][Release] Statically link clang with stage1 runtimes (PR #127268)

2025-02-15 Thread Tom Stellard via cfe-commits

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

>From a705acfd439e6310648b0ed1ad612eaffc408ad5 Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Fri, 14 Feb 2025 17:46:25 +
Subject: [PATCH 1/6] [CMake][Release] Statically link clang with stage1
 runtimes

This change will cause clang and the other tools to statically link
against the runtimes built in stage1.  This will make the built binaries
more portable by eliminating dependencies on system libraries like
libgcc and libstdc++.
---
 clang/cmake/caches/Release.cmake | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index 23e99493087ff..290e186baf6fe 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -48,10 +48,8 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
 
 set(STAGE1_PROJECTS "clang")
 
-# Building Flang on Windows requires compiler-rt, so we need to build it in
-# stage1.  compiler-rt is also required for building the Flang tests on
-# macOS.
-set(STAGE1_RUNTIMES "compiler-rt")
+# Build all runtimes so we can statically link them into the stage2 compiler.
+set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind")
 
 if (LLVM_RELEASE_ENABLE_PGO)
   list(APPEND STAGE1_PROJECTS "lld")
@@ -90,9 +88,18 @@ else()
   set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING 
"")
 endif()
 
+if (LLVM_RELEASE_ENABLE_LTO)
+  # Enable LTO for the runtimes.  We need to configure stage1 clang to default
+  # to using lld as the linker because the stage1 toolchain will be used to
+  # build and link the runtimes.
+  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE 
STRING "")
+  set(LLVM_ENABLE_LLD ON CACHE STRING "")
+endif()
+
 # Stage 1 Common Config
 set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")
 set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")
+set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")
 
 # stage2-instrumented and Final Stage Config:
 # Options that need to be set in both the instrumented stage (if we are doing
@@ -102,6 +109,11 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO 
"${LLVM_RELEASE_ENABLE_LTO}"
 if (LLVM_RELEASE_ENABLE_LTO)
   set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
 endif()
+set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
+set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
+set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS "-rtlib=compiler-rt 
--unwindlib=libunwind -static-libgcc" STRING)
+set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS 
"-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING)
+set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS 
"-rtlib=compiler-rt --unwindlib=libunwind -static-libgcc" STRING)
 
 # Final Stage Config (stage2)
 set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" 
STRING)

>From c5680225d3fa6ef229b9d7bf8624fb9c81dddb2b Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 15 Feb 2025 03:02:07 +
Subject: [PATCH 2/6] Fix linker usage

---
 clang/cmake/caches/Release.cmake | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index 290e186baf6fe..310717ab47889 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -92,8 +92,7 @@ if (LLVM_RELEASE_ENABLE_LTO)
   # Enable LTO for the runtimes.  We need to configure stage1 clang to default
   # to using lld as the linker because the stage1 toolchain will be used to
   # build and link the runtimes.
-  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE 
STRING "")
-  set(LLVM_ENABLE_LLD ON CACHE STRING "")
+  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON 
-DLLVM_ENABLE_LLD=ON" CACHE STRING "")
 endif()
 
 # Stage 1 Common Config

>From 88e8ad406c26c6c65a2a6ed51d8b4696a0acf36e Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Sat, 15 Feb 2025 14:46:20 +
Subject: [PATCH 3/6] flang: Fix build with latest libc++

I think this first stopped working with
954836634abb446f18719b14120c386a929a42d1.  This patch fixes the
following error:

/home/runner/work/llvm-project/llvm-project/flang/runtime/io-api-minimal.cpp:153:11:
 error: '__libcpp_verbose_abort' is missing exception specification 'noexcept'
   153 | void std::__libcpp_verbose_abort(char const *format, ...) {
   |   ^
   |   noexcept
/mnt/build/bin/../include/c++/v1/__verbose_abort:30:28: note: previous 
declaration is here
30 | __printf__, 1, 2) void __libcpp_verbose_abort(const char* 
__format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
   |^
1 error generated.
---
 flang/runtime/io-api-minimal.cpp | 7 ++-
 1 file changed, 6 insertions

[clang] [clang-tools-extra] [libcxx] [llvm] [libc++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-15 Thread Nhat Nguyen via cfe-commits

https://github.com/changkhothuychung updated 
https://github.com/llvm/llvm-project/pull/120920

error: too big or took too long to generate
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-02-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/127346

>From e62dc4bfc4f1cff2a624caf70fcc7bb0dc4a6236 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Sat, 15 Feb 2025 14:34:05 -0600
Subject: [PATCH 1/2] [HLSL] Disallow virtual inheritance and functions

This PR disallows virtual inheritance and virtual functions in HLSL.
---
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Parse/ParseDecl.cpp |  7 ++-
 clang/lib/Parse/ParseDeclCXX.cpp  |  3 +++
 clang/test/SemaHLSL/Language/NoVirtual.hlsl   | 14 ++
 4 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaHLSL/Language/NoVirtual.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..bec3b5d48fd51 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,5 +1817,7 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
+def err_hlsl_virtual_function : Error<"virtual functions are unsupported in 
HLSL">;
+def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported 
in HLSL">;
 
 } // end of Parser diagnostics
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 7ae136af47391..dfa2dbf5ab61f 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4411,7 +4411,12 @@ void Parser::ParseDeclarationSpecifiers(
 DiagID = diag::err_openclcxx_virtual_function;
 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
 isInvalid = true;
-  } else {
+  } else if (getLangOpts().HLSL) {
+DiagID = diag::err_hlsl_virtual_function;
+PrevSpec = Tok.getIdentifierInfo()->getNameStart();
+isInvalid = true;
+  }
+  else {
 isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID);
   }
   break;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 43db715ac6d70..dbc6d5f7c43a3 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2491,6 +2491,9 @@ BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) {
 IsVirtual = true;
   }
 
+  if (getLangOpts().HLSL && IsVirtual)
+Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
+
   CheckMisplacedCXX11Attribute(Attributes, StartLoc);
 
   // Parse the class-name.
diff --git a/clang/test/SemaHLSL/Language/NoVirtual.hlsl 
b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
new file mode 100644
index 0..8d61bde7d836e
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoVirtual.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -verify %s
+
+struct Base {
+  int X;
+  void MemberFunction();  // valid
+  virtual void MemberFunction2(); // expected-error{{virtual functions are 
unsupported in HLSL}}
+};
+
+struct Derived : virtual Base { // expected-error{{virtual inheritance is 
unsupported in HLSL}}
+  int Y;
+
+  void MemberFunction2() override; // expected-error{{only virtual member 
functions can be marked 'override'}}
+};
+

>From 7dc22f96df9cefc3e7dc8c3aade57290f65655aa Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Sat, 15 Feb 2025 16:58:07 -0600
Subject: [PATCH 2/2] clang-format

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 6 --
 clang/lib/Parse/ParseDecl.cpp | 3 +--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index bec3b5d48fd51..a9a8b272bef15 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1817,7 +1817,9 @@ def ext_hlsl_access_specifiers : ExtWarn<
   InGroup;
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
-def err_hlsl_virtual_function : Error<"virtual functions are unsupported in 
HLSL">;
-def err_hlsl_virtual_inheritance : Error<"virtual inheritance is unsupported 
in HLSL">;
+def err_hlsl_virtual_function
+: Error<"virtual functions are unsupported in HLSL">;
+def err_hlsl_virtual_inheritance
+: Error<"virtual inheritance is unsupported in HLSL">;
 
 } // end of Parser diagnostics
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index dfa2dbf5ab61f..eb72fb892b5f1 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4415,8 +4415,7 @@ void Parser::ParseDeclarationSpecifiers(

[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.


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


[clang] [FreeBSD] Support -stdlib=libstdc++ (PR #126302)

2025-02-15 Thread Fangrui Song via cfe-commits


@@ -1,9 +1,13 @@
 // RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd 
-stdlib=platform 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-DEFAULT %s
 // RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd10.0 
-stdlib=platform 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-TEN %s
+// RUN:   | FileCheck --check-prefix=CHECK-DEFAULT %s
+// RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd -stdlib=libc++ 
2>&1 \

MaskRay wrote:

`-o %t.o` is unneeded and can be dropped. We use `-###`, so there is no output.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -4765,6 +4765,12 @@ def HLSLAll : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool(...)";
 }
 
+def HLSLAnd : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_and"];

farzonl wrote:

I suppose the reason there is no c++ builtin existing here is because this case 
was covered only for scalars and further via the and operator.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -19463,6 +19463,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 CGM.getHLSLRuntime().getAllIntrinsic(), ArrayRef{Op0}, 
nullptr,
 "hlsl.all");
   }
+  case Builtin::BI__builtin_hlsl_and: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+return Builder.CreateAnd(Op0, Op1, "hlsl.and");

farzonl wrote:

This is a bit cleaner than a loop unroll in HLSL. I'm fine with this.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

farzonl wrote:

For lines 2258 through 2264 look into `CheckAllArgTypesAreCorrect` you will 
need to add a bool version similar to `CheckFloatingOrIntRepresentation` or 
`CheckUnsignedIntRepresentation` or `CheckFloatOrHalfRepresentations`.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&

farzonl wrote:

This assert is unecessary here. If you want to assert do it in CGBuiltins.cpp.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits

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

Codgen  and testing is fine. SemaHLSL needs work to conform to how we have been 
doing things.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Deric Cheung via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

Icohedron wrote:

I did try that. I had defined the following function:
```c++
static bool CheckBoolRepresentation(Sema *S, CallExpr *TheCall) {
  auto checkAllBoolTypes = [](clang::QualType PassedType) -> bool {
return !PassedType->isBooleanType();
  };
  return CheckAllArgTypesAreCorrect(S, TheCall, S->Context.BoolTy,
checkAllBoolTypes);
}
```
and when I tried to use it, I got a strange errors when running the test
```
 TEST 'Clang :: CodeGenHLSL/builtins/and.hlsl' FAILED 
***
*
Exit Code: 2

Command Output (stderr):
--
 TEST 'Clang :: CodeGenHLSL/builtins/and.hlsl' FAILED 
***
*
Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: /workspace/feature-and/build/bin/clang -cc1 -internal-isystem 
/workspace/feature-and/build/lib/clang/21/include -nostdsysteminc 
-finclude-default-header -tripledxil-pc-shadermodel6.3-library 
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl-emit-llvm 
-O1 -o - | /workspace/feature-and/build/bin/FileCheck 
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl
+ /workspace/feature-and/build/bin/clang -cc1 -internal-isystem 
/workspace/feature-and/build/lib/clang/21/include -nostdsysteminc 
-finclude-default-header -triple dxil-pc-shadermodel6.3-library 
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl -emit-llvm -O1 
-o -
+ /workspace/feature-and/build/bin/FileCheck 
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl:23:14: error: 
passing 'bool2' (aka 'vector') to parameter of incompatible type 
'__attribute__((__vector_size__(2 * sizeof(bool bool' (vector of 2 'bool' 
values)
   23 |   return and(x, y);
  |  ^
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl:33:14: error: 
passing 'bool3' (aka 'vector') to parameter of incompatible type 
'__attribute__((__vector_size__(3 * sizeof(bool bool' (vector of 3 'bool' 
values)
   33 |   return and(x, y);
  |  ^
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl:43:14: error: 
passing 'bool4' (aka 'vector') to parameter of incompatible type 
'__attribute__((__vector_size__(4 * sizeof(bool bool' (vector of 4 'bool' 
values)
   43 |   return and(x, y);
  |  ^
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl:55:14: error: 
passing 'vector' (vector of 4 'bool' values) to parameter of 
incompatible type '__attribute__((__vector_size__(4 * sizeof(bool bool' 
(vector of 4 'bool' values)
   55 |   return and(x, y);
  |  ^
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl:67:14: error: 
passing 'vector' (vector of 4 'bool' values) to parameter of 
incompatible type '__attribute__((__vector_size__(4 * sizeof(bool bool' 
(vector of 4 'bool' values)
   67 |   return and(x, y);
  |  ^
5 errors generated.
FileCheck error: '' is empty.
FileCheck command line:  /workspace/feature-and/build/bin/FileCheck 
/workspace/feature-and/clang/test/CodeGenHLSL/builtins/and.hlsl

--
```

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Deric Cheung via cfe-commits

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

farzonl wrote:

You aren't doing your lambda right. Check the base type. See 
`CheckFloatOrHalfRepresentations` for an example or look below:

```cpp
auto checkAllBoolTypes = [](clang::QualType PassedType) -> bool {
clang::QualType BaseType =
PassedType->isVectorType()
? PassedType->getAs()->getElementType()
: PassedType;
return !BaseType->isBooleanType();
  };
```

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Chris B via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

llvm-beanz wrote:

I think the way the code is written now is a lot easier to read.

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Trevor Laughlin via cfe-commits

https://github.com/trelau updated 
https://github.com/llvm/llvm-project/pull/123539

>From bb0542e8f2ad50892ee9d2c1f76ec1def85c3e56 Mon Sep 17 00:00:00 2001
From: Trevor Laughlin 
Date: Sun, 19 Jan 2025 19:21:10 -0500
Subject: [PATCH] [cindex] Add API to query the class methods of a type

---
 clang/bindings/python/clang/cindex.py | 16 +++
 .../bindings/python/tests/cindex/test_type.py | 18 +
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/include/clang-c/Index.h | 23 
 clang/tools/libclang/CIndexCXX.cpp| 27 +++
 clang/tools/libclang/libclang.map |  1 +
 6 files changed, 89 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 806e1b40f3c9e..9e65ea2942d16 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2710,6 +2710,21 @@ def visitor(base, children):
 conf.lib.clang_visitCXXBaseClasses(self, 
fields_visit_callback(visitor), bases)
 return iter(bases)
 
+def get_methods(self):
+"""Return an iterator for accessing the methods of this type."""
+
+def visitor(method, children):
+assert method != conf.lib.clang_getNullCursor()
+
+# Create reference to TU so it isn't GC'd before Cursor.
+method._tu = self._tu
+methods.append(method)
+return 1  # continue
+
+methods: list[Cursor] = []
+conf.lib.clang_visitCXXMethods(self, fields_visit_callback(visitor), 
methods)
+return iter(methods)
+
 def get_exception_specification_kind(self):
 """
 Return the kind of the exception specification; a value from
@@ -4017,6 +4032,7 @@ def set_property(self, property, value):
 ),
 ("clang_visitChildren", [Cursor, cursor_visit_callback, py_object], 
c_uint),
 ("clang_visitCXXBaseClasses", [Type, fields_visit_callback, py_object], 
c_uint),
+("clang_visitCXXMethods", [Type, fields_visit_callback, py_object], 
c_uint),
 ("clang_Cursor_getNumArguments", [Cursor], c_int),
 ("clang_Cursor_getArgument", [Cursor, c_uint], Cursor),
 ("clang_Cursor_getNumTemplateArguments", [Cursor], c_int),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index 9bac33f3041f4..bc893d509524e 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -559,3 +559,21 @@ class Template : public A, public B, virtual C {
 self.assertEqual(bases[1].get_base_offsetof(cursor_type_decl), 96)
 self.assertTrue(bases[2].is_virtual_base())
 self.assertEqual(bases[2].get_base_offsetof(cursor_type_decl), 128)
+
+def test_class_methods(self):
+source = """
+template 
+class Template { void Foo(); };
+typedef Template instance;
+instance bar;
+"""
+tu = get_tu(source, lang="cpp", flags=["--target=x86_64-linux-gnu"])
+cursor = get_cursor(tu, "instance")
+cursor_type = cursor.underlying_typedef_type
+self.assertEqual(cursor.kind, CursorKind.TYPEDEF_DECL)
+methods = list(cursor_type.get_methods())
+self.assertEqual(len(methods), 4)
+self.assertEqual(methods[0].kind, CursorKind.CXX_METHOD)
+self.assertEqual(methods[1].kind, CursorKind.CONSTRUCTOR)
+self.assertEqual(methods[2].kind, CursorKind.CONSTRUCTOR)
+self.assertEqual(methods[3].kind, CursorKind.CONSTRUCTOR)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b02ac467cd3a2..dd9f722a6a08c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1241,6 +1241,8 @@ libclang
   of a class.
 - Added ``clang_getOffsetOfBase``, which allows computing the offset of a base
   class in a class's layout.
+- Added ``clang_visitCXXMethods``, which allows visiting the methods
+  of a class.
 
 Static Analyzer
 ---
@@ -1394,6 +1396,8 @@ Python Binding Changes
   allows visiting the base classes of a class.
 - Added ``Cursor.get_base_offsetof``, a binding for ``clang_getOffsetOfBase``,
   which allows computing the offset of a base class in a class's layout.
+- Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which
+  allows visiting the methods of a class.
 
 OpenMP Support
 --
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index aac5d1fa8aa2e..5d961ca0cdd7f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -6680,6 +6680,29 @@ CINDEX_LINKAGE unsigned clang_visitCXXBaseClasses(CXType 
T,
   CXFieldVisitor visitor,
   CXClientData client_data);
 
+/**
+ * Visit the class methods of a type.
+ *
+ * This function visits all the methods of the g

[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Deric Cheung via cfe-commits

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Trevor Laughlin via cfe-commits

trelau wrote:

Not sure what happen, but there was a merge conflict with ReleaseNotes.rst 
where it looked like previous enhancements to liblang and Python bindings had 
been removed. To resolve the conflict I only left changes relevant to this PR.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

farzonl wrote:

We can talk about it Monday. But as is and builtin will be inconsistent with 
the errors we are using for all other intrinsics that do this same check.  

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Trevor Laughlin via cfe-commits

trelau wrote:

Ping

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


[clang] [FreeBSD] Support -stdlib=libstdc++ (PR #126302)

2025-02-15 Thread John Baldwin via cfe-commits

bsdjhb wrote:

> It's not missing as in like someone forgot. It is intentional. Same goes for 
> FreeBSD and OpenBSD's Drivers. The base OS uses libc++ and anything else is 
> not supported.

You could use it with a libstdc++ from ports.  GCC supports both variants for 
the same reason.  FreeBSD's default GCC ports include libstdc++ which is used 
for 3rd party packages built with GCC instead of clang.  I also suggested this 
approach to Alex for fixing the test failure.  I'd really rather the option 
"work".  I depend on the option working in the reverse when using GCC to build 
FreeBSD's base system (that is, -stdlib=c++).  Someone using -stdlib=stdc++ 
should get what they have explicitly asked for.

https://github.com/llvm/llvm-project/pull/126302
___
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 invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-02-15 Thread via cfe-commits

https://github.com/Andrewyuan34 updated 
https://github.com/llvm/llvm-project/pull/127162

>From c6a732cb59340adfc045196c9c27ad9b2227c377 Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Thu, 13 Feb 2025 22:35:36 -0500
Subject: [PATCH] [clang-tidy] Fix invalid fixit from modernize-use-ranges for
 nullptr used with std::unique_ptr

---
 .../clang-tidy/utils/UseRangesCheck.cpp   |  9 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../checkers/modernize/use-ranges.cpp | 26 ---
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..ce86a27ad69b2 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,15 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..4fdb5aa367c68 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,10 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
+  warnings logic for ``nullptr`` in ``std::find``.
 
 Removed checks
 ^^
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

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


[clang-tools-extra] [clang-tidy] Add support for `-ignore-insert-conflict` in `run-clang-tidy.py` (PR #127066)

2025-02-15 Thread Congcong Cai via cfe-commits
Vicente Mataix =?utf-8?q?Ferrándiz?= ,
Vicente Mataix =?utf-8?q?Ferrándiz?= ,
Vicente Mataix =?utf-8?q?Ferrándiz?= 
Message-ID:
In-Reply-To: 


HerrCai0907 wrote:

> Can you help me?, I have no experience in this repository

release-note is placed `clang-tools-extra/docs/ReleaseNotes.rst`. You can 
follow the this format to add 
 new item. 
https://releases.llvm.org/19.1.0/tools/clang/tools/extra/docs/ReleaseNotes.html#improvements-to-clang-tidy
 

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


[libclc] dbc98cf - [libclc] [cmake] Fix per-target *_convert.cl dependencies (#127315)

2025-02-15 Thread via cfe-commits

Author: Michał Górny
Date: 2025-02-16T08:48:52+01:00
New Revision: dbc98cfa46d52ede06e8be7fc5e855d807ba0fac

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

LOG: [libclc] [cmake] Fix per-target *_convert.cl dependencies (#127315)

Fix `add_libclc_builtin_set` to add an appropriate dependency to either
`clspv-generate_convert.cl` or `generate_convert.cl` based on the `ARCH`
argument, rather than to both unconditionally. This fixes build failures
due to missing dependencies when `clspv*` targets are not enabled.

The added check mirrors the one from `libclc/CMakeLists.txt`.

Fixes: #127378

Added: 


Modified: 
libclc/cmake/modules/AddLibclc.cmake

Removed: 




diff  --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index b520626c6ffd1..a3b311f12a1e3 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -249,13 +249,19 @@ function(add_libclc_builtin_set)
 
 get_filename_component( file_dir ${file} DIRECTORY )
 
+if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
+  set(CONVERT_DEP clspv-generate_convert.cl)
+else()
+  set(CONVERT_DEP generate_convert.cl)
+endif()
+
 compile_to_bc(
   TRIPLE ${ARG_TRIPLE}
   INPUT ${input_file}
   OUTPUT ${output_file}
   EXTRA_OPTS -fno-builtin -nostdlib
 "${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
-  DEPENDENCIES generate_convert.cl clspv-generate_convert.cl
+  DEPENDENCIES ${CONVERT_DEP}
 )
 list( APPEND bytecode_files ${output_file} )
   endforeach()



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


[libclc] [libclc] [cmake] Fix per-target *_convert.cl dependencies (PR #127315)

2025-02-15 Thread Sylvestre Ledru via cfe-commits

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


[libclc] [libclc] [cmake] Fix per-target *_convert.cl dependencies (PR #127315)

2025-02-15 Thread Sylvestre Ledru via cfe-commits

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


[libclc] [libclc] [cmake] Fix per-target *_convert.cl dependencies (PR #127315)

2025-02-15 Thread Sylvestre Ledru via cfe-commits

sylvestre wrote:

I will merge it as it as it fixes 
https://github.com/llvm/llvm-project/issues/127378 and apt.llvm.org has been 
broken for a few days because of this

This PR can be improved later.


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


[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)

2025-02-15 Thread via cfe-commits

yronglin wrote:

> Well, I don't really know much about these default init exprs but your 
> explanation looks reasonable. I'd say, we should try it and revert it again 
> if there are still some problems.

Many thanks for the review!

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


[clang] c17df0a - [webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis (#127309)

2025-02-15 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2025-02-15T11:04:06-08:00
New Revision: c17df0af23c941cd4fc97851ea51c91eee7c49e4

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

LOG: [webkit.UncountedLambdaCapturesChecker] Fix a crash in declProtectsThis 
(#127309)

Add a missing nullptr check to declProtectsThis.

Added: 

clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index 4ffdac5ca4873..9527993d0edeb 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -267,6 +267,8 @@ class UncountedLambdaCapturesChecker
 auto OpCode = OpCE->getOperator();
 if (OpCode == OO_Star || OpCode == OO_Amp) {
   auto *Callee = OpCE->getDirectCallee();
+  if (!Callee)
+return false;
   auto clsName = safeGetName(Callee->getParent());
   if (!isRefType(clsName) || !OpCE->getNumArgs())
 return false;
@@ -276,9 +278,10 @@ class UncountedLambdaCapturesChecker
   }
   if (auto *UO = dyn_cast(Arg)) {
 auto OpCode = UO->getOpcode();
-if (OpCode == UO_Deref || OpCode == UO_AddrOf)
+if (OpCode == UO_Deref || OpCode == UO_AddrOf) {
   Arg = UO->getSubExpr()->IgnoreParenCasts();
-continue;
+  continue;
+}
   }
   break;
 } while (Arg);

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp
 
b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp
new file mode 100644
index 0..840433db5133a
--- /dev/null
+++ 
b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s
+
+struct Foo {
+  int x;
+  int y;
+  Foo(int x, int y) : x(x) , y(y) { }
+};
+
+template 
+struct Baz {
+  void ref() const;
+  void deref() const;
+  Foo operator*();
+  bool operator!();
+};
+
+inline Foo operator*(const Foo& a, const Foo& b);
+
+Baz someFunction();
+template  void bar(CallbackType callback) {
+  auto baz = someFunction();
+  callback(baz);
+}
+
+struct Obj {
+  void ref() const;
+  void deref() const;
+
+  void foo(Foo foo) {
+bar([this](auto baz) {
+  // expected-warning@-1{{Captured raw-pointer 'this' to ref-counted type 
or CheckedPtr-capable type is unsafe [webkit.UncountedLambdaCapturesChecker]}}
+  bar([this, foo = *baz, foo2 = !baz](auto&&) {
+// expected-warning@-1{{Captured raw-pointer 'this' to ref-counted 
type or CheckedPtr-capable type is unsafe 
[webkit.UncountedLambdaCapturesChecker]}}
+someFunction();
+  });
+});
+  }
+};



___
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 invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-02-15 Thread Baranov Victor via cfe-commits


@@ -109,6 +109,9 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
warnings logic for ``nullptr`` in ``std::find``.

vbvictor wrote:

Please make lines no more than 80 characters long (rule applied to all docs).

https://github.com/llvm/llvm-project/pull/127162
___
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 invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-02-15 Thread via cfe-commits

https://github.com/Andrewyuan34 updated 
https://github.com/llvm/llvm-project/pull/127162

>From 101ec5ef672d385d91d35c23e3472b7b1d91bc15 Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Thu, 13 Feb 2025 22:35:36 -0500
Subject: [PATCH 1/2] [clang-tidy] Fix invalid fixit from modernize-use-ranges
 for nullptr used with std::unique_ptr

---
 .../clang-tidy/utils/UseRangesCheck.cpp   |  9 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +++
 .../checkers/modernize/use-ranges.cpp | 26 ---
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..ce86a27ad69b2 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,15 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b8fe22242417..2e6bd1a02aa9d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,9 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
warnings logic for ``nullptr`` in ``std::find``.
 
 Removed checks
 ^^
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

>From a9b76a20f6ad9594530ff765edaba73bf72049da Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Sat, 15 Feb 2025 16:01:43 -0500
Subject: [PATCH 2/2] Update ReleaseNotes.rst

---
 clang-tools-extra/docs/ReleaseNotes.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2e6bd1a02aa9d..4fdb5aa367c68 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -111,7 +111,8 @@ Changes in existing checks
   examples and fixing some macro related false positives.
  

[clang] [HLSL] Disallow virtual inheritance and functions (PR #127346)

2025-02-15 Thread Farzon Lotfi via cfe-commits

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


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


[clang] [FreeBSD] Support -stdlib=libstdc++ (PR #126302)

2025-02-15 Thread Fangrui Song via cfe-commits

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

code/test looks good for me as a driver maintainer. Needs a stamp from a 
FreeBSD reviewer.

https://github.com/llvm/llvm-project/pull/126302
___
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++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-15 Thread Nhat Nguyen via cfe-commits

https://github.com/changkhothuychung updated 
https://github.com/llvm/llvm-project/pull/120920

error: too big or took too long to generate
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits

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


[clang] [FreeBSD] Support -stdlib=libstdc++ (PR #126302)

2025-02-15 Thread Dimitry Andric via cfe-commits

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


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


[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)

2025-02-15 Thread via cfe-commits

ronlieb wrote:

seeing breaks in downstream build of rocPRIM

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


[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)

2025-02-15 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Please update test in clang\test\Headers\cpuid.c

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Chris B via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

llvm-beanz wrote:

> We can talk about it Monday. But as is and builtin will be inconsistent with 
> the errors we are using for all other hls builtins that do this same check.

There are no builtins doing this same check. `and`'s arguments _must_ be bool 
or vector of bool.

There probably is a valid criticism that the diagnostic in the current change 
is less than ideal because it uses the same diagnostic that 
`CheckFloatOrHalfRepresentation` does. Instead it should probably use language 
more like `err_typecheck_expect_scalar_or_vector` to emit a diagnostic that 
clearly denotes parameters should be `bool` or vector of `bool`.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Chris B via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

llvm-beanz wrote:

Okay... I agree we should discuss this this week, but maybe not for the reason 
you do. The current diagnostics are _terrible_. We need to do better.

See: https://godbolt.org/z/TP3bTGWGc

Calling `__builtin_hlsl_cross` with `int4` arguments should not give the error 
message:
>error: passing 'int4' (aka 'vector') to parameter of incompatible type 
>'__attribute__((__vector_size__(4 * sizeof(float float' (vector of 4 
>'float' values)

Besides the fact that we've lost all type sugaring, it isn't actually helpful 
because it doesn't properly convey the real constraints of the builtin.

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

@Endilll can you also review the non-Python part, or do you know someone who 
can?

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> edit: looks like release notes were "reset" after cutting rc (?)

Yes, this happens every time a release branch is created.
I checked your release notes, they seem fine to me.

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


[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)

2025-02-15 Thread via cfe-commits

https://github.com/Alcaro updated 
https://github.com/llvm/llvm-project/pull/127331

>From 90e3f502e582f44cd19e1b8b71d218330b13c9e4 Mon Sep 17 00:00:00 2001
From: Alcaro 
Date: Sat, 15 Feb 2025 16:05:40 +0100
Subject: [PATCH 1/4] [clang][x86] Support -masm=intel in cpuid.h

---
 clang/lib/Headers/cpuid.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 2601aa5724f05..d8ace39d4e7d1 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -268,16 +268,16 @@
 #else
 /* x86-64 uses %rbx as the base register, so preserve it. */
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
-__asm("  xchgq  %%rbx,%q1\n" \
+__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
   "  cpuid\n" \
-  "  xchgq  %%rbx,%q1" \
+  "  xchg{q|}  {%%|}rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
 : "0"(__leaf))
 
 #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
-__asm("  xchgq  %%rbx,%q1\n" \
+__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
   "  cpuid\n" \
-  "  xchgq  %%rbx,%q1" \
+  "  xchg{q|}  {%%|}rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
 : "0"(__leaf), "2"(__count))
 #endif
@@ -289,18 +289,18 @@ static __inline unsigned int __get_cpuid_max (unsigned 
int __leaf,
 #ifdef __i386__
 int __cpuid_supported;
 
-__asm("  pushfl\n"
-  "  popl   %%eax\n"
-  "  movl   %%eax,%%ecx\n"
-  "  xorl   $0x0020,%%eax\n"
-  "  pushl  %%eax\n"
-  "  popfl\n"
-  "  pushfl\n"
-  "  popl   %%eax\n"
-  "  movl   $0,%0\n"
-  "  cmpl   %%eax,%%ecx\n"
+__asm("  pushf{l|d}\n"
+  "  pop{l|}   {%%|}eax\n"
+  "  mov{l|}   {%%eax,%%ecx|ecx,eax}\n"
+  "  xor{l|}   {$0x0020,%%eax|eax,0x0020}\n"
+  "  push{l|}  {%%|}eax\n"
+  "  popf{l|d}\n"
+  "  pushf{l|d}\n"
+  "  pop{l|}   {%%|}eax\n"
+  "  mov{l|}   {$0,%0|%0,0}\n"
+  "  cmp{l|}   {%%eax,%%ecx|ecx,eax}\n"
   "  je 1f\n"
-  "  movl   $1,%0\n"
+  "  mov{l|}   {$1,%0|%0,1}\n"
   "1:"
 : "=r" (__cpuid_supported) : : "eax", "ecx");
 if (!__cpuid_supported)

>From ca0728b407af361559f954d9f25498c4af905dec Mon Sep 17 00:00:00 2001
From: Alcaro 
Date: Sat, 15 Feb 2025 16:41:57 +0100
Subject: [PATCH 2/4] fix indentation

---
 clang/lib/Headers/cpuid.h | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index d8ace39d4e7d1..cd7d06ab29009 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -268,17 +268,18 @@
 #else
 /* x86-64 uses %rbx as the base register, so preserve it. */
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
-__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
-  "  cpuid\n" \
-  "  xchg{q|}  {%%|}rbx,%q1" \
-: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
+#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx)
\
+  __asm("  xchg{q|}  {%%|}rbx,%q1\n"   
\
+"  cpuid\n"
\
+"  xchg{q|}  {%%|}rbx,%q1" 
\
+: "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)   
\
 : "0"(__leaf))
 
-#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
-__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
-  "  cpuid\n" \
-  "  xchg{q|}  {%%|}rbx,%q1" \
-: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
+#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) 
\
+  __asm("  xchg{q|}  {%%|}rbx,%q1\n"   
\
+"  cpuid\n"
\
+"  xchg{q|}  {%%|}rbx,%q1" 
\
+: "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)   
\
 : "0"(__leaf), "2"(__count))
 #endif
 
@@ -302,7 +303,9 @@ static __inline unsigned int __get_cpuid_max (unsigned int 
__leaf,
   "  je 1f\n"
   "  mov{l|}   {$1,%0|%0,1}\n"
   "1:"
-: "=r" (__cpuid_supported) : : "eax", "ecx");
+  : "=r"(__cpuid_supported)
+  :
+  : "eax", "ecx");
 if (!__cpuid_supported)
 return 0;
 #endif

>From 60cb44507360cfbb13d36dacde24807e1bb22254 Mon Sep 17 00:00:00 2001
From: Alcaro 
Date: Sat, 15 Feb 2025 16:48:22 +0100
Subject: [PATCH 3/4] fix copypaste fail

---
 clang/lib/Headers/cpuid.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index cd7d06ab29009..52addb7bfa856 100644
--- a/clang/l

[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Vlad Serebrennikov via cfe-commits


@@ -54,6 +54,33 @@ unsigned clang_visitCXXBaseClasses(CXType PT, CXFieldVisitor 
visitor,
   return true;
 }
 
+unsigned clang_visitCXXMethods(CXType PT, CXFieldVisitor visitor,
+   CXClientData client_data) {
+  CXCursor PC = clang_getTypeDeclaration(PT);
+  if (clang_isInvalid(PC.kind))
+return false;
+  const CXXRecordDecl *RD =
+  dyn_cast_if_present(cxcursor::getCursorDecl(PC));
+  if (!RD || RD->isInvalidDecl())
+return false;
+  RD = RD->getDefinition();
+  if (!RD || RD->isInvalidDecl())
+return false;
+
+  for (auto Method : RD->methods()) {

Endilll wrote:

```suggestion
  for (const auto *Method : RD->methods()) {
```

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


[clang-tools-extra] [clangd] Enable parsing of forwarding functions in the preamble by default (PR #127359)

2025-02-15 Thread Nathan Ridge via cfe-commits

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

Fixes https://github.com/clangd/clangd/issues/2324

>From 0ff06807c2c8255f472fc45e9a8922201384bf08 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 15 Feb 2025 01:57:10 -0500
Subject: [PATCH] [clangd] Enable parsing of forwarding functions in the
 preamble by default

Fixes https://github.com/clangd/clangd/issues/2324
---
 clang-tools-extra/clangd/Compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/Compiler.h 
b/clang-tools-extra/clangd/Compiler.h
index 4e68da7610ca2..e513e4c40794a 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -40,7 +40,7 @@ class IgnoreDiagnostics : public DiagnosticConsumer {
 
 // Options to run clang e.g. when parsing AST.
 struct ParseOptions {
-  bool PreambleParseForwardingFunctions = false;
+  bool PreambleParseForwardingFunctions = true;
 
   bool ImportInsertions = false;
 };

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Seems fine to me, but I'd like @AaronBallman to take a look, too, because 
libclang doesn't have a dedicated maintainer and I'm not familiar enough with 
it to sign off new functions we add to it.

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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] [clangd] Enable parsing of forwarding functions in the preamble by default (PR #127359)

2025-02-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: Nathan Ridge (HighCommander4)


Changes

Fixes https://github.com/clangd/clangd/issues/2324

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/Compiler.h (+1-1) 


``diff
diff --git a/clang-tools-extra/clangd/Compiler.h 
b/clang-tools-extra/clangd/Compiler.h
index 4e68da7610ca2..e513e4c40794a 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -40,7 +40,7 @@ class IgnoreDiagnostics : public DiagnosticConsumer {
 
 // Options to run clang e.g. when parsing AST.
 struct ParseOptions {
-  bool PreambleParseForwardingFunctions = false;
+  bool PreambleParseForwardingFunctions = true;
 
   bool ImportInsertions = false;
 };

``




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


[clang] [cindex] Add API to query the class methods of a type (PR #123539)

2025-02-15 Thread Trevor Laughlin via cfe-commits

https://github.com/trelau updated 
https://github.com/llvm/llvm-project/pull/123539

>From bb0542e8f2ad50892ee9d2c1f76ec1def85c3e56 Mon Sep 17 00:00:00 2001
From: Trevor Laughlin 
Date: Sun, 19 Jan 2025 19:21:10 -0500
Subject: [PATCH 1/2] [cindex] Add API to query the class methods of a type

---
 clang/bindings/python/clang/cindex.py | 16 +++
 .../bindings/python/tests/cindex/test_type.py | 18 +
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/include/clang-c/Index.h | 23 
 clang/tools/libclang/CIndexCXX.cpp| 27 +++
 clang/tools/libclang/libclang.map |  1 +
 6 files changed, 89 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 806e1b40f3c9e..9e65ea2942d16 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2710,6 +2710,21 @@ def visitor(base, children):
 conf.lib.clang_visitCXXBaseClasses(self, 
fields_visit_callback(visitor), bases)
 return iter(bases)
 
+def get_methods(self):
+"""Return an iterator for accessing the methods of this type."""
+
+def visitor(method, children):
+assert method != conf.lib.clang_getNullCursor()
+
+# Create reference to TU so it isn't GC'd before Cursor.
+method._tu = self._tu
+methods.append(method)
+return 1  # continue
+
+methods: list[Cursor] = []
+conf.lib.clang_visitCXXMethods(self, fields_visit_callback(visitor), 
methods)
+return iter(methods)
+
 def get_exception_specification_kind(self):
 """
 Return the kind of the exception specification; a value from
@@ -4017,6 +4032,7 @@ def set_property(self, property, value):
 ),
 ("clang_visitChildren", [Cursor, cursor_visit_callback, py_object], 
c_uint),
 ("clang_visitCXXBaseClasses", [Type, fields_visit_callback, py_object], 
c_uint),
+("clang_visitCXXMethods", [Type, fields_visit_callback, py_object], 
c_uint),
 ("clang_Cursor_getNumArguments", [Cursor], c_int),
 ("clang_Cursor_getArgument", [Cursor, c_uint], Cursor),
 ("clang_Cursor_getNumTemplateArguments", [Cursor], c_int),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index 9bac33f3041f4..bc893d509524e 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -559,3 +559,21 @@ class Template : public A, public B, virtual C {
 self.assertEqual(bases[1].get_base_offsetof(cursor_type_decl), 96)
 self.assertTrue(bases[2].is_virtual_base())
 self.assertEqual(bases[2].get_base_offsetof(cursor_type_decl), 128)
+
+def test_class_methods(self):
+source = """
+template 
+class Template { void Foo(); };
+typedef Template instance;
+instance bar;
+"""
+tu = get_tu(source, lang="cpp", flags=["--target=x86_64-linux-gnu"])
+cursor = get_cursor(tu, "instance")
+cursor_type = cursor.underlying_typedef_type
+self.assertEqual(cursor.kind, CursorKind.TYPEDEF_DECL)
+methods = list(cursor_type.get_methods())
+self.assertEqual(len(methods), 4)
+self.assertEqual(methods[0].kind, CursorKind.CXX_METHOD)
+self.assertEqual(methods[1].kind, CursorKind.CONSTRUCTOR)
+self.assertEqual(methods[2].kind, CursorKind.CONSTRUCTOR)
+self.assertEqual(methods[3].kind, CursorKind.CONSTRUCTOR)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b02ac467cd3a2..dd9f722a6a08c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1241,6 +1241,8 @@ libclang
   of a class.
 - Added ``clang_getOffsetOfBase``, which allows computing the offset of a base
   class in a class's layout.
+- Added ``clang_visitCXXMethods``, which allows visiting the methods
+  of a class.
 
 Static Analyzer
 ---
@@ -1394,6 +1396,8 @@ Python Binding Changes
   allows visiting the base classes of a class.
 - Added ``Cursor.get_base_offsetof``, a binding for ``clang_getOffsetOfBase``,
   which allows computing the offset of a base class in a class's layout.
+- Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which
+  allows visiting the methods of a class.
 
 OpenMP Support
 --
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index aac5d1fa8aa2e..5d961ca0cdd7f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -6680,6 +6680,29 @@ CINDEX_LINKAGE unsigned clang_visitCXXBaseClasses(CXType 
T,
   CXFieldVisitor visitor,
   CXClientData client_data);
 
+/**
+ * Visit the class methods of a type.
+ *
+ * This function visits all the methods of t

[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)

2025-02-15 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-15 Thread Farzon Lotfi via cfe-commits


@@ -2245,6 +2245,36 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
 break;
   }
+  case Builtin::BI__builtin_hlsl_and: {
+if (SemaRef.checkArgCount(TheCall, 2))
+  return true;
+if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+  return true;
+
+// CheckVectorElementCallArgs(...) guarantees both args are the same type.
+assert(TheCall->getArg(0)->getType() == TheCall->getArg(1)->getType() &&
+   "Both args must be of the same type");
+
+// check that the arguments are bools or, if vectors,
+// vectors of bools
+QualType ArgTy = TheCall->getArg(0)->getType();
+if (const auto *VecTy = ArgTy->getAs()) {
+  ArgTy = VecTy->getElementType();
+}
+if (!getASTContext().hasSameUnqualifiedType(ArgTy,

farzonl wrote:

You have valid points about things needing to be better. Keep in mind though 
that this pattern has been extended by multiple devs on the team, that have 
gone through PR reviews and got stamps of approval as "good" to merge. 

My concern isn't what todays definition of good or bad is. In fact I find the 
whole discussion about what is good or terrible to be incredibly subjective. My 
concern is more with sticking to a pattern for how we will address certain 
problems So that its easier to onboard new folks onto HLSL. I'm fine if those 
patterns evolve, but they need to evolve consistently. I'm happy to take 
suggestions and file tickets for what needs to improve, but I don't think this 
is the PR to do it. We will talk more next week and work towards a plan forward 
on this PR and improving the pattern.

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


[clang] [AST] Avoid repeated map lookups (NFC) (PR #127369)

2025-02-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/AST/ExternalASTMerger.cpp (+7-9) 


``diff
diff --git a/clang/lib/AST/ExternalASTMerger.cpp 
b/clang/lib/AST/ExternalASTMerger.cpp
index 257e8338dedef..1c903b5104bf4 100644
--- a/clang/lib/AST/ExternalASTMerger.cpp
+++ b/clang/lib/AST/ExternalASTMerger.cpp
@@ -206,16 +206,14 @@ class LazyASTImporter : public ASTImporter {
<< "\n";
   Source FromDC(
   cast(From)->getPrimaryContext());
-  if (FromOrigins.count(FromDC) &&
-  Parent.HasImporterForOrigin(*FromOrigins.at(FromDC).AST)) {
+  if (auto It = FromOrigins.find(FromDC);
+  It != FromOrigins.end() &&
+  Parent.HasImporterForOrigin(*It->second.AST)) {
 if (LoggingEnabled)
-  logs() << "(ExternalASTMerger*)" << (void*)&Parent
- << " forced origin (DeclContext*)"
- << (void*)FromOrigins.at(FromDC).DC
- << ", (ASTContext*)"
- << (void*)FromOrigins.at(FromDC).AST
- << "\n";
-Parent.ForceRecordOrigin(ToDC, FromOrigins.at(FromDC));
+  logs() << "(ExternalASTMerger*)" << (void *)&Parent
+ << " forced origin (DeclContext*)" << (void *)It->second.DC
+ << ", (ASTContext*)" << (void *)It->second.AST << "\n";
+Parent.ForceRecordOrigin(ToDC, It->second);
   } else {
 if (LoggingEnabled)
   logs() << "(ExternalASTMerger*)" << (void*)&Parent

``




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


[clang] [AST] Avoid repeated map lookups (NFC) (PR #127369)

2025-02-15 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/127369

None

>From 9400819602c7c8b79cb21528cd668070132bc608 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 15 Feb 2025 01:41:07 -0800
Subject: [PATCH] [AST] Avoid repeated map lookups (NFC)

---
 clang/lib/AST/ExternalASTMerger.cpp | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/ExternalASTMerger.cpp 
b/clang/lib/AST/ExternalASTMerger.cpp
index 257e8338dedef..1c903b5104bf4 100644
--- a/clang/lib/AST/ExternalASTMerger.cpp
+++ b/clang/lib/AST/ExternalASTMerger.cpp
@@ -206,16 +206,14 @@ class LazyASTImporter : public ASTImporter {
<< "\n";
   Source FromDC(
   cast(From)->getPrimaryContext());
-  if (FromOrigins.count(FromDC) &&
-  Parent.HasImporterForOrigin(*FromOrigins.at(FromDC).AST)) {
+  if (auto It = FromOrigins.find(FromDC);
+  It != FromOrigins.end() &&
+  Parent.HasImporterForOrigin(*It->second.AST)) {
 if (LoggingEnabled)
-  logs() << "(ExternalASTMerger*)" << (void*)&Parent
- << " forced origin (DeclContext*)"
- << (void*)FromOrigins.at(FromDC).DC
- << ", (ASTContext*)"
- << (void*)FromOrigins.at(FromDC).AST
- << "\n";
-Parent.ForceRecordOrigin(ToDC, FromOrigins.at(FromDC));
+  logs() << "(ExternalASTMerger*)" << (void *)&Parent
+ << " forced origin (DeclContext*)" << (void *)It->second.DC
+ << ", (ASTContext*)" << (void *)It->second.AST << "\n";
+Parent.ForceRecordOrigin(ToDC, It->second);
   } else {
 if (LoggingEnabled)
   logs() << "(ExternalASTMerger*)" << (void*)&Parent

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


[clang-tools-extra] [clang-tidy] Avoid repeated hash lookups (NFC) (PR #127370)

2025-02-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp 
(+3-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index 76fa2d916f0e8..509fce3a38471 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -179,15 +179,15 @@ static bool checkOverrideByDerivedMethod(const 
CXXMethodDecl *BaseMD,
 
 bool VirtualNearMissCheck::isPossibleToBeOverridden(
 const CXXMethodDecl *BaseMD) {
-  auto Iter = PossibleMap.find(BaseMD);
-  if (Iter != PossibleMap.end())
+  auto [Iter, Inserted] = PossibleMap.try_emplace(BaseMD);
+  if (!Inserted)
 return Iter->second;
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) 
&&
 !isa(BaseMD) && BaseMD->isVirtual() &&
 !BaseMD->isOverloadedOperator() &&
 !isa(BaseMD);
-  PossibleMap[BaseMD] = IsPossible;
+  Iter->second = IsPossible;
   return IsPossible;
 }
 

``




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


[clang-tools-extra] [clang-tidy] Avoid repeated hash lookups (NFC) (PR #127370)

2025-02-15 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/127370

None

>From 356e99802d0d77be7fad4f9297a605334e08ffbd Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 15 Feb 2025 01:40:13 -0800
Subject: [PATCH] [clang-tidy] Avoid repeated hash lookups (NFC)

---
 .../clang-tidy/bugprone/VirtualNearMissCheck.cpp| 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index 76fa2d916f0e8..509fce3a38471 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -179,15 +179,15 @@ static bool checkOverrideByDerivedMethod(const 
CXXMethodDecl *BaseMD,
 
 bool VirtualNearMissCheck::isPossibleToBeOverridden(
 const CXXMethodDecl *BaseMD) {
-  auto Iter = PossibleMap.find(BaseMD);
-  if (Iter != PossibleMap.end())
+  auto [Iter, Inserted] = PossibleMap.try_emplace(BaseMD);
+  if (!Inserted)
 return Iter->second;
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) 
&&
 !isa(BaseMD) && BaseMD->isVirtual() &&
 !BaseMD->isOverloadedOperator() &&
 !isa(BaseMD);
-  PossibleMap[BaseMD] = IsPossible;
+  Iter->second = IsPossible;
   return IsPossible;
 }
 

___
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++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-02-15 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,638 @@
+// -*- 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_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+namespace ranges {
+
+#  ifdef __cpp_pack_indexing
+template 
+using __extract_last _LIBCPP_NODEBUG = _Tp...[sizeof...(_Tp) - 1];
+#  else
+template 
+struct __extract_last_impl : __extract_last_impl<_Tail...> {};
+template 
+struct __extract_last_impl<_Tp> {
+  using type _LIBCPP_NODEBUG = _Tp;
+};

Zingam wrote:

https://gcc.gnu.org/projects/cxx-status.html

It looks like GCC 15 implements it.

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-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Baranov Victor via cfe-commits

vbvictor wrote:

@PiotrZSL, @5chmidti Ping

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,146 @@
+//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER_P(CallExpr, everyArgumentMatches,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : Node.arguments()) {
+if (!InnerMatcher.matches(*Arg, Finder, Builder))
+  return false;
+  }
+
+  return true;
+}
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr";
+} // namespace
+
+SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SmartPointers(utils::options::parseStringList(
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
+
+void SmartptrResetAmbiguousCallCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SmartPointers",
+utils::options::serializeStringList(SmartPointers));
+}
+
+void SmartptrResetAmbiguousCallCheck::registerMatchers(MatchFinder *Finder) {
+  const auto IsSmartptr = hasAnyName(SmartPointers);
+
+  const auto ResetMethod =
+  cxxMethodDecl(hasName("reset"), hasOnlyDefaultParameters());
+
+  const auto TypeWithReset =
+  anyOf(cxxRecordDecl(hasMethod(ResetMethod)),
+classTemplateSpecializationDecl(
+hasSpecializedTemplate(classTemplateDecl(has(ResetMethod);
+
+  const auto SmartptrWithBugproneReset = classTemplateSpecializationDecl(
+  IsSmartptr,
+  hasTemplateArgument(
+  0, templateArgument(refersToType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(TypeWithReset)));
+
+  // Find a.reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(callee(memberExpr(member(hasName("reset",
+everyArgumentMatches(cxxDefaultArgExpr()),
+on(expr(hasType(SmartptrWithBugproneReset
+  .bind("smartptrResetCall"),
+  this);
+
+  // Find a->reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  callee(memberExpr(
+  member(ResetMethod),
+  hasObjectExpression(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("->"),
+  hasArgument(
+  0, expr(hasType(
+ 
classTemplateSpecializationDecl(IsSmartptr)
+  .bind("OpCall",
+  everyArgumentMatches(cxxDefaultArgExpr()))
+  .bind("objectResetCall"),
+  this);
+}
+
+void SmartptrResetAmbiguousCallCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  if (const auto *SmartptrResetCall =
+  Result.Nodes.getNodeAs("smartptrResetCall")) {
+const auto *Member = cast(SmartptrResetCall->getCallee());
+
+diag(SmartptrResetCall->getBeginLoc(),
+ "be explicit when calling 'reset()' on a smart pointer with a "
+ "pointee that has a 'reset()' method");
+
+diag(SmartptrResetCall->getBeginLoc(), "assign the pointer to 'nullptr'",
+ DiagnosticIDs::Note)
+<< FixItHint::CreateReplacement(
+   SourceRange(Member->getOperatorLoc(),
+   Member->getOperatorLoc().getLocWithOffset(0)),
+   " =")
+<< FixItHint::CreateReplacement(
+   SourceRange(Member->getMemberLoc(),
+   SmartptrResetCall->getEndLoc()),
+   " nullptr");
+return;
+  }
+
+  if (const auto *ObjectResetCall =
+  Result.Nodes.getNodeAs("objectResetCall")) {
+const auto *Arrow = Result.Nodes.getNodeAs("OpCall");
+
+const CharSourceRange SmartptrSourceRange =
+Lexer::getAsCharRange(Arrow->getArg(0)->getSourceRange(),
+  *Result.SourceManager, getLangOpts());
+
+diag(ObjectResetCall->getBeginLoc(),
+ "be explicit when calling 'reset()' on a pointee of a smart pointer");

PiotrZSL wrote:

same comments related to msg as before

https://github.com/llvm/llvm-project/pull/121291
___
cfe-commits mailing list
cfe-commits@list

[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,146 @@
+//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER_P(CallExpr, everyArgumentMatches,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : Node.arguments()) {
+if (!InnerMatcher.matches(*Arg, Finder, Builder))
+  return false;
+  }
+
+  return true;
+}
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr";
+} // namespace
+
+SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SmartPointers(utils::options::parseStringList(
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
+
+void SmartptrResetAmbiguousCallCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SmartPointers",
+utils::options::serializeStringList(SmartPointers));
+}
+
+void SmartptrResetAmbiguousCallCheck::registerMatchers(MatchFinder *Finder) {
+  const auto IsSmartptr = hasAnyName(SmartPointers);
+
+  const auto ResetMethod =
+  cxxMethodDecl(hasName("reset"), hasOnlyDefaultParameters());
+
+  const auto TypeWithReset =
+  anyOf(cxxRecordDecl(hasMethod(ResetMethod)),
+classTemplateSpecializationDecl(
+hasSpecializedTemplate(classTemplateDecl(has(ResetMethod);
+
+  const auto SmartptrWithBugproneReset = classTemplateSpecializationDecl(
+  IsSmartptr,
+  hasTemplateArgument(
+  0, templateArgument(refersToType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(TypeWithReset)));
+
+  // Find a.reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(callee(memberExpr(member(hasName("reset",
+everyArgumentMatches(cxxDefaultArgExpr()),
+on(expr(hasType(SmartptrWithBugproneReset
+  .bind("smartptrResetCall"),
+  this);
+
+  // Find a->reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  callee(memberExpr(
+  member(ResetMethod),
+  hasObjectExpression(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("->"),
+  hasArgument(
+  0, expr(hasType(
+ 
classTemplateSpecializationDecl(IsSmartptr)
+  .bind("OpCall",
+  everyArgumentMatches(cxxDefaultArgExpr()))
+  .bind("objectResetCall"),
+  this);
+}
+
+void SmartptrResetAmbiguousCallCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  if (const auto *SmartptrResetCall =
+  Result.Nodes.getNodeAs("smartptrResetCall")) {
+const auto *Member = cast(SmartptrResetCall->getCallee());
+
+diag(SmartptrResetCall->getBeginLoc(),
+ "be explicit when calling 'reset()' on a smart pointer with a "
+ "pointee that has a 'reset()' method");
+
+diag(SmartptrResetCall->getBeginLoc(), "assign the pointer to 'nullptr'",

PiotrZSL wrote:

again, `consider assigning 'nullptr' here`

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,47 @@
+.. title:: clang-tidy - bugprone-smartptr-reset-ambiguous-call
+
+bugprone-smartptr-reset-ambiguous-call
+==
+
+Finds potentially erroneous calls to ``reset`` method on smart pointers when
+the pointee type also has a ``reset`` method. Having a ``reset`` method in
+both classes makes it easy to accidentally make the pointer null when
+intending to reset the underlying object.
+
+.. code-block:: c++
+
+  struct Resettable {
+void reset() { /* Own reset logic */ }
+  };
+
+  auto ptr = std::make_unique();
+
+  ptr->reset();  // Calls underlying reset method
+  ptr.reset();   // Makes the pointer null
+
+Both calls are valid C++ code, but the second one might not be what the
+developer intended, as it destroys the pointed-to object rather than resetting
+its state. It's easy to make such a typo because the difference between
+``.`` and ``->`` is really small.
+
+The recommended approach is to make the intent explicit by using either member
+access or direct assignment:
+
+.. code-block:: c++
+
+  std::unique_ptr ptr = std::make_unique();
+
+  (*ptr).reset();  // Clearly calls underlying reset method
+  ptr = nullptr;   // Clearly makes the pointer null
+
+The default smart pointers that are considered are ``std::unique_ptr``,
+``std::shared_ptr``. To specify other smart pointers or other classes use the
+:option:`SmartPointers` option.
+
+Options
+---
+
+.. option:: SmartPointers
+
+Semicolon-separated list of class names of custom smart pointers.

PiotrZSL wrote:

add fully qualified

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,34 @@
+//===--- SmartptrResetAmbiguousCallCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRRESETAMBIGUOUSCALLCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRRESETAMBIGUOUSCALLCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Finds potentially erroneous calls to 'reset' method on smart pointers when
+/// the pointee type also has a 'reset' method
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/smartptr-reset-ambiguous-call.html
+class SmartptrResetAmbiguousCallCheck : public ClangTidyCheck {
+public:
+  SmartptrResetAmbiguousCallCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus;

PiotrZSL wrote:

Ok, but then add "boost::shared_ptr" to default configuration

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,146 @@
+//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER_P(CallExpr, everyArgumentMatches,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : Node.arguments()) {
+if (!InnerMatcher.matches(*Arg, Finder, Builder))
+  return false;
+  }
+
+  return true;
+}
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr";
+} // namespace
+
+SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SmartPointers(utils::options::parseStringList(
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
+
+void SmartptrResetAmbiguousCallCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SmartPointers",
+utils::options::serializeStringList(SmartPointers));
+}
+
+void SmartptrResetAmbiguousCallCheck::registerMatchers(MatchFinder *Finder) {
+  const auto IsSmartptr = hasAnyName(SmartPointers);
+
+  const auto ResetMethod =
+  cxxMethodDecl(hasName("reset"), hasOnlyDefaultParameters());
+
+  const auto TypeWithReset =
+  anyOf(cxxRecordDecl(hasMethod(ResetMethod)),
+classTemplateSpecializationDecl(
+hasSpecializedTemplate(classTemplateDecl(has(ResetMethod);
+
+  const auto SmartptrWithBugproneReset = classTemplateSpecializationDecl(
+  IsSmartptr,
+  hasTemplateArgument(
+  0, templateArgument(refersToType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(TypeWithReset)));
+
+  // Find a.reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(callee(memberExpr(member(hasName("reset",
+everyArgumentMatches(cxxDefaultArgExpr()),
+on(expr(hasType(SmartptrWithBugproneReset
+  .bind("smartptrResetCall"),
+  this);
+
+  // Find a->reset() calls
+  Finder->addMatcher(

PiotrZSL wrote:

you could merge both addMatcher by using "anyOf".


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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

1. Overall ok, please work a little bit on an warning message.
2. Probably better name would be: readability-ambiguous-smartptr-reset-call
3. Same issue exist on other objects like std::optional, and other methods like 
std::optional and call to `emplace`. Maybe more checks or more 
generic check could be constructed where configuration is an pair of "object" 
and "method".

Consider points 1 & 2. And after that it could be delivered.


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


[libunwind] Silence -Wunused-parameter warnings in Unwind-wasm.c (PR #125412)

2025-02-15 Thread Yuriy Chernyshov via cfe-commits

https://github.com/georgthegreat updated 
https://github.com/llvm/llvm-project/pull/125412

>From 69307d52fc749c847da74e98624ce1c39f2fe2d9 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Sun, 2 Feb 2025 14:35:53 +0100
Subject: [PATCH 1/3] Silence -Wunused-parameter warnings in Unwind-wasm.c

---
 libunwind/src/Unwind-wasm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index b18b32c5d1784..4b893c8b4f623 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -102,8 +102,9 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 }
 
 /// Not used in Wasm.
-_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
- uintptr_t value) {}
+_LIBUNWIND_EXPORT void
+_Unwind_SetIP([[maybe_unused]] struct _Unwind_Context *context,
+  [[maybe_unused]] uintptr_t value) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t
@@ -116,7 +117,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context 
*context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT uintptr_t
-_Unwind_GetRegionStart(struct _Unwind_Context *context) {
+_Unwind_GetRegionStart([[maybe_unused]] struct _Unwind_Context *context) {
   return 0;
 }
 

>From acf1c4a81c84071e4a5550e85dd2aecfdac323f1 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Wed, 5 Feb 2025 21:26:24 +0100
Subject: [PATCH 2/3] Apply suggestions from code review

Co-authored-by: Louis Dionne 
---
 libunwind/src/Unwind-wasm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 4b893c8b4f623..caf92eb0dea0f 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -103,8 +103,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT void
-_Unwind_SetIP([[maybe_unused]] struct _Unwind_Context *context,
-  [[maybe_unused]] uintptr_t value) {}
+_Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t
@@ -117,7 +116,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context 
*context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT uintptr_t
-_Unwind_GetRegionStart([[maybe_unused]] struct _Unwind_Context *context) {
+_Unwind_GetRegionStart(struct _Unwind_Context *) {
   return 0;
 }
 

>From 749510a9fd13172f76ea9e574d623f6145249255 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Sat, 15 Feb 2025 14:42:55 +0300
Subject: [PATCH 3/3] Fix formatting

---
 libunwind/src/Unwind-wasm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index caf92eb0dea0f..1b97f9763477d 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -102,8 +102,8 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 }
 
 /// Not used in Wasm.
-_LIBUNWIND_EXPORT void
-_Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
+_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *,
+ uintptr_t) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t

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


[clang] [Sema] Add code completion for if constexpr (PR #124315)

2025-02-15 Thread Younan Zhang via cfe-commits


@@ -6749,6 +6749,21 @@ void SemaCodeCompletion::CodeCompleteInitializer(Scope 
*S, Decl *D) {
   CodeCompleteExpression(S, Data);
 }
 
+void SemaCodeCompletion::CodeCompleteIfConstExpr(Scope *S) const {
+  ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_SymbolOrNewName);
+  Results.EnterNewScope();

zyn0217 wrote:

I don’t think that’s needed to complete a simple keyword. We shouldn’t add code 
that isn’t practically useful.

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


[libclc] [libclc] Move conversion builtins to the CLC library (PR #124727)

2025-02-15 Thread Michał Górny via cfe-commits

mgorny wrote:

I'm guessing that both `amdgcn` and `nvptx` targets now require 
`clspv-generate_convert.cl`, but the targets for them are defined only when 
`clspv` targets are enabled. No clue whether it means that the targets need to 
be defined unconditionally, or `clc-convert.cl` skipped when `clspv` targets 
are disabled.

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


[clang] [Sema] Add code completion for if constexpr (PR #124315)

2025-02-15 Thread Younan Zhang via cfe-commits


@@ -6749,6 +6749,21 @@ void SemaCodeCompletion::CodeCompleteInitializer(Scope 
*S, Decl *D) {
   CodeCompleteExpression(S, Data);
 }
 
+void SemaCodeCompletion::CodeCompleteIfConstExpr(Scope *S) const {
+  ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_SymbolOrNewName);

zyn0217 wrote:

What kind of 'unwanted' results are they, and can you please say more? Thanks

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


[libunwind] Silence -Wunused-parameter warnings in Unwind-wasm.c (PR #125412)

2025-02-15 Thread Yuriy Chernyshov via cfe-commits

https://github.com/georgthegreat updated 
https://github.com/llvm/llvm-project/pull/125412

>From 69307d52fc749c847da74e98624ce1c39f2fe2d9 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Sun, 2 Feb 2025 14:35:53 +0100
Subject: [PATCH 1/3] Silence -Wunused-parameter warnings in Unwind-wasm.c

---
 libunwind/src/Unwind-wasm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index b18b32c5d1784..4b893c8b4f623 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -102,8 +102,9 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 }
 
 /// Not used in Wasm.
-_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
- uintptr_t value) {}
+_LIBUNWIND_EXPORT void
+_Unwind_SetIP([[maybe_unused]] struct _Unwind_Context *context,
+  [[maybe_unused]] uintptr_t value) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t
@@ -116,7 +117,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context 
*context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT uintptr_t
-_Unwind_GetRegionStart(struct _Unwind_Context *context) {
+_Unwind_GetRegionStart([[maybe_unused]] struct _Unwind_Context *context) {
   return 0;
 }
 

>From acf1c4a81c84071e4a5550e85dd2aecfdac323f1 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Wed, 5 Feb 2025 21:26:24 +0100
Subject: [PATCH 2/3] Apply suggestions from code review

Co-authored-by: Louis Dionne 
---
 libunwind/src/Unwind-wasm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 4b893c8b4f623..caf92eb0dea0f 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -103,8 +103,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT void
-_Unwind_SetIP([[maybe_unused]] struct _Unwind_Context *context,
-  [[maybe_unused]] uintptr_t value) {}
+_Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t
@@ -117,7 +116,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context 
*context) {
 
 /// Not used in Wasm.
 _LIBUNWIND_EXPORT uintptr_t
-_Unwind_GetRegionStart([[maybe_unused]] struct _Unwind_Context *context) {
+_Unwind_GetRegionStart(struct _Unwind_Context *) {
   return 0;
 }
 

>From c064b57d771eb75cd02ee7aeb937e284bebc4881 Mon Sep 17 00:00:00 2001
From: Yuriy Chernyshov 
Date: Sat, 15 Feb 2025 14:42:55 +0300
Subject: [PATCH 3/3] Fix formatting

---
 libunwind/src/Unwind-wasm.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index caf92eb0dea0f..b8b7bc2779f17 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -102,8 +102,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct 
_Unwind_Context *context) {
 }
 
 /// Not used in Wasm.
-_LIBUNWIND_EXPORT void
-_Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
+_LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t) {}
 
 /// Called by personality handler to get LSDA for current frame.
 _LIBUNWIND_EXPORT uintptr_t
@@ -115,8 +114,7 @@ _Unwind_GetLanguageSpecificData(struct _Unwind_Context 
*context) {
 }
 
 /// Not used in Wasm.
-_LIBUNWIND_EXPORT uintptr_t
-_Unwind_GetRegionStart(struct _Unwind_Context *) {
+_LIBUNWIND_EXPORT uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *) {
   return 0;
 }
 

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


[libclc] [libclc] Move conversion builtins to the CLC library (PR #124727)

2025-02-15 Thread Michał Górny via cfe-commits

mgorny wrote:

Ah, it's just incorrect dependency. Filed #127315 to fix it.

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


[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

2025-02-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,146 @@
+//===--- SmartptrResetAmbiguousCallCheck.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 "SmartptrResetAmbiguousCallCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER_P(CallExpr, everyArgumentMatches,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  for (const auto *Arg : Node.arguments()) {
+if (!InnerMatcher.matches(*Arg, Finder, Builder))
+  return false;
+  }
+
+  return true;
+}
+
+AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
+  for (const auto *Param : Node.parameters()) {
+if (!Param->hasDefaultArg())
+  return false;
+  }
+
+  return true;
+}
+
+const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr";
+} // namespace
+
+SmartptrResetAmbiguousCallCheck::SmartptrResetAmbiguousCallCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SmartPointers(utils::options::parseStringList(
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
+
+void SmartptrResetAmbiguousCallCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SmartPointers",
+utils::options::serializeStringList(SmartPointers));
+}
+
+void SmartptrResetAmbiguousCallCheck::registerMatchers(MatchFinder *Finder) {
+  const auto IsSmartptr = hasAnyName(SmartPointers);
+
+  const auto ResetMethod =
+  cxxMethodDecl(hasName("reset"), hasOnlyDefaultParameters());
+
+  const auto TypeWithReset =
+  anyOf(cxxRecordDecl(hasMethod(ResetMethod)),
+classTemplateSpecializationDecl(
+hasSpecializedTemplate(classTemplateDecl(has(ResetMethod);
+
+  const auto SmartptrWithBugproneReset = classTemplateSpecializationDecl(
+  IsSmartptr,
+  hasTemplateArgument(
+  0, templateArgument(refersToType(hasUnqualifiedDesugaredType(
+ recordType(hasDeclaration(TypeWithReset)));
+
+  // Find a.reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(callee(memberExpr(member(hasName("reset",
+everyArgumentMatches(cxxDefaultArgExpr()),
+on(expr(hasType(SmartptrWithBugproneReset
+  .bind("smartptrResetCall"),
+  this);
+
+  // Find a->reset() calls
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  callee(memberExpr(
+  member(ResetMethod),
+  hasObjectExpression(
+  cxxOperatorCallExpr(
+  hasOverloadedOperatorName("->"),
+  hasArgument(
+  0, expr(hasType(
+ 
classTemplateSpecializationDecl(IsSmartptr)
+  .bind("OpCall",
+  everyArgumentMatches(cxxDefaultArgExpr()))
+  .bind("objectResetCall"),
+  this);
+}
+
+void SmartptrResetAmbiguousCallCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  if (const auto *SmartptrResetCall =
+  Result.Nodes.getNodeAs("smartptrResetCall")) {
+const auto *Member = cast(SmartptrResetCall->getCallee());
+
+diag(SmartptrResetCall->getBeginLoc(),
+ "be explicit when calling 'reset()' on a smart pointer with a "
+ "pointee that has a 'reset()' method");

PiotrZSL wrote:

consider format "whats wrong, how to fix". In this case warning probably could 
start with `ambiguous call to `reset()` on a smart pointer with pointee that 
also has a 'reset()' method, prefer more explicit approach`

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


[clang] [Sema] Add code completion for if constexpr (PR #124315)

2025-02-15 Thread via cfe-commits


@@ -6749,6 +6749,21 @@ void SemaCodeCompletion::CodeCompleteInitializer(Scope 
*S, Decl *D) {
   CodeCompleteExpression(S, Data);
 }
 
+void SemaCodeCompletion::CodeCompleteIfConstExpr(Scope *S) const {
+  ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_SymbolOrNewName);

FantasqueX wrote:

https://github.com/user-attachments/assets/0f2e681e-636e-44bc-8789-c46270ebafa8";
 />

I think what we want here is only one keyword.

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


[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

2025-02-15 Thread Balazs Benics via cfe-commits

steakhal wrote:

> Thanks for the insight. Take your time.

So, I spent a few hours experimenting and it's really difficult to do, only 
using `ExprSequence`.
Just to recap, my idea was to match the assignments and inc/dec unary operator 
calls to detect if the container or the key object is mutated.
Then partition the lookup events if any of the lookups were "separated" by such 
a mutation.
Then check if the remaining group has at least 2 lookups, if so, report them.

It got fairly complicated and still buggy. I definitely think it's achievable, 
it's just too much that I could invest into.

So, let's say, I'd stick with the current version of [this 
branch](https://github.com/steakhal/llvm-project/tree/bb/tidy-add-redundant-lookup-check),
 what would be left to continue the review? @firewave 

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


[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)

2025-02-15 Thread via cfe-commits

https://github.com/Alcaro updated 
https://github.com/llvm/llvm-project/pull/127331

>From 90e3f502e582f44cd19e1b8b71d218330b13c9e4 Mon Sep 17 00:00:00 2001
From: Alcaro 
Date: Sat, 15 Feb 2025 16:05:40 +0100
Subject: [PATCH 1/2] [clang][x86] Support -masm=intel in cpuid.h

---
 clang/lib/Headers/cpuid.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 2601aa5724f05..d8ace39d4e7d1 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -268,16 +268,16 @@
 #else
 /* x86-64 uses %rbx as the base register, so preserve it. */
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
-__asm("  xchgq  %%rbx,%q1\n" \
+__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
   "  cpuid\n" \
-  "  xchgq  %%rbx,%q1" \
+  "  xchg{q|}  {%%|}rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
 : "0"(__leaf))
 
 #define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
-__asm("  xchgq  %%rbx,%q1\n" \
+__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
   "  cpuid\n" \
-  "  xchgq  %%rbx,%q1" \
+  "  xchg{q|}  {%%|}rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
 : "0"(__leaf), "2"(__count))
 #endif
@@ -289,18 +289,18 @@ static __inline unsigned int __get_cpuid_max (unsigned 
int __leaf,
 #ifdef __i386__
 int __cpuid_supported;
 
-__asm("  pushfl\n"
-  "  popl   %%eax\n"
-  "  movl   %%eax,%%ecx\n"
-  "  xorl   $0x0020,%%eax\n"
-  "  pushl  %%eax\n"
-  "  popfl\n"
-  "  pushfl\n"
-  "  popl   %%eax\n"
-  "  movl   $0,%0\n"
-  "  cmpl   %%eax,%%ecx\n"
+__asm("  pushf{l|d}\n"
+  "  pop{l|}   {%%|}eax\n"
+  "  mov{l|}   {%%eax,%%ecx|ecx,eax}\n"
+  "  xor{l|}   {$0x0020,%%eax|eax,0x0020}\n"
+  "  push{l|}  {%%|}eax\n"
+  "  popf{l|d}\n"
+  "  pushf{l|d}\n"
+  "  pop{l|}   {%%|}eax\n"
+  "  mov{l|}   {$0,%0|%0,0}\n"
+  "  cmp{l|}   {%%eax,%%ecx|ecx,eax}\n"
   "  je 1f\n"
-  "  movl   $1,%0\n"
+  "  mov{l|}   {$1,%0|%0,1}\n"
   "1:"
 : "=r" (__cpuid_supported) : : "eax", "ecx");
 if (!__cpuid_supported)

>From ca0728b407af361559f954d9f25498c4af905dec Mon Sep 17 00:00:00 2001
From: Alcaro 
Date: Sat, 15 Feb 2025 16:41:57 +0100
Subject: [PATCH 2/2] fix indentation

---
 clang/lib/Headers/cpuid.h | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index d8ace39d4e7d1..cd7d06ab29009 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -268,17 +268,18 @@
 #else
 /* x86-64 uses %rbx as the base register, so preserve it. */
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
-__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
-  "  cpuid\n" \
-  "  xchg{q|}  {%%|}rbx,%q1" \
-: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
+#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx)
\
+  __asm("  xchg{q|}  {%%|}rbx,%q1\n"   
\
+"  cpuid\n"
\
+"  xchg{q|}  {%%|}rbx,%q1" 
\
+: "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)   
\
 : "0"(__leaf))
 
-#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
-__asm("  xchg{q|}  {%%|}rbx,%q1\n" \
-  "  cpuid\n" \
-  "  xchg{q|}  {%%|}rbx,%q1" \
-: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
+#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) 
\
+  __asm("  xchg{q|}  {%%|}rbx,%q1\n"   
\
+"  cpuid\n"
\
+"  xchg{q|}  {%%|}rbx,%q1" 
\
+: "=a"(__eax), "=r"(__ebx), "=c"(__ecx), "=d"(__edx)   
\
 : "0"(__leaf), "2"(__count))
 #endif
 
@@ -302,7 +303,9 @@ static __inline unsigned int __get_cpuid_max (unsigned int 
__leaf,
   "  je 1f\n"
   "  mov{l|}   {$1,%0|%0,1}\n"
   "1:"
-: "=r" (__cpuid_supported) : : "eax", "ecx");
+  : "=r"(__cpuid_supported)
+  :
+  : "eax", "ecx");
 if (!__cpuid_supported)
 return 0;
 #endif

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


[clang] [llvm] [RISCV] Support Zb*/P Shared Instructions (PR #127160)

2025-02-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-s390x-linux` running 
on `systemz-1` while building `clang,llvm` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'libFuzzer-s390x-default-Linux :: 
fuzzer-timeout.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
RUN: at line 2: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang 
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta 
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/fuzzer 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp
 -o 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest
RUN: at line 3: not  
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1 2>&1 | FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
+ not 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest
 -timeout=1
+ FileCheck 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test
 --check-prefix=TimeoutTest
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test:7:14:
 error: TimeoutTest: expected string not found in input
TimeoutTest: #0
 ^
:27:44: note: scanning from here
==1515887== ERROR: libFuzzer: timeout after 1 seconds
   ^
:32:104: note: possible intended match here
AddressSanitizer: CHECK failed: asan_report.cpp:199 "((current_error_.kind)) == 
((kErrorKindInvalid))" (0x1, 0x0) (tid=1515887)

   ^

Input file: 
Check file: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test

-dump-input=help explains the following input dump.

Input was:
<<
   .
   .
   .
  22: MS: 4 CrossOver-CopyPart-CrossOver-ChangeByte-; base unit: 
94dd9e08c129c785f7f256e82fbe0a30e6d1ae40 
  23: 0x48,0x69,0x21,0x48, 
  24: Hi!H 
  25: artifact_prefix='./'; Test unit written to 
./timeout-c9f7ef19d5ac7565f3dcaf7a3221ae711a187db5 
  26: Base64: SGkhSA== 
  27: ==1515887== ERROR: libFuzzer: timeout after 1 seconds 
check:7'0X~~ error: no 
match found
  28: AddressSanitizer:DEADLYSIGNAL 
check:7'0 ~~
  29: = 
check:7'0

[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)

2025-02-15 Thread via cfe-commits

Alcaro wrote:

Oh come on, it was like that when I found it.

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


  1   2   >