[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-18 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/108900

>From 754ae098e55cd9ea6f7ebeed37aad761598af0f2 Mon Sep 17 00:00:00 2001
From: einvbri 
Date: Tue, 17 Sep 2024 01:25:20 +0200
Subject: [PATCH] [analyzer] Indicate UnarySymExpr is not supported by Z3

Random testing found that the Z3 wrapper does not support UnarySymExpr,
which was added recently and not included in the original Z3 wrapper.
For now, just avoid submitting expressions to Z3 to avoid compiler crashes.

Some crash context ...

clang -cc1 -analyze -analyzer-checker=core z3-unarysymexpr.c 
-analyzer-constraints=z3

Unsupported expression to reason about!
UNREACHABLE executed at 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h:297!

Stack dump:
3.  /clang/test/Analysis/z3-unarysymexpr.c:13:7: Error evaluating 
branch
 #0  llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
 #1  llvm::sys::RunSignalHandlers()
 #8  clang::ento::SimpleConstraintManager::assumeAux(
llvm::IntrusiveRefCntPtr, 
clang::ento::NonLoc, bool)
 #9  clang::ento::SimpleConstraintManager::assume(
llvm::IntrusiveRefCntPtr, 
clang::ento::NonLoc, bool)
---
 .../Core/PathSensitive/SMTConstraintManager.h |  7 +++
 clang/test/Analysis/z3-unarysymexpr.c | 15 +++
 2 files changed, 22 insertions(+)
 create mode 100644 clang/test/Analysis/z3-unarysymexpr.c

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index bf18c353b85083..86342a4080375f 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -278,6 +278,13 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 if (const SymbolCast *SC = dyn_cast(Sym))
   return canReasonAbout(SVB.makeSymbolVal(SC->getOperand()));
 
+// If a UnarySymExpr is encountered, the Z3
+// wrapper does not support those. So indicate Z3 does not
+// support those and return.
+if (isa(Sym)) {
+  return false;
+}
+
 if (const BinarySymExpr *BSE = dyn_cast(Sym)) {
   if (const SymIntExpr *SIE = dyn_cast(BSE))
 return canReasonAbout(SVB.makeSymbolVal(SIE->getLHS()));
diff --git a/clang/test/Analysis/z3-unarysymexpr.c 
b/clang/test/Analysis/z3-unarysymexpr.c
new file mode 100644
index 00..ed9ba72468422e
--- /dev/null
+++ b/clang/test/Analysis/z3-unarysymexpr.c
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s \
+// RUN:  -analyzer-constraints=z3 
+
+// REQUIRES: Z3
+//
+// Previously Z3 analysis crashed when it encountered an UnarySymExpr, validate
+// that this no longer happens.
+//
+
+// expected-no-diagnostics
+int negate(int x, int y) {
+  if ( ~(x && y))
+return 0;
+  return 1;
+}

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread via cfe-commits

cor3ntin wrote:

I think that if we don't have a fix in the next 24-48 hours, and no clarity on 
the issue - a revert should be considered (note that I think it will be 
disruptive for llvm too as we are, I think, 3 patches deep, but i agree that 
keeping a regression on trunk for too long is undesirable)

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


[clang-tools-extra] [include-cleaner] Suppress all clang warnings (PR #109099)

2024-09-18 Thread Haojian Wu via cfe-commits

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


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


[clang] [llvm] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED (PR #79942)

2024-09-18 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/79942

>From efac76027bd9294d734c3eee77ad582ad0fa9ebe Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Wed, 19 Jul 2023 20:30:29 -0700
Subject: [PATCH] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED

Build on Clang-BOLT infrastructure to collect sample profiles for CSSPGO.
Add clang/cmake/caches/CSSPGO.cmake to automate CSSPGO Clang build.

Differential Revision: https://reviews.llvm.org/D155419
---
 clang/CMakeLists.txt   | 12 -
 clang/cmake/caches/CSSPGO.cmake|  3 ++
 clang/utils/perf-training/CMakeLists.txt   | 26 +-
 clang/utils/perf-training/lit.cfg  |  6 +++
 clang/utils/perf-training/lit.site.cfg.in  |  1 +
 clang/utils/perf-training/perf-helper.py   | 56 ++
 llvm/CMakeLists.txt|  3 ++
 llvm/cmake/modules/HandleLLVMOptions.cmake | 26 +-
 8 files changed, 120 insertions(+), 13 deletions(-)
 create mode 100644 clang/cmake/caches/CSSPGO.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index c6496167d3828b..46e1412c0727aa 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -744,11 +744,21 @@ if (CLANG_ENABLE_BOOTSTRAP)
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+string(TOUPPER "${BOOTSTRAP_LLVM_BUILD_INSTRUMENTED}" 
BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+if (BOOTSTRAP_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  add_dependencies(clang-bootstrap-deps llvm-profgen)
+  list(APPEND PGO_OPT 
-DLLVM_PROFGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profgen)
+endif()
   endif()
 
   if(LLVM_BUILD_INSTRUMENTED)
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps generate-profdata)
-set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PGO_OPT 
-DLLVM_SPROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+else()
+  set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+endif()
 # Use the current tools for LTO instead of the instrumented ones
 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
   CMAKE_CXX_COMPILER
diff --git a/clang/cmake/caches/CSSPGO.cmake b/clang/cmake/caches/CSSPGO.cmake
new file mode 100644
index 00..34159068d5ea3f
--- /dev/null
+++ b/clang/cmake/caches/CSSPGO.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED "CSSPGO" CACHE STRING "")
+include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 49673790ff6e84..a3db3b7c1fcdd2 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -20,6 +20,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 
   add_custom_target(clear-profraw
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} perf.data
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -29,6 +30,10 @@ if(LLVM_BUILD_INSTRUMENTED)
   if(NOT LLVM_PROFDATA)
 message(STATUS "To enable merging PGO data LLVM_PROFDATA has to point to 
llvm-profdata")
   else()
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PROFDATA_SAMPLE "--sample")
+endif()
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clang.profdata
   # generate-profraw is a custom_target which are always considered stale.
@@ -39,7 +44,7 @@ if(LLVM_BUILD_INSTRUMENTED)
   # Therefor we call the generate-profraw target manually as part of this 
custom
   # command, which will only run if clang or ${CLANG_PGO_TRAINING_DEPS} 
are updated.
   COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target 
generate-profraw
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
+  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/ ${PROFDATA_SAMPLE}
   COMMENT "Merging profdata"
   DEPENDS clang ${CLANG_PGO_TRAINING_DEPS}
 )
@@ -49,6 +54,25 @@ if(LLVM_BUILD_INSTRUMENTED)
   USE_TOOLCHAIN EXLUDE_FROM_ALL NO_INSTALL DEPENDS 
generate-profraw)
   ad

[clang-tools-extra] 1be4c97 - [clang-tidy][readability-container-contains] Extend to any class with contains (#107521)

2024-09-18 Thread via cfe-commits

Author: Nicolas van Kempen
Date: 2024-09-18T14:57:31-04:00
New Revision: 1be4c9710bd09e2f56908ca6cee54cb80ca1774d

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

LOG: [clang-tidy][readability-container-contains] Extend to any class with 
contains (#107521)

This check will now work out of the box with other containers that have a
`contains` method, such as `folly::F14` or Abseil containers.

It will also work with strings, which are basically just weird containers.
`std::string` and `std::string_view` will have a `contains` method starting with
C++23. `llvm::StringRef` and `folly::StringPiece` are examples of existing 
implementations with a `contains` method.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst

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

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index dbb50a060e5960..698231d777d2d4 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -13,30 +13,40 @@
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
-
 void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
-  const auto SupportedContainers = hasType(
-  hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
-  hasAnyName("::std::set", "::std::unordered_set", "::std::map",
- "::std::unordered_map", "::std::multiset",
- "::std::unordered_multiset", "::std::multimap",
- "::std::unordered_multimap"));
+  const auto HasContainsMatchingParamType = hasMethod(
+  cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
+hasName("contains"), unless(isDeleted()), isPublic(),
+hasParameter(0, hasType(hasUnqualifiedDesugaredType(
+equalsBoundNode("parameterType"));
 
   const auto CountCall =
-  cxxMemberCallExpr(on(SupportedContainers),
-callee(cxxMethodDecl(hasName("count"))),
-argumentCountIs(1))
+  cxxMemberCallExpr(
+  argumentCountIs(1),
+  callee(cxxMethodDecl(
+  hasName("count"),
+  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
+  type().bind("parameterType",
+  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
   .bind("call");
 
   const auto FindCall =
-  cxxMemberCallExpr(on(SupportedContainers),
-callee(cxxMethodDecl(hasName("find"))),
-argumentCountIs(1))
+  cxxMemberCallExpr(
+  argumentCountIs(1),
+  callee(cxxMethodDecl(
+  hasName("find"),
+  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
+  type().bind("parameterType",
+  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
   .bind("call");
 
-  const auto EndCall = cxxMemberCallExpr(on(SupportedContainers),
- callee(cxxMethodDecl(hasName("end"))),
- argumentCountIs(0));
+  const auto EndCall = cxxMemberCallExpr(
+  argumentCountIs(0),
+  callee(
+  cxxMethodDecl(hasName("end"),
+// In the matchers below, FindCall should always appear
+// before EndCall so 'parameterType' is properly bound.
+
ofClass(cxxRecordDecl(HasContainsMatchingParamType);
 
   const auto Literal0 = integerLiteral(equals(0));
   const auto Literal1 = integerLiteral(equals(1));

diff  --git a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
index 2e8276d684cd79..753603ed825372 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
@@ -13,8 +13,9 @@
 
 namespace clang::tidy::readability {
 
-/// Finds usages of `container.count()` and `find() == end()` which should be
-/// replaced by a call to the `container.contains()` method introduced in 
C++20.
+/// Finds usages of `container.count()` and
+/// `container.find() == container.end()` which should be replace

[clang] [Clang] Automatically link the `compiler-rt` for GPUs if present (PR #109152)

2024-09-18 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

I guess that makes sense.

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


[clang-tools-extra] [clang-tidy][readability-container-contains] Extend to any class with contains (PR #107521)

2024-09-18 Thread Nicolas van Kempen via cfe-commits

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


[clang] [Clang] Automatically link the `compiler-rt` for GPUs if present (PR #109152)

2024-09-18 Thread Shilei Tian via cfe-commits

shiltian wrote:

I'm not sure about this. What does `compiler-rt` provide?

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


[clang] [Clang] Automatically link the `compiler-rt` for GPUs if present (PR #109152)

2024-09-18 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I'm not sure about this. What does `compiler-rt` provide?

It's `clang_rt.builtins`. So, basically complex number multiplication / 
division, wide integer stuff (I think the backend handles i128 now though). We 
currently have a wrapper header that defined `__mulsc3` for the device even 
though it's supposed to come from the compiler-rt.

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


[clang] [HLSL] Warn about incomplete language support (PR #108894)

2024-09-18 Thread Damyan Pepper via cfe-commits

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

LGTM, I'm happy to get this warning in!

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


[clang] [llvm] [clang][OpenMP] Add codegen for scope directive (PR #109197)

2024-09-18 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,2267 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=52 
-fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm 
%s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix=CHECK1
+
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 
-include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK1
+
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 
-include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK4
+
+// RUN: %clang_cc1 -verify -Wno-vla -triple x86_64-apple-darwin10 -std=c++11 
-fopenmp -fopenmp-version=52 -fnoopenmp-use-tls -fexceptions -fcxx-exceptions 
-debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK5
+// RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=52 
-fnoopenmp-use-tls -x c++ -std=c++11 -DARRAY -triple x86_64-apple-darwin10 
-emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK6
+
+// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -fopenmp-version=52 
-fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-llvm 
%s -fexceptions -fcxx-exceptions -o - | FileCheck %s 
--implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -fnoopenmp-use-tls -x c++ 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 
-include-pch %t -verify %s -emit-llvm -o - | FileCheck %s 
--implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -Wno-vla -triple x86_64-apple-darwin10 -std=c++11 
-fopenmp-simd -fopenmp-version=52 -fnoopenmp-use-tls -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -fopenmp-version=52 
-fnoopenmp-use-tls -x c++ -std=c++11 -DARRAY -triple x86_64-apple-darwin10 
-emit-llvm %s -o - | FileCheck %s --implicit-check-not="{{__kmpc|__tgt}}"
+// expected-no-diagnostics
+
+typedef void **omp_allocator_handle_t;
+extern const omp_allocator_handle_t omp_null_allocator;
+extern const omp_allocator_handle_t omp_default_mem_alloc;
+extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
+extern const omp_allocator_handle_t omp_const_mem_alloc;
+extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
+extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
+extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
+extern const omp_allocator_handle_t omp_pteam_mem_alloc;
+extern const omp_allocator_handle_t omp_thread_mem_alloc;

alexey-bataev wrote:

Why do you need these decls?

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

It was faster than I thought. The original code for case 2 is indeed invalid. 
Having looked carefully at the two definitions of PrintTo, I clearly see they 
are violating ODR. And both are originating in the internal code, so nothing 
specific to Eigen. Thanks again for the good explanation!

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


[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)

2024-09-18 Thread John McCall via cfe-commits


@@ -2419,8 +2419,13 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 return Visit(const_cast(E));
 
   case CK_NoOp: {
-return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
-  : Visit(const_cast(E));
+if (CE->changesVolatileQualification())
+  return EmitLoadOfLValue(CE);
+auto V = Visit(const_cast(E));
+if (CGF.CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers &&
+CE->getType()->isMemberFunctionPointerType())
+  V = CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, V);
+return V;

rjmccall wrote:

Why do we not need similar logic here when casting function pointer types when 
function pointer type diversity is enabled?  Does Sema not use `CK_NoOp` for 
those?  Maybe we should do the same for member pointer conversions and make 
sure there's a better cast kind to use.

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


[clang] abb317f - [clang-tidy] Fix performance-unnecessary-value-param (#109145)

2024-09-18 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-18T14:18:04-07:00
New Revision: abb317ff9aba8a58449d91f6162597e54d02a57c

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

LOG: [clang-tidy] Fix performance-unnecessary-value-param (#109145)

This patch essentially reverts #108674 while adding a testcase that
triggers a crash in clang-tidy.

Fixes #108963.

Added: 

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp

Modified: 
clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
new file mode 100644
index 00..99c2fe905bdf37
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy  -std=c++14-or-later %s 
performance-unnecessary-value-param %t
+
+// The test case used to crash clang-tidy.
+// https://github.com/llvm/llvm-project/issues/108963
+
+struct A
+{
+  template A(T&&) {}
+};
+
+struct B
+{
+  ~B();
+};
+
+struct C
+{
+  A a;
+  C(B, int i) : a(i) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: the parameter #1 is copied for 
each invocation but only used as a const reference; consider making it a const 
reference
+};
+
+C c(B(), 0);

diff  --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index b7b84852168e2e..c7a5b016c949d0 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -118,10 +118,19 @@ class FunctionParmMutationAnalyzer {
   static FunctionParmMutationAnalyzer *
   getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext 
&Context,
   ExprMutationAnalyzer::Memoized &Memorized) {
-auto [it, Inserted] = Memorized.FuncParmAnalyzer.try_emplace(&Func);
-if (Inserted)
-  it->second = std::unique_ptr(
-  new FunctionParmMutationAnalyzer(Func, Context, Memorized));
+auto it = Memorized.FuncParmAnalyzer.find(&Func);
+if (it == Memorized.FuncParmAnalyzer.end()) {
+  // Creating a new instance of FunctionParmMutationAnalyzer below may add
+  // additional elements to FuncParmAnalyzer. If we did try_emplace before
+  // creating a new instance, the returned iterator of try_emplace could be
+  // invalidated.
+  it =
+  Memorized.FuncParmAnalyzer
+  .try_emplace(&Func, 
std::unique_ptr(
+  new FunctionParmMutationAnalyzer(
+  Func, Context, Memorized)))
+  .first;
+}
 return it->getSecond().get();
   }
 



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


[clang] [clang-tools-extra] [clang-tidy] Fix performance-unnecessary-value-param (PR #109145)

2024-09-18 Thread Kazu Hirata via cfe-commits

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


[clang] e0ad34e - [clang] Use canonical type for substitution which might be incomplete (#109065)

2024-09-18 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-09-18T18:22:14-03:00
New Revision: e0ad34e56590fa2e6ffdf617e044de7eadee2139

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

LOG: [clang] Use canonical type for substitution which might be incomplete 
(#109065)

When checking deduction consistency, a substitution can be incomplete
such that only sugar parts refer to non-deduced template parameters.

This would not otherwise lead to an inconsistent deduction, so this
patch makes it so we canonicalize the types before substitution in order
to avoid that possibility, for now.

When we are able to produce substitution failure diagnostics for partial
ordering, we might want to improve the TemplateInstantiator so that it
does not fail in that case.

This fixes a regression on top of #100692, which was reported on the PR.
This was never released, so there are no release notes.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/GH18291.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index b50648d5752ce5..7d83b86a007337 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5505,8 +5505,11 @@ static TemplateDeductionResult CheckDeductionConsistency(
   Sema::ArgumentPackSubstitutionIndexRAII PackIndex(
   S, ArgIdx != -1 ? ::getPackIndexForParam(S, FTD, MLTAL, ArgIdx) : -1);
   bool IsIncompleteSubstitution = false;
-  QualType InstP = S.SubstType(P, MLTAL, FTD->getLocation(), 
FTD->getDeclName(),
-   &IsIncompleteSubstitution);
+  // FIXME: A substitution can be incomplete on a non-structural part of the
+  // type. Use the canonical type for now, until the TemplateInstantiator can
+  // deal with that.
+  QualType InstP = S.SubstType(P.getCanonicalType(), MLTAL, FTD->getLocation(),
+   FTD->getDeclName(), &IsIncompleteSubstitution);
   if (InstP.isNull() && !IsIncompleteSubstitution)
 return TemplateDeductionResult::SubstitutionFailure;
   if (!CheckConsistency)

diff  --git a/clang/test/SemaTemplate/GH18291.cpp 
b/clang/test/SemaTemplate/GH18291.cpp
index 820564ffa6f1a0..2e9754b6561740 100644
--- a/clang/test/SemaTemplate/GH18291.cpp
+++ b/clang/test/SemaTemplate/GH18291.cpp
@@ -112,3 +112,12 @@ namespace static_vs_nonstatic {
 }
   } // namespace explicit_obj_param
 } // namespace static_vs_nonstatic
+
+namespace incomplete_on_sugar {
+  template  void f(T[P]) = delete;
+  template  void f(int[][P]);
+  void test() {
+int array[1][8];
+f<8>(array);
+  }
+} // namespace incomplete_on_sugar



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


[clang] [clang] Use canonical type for substitution which might be incomplete (PR #109065)

2024-09-18 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang][powerpc][wasm][systemz][x86] Replace target vector popcount intrinsics with __builtin_elementwise_popcount (PR #109160)

2024-09-18 Thread Thomas Lively via cfe-commits

https://github.com/tlively commented:

WebAssembly changes LGTM.

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


[clang] [NFC] Delete unused clang-formatted-files.txt file (PR #109220)

2024-09-18 Thread Rahul Joshi via cfe-commits

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


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Thomas Köppe via cfe-commits

https://github.com/tkoeppe updated 
https://github.com/llvm/llvm-project/pull/109169

From d8a46761ef175194c7e7272313807d2ef25aa497 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= 
Date: Wed, 18 Sep 2024 17:04:44 +
Subject: [PATCH] [clang-tidy] Make modernize-use-nullptr matcher also match
 "NULL", but not "0", when it appears on a substituted type of a template
 specialization.

Previously, any matches on a substituted type were excluded, but this meant 
that a situation like the following is not diagnosed:

```c++
template 
struct X {
  T val;
  X() { val = NULL; }  // should diagnose
};
```

When the user says `NULL`, we expect that the destination type is always meant 
to be a pointer type, so this should be converted to `nullptr`. By contrast, we 
do not propose changing a literal `0` in that case, which appears as 
initializers of both pointer and integer specializations in reasonable real 
code. (If `NULL` is used erroneously in such a situation, it should be changed 
to `0` or `{}`.)
---
 .../clang-tidy/modernize/UseNullptrCheck.cpp  |  4 +++-
 .../checkers/modernize/use-nullptr.cpp| 22 +++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 6a003a347badac..b2921690863b84 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -38,7 +38,9 @@ AST_MATCHER(Type, sugaredNullptrType) {
 StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef NameList) {
   auto ImplicitCastToNull = implicitCastExpr(
   anyOf(hasCastKind(CK_NullToPointer), 
hasCastKind(CK_NullToMemberPointer)),
-  
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(,
+  anyOf(hasSourceExpression(gnuNullExpr()),
+unless(hasImplicitDestinationType(
+qualType(substTemplateTypeParmType(),
   unless(hasSourceExpression(hasType(sugaredNullptrType(,
   unless(hasImplicitDestinationType(
   qualType(matchers::matchesAnyListedTypeName(NameList);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 7bc0925136aa86..c32524eee88bc8 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -84,6 +84,28 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  // If you say __null (or NULL), we assume that T will always be a pointer
+  // type, so we suggest replacing it with nullptr.
+  void f() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+
+  // But if you say 0, we allow the possibility that T can be used with 
integral
+  // and pointer types, and "0" is an acceptable initializer (even if "{}" 
might
+  // be even better).
+  void g() { y = 0; }
+
+  T x;
+  T y;
+};
+void test_templated() {
+  pear p;
+  p.f();
+  p.g();
+  dummy(p.x);
+}
+
 #define IS_EQ(x, y) if (x != y) return;
 void test_macro_args() {
   int 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] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Thomas Köppe via cfe-commits


@@ -84,6 +84,14 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  T x;
+};
+void test_templated() {
+  pear p = { NULL };

tkoeppe wrote:

Done now. A key insight was that the test defines `NULL` as `0`, so in order 
for the new check to kick in, we're using `__null` as the to-be-diagnosed 
spelling.

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits

eddyz87 wrote:

@peilin-ye ,
 
> However, I didn't want to use `lock` because I feel like it's too similar to 
> the x86 `LOCK` prefix (implies a full memory barrier, which could be 
> confusing here). WDYT? Cc: @yonghong-song @4ast

Well, we already confuse people in a way, since existing `lock *(u64 *)(r1 + 
0x0) += r2` does not imply full barrier (it is translated to `stadd` by arm jit 
in kernel, which is documented as "has no memory ordering semantics"). So, 
`lock ... {acquire,release}` shouldn't make things worse.

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits

eddyz87 wrote:

> > Also a question regarding 3 commits in one pull request. As far as I 
> > understand [current](https://llvm.org/docs/GitHub.html) policy, the idea is 
> > to have a separate pull request for each commit (and fork branches from one 
> > another to build a stack). Otherwise the commits are squashed. What's the 
> > idea with current pull request?
> 
> Got it, I'll split this into separate PRs later.

(Not that I like this policy, but that's the way LLVM team decided to use 
github :man_shrugging:)

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


[clang] [clang-tools-extra] Remove clang-pseudo (PR #109154)

2024-09-18 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

For visibility, see the last attempt at removal: 
https://github.com/llvm/llvm-project/pull/80081

AFAIK, some Clangd features e.g. code folding, are still relying on it, so 
ditching it completely is probably not an option at the moment.

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


[clang] [llvm] Buffer_store_lds_dword, buffer_wbinvl1, and buffer_wbinvl1_vol should not be supported in GFX940 (PR #109223)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Jun Wang (jwanggit86)


Changes

Three instructions, namely, buffer_store_lds_dword, buffer_wbinvl1, and
buffer_wbinvl1_vol are obsolete in GFX940 and should not be supported.

---

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


35 Files Affected:

- (modified) clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributes.def (+1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+76) 
- (modified) llvm/lib/Target/AMDGPU/BUFInstructions.td (+9-3) 
- (modified) llvm/test/CodeGen/AMDGPU/addrspacecast-constantexpr.ll (+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/amdgpu-attributor-no-agpr.ll (+9-9) 
- (modified) llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa-call.ll 
(+27-26) 
- (modified) llvm/test/CodeGen/AMDGPU/annotate-kernel-features-hsa.ll (+16-15) 
- (modified) llvm/test/CodeGen/AMDGPU/annotate-kernel-features.ll (+9-9) 
- (added) llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit-globalisel.ll 
(+567) 
- (added) llvm/test/CodeGen/AMDGPU/attributor-flatscratchinit.ll (+606) 
- (modified) llvm/test/CodeGen/AMDGPU/direct-indirect-call.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/duplicate-attribute-indirect.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/flat-address-space.ll (+4-4) 
- (modified) llvm/test/CodeGen/AMDGPU/implicit-kernarg-backend-usage.ll (+1) 
- (modified) llvm/test/CodeGen/AMDGPU/implicitarg-offset-attributes.ll (+15-15) 
- (modified) llvm/test/CodeGen/AMDGPU/indirect-call-set-from-other-function.ll 
(+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-module-lds-via-hybrid.ll (+1) 
- (modified) llvm/test/CodeGen/AMDGPU/propagate-flat-work-group-size.ll 
(+10-10) 
- (modified) llvm/test/CodeGen/AMDGPU/propagate-waves-per-eu.ll (+23-23) 
- (modified) llvm/test/CodeGen/AMDGPU/recursive_global_initializer.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/remove-no-kernel-id-attribute.ll (+5-5) 
- (modified) llvm/test/CodeGen/AMDGPU/simple-indirect-call-2.ll (+2-4) 
- (modified) llvm/test/CodeGen/AMDGPU/simple-indirect-call.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/uniform-work-group-attribute-missing.ll 
(+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/uniform-work-group-multistep.ll (+2-2) 
- (modified) 
llvm/test/CodeGen/AMDGPU/uniform-work-group-nested-function-calls.ll (+2-2) 
- (modified) 
llvm/test/CodeGen/AMDGPU/uniform-work-group-prevent-attribute-propagation.ll 
(+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/uniform-work-group-propagate-attribute.ll 
(+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/uniform-work-group-recursion-test.ll 
(+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/uniform-work-group-test.ll (+2-2) 
- (modified) llvm/test/MC/AMDGPU/gfx10_unsupported.s (+3) 
- (modified) llvm/test/MC/AMDGPU/gfx11_unsupported.s (+3) 
- (modified) llvm/test/MC/AMDGPU/gfx12_unsupported.s (+6) 
- (added) llvm/test/MC/AMDGPU/gfx940_unsupported.s (+11) 


``diff
diff --git a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
index b295bbbdaaf955..7f016180629e4b 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
@@ -432,7 +432,7 @@ __global__ void kernel4(struct S s) {
 // CHECK-SPIRV-NEXT:ret void
 //
 // OPT-LABEL: define dso_local amdgpu_kernel void @_Z7kernel5P1S(
-// OPT-SAME: ptr addrspace(1) nocapture noundef readonly [[S_COERCE:%.*]]) 
local_unnamed_addr #[[ATTR2]] {
+// OPT-SAME: ptr addrspace(1) nocapture noundef readonly [[S_COERCE:%.*]]) 
local_unnamed_addr #[[ATTR3:[0-9]+]] {
 // OPT-NEXT:  [[ENTRY:.*:]]
 // OPT-NEXT:[[TMP0:%.*]] = load ptr, ptr addrspace(1) [[S_COERCE]], align 8
 // OPT-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributes.def 
b/llvm/lib/Target/AMDGPU/AMDGPUAttributes.def
index bacc8e4e821e5d..8c1c8219690ba5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributes.def
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributes.def
@@ -30,5 +30,6 @@ AMDGPU_ATTRIBUTE(WORKITEM_ID_Z, "amdgpu-no-workitem-id-z")
 AMDGPU_ATTRIBUTE(LDS_KERNEL_ID, "amdgpu-no-lds-kernel-id")
 AMDGPU_ATTRIBUTE(DEFAULT_QUEUE, "amdgpu-no-default-queue")
 AMDGPU_ATTRIBUTE(COMPLETION_ACTION, "amdgpu-no-completion-action")
+AMDGPU_ATTRIBUTE(FLAT_SCRATCH_INIT, "amdgpu-no-flat-scratch-init")
 
 #undef AMDGPU_ATTRIBUTE
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index d65e0ae92308e6..b3bcc979e23a5e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -434,6 +434,26 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
   indicatePessimisticFixpoint();
   return;
 }
+
+SmallPtrSet VisitedConsts;
+
+for (Instruction &I : instructions(F)) {
+  if (isa(I) 

[clang] [llvm] Buffer_store_lds_dword, buffer_wbinvl1, and buffer_wbinvl1_vol should not be supported in GFX940 (PR #109223)

2024-09-18 Thread Jun Wang via cfe-commits

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


[clang] [llvm] Buffer_store_lds_dword, buffer_wbinvl1, and buffer_wbinvl1_vol should not be supported in GFX940 (PR #109223)

2024-09-18 Thread Jun Wang via cfe-commits

jwanggit86 wrote:

Based off wrong branch.

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


[clang] 258fc7f - [Clang] Fix -ast-dump-decl-types crashes on concepts (#108142)

2024-09-18 Thread via cfe-commits

Author: ofAlpaca
Date: 2024-09-19T08:33:37+08:00
New Revision: 258fc7f582877d3bc2a26e62da4f50e467d8c640

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

LOG: [Clang] Fix -ast-dump-decl-types crashes on concepts (#108142)

Resolve #94928

This PR adds `if (TD->getTemplateDecl())` to prevent `InnerD` becoming
`nullptr`, suggested by @firstmoonlight.

I also add `-ast-dump-decl-types` option and declare type `CHECK` to the
testcase `clang/test/AST/ast-dump-concepts.cpp`.

-

Co-authored-by: Aaron Ballman 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Frontend/ASTConsumers.cpp
clang/test/AST/ast-dump-concepts.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d10b284310071e..b8816d7b555e87 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,8 @@ Miscellaneous Clang Crashes Fixed
 - Fixed a crash when function has more than 65536 parameters.
   Now a diagnostic is emitted. (#GH35741)
 
+- Fixed ``-ast-dump`` crashes on codes involving ``concept`` with 
``-ast-dump-decl-types``. (#GH94928)
+
 OpenACC Specific Changes
 
 

diff  --git a/clang/lib/Frontend/ASTConsumers.cpp 
b/clang/lib/Frontend/ASTConsumers.cpp
index 7b58eaa04df95a..a6e35452b4fbe6 100644
--- a/clang/lib/Frontend/ASTConsumers.cpp
+++ b/clang/lib/Frontend/ASTConsumers.cpp
@@ -101,7 +101,8 @@ namespace {
   if (DumpDeclTypes) {
 Decl *InnerD = D;
 if (auto *TD = dyn_cast(D))
-  InnerD = TD->getTemplatedDecl();
+  if (Decl *TempD = TD->getTemplatedDecl())
+InnerD = TempD;
 
 // FIXME: Support OutputFormat in type dumping.
 // FIXME: Support combining -ast-dump-decl-types with 
-ast-dump-lookups.

diff  --git a/clang/test/AST/ast-dump-concepts.cpp 
b/clang/test/AST/ast-dump-concepts.cpp
index a5e0673c241ef4..84d981d2ab8dec 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump 
-ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump 
-ast-dump-decl-types -ast-dump-filter Foo %s | FileCheck -strict-whitespace %s
 
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown 
-include-pch %t \
-// RUN: -ast-dump-all -ast-dump-filter Foo /dev/null \
+// RUN: -ast-dump-all -ast-dump-decl-types -ast-dump-filter Foo /dev/null \
 // RUN: | FileCheck --strict-whitespace %s
 
 template 
@@ -56,6 +56,9 @@ struct Foo {
   // CHECK: CXXFoldExpr {{.*}} 
   template ... Ts>
   Foo();
+  
+  // CHECK:InjectedClassNameType
+  // CHECK-NEXT: CXXRecord {{.*}} 'Foo'
 };
 
 namespace GH82628 {
@@ -75,20 +78,28 @@ template 
 concept Foo = C;
 
 // CHECK: TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 
'C')
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
 template 
 constexpr bool FooVar = false;
 
 // CHECK: ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
 template  requires C
 constexpr bool FooVar2 = true;
 
 // CHECK: SimpleRequirement
 // CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
 template  requires requires (T) { C; }
 constexpr bool FooVar3 = true;
 
 // CHECK: NonTypeTemplateParmDecl
 // CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
+// CHECK: QualType
+// CHECK-NEXT: `-BuiltinType {{.*}} 'bool'
 template 
 constexpr bool FooVar4 = bool(T());
 
@@ -97,7 +108,9 @@ constexpr bool FooVar4 = bool(T());
 // CHECK: NonTypeTemplateParmDecl {{.*}} depth 0 index 1 U
 // CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} UsingShadow {{.*}} 'C'
 // CHECK: |-TemplateTypeParmDecl {{.*}} Concept {{.*}} 'C' (UsingShadow {{.*}} 
'C') depth 0 index 2 V:auto
-
+// CHECK: FunctionProtoType
+// CHECK: `-Concept {{.*}} 'C'
+// CHECK: `-TemplateTypeParm {{.*}} 'V:auto'
 template 
 auto FooFunc(C auto V) -> C decltype(auto) {
   // FIXME: TypeLocs inside of the function body cannot be dumped via 
-ast-dump for now.



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


[clang] -ast-dump-decl-types crashes on codes involving concepts #94928 (PR #108142)

2024-09-18 Thread Younan Zhang via cfe-commits

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


[clang] [clang] implement current CWG direction for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

In case I don't get a chance to look at this in more detail right away can you 
please reference specific CWG issues in the summary and in comments in the 
code? Thank you.

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


[clang] [llvm] [AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (PR #94647)

2024-09-18 Thread Jun Wang via cfe-commits


@@ -678,6 +690,37 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
 return !A.checkForAllCallLikeInstructions(DoesNotRetrieve, *this,
   UsedAssumedInformation);
   }
+
+  // Returns true if FlatScratchInit is needed, i.e., no-flat-scratch-init is
+  // not to be set.
+  bool needFlatScratchInit(Attributor &A) {
+assert(isAssumed(FLAT_SCRATCH_INIT)); // only called if the bit is still 
set
+
+// This is called on each callee; false means callee shouldn't have
+// no-flat-scratch-init.
+auto CheckForNoFlatScratchInit = [&](Instruction &I) {
+  const auto &CB = cast(I);
+  const Function *Callee = CB.getCalledFunction();
+
+  // Callee == 0 for inline asm or indirect call with known callees.
+  // In the latter case, updateImpl() already checked the callees and we
+  // know their FLAT_SCRATCH_INIT bit is set.
+  // If function has indirect call with unknown callees, the bit is
+  // already removed in updateImpl() and execution won't reach here.
+  if (!Callee)
+return true;
+  else

jwanggit86 wrote:

Done.

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


[clang] [lld] [llvm] [mlir] [IR] Introduce `T` to `DataLayout` to represent flat address space if a target supports it (PR #108786)

2024-09-18 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/108786

>From cad9ac7478a158c455b8865cab8bb553a46f7773 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Tue, 17 Sep 2024 21:47:45 -0400
Subject: [PATCH] [IR] Introduce `T` to `DataLayout` to
 represent flat address space if a target supports it

---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 clang/lib/Basic/Targets/NVPTX.cpp |  8 ++--
 clang/test/CodeGen/target-data.c  |  8 ++--
 clang/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl |  2 +-
 lld/test/ELF/lto/amdgcn-oses.ll   |  6 +--
 lld/test/ELF/lto/amdgcn.ll|  2 +-
 llvm/docs/LangRef.rst | 19 +
 llvm/docs/ReleaseNotes.rst|  3 ++
 llvm/include/llvm/IR/DataLayout.h |  4 ++
 llvm/lib/IR/AutoUpgrade.cpp   | 10 +
 llvm/lib/IR/DataLayout.cpp| 11 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp  |  2 +-
 llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp  |  6 +--
 .../Bitcode/DataLayoutUpgradeTest.cpp | 40 +--
 .../GPUToROCDL/LowerGpuOpsToROCDLOps.cpp  |  2 +-
 16 files changed, 87 insertions(+), 40 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 3b748d0249d57b..0ee56848a6cb98 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -36,7 +36,7 @@ static const char *const DataLayoutStringAMDGCN =
 "-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:"
 "32-v48:64-v96:128"
 "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1"
-"-ni:7:8:9";
+"-ni:7:8:9-T0";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
 llvm::AMDGPUAS::FLAT_ADDRESS, // Default
diff --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index 43b653dc52ce0d..59344c3c71aee2 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -66,12 +66,12 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
   HasFloat16 = true;
 
   if (TargetPointerWidth == 32)
-resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64-T0");
   else if (Opts.NVPTXUseShortPointers)
-resetDataLayout(
-
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+resetDataLayout("e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:"
+"32-n16:32:64-T0");
   else
-resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64-T0");
 
   // If possible, get a TargetInfo for our host triple, so we can match its
   // types.
diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c
index 41cbd5a0219d5e..a3d1a8cb9ee234 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -160,11 +160,11 @@
 
 // RUN: %clang_cc1 -triple nvptx-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX
-// NVPTX: target datalayout = 
"e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
+// NVPTX: target datalayout = 
"e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64-T0"
 
 // RUN: %clang_cc1 -triple nvptx64-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX64
-// NVPTX64: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
+// NVPTX64: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64-T0"
 
 // RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=R600
@@ -176,12 +176,12 @@
 
 // RUN: %clang_cc1 -triple amdgcn-unknown -target-cpu hawaii -o - -emit-llvm 
%s \
 // RUN: | FileCheck %s -check-prefix=R600SI
-// R600SI: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+// R600SI: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9-T0"
 
 // Test default -target-cpu
 // RUN: %clang_cc1 -triple amdgcn-unknown -o - -emit-llvm %s \
 // RUN: | FileCheck %s -check-prefix=R600SIDefault
-// R600SIDefault: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+// R600SIDefault: target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-09-18 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

The buildkite is failing on Windows because `flang` does not print anything on 
Windows. It is not clear to me why this is the case. I do not have access to a 
windows machine on which to debug this. The test, `time.f90` has been disabled 
on Windows with a comment explaining why it has been disabled.

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


[clang] [llvm] Add cross builtins and cross HLSL function to DirectX and SPIR-V backend (PR #109180)

2024-09-18 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 created 
https://github.com/llvm/llvm-project/pull/109180

This PR adds the step intrinsic and an HLSL function that uses it.
The SPIRV backend is also implemented.

Used https://github.com/llvm/llvm-project/pull/106471 as a reference.
Fixes https://github.com/llvm/llvm-project/issues/99095

>From 3c58861f3e8c2f1333d0b36c6f5b7ba7f3d9e187 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 18 Sep 2024 12:20:19 -0700
Subject: [PATCH] add cross hlsl function

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 15 +
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 22 +++
 clang/lib/Sema/SemaHLSL.cpp   | 14 +
 clang/test/CodeGenHLSL/builtins/cross.hlsl| 36 
 .../test/SemaHLSL/BuiltIns/cross-errors.hlsl  | 31 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 40 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 24 +++-
 llvm/test/CodeGen/DirectX/cross.ll| 57 +++
 .../CodeGen/SPIRV/hlsl-intrinsics/cross.ll| 33 +++
 13 files changed, 280 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/cross.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/cross.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8c5d7ad763bf97..c4735b59dfb0be 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4709,6 +4709,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLCross: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_cross"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_dot"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7e18aafcdd4b8a..0883ad17ce0ffd 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18639,6 +18639,21 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
 ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
   }
+  case Builtin::BI__builtin_hlsl_cross: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   E->getArg(1)->getType()->hasFloatingRepresentation() &&
+   "step operands must have a float representation");
+// make sure each vector has exactly 3 elements
+auto *XVecTy1 = E->getArg(0)->getType()->getAs();
+auto *XVecTy2 = E->getArg(1)->getType()->getAs();
+assert(XVecTy1->getNumElements() == 3 && XVecTy2->getNumElements() == 3 &&
+   "input vectors must have 3 elements each");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Op0->getType(), 
CGM.getHLSLRuntime().getCrossIntrinsic(),
+ArrayRef{Op0, Op1}, nullptr, "hlsl.cross");
+  }
   case Builtin::BI__builtin_hlsl_dot: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..6722d2c7c50a2b 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -74,6 +74,7 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6cd6a2caf19994..e4b40978dea6b9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1563,6 +1563,28 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// cross builtins
+//===--===//
+
+/// \fn T cross(T x, T y)
+/// \brief Returns the cross product of two floating-point, 3D vectors.
+/// \param x [in] The first floating-point, 3D vector.
+/// \param y [in] The second floating-point, 3D vector.
+///
+/// Result is the cross product of x and y, i.e., the resulting
+/// 

[clang] [llvm] Add cross builtins and cross HLSL function to DirectX and SPIR-V backend (PR #109180)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Joshua Batista (bob80905)


Changes

This PR adds the step intrinsic and an HLSL function that uses it.
The SPIRV backend is also implemented.

Used https://github.com/llvm/llvm-project/pull/106471 as a reference.
Fixes https://github.com/llvm/llvm-project/issues/99095

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


13 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+15) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+22) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+14) 
- (added) clang/test/CodeGenHLSL/builtins/cross.hlsl (+36) 
- (added) clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl (+31) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) 
- (modified) llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp (+40) 
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+23-1) 
- (added) llvm/test/CodeGen/DirectX/cross.ll (+57) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll (+33) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8c5d7ad763bf97..c4735b59dfb0be 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4709,6 +4709,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLCross: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_cross"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_dot"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7e18aafcdd4b8a..0883ad17ce0ffd 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18639,6 +18639,21 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
 ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
   }
+  case Builtin::BI__builtin_hlsl_cross: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   E->getArg(1)->getType()->hasFloatingRepresentation() &&
+   "step operands must have a float representation");
+// make sure each vector has exactly 3 elements
+auto *XVecTy1 = E->getArg(0)->getType()->getAs();
+auto *XVecTy2 = E->getArg(1)->getType()->getAs();
+assert(XVecTy1->getNumElements() == 3 && XVecTy2->getNumElements() == 3 &&
+   "input vectors must have 3 elements each");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Op0->getType(), 
CGM.getHLSLRuntime().getCrossIntrinsic(),
+ArrayRef{Op0, Op1}, nullptr, "hlsl.cross");
+  }
   case Builtin::BI__builtin_hlsl_dot: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..6722d2c7c50a2b 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -74,6 +74,7 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6cd6a2caf19994..e4b40978dea6b9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1563,6 +1563,28 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// cross builtins
+//===--===//
+
+/// \fn T cross(T x, T y)
+/// \brief Returns the cross product of two floating-point, 3D vectors.
+/// \param x [in] The first floating-point, 3D vector.
+/// \param y [in] The second floating-point, 3D vector.
+///
+/// Result is the cross product of x and y, i.e., the resulting
+/// components are, in order :
+/// x[1] * y[2] - y[1] * x[2]
+/// x[2] * y[0] - y[2] * x[0]
+/// x[0] * y[1] - y[0] * x[1]
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
+half3 cross(half3, half3);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
+float3 cross(float3, float3);
+
 
//===-

[clang] [HLSL] Make casting functions constexpr (PR #108902)

2024-09-18 Thread Justin Bogner via cfe-commits


@@ -13,23 +13,23 @@ namespace hlsl {
 
 namespace __detail {
 
-#define _HLSL_INLINE   
\
-  __attribute__((__always_inline__, __nodebug__)) static inline

bogner wrote:

Note that while constexpr implies `inline` and since it also implies `const` 
dropping `static here is fine too, we are dropping the two attributes here. 
`__always_inline__` shouldn't matter, but dropping `nodebug` presumably does 
have an effect. I don't fully understand what `nodebug` is gaining us though, 
and if we really want to use it we should probably do that more systematically 
in this header anyway, so this all seems fine.

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


[clang] [llvm] Add cross builtins and cross HLSL function to DirectX and SPIR-V backend (PR #109180)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-directx

Author: Joshua Batista (bob80905)


Changes

This PR adds the step intrinsic and an HLSL function that uses it.
The SPIRV backend is also implemented.

Used https://github.com/llvm/llvm-project/pull/106471 as a reference.
Fixes https://github.com/llvm/llvm-project/issues/99095

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


13 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+15) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+22) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+14) 
- (added) clang/test/CodeGenHLSL/builtins/cross.hlsl (+36) 
- (added) clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl (+31) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+1) 
- (modified) llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp (+40) 
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+23-1) 
- (added) llvm/test/CodeGen/DirectX/cross.ll (+57) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll (+33) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8c5d7ad763bf97..c4735b59dfb0be 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4709,6 +4709,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLCross: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_cross"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_dot"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7e18aafcdd4b8a..0883ad17ce0ffd 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18639,6 +18639,21 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
 ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
   }
+  case Builtin::BI__builtin_hlsl_cross: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+Value *Op1 = EmitScalarExpr(E->getArg(1));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   E->getArg(1)->getType()->hasFloatingRepresentation() &&
+   "step operands must have a float representation");
+// make sure each vector has exactly 3 elements
+auto *XVecTy1 = E->getArg(0)->getType()->getAs();
+auto *XVecTy2 = E->getArg(1)->getType()->getAs();
+assert(XVecTy1->getNumElements() == 3 && XVecTy2->getNumElements() == 3 &&
+   "input vectors must have 3 elements each");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Op0->getType(), 
CGM.getHLSLRuntime().getCrossIntrinsic(),
+ArrayRef{Op0, Op1}, nullptr, "hlsl.cross");
+  }
   case Builtin::BI__builtin_hlsl_dot: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..6722d2c7c50a2b 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -74,6 +74,7 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6cd6a2caf19994..e4b40978dea6b9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1563,6 +1563,28 @@ uint64_t3 reversebits(uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
 uint64_t4 reversebits(uint64_t4);
 
+//===--===//
+// cross builtins
+//===--===//
+
+/// \fn T cross(T x, T y)
+/// \brief Returns the cross product of two floating-point, 3D vectors.
+/// \param x [in] The first floating-point, 3D vector.
+/// \param y [in] The second floating-point, 3D vector.
+///
+/// Result is the cross product of x and y, i.e., the resulting
+/// components are, in order :
+/// x[1] * y[2] - y[1] * x[2]
+/// x[2] * y[0] - y[2] * x[0]
+/// x[0] * y[1] - y[0] * x[1]
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
+half3 cross(half3, half3);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
+float3 cross(float3, float3);
+
 
//===---

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread Peilin Ye via cfe-commits


@@ -69,29 +69,25 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, 
StringRef FS) {
 CPU = "v3";
   if (CPU == "probe")
 CPU = sys::detail::getHostCPUNameForBPF();
-  if (CPU == "generic" || CPU == "v1")
+  if (CPU.empty() || CPU == "generic" || CPU == "v1")

peilin-ye wrote:

Ah, right, because recently #107008 made it default to `"v3"`.  Thanks, I 
didn't notice it when rebasing.

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


[clang] [Clang][NFC] Remove incorrect SYCL tests (PR #109182)

2024-09-18 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

> > Instead of removing the test case altogether, does it not suffice to remove 
> > the SYCL reference / SYCL specific flag, which I interpret as the problem 
> > being addressed? SYCL per se is not a target, but rather a language? 
> > Apologies if I'm missing something.
> 
> I tried that but there was no address spaces then. I wasn't sure if the tests 
> were relevant anymore in that case. I'll paste a snippet of what I saw below -
> 
> ```
> ; Function Attrs: mustprogress noinline optnone
> define spir_func noundef nonnull align 8 dereferenceable(8) ptr @_Z1fP1A(ptr 
> noundef %a) #0 personality ptr @__gxx_personality_v0 {
> entry:
>   %a.addr = alloca ptr, align 8
>   %exn.slot = alloca ptr, align 8
>   %ehselector.slot = alloca i32, align 4
>   store ptr %a, ptr %a.addr, align 8
>   %0 = load ptr, ptr %a.addr, align 8
>   %1 = call spir_func ptr @__dynamic_cast(ptr %0, ptr addrspace(1) @_ZTI1A, 
> ptr addrspace(1) @_ZTI1B, i64 0) #3
>   %2 = icmp eq ptr %1, null
>   br i1 %2, label %dynamic_cast.bad_cast, label %dynamic_cast.end
> 
> dynamic_cast.bad_cast:; preds = %entry
>   invoke spir_func void @__cxa_bad_cast() #4
>   to label %invoke.cont unwind label %lpad
> 
> invoke.cont:  ; preds = 
> %dynamic_cast.bad_cast
>   unreachable
> 
> dynamic_cast.end: ; preds = %entry
>   br label %try.cont
> 
> lpad: ; preds = 
> %dynamic_cast.bad_cast
>   %3 = landingpad { ptr, i32 }
>   catch ptr null
>   %4 = extractvalue { ptr, i32 } %3, 0
>   store ptr %4, ptr %exn.slot, align 8
>   %5 = extractvalue { ptr, i32 } %3, 1
>   store i32 %5, ptr %ehselector.slot, align 4
>   br label %catch
> ```
> 
> vs what the test was checking
> 
> ```
> // WITH-NONZERO-DEFAULT-AS-LABEL: define spir_func noundef align 8 
> dereferenceable(8) ptr addrspace(4) @_Z1fP1A(
> // WITH-NONZERO-DEFAULT-AS-SAME: ptr addrspace(4) noundef [[A:%.*]]) 
> #[[ATTR0:[0-9]+]] personality ptr @__gxx_personality_v0 {
> // WITH-NONZERO-DEFAULT-AS-NEXT:  entry:
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[RETVAL:%.*]] = alloca ptr addrspace(4), 
> align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[A_ADDR:%.*]] = alloca ptr addrspace(4), 
> align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[EXN_SLOT:%.*]] = alloca ptr 
> addrspace(4), align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[EHSELECTOR_SLOT:%.*]] = alloca i32, 
> align 4
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr 
> [[RETVAL]] to ptr addrspace(4)
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr 
> [[A_ADDR]] to ptr addrspace(4)
> // WITH-NONZERO-DEFAULT-AS-NEXT:store ptr addrspace(4) [[A]], ptr 
> addrspace(4) [[A_ADDR_ASCAST]], align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP0:%.*]] = load ptr addrspace(4), ptr 
> addrspace(4) [[A_ADDR_ASCAST]], align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP1:%.*]] = call spir_func ptr 
> addrspace(4) @__dynamic_cast(ptr addrspace(4) [[TMP0]], ptr addrspace(1) 
> @_ZTI1A, ptr addrspace(1) @_ZTI1B, i64 0) #[[ATTR3:[0-9]+]]
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP2:%.*]] = icmp eq ptr addrspace(4) 
> [[TMP1]], null
> // WITH-NONZERO-DEFAULT-AS-NEXT:br i1 [[TMP2]], label 
> [[DYNAMIC_CAST_BAD_CAST:%.*]], label [[DYNAMIC_CAST_END:%.*]]
> // WITH-NONZERO-DEFAULT-AS:   dynamic_cast.bad_cast:
> // WITH-NONZERO-DEFAULT-AS-NEXT:invoke spir_func void @__cxa_bad_cast() 
> #[[ATTR4:[0-9]+]]
> // WITH-NONZERO-DEFAULT-AS-NEXT:to label [[INVOKE_CONT:%.*]] 
> unwind label [[LPAD:%.*]]
> // WITH-NONZERO-DEFAULT-AS:   invoke.cont:
> // WITH-NONZERO-DEFAULT-AS-NEXT:unreachable
> // WITH-NONZERO-DEFAULT-AS:   dynamic_cast.end:
> // WITH-NONZERO-DEFAULT-AS-NEXT:br label [[TRY_CONT:%.*]]
> // WITH-NONZERO-DEFAULT-AS:   lpad:
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP3:%.*]] = landingpad { ptr 
> addrspace(4), i32 }
> // WITH-NONZERO-DEFAULT-AS-NEXT:catch ptr addrspace(4) null
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP4:%.*]] = extractvalue { ptr 
> addrspace(4), i32 } [[TMP3]], 0
> // WITH-NONZERO-DEFAULT-AS-NEXT:store ptr addrspace(4) [[TMP4]], ptr 
> [[EXN_SLOT]], align 8
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[TMP5:%.*]] = extractvalue { ptr 
> addrspace(4), i32 } [[TMP3]], 1
> // WITH-NONZERO-DEFAULT-AS-NEXT:store i32 [[TMP5]], ptr 
> [[EHSELECTOR_SLOT]], align 4
> // WITH-NONZERO-DEFAULT-AS-NEXT:br label [[CATCH:%.*]]
> // WITH-NONZERO-DEFAULT-AS:   catch:
> // WITH-NONZERO-DEFAULT-AS-NEXT:[[EXN:%.*]] = load ptr addrspace(4), ptr 
> [[EXN_SLOT]], align 
> ```

Ah, I remember now why the SYCL flag / mode was abused here (the default AS Map 
for SPIR-V is problematic in this case); I believe that using the 
`spirv64-amd-amdhsa` triple instead of `spirv64-unknown-unknown` will work, and 
allow for the removal of the SYCL references. 

https://github.com/llvm/l

[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Thomas Köppe via cfe-commits


@@ -84,6 +84,14 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  T x;
+};
+void test_templated() {
+  pear p = { NULL };

tkoeppe wrote:

It definitely does, but I was hoping that the absence would cause some kind of 
test failure! I.e. "first make sure you see the test fail"... Let me add a 
bogus expectation to confirm.

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


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Thomas Köppe via cfe-commits

https://github.com/tkoeppe updated 
https://github.com/llvm/llvm-project/pull/109169

From d6a67729477b178d2439dfd31539a82ab7041e10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= 
Date: Wed, 18 Sep 2024 17:04:44 +
Subject: [PATCH 1/2] [clang-tidy] Make modernize-use-nullptr matcher also
 match "NULL", but not "0", when it appears on a substituted type of a
 template specialization.

Previously, any matches on a substituted type were excluded, but this meant 
that a situation like the following is not diagnosed:

```c++
template 
struct X {
  T val;
  X() { val = NULL; }  // should diagnose
};
```

When the user says `NULL`, we expect that the destination type is always meant 
to be a pointer type, so this should be converted to `nullptr`. By contrast, we 
do not propose changing a literal `0` in that case, which appears as 
initializers of both pointer and integer specializations in reasonable real 
code. (If `NULL` is used erroneously in such a situation, it should be changed 
to `0` or `{}`.)
---
 .../clang-tidy/modernize/UseNullptrCheck.cpp  | 4 +++-
 .../test/clang-tidy/checkers/modernize/use-nullptr.cpp| 8 
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 6a003a347badac..b2921690863b84 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -38,7 +38,9 @@ AST_MATCHER(Type, sugaredNullptrType) {
 StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef NameList) {
   auto ImplicitCastToNull = implicitCastExpr(
   anyOf(hasCastKind(CK_NullToPointer), 
hasCastKind(CK_NullToMemberPointer)),
-  
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(,
+  anyOf(hasSourceExpression(gnuNullExpr()),
+unless(hasImplicitDestinationType(
+qualType(substTemplateTypeParmType(),
   unless(hasSourceExpression(hasType(sugaredNullptrType(,
   unless(hasImplicitDestinationType(
   qualType(matchers::matchesAnyListedTypeName(NameList);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 7bc0925136aa86..1807d6bd56125b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -84,6 +84,14 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  T x;
+};
+void test_templated() {
+  pear p = { NULL };
+  dummy(p.x);
+}
+
 #define IS_EQ(x, y) if (x != y) return;
 void test_macro_args() {
   int i = 0;

From 8fcc4b809cc9418473d362ef344c2fb0106f47ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= 
Date: Wed, 18 Sep 2024 20:25:13 +
Subject: [PATCH 2/2] Add bogus CHECK to see if this makes the test fail

---
 .../test/clang-tidy/checkers/modernize/use-nullptr.cpp   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 1807d6bd56125b..3c2e486538fe07 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -89,6 +89,7 @@ template  struct pear {
 };
 void test_templated() {
   pear p = { NULL };
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use fullptr
   dummy(p.x);
 }
 

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

Thanks for the clarification! The fact that there's code around that isn't 
quite following the standard, is not news, but the regular way to approach 
tightening the compiler is to  provide an opt-out mechanism for some time (one 
release cycle?) in the shape of a flag or otherwise. Do you think it could be a 
good option here? Alternatively, do you see a standard-compliant way to rewrite 
this code?

And did you have a chance to look at the third test case? It would be nice to 
know if Clang is acting according to the standard there.

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

> However, I suspect that the parentheses reduction and the one with a ternary 
> are actually the same issue - The code is IFNDR per 
> https://eel.is/c++draft/temp.over.link#5
> 
> In you last example, M*2 and the conditional with M+N after the substitution 
> of the default argument aren't equivalent despite having the same value after 
> instantiation.

Actually, I'm not sure the code I provided as "a bit closer to the original" is 
actually close enough to retain the relevant properties. I'll try to look at 
the original code to see if it actually is IFNDR according to 
https://eel.is/c++draft/temp.over.link#5. It's going to take some time though.

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


[clang] Implement current CWG direction for string literal comparisons. (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

https://github.com/zygoloid updated 
https://github.com/llvm/llvm-project/pull/109208

>From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001
From: Richard Smith 
Date: Wed, 18 Sep 2024 21:59:56 +
Subject: [PATCH 1/2] Implement current CWG direction for string literal
 comparisons.

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.
---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/lib/AST/ExprConstant.cpp| 119 +++---
 clang/test/AST/ByteCode/builtin-functions.cpp |   3 +-
 clang/test/AST/ByteCode/cxx20.cpp |  20 ++-
 clang/test/SemaCXX/builtins.cpp   |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  36 --
 7 files changed, 154 insertions(+), 39 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..6170bcd4f15ae3 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase {
   /// This is lazily created.  This is intentionally not serialized.
   mutable llvm::StringMap StringLiteralCache;
 
+  /// The next string literal "version" to allocate during constant evaluation.
+  /// This is used to distinguish between repeated evaluations of the same
+  /// string literal.
+  ///
+  /// TODO: Ensure version numbers don't collide when deserialized.
+  unsigned NextStringLiteralVersion = 0;
+
   /// MD5 hash of CUID. It is calculated when first used and cached by this
   /// data member.
   mutable std::string CUIDHash;
@@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Return the next version number to be used for a string literal evaluated
+  /// as part of constant evaluation.
+  unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
+
   /// Return a declaration for the global GUID object representing the given
   /// GUID value.
   MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const;
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 21a307d1e89878..76e693f6b4a6ca 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;
 def note_constexpr_pointer_weak_comparison : Note<
   "comparison against address of weak declaration '%0' can only be performed "
   "at runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..d9384a7c125a82 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,8 +54,10 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/SipHash.h"
@@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
@@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) {
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());
+  return BaseExpr && IsOpaqueConstantCall(BaseExpr);
+}
+
 static bool IsGlobalLValue(APValue::LValueBase B) {
   // C++11 [expr.const]p3 An address constant expression is a prvalue core
   // constant expression of pointer type that evaluates to...
@@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
   case Expr::ObjCBoxedExprClass:
 return cast(E)->isExpressibleAsConstantInitializer();
   cas

[clang] [clang] implement current CWG direction for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Richard Smith (zygoloid)


Changes

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.


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


8 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+11) 
- (modified) clang/include/clang/Basic/DiagnosticASTKinds.td (+2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+104-15) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+2-1) 
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+7-13) 
- (modified) clang/test/SemaCXX/builtins.cpp (+1-1) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+27-9) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+15) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..6170bcd4f15ae3 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase {
   /// This is lazily created.  This is intentionally not serialized.
   mutable llvm::StringMap StringLiteralCache;
 
+  /// The next string literal "version" to allocate during constant evaluation.
+  /// This is used to distinguish between repeated evaluations of the same
+  /// string literal.
+  ///
+  /// TODO: Ensure version numbers don't collide when deserialized.
+  unsigned NextStringLiteralVersion = 0;
+
   /// MD5 hash of CUID. It is calculated when first used and cached by this
   /// data member.
   mutable std::string CUIDHash;
@@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Return the next version number to be used for a string literal evaluated
+  /// as part of constant evaluation.
+  unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
+
   /// Return a declaration for the global GUID object representing the given
   /// GUID value.
   MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const;
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 21a307d1e89878..76e693f6b4a6ca 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;
 def note_constexpr_pointer_weak_comparison : Note<
   "comparison against address of weak declaration '%0' can only be performed "
   "at runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..d9384a7c125a82 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,8 +54,10 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/SipHash.h"
@@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
@@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) {
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());
+  return BaseExpr && IsOpaqueConstantCall(BaseExpr);
+}
+
 static bool IsGlobalLValue(APValue::LValueBase B) {
   // C++11 [expr.const]p3 An address constant expression is a prvalue core
   // constant expression of pointer type that evaluates to...
@@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
   case Expr::ObjCBoxedExprClass:
 return cast(E)->isExpressibleAsConstantInitializer();
   case Expr::CallExprClass:
-return IsNoOpCall(cast(E));
+return IsOpaqueCons

[clang] Implement current CWG direction for string literal comparisons. (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

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


[clang] [clang] implement current CWG direction for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

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


[clang] [flang] [flang][Driver] Support -fdiagnostics-color (PR #109210)

2024-09-18 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/109210

Add support for -fdiagnostics-color and -fdiagnostics-color=. Add documentation 
for -fdiagnostics-color= which should also be visible in clang.

Partially addresses requests in #89888

>From c5c827ab2c65da7b5fa04a2906d3d03d3dbfc508 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 18 Sep 2024 16:12:36 -0600
Subject: [PATCH] [flang][Driver] Support -fdiagnostics-color

Add support for -fdiagnostics-color and -fdiagnostics-color=. Add documentation
for -fdiagnostics-color= which should also be visible in clang.

Partially addresses requests in #89888
---
 clang/include/clang/Driver/Options.td | 11 --
 clang/lib/Driver/ToolChains/Flang.cpp |  6 
 .../Driver/color-diagnostics-forwarding.f90   | 36 +--
 flang/test/Driver/color-diagnostics-parse.f90 | 14 ++--
 flang/test/Driver/color-diagnostics-scan.f| 15 ++--
 flang/test/Driver/color-diagnostics-sema.f90  | 15 ++--
 flang/test/Driver/color-diagnostics.f90   | 28 +--
 7 files changed, 111 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..e6a4c9f7af28a1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1975,10 +1975,15 @@ def fno_color_diagnostics : Flag<["-"], 
"fno-color-diagnostics">, Group
   Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Disable colors in diagnostics">;
 def : Flag<["-"], "fdiagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
 def : Flag<["-"], "fno-diagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
-def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
+def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Values<"auto,always,never">,
+  HelpText<"When to use colors in diagnostics">;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
   Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
   HelpText<"Use ANSI escape codes for diagnostics">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..416a431f1e835f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -732,6 +732,12 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // to avoid warn_drv_unused_argument.
   Args.getLastArg(options::OPT_fcolor_diagnostics,
   options::OPT_fno_color_diagnostics);
+  if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
+StringRef Value(A->getValue());
+if (Value != "always" && Value != "never" && Value != "auto")
+  D.Diag(diag::err_drv_invalid_argument_to_option)
+  << Value << A->getOption().getName();
+  }
   if (Diags.getDiagnosticOptions().ShowColors)
 CmdArgs.push_back("-fcolor-diagnostics");
 
diff --git a/flang/test/Driver/color-diagnostics-forwarding.f90 
b/flang/test/Driver/color-diagnostics-forwarding.f90
index daef17cb757878..368fa8834142ab 100644
--- a/flang/test/Driver/color-diagnostics-forwarding.f90
+++ b/flang/test/Driver/color-diagnostics-forwarding.f90
@@ -1,21 +1,53 @@
-! Test that flang-new forwards -f{no-}color-diagnostics options to
-! flang-new -fc1 as expected.
+! Test that flang-new forwards -f{no-}color-diagnostics and
+! -f{no-}diagnostics-color options to flang-new -fc1 as expected.
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=always \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
 ! CHECK-CD: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fno-color-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t -fno-diagnostics-color 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=never \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
 ! CHECK-NCD-NOT: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! Check that the last flag wins.
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: -fno-color-diagnostics -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fno-diagnostics-color -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN

[clang] Implement current CWG direction for string literal comparisons. (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

https://github.com/zygoloid created 
https://github.com/llvm/llvm-project/pull/109208

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.


>From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001
From: Richard Smith 
Date: Wed, 18 Sep 2024 21:59:56 +
Subject: [PATCH] Implement current CWG direction for string literal
 comparisons.

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.
---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/lib/AST/ExprConstant.cpp| 119 +++---
 clang/test/AST/ByteCode/builtin-functions.cpp |   3 +-
 clang/test/AST/ByteCode/cxx20.cpp |  20 ++-
 clang/test/SemaCXX/builtins.cpp   |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  36 --
 7 files changed, 154 insertions(+), 39 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..6170bcd4f15ae3 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase {
   /// This is lazily created.  This is intentionally not serialized.
   mutable llvm::StringMap StringLiteralCache;
 
+  /// The next string literal "version" to allocate during constant evaluation.
+  /// This is used to distinguish between repeated evaluations of the same
+  /// string literal.
+  ///
+  /// TODO: Ensure version numbers don't collide when deserialized.
+  unsigned NextStringLiteralVersion = 0;
+
   /// MD5 hash of CUID. It is calculated when first used and cached by this
   /// data member.
   mutable std::string CUIDHash;
@@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Return the next version number to be used for a string literal evaluated
+  /// as part of constant evaluation.
+  unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
+
   /// Return a declaration for the global GUID object representing the given
   /// GUID value.
   MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const;
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 21a307d1e89878..76e693f6b4a6ca 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;
 def note_constexpr_pointer_weak_comparison : Note<
   "comparison against address of weak declaration '%0' can only be performed "
   "at runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..d9384a7c125a82 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,8 +54,10 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/SipHash.h"
@@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
@@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) {
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());
+  return BaseExpr && IsOpaqueConstantCall(BaseExpr);
+}
+
 static bool IsGlobalLValue(APValue::LValueBase B) {
   // C+

[clang] [flang] [flang][Driver] Support -fdiagnostics-color (PR #109210)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-driver

Author: Tarun Prabhu (tarunprabhu)


Changes

Add support for -fdiagnostics-color and -fdiagnostics-color=. Add documentation 
for -fdiagnostics-color= which should also be visible in clang.

Partially addresses requests in #89888

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+8-3) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+6) 
- (modified) flang/test/Driver/color-diagnostics-forwarding.f90 (+34-2) 
- (modified) flang/test/Driver/color-diagnostics-parse.f90 (+12-2) 
- (modified) flang/test/Driver/color-diagnostics-scan.f (+13-2) 
- (modified) flang/test/Driver/color-diagnostics-sema.f90 (+13-2) 
- (modified) flang/test/Driver/color-diagnostics.f90 (+25-3) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..e6a4c9f7af28a1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1975,10 +1975,15 @@ def fno_color_diagnostics : Flag<["-"], 
"fno-color-diagnostics">, Group
   Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Disable colors in diagnostics">;
 def : Flag<["-"], "fdiagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
 def : Flag<["-"], "fno-diagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
-def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
+def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Values<"auto,always,never">,
+  HelpText<"When to use colors in diagnostics">;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
   Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
   HelpText<"Use ANSI escape codes for diagnostics">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..416a431f1e835f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -732,6 +732,12 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // to avoid warn_drv_unused_argument.
   Args.getLastArg(options::OPT_fcolor_diagnostics,
   options::OPT_fno_color_diagnostics);
+  if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
+StringRef Value(A->getValue());
+if (Value != "always" && Value != "never" && Value != "auto")
+  D.Diag(diag::err_drv_invalid_argument_to_option)
+  << Value << A->getOption().getName();
+  }
   if (Diags.getDiagnosticOptions().ShowColors)
 CmdArgs.push_back("-fcolor-diagnostics");
 
diff --git a/flang/test/Driver/color-diagnostics-forwarding.f90 
b/flang/test/Driver/color-diagnostics-forwarding.f90
index daef17cb757878..368fa8834142ab 100644
--- a/flang/test/Driver/color-diagnostics-forwarding.f90
+++ b/flang/test/Driver/color-diagnostics-forwarding.f90
@@ -1,21 +1,53 @@
-! Test that flang-new forwards -f{no-}color-diagnostics options to
-! flang-new -fc1 as expected.
+! Test that flang-new forwards -f{no-}color-diagnostics and
+! -f{no-}diagnostics-color options to flang-new -fc1 as expected.
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=always \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
 ! CHECK-CD: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fno-color-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t -fno-diagnostics-color 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=never \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
 ! CHECK-NCD-NOT: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! Check that the last flag wins.
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: -fno-color-diagnostics -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fno-diagnostics-color -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t \
+! RUN: -fno-color-diagnostics -fdiagnostics-color=always 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t \
+! RUN: -fdiagnostics-color=never -fdiagnostics-color=always 2>&1 \
+! RUN:   | FileCheck %s 

[clang] [flang] [flang][Driver] Support -fdiagnostics-color (PR #109210)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Tarun Prabhu (tarunprabhu)


Changes

Add support for -fdiagnostics-color and -fdiagnostics-color=. Add documentation 
for -fdiagnostics-color= which should also be visible in clang.

Partially addresses requests in #89888

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+8-3) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+6) 
- (modified) flang/test/Driver/color-diagnostics-forwarding.f90 (+34-2) 
- (modified) flang/test/Driver/color-diagnostics-parse.f90 (+12-2) 
- (modified) flang/test/Driver/color-diagnostics-scan.f (+13-2) 
- (modified) flang/test/Driver/color-diagnostics-sema.f90 (+13-2) 
- (modified) flang/test/Driver/color-diagnostics.f90 (+25-3) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..e6a4c9f7af28a1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1975,10 +1975,15 @@ def fno_color_diagnostics : Flag<["-"], 
"fno-color-diagnostics">, Group
   Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Disable colors in diagnostics">;
 def : Flag<["-"], "fdiagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
 def : Flag<["-"], "fno-diagnostics-color">, Group,
-  Visibility<[ClangOption, CLOption, DXCOption]>, Alias;
-def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Alias;
+def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Values<"auto,always,never">,
+  HelpText<"When to use colors in diagnostics">;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
   Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>,
   HelpText<"Use ANSI escape codes for diagnostics">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..416a431f1e835f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -732,6 +732,12 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // to avoid warn_drv_unused_argument.
   Args.getLastArg(options::OPT_fcolor_diagnostics,
   options::OPT_fno_color_diagnostics);
+  if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
+StringRef Value(A->getValue());
+if (Value != "always" && Value != "never" && Value != "auto")
+  D.Diag(diag::err_drv_invalid_argument_to_option)
+  << Value << A->getOption().getName();
+  }
   if (Diags.getDiagnosticOptions().ShowColors)
 CmdArgs.push_back("-fcolor-diagnostics");
 
diff --git a/flang/test/Driver/color-diagnostics-forwarding.f90 
b/flang/test/Driver/color-diagnostics-forwarding.f90
index daef17cb757878..368fa8834142ab 100644
--- a/flang/test/Driver/color-diagnostics-forwarding.f90
+++ b/flang/test/Driver/color-diagnostics-forwarding.f90
@@ -1,21 +1,53 @@
-! Test that flang-new forwards -f{no-}color-diagnostics options to
-! flang-new -fc1 as expected.
+! Test that flang-new forwards -f{no-}color-diagnostics and
+! -f{no-}diagnostics-color options to flang-new -fc1 as expected.
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=always \
+! RUN:   | FileCheck %s --check-prefix=CHECK-CD
 ! CHECK-CD: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fno-color-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t -fno-diagnostics-color 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 -fdiagnostics-color=never \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD
 ! CHECK-NCD-NOT: "-fc1"{{.*}} "-fcolor-diagnostics"
 
 ! Check that the last flag wins.
 ! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: -fno-color-diagnostics -fcolor-diagnostics \
 ! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN: -fno-diagnostics-color -fdiagnostics-color \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t \
+! RUN: -fno-color-diagnostics -fdiagnostics-color=always 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=CHECK-NCD_CD_S
+! RUN: %flang -fsyntax-only -### %s -o %t \
+! RUN: -fdiagnostics-color=never -fdiagnostics-color=always 2>&1 \
+! RUN:   | FileCheck %s 

[clang] [clang] implement current CWG direction for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

https://github.com/zygoloid updated 
https://github.com/llvm/llvm-project/pull/109208

>From 81193568c17a89f6cf42f43a82fb1fbf0f90184d Mon Sep 17 00:00:00 2001
From: Richard Smith 
Date: Wed, 18 Sep 2024 21:59:56 +
Subject: [PATCH 1/3] Implement current CWG direction for string literal
 comparisons.

Track the identity of each string literal object produced by evaluation
with a global version number. Accept comparisons between literals of the
same version, and between literals of different versions that cannot
possibly be placed in overlapping storage. Treat the remaining
comparisons as non-constant.
---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |   2 +
 clang/lib/AST/ExprConstant.cpp| 119 +++---
 clang/test/AST/ByteCode/builtin-functions.cpp |   3 +-
 clang/test/AST/ByteCode/cxx20.cpp |  20 ++-
 clang/test/SemaCXX/builtins.cpp   |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  36 --
 7 files changed, 154 insertions(+), 39 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..6170bcd4f15ae3 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -324,6 +324,13 @@ class ASTContext : public RefCountedBase {
   /// This is lazily created.  This is intentionally not serialized.
   mutable llvm::StringMap StringLiteralCache;
 
+  /// The next string literal "version" to allocate during constant evaluation.
+  /// This is used to distinguish between repeated evaluations of the same
+  /// string literal.
+  ///
+  /// TODO: Ensure version numbers don't collide when deserialized.
+  unsigned NextStringLiteralVersion = 0;
+
   /// MD5 hash of CUID. It is calculated when first used and cached by this
   /// data member.
   mutable std::string CUIDHash;
@@ -3278,6 +3285,10 @@ class ASTContext : public RefCountedBase {
   /// PredefinedExpr to cache evaluated results.
   StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const;
 
+  /// Return the next version number to be used for a string literal evaluated
+  /// as part of constant evaluation.
+  unsigned getNextStringLiteralVersion() { return NextStringLiteralVersion++; }
+
   /// Return a declaration for the global GUID object representing the given
   /// GUID value.
   MSGuidDecl *getMSGuidDecl(MSGuidDeclParts Parts) const;
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 21a307d1e89878..76e693f6b4a6ca 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;
 def note_constexpr_pointer_weak_comparison : Note<
   "comparison against address of weak declaration '%0' can only be performed "
   "at runtime">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..d9384a7c125a82 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,8 +54,10 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/SipHash.h"
@@ -2061,8 +2063,8 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
@@ -2070,6 +2072,12 @@ static bool IsNoOpCall(const CallExpr *E) {
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());
+  return BaseExpr && IsOpaqueConstantCall(BaseExpr);
+}
+
 static bool IsGlobalLValue(APValue::LValueBase B) {
   // C++11 [expr.const]p3 An address constant expression is a prvalue core
   // constant expression of pointer type that evaluates to...
@@ -2115,7 +2123,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
   case Expr::ObjCBoxedExprClass:
 return cast(E)->isExpressibleAsConstantInitializer();
   cas

[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Wow, I would never have thought it was a problem. Making these the same type 
> removes the compilation error. Can you explain why this is a problem from the 
> C++ standard PoV?

That's https://eel.is/c++draft/temp.deduct.type#20

In deduced contexts for an NTTP, the type of the argument and the parameter 
must match exactly.

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


[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)

2024-09-18 Thread John McCall via cfe-commits


@@ -2419,8 +2419,13 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 return Visit(const_cast(E));
 
   case CK_NoOp: {
-return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
-  : Visit(const_cast(E));
+if (CE->changesVolatileQualification())
+  return EmitLoadOfLValue(CE);
+auto V = Visit(const_cast(E));
+if (CGF.CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers &&
+CE->getType()->isMemberFunctionPointerType())
+  V = CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, V);
+return V;

rjmccall wrote:

Okay, but that's coincidental, right?  The language doesn't semantically 
guarantee that that conversion is a no-op, it just happens to be under normal 
conditions, even with function pointer type diversity enabled.

What cast kind do we use if you cast a function pointer to a completely 
different type?

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


[clang] fix(clang/**.py): fix comparison to None (PR #94014)

2024-09-18 Thread Eisuke Kawashima via cfe-commits

e-kwsm wrote:

This PR is ready but I have no permission.

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

I see. A clear diagnostic wouldn't hurt indeed. Thanks a lot for the analysis! 
No more concerns from our side at this point.

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


[clang] [clang-scan-deps] Don't inspect Args[0] as an option (PR #109050)

2024-09-18 Thread Jan Svoboda via cfe-commits


@@ -839,9 +839,11 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   auto R = std::make_reverse_iterator(FlagsEnd);
   for (auto I = R, E = Args.rend(); I != E; ++I) {
 StringRef Arg = *I;
+if ((I + 1) == E) // Don't inspect Args[0] as an option.
+  break;

jansvoboda11 wrote:

Why not adjust `E` in the loop header instead of checking this on each 
iteration?

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


[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Thomas Köppe via cfe-commits

https://github.com/tkoeppe updated 
https://github.com/llvm/llvm-project/pull/109169

From 6e056a2aad2b9b7957c18c8dfb8f64a44c7c785f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= 
Date: Wed, 18 Sep 2024 17:04:44 +
Subject: [PATCH] [clang-tidy] Make modernize-use-nullptr matcher also match
 "NULL", but not "0", when it appears on a substituted type of a template
 specialization.

Previously, any matches on a substituted type were excluded, but this meant 
that a situation like the following is not diagnosed:

```c++
template 
struct X {
  T val;
  X() { val = NULL; }  // should diagnose
};
```

When the user says `NULL`, we expect that the destination type is always meant 
to be a pointer type, so this should be converted to `nullptr`. By contrast, we 
do not propose changing a literal `0` in that case, which appears as 
initializers of both pointer and integer specializations in reasonable real 
code. (If `NULL` is used erroneously in such a situation, it should be changed 
to `0` or `{}`.)
---
 .../clang-tidy/modernize/UseNullptrCheck.cpp  |  4 +++-
 .../clang-tidy/checkers/modernize/use-nullptr.cpp | 11 +++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 6a003a347badac..b2921690863b84 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -38,7 +38,9 @@ AST_MATCHER(Type, sugaredNullptrType) {
 StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef NameList) {
   auto ImplicitCastToNull = implicitCastExpr(
   anyOf(hasCastKind(CK_NullToPointer), 
hasCastKind(CK_NullToMemberPointer)),
-  
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(,
+  anyOf(hasSourceExpression(gnuNullExpr()),
+unless(hasImplicitDestinationType(
+qualType(substTemplateTypeParmType(),
   unless(hasSourceExpression(hasType(sugaredNullptrType(,
   unless(hasImplicitDestinationType(
   qualType(matchers::matchesAnyListedTypeName(NameList);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
index 7bc0925136aa86..df99a78efd0c80 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp
@@ -84,6 +84,17 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  pear() { x = __null; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr 
[modernize-use-nullptr]
+  // CHECK-FIXES: x = nullptr;
+  T x;
+};
+void test_templated() {
+  pear p;
+  dummy(p.x);
+}
+
 #define IS_EQ(x, y) if (x != y) return;
 void test_macro_args() {
   int i = 0;

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


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-09-18 Thread Michael Buch via cfe-commits

Michael137 wrote:

> This change leads to a crash in `ConstStructBuilder::Build()` for the 
> following program:
> 
> ```
> struct S {
> };
> 
> union U {
> struct S s;
> int x;
> };
> 
> void foo() {
> union U bar = {};
> }
> ```
> 
> `isEmptyRecordForLayout` returns false for `union U` because the recursive 
> call for `U::x` returns false. This means we call `Init->HasSideEffects()` 
> despite `Init` being null (because `ILE->getNumInits()` is `0`).

Thanks for reporting. It looks like this is only happening when compiling with 
`C`. A slightly more condensed reproducer:
```
union U {
struct S {} s;
};

void foo() {
// union U bar = {{}}; // WORKS
union U bar = {}; // CRASHES
}
```

Looks like when the brace initializer is empty, in C, `ILE->getNumInits()` 
returns `0` (not entirely sure off the top why this is the case). Previously, 
`isZeroSize` would never have been true for fields in C, so this wasn't an 
issue. Now we do hit this code-path and blindly dereference a null `Init`. I 
think we can probably just add a nullptr check here: 
https://github.com/llvm/llvm-project/blob/38752ffd417103621232e6ba6ba70e970e0d6356/clang/lib/CodeGen/CGExprConstant.cpp#L741

Though would like to understand the C vs. C++ significance here first.

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


[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)

2024-09-18 Thread Akira Hatanaka via cfe-commits


@@ -2419,8 +2419,13 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 return Visit(const_cast(E));
 
   case CK_NoOp: {
-return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
-  : Visit(const_cast(E));
+if (CE->changesVolatileQualification())
+  return EmitLoadOfLValue(CE);
+auto V = Visit(const_cast(E));
+if (CGF.CGM.getCodeGenOpts().PointerAuth.CXXMemberFunctionPointers &&
+CE->getType()->isMemberFunctionPointerType())
+  V = CGF.CGM.getCXXABI().EmitMemberPointerConversion(CGF, CE, V);
+return V;

ahatanak wrote:

Depending on the kind of casts in the source code, `CStyleCastExpr` or 
`CXXReinterpretCastExpr` (or possibly another cast kind) is used when casting 
to a completely different function pointer type.

But those are explicit casts. I'm not sure there's another cast operation other 
than `CK_NoOp` in `clang/AST/OperationKinds.def` that we can use for that 
purpose.

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


[clang] [Clang] Automatically link the `compiler-rt` for GPUs if present (PR #109152)

2024-09-18 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I like this direction and I think it should be the right way. However, IMHO, 
> I think it needs discussion (and potentially an RFC).

Moving from the header to the definition in `compiler-rt` would warrant an RFC, 
this patch just automatically links something that exists and will only provide 
definitions if they are undefined. So the only effect this has right now is 
linking in a symbol that would otherwise be a linker error.

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


[clang] [Clang][NFC] Remove incorrect SYCL tests (PR #109182)

2024-09-18 Thread via cfe-commits

https://github.com/elizabethandrews created 
https://github.com/llvm/llvm-project/pull/109182

The tests added for SYCL device compilation in 
https://github.com/llvm/llvm-project/pull/88182 are incorrect SYCL tests. Code 
technically should not have been emitted in SYCL device compilation for these 
tests since they did not use the a SYCL kernel or the SYCL_EXTERNAL macro. Code 
is emitted currently in Clang due to missing SYCL support. Additionally some of 
the features tested like RTTI are illegal constructs in SYCL device code. It is 
undiagnosed in Clang due to incomplete support again. We are working on 
improving and adding more SYCL support through our implementation of RFC - 
https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080.

However, since the current SYCL support in Clang is incomplete, I would suggest 
using some other target with non-zero value for generic address space for these 
tests if required.

>From de0278d21e737c7ac8cd0165f05484c40aeb46fa Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Wed, 18 Sep 2024 12:34:06 -0700
Subject: [PATCH] [Clang][NFC] Remove incorrect SYCL tests

The tests added for SYCL device compilation in 
https://github.com/llvm/llvm-project/pull/88182
are incorrect SYCL tests. Code technically should not have been emitted in SYCL 
device compilation
for these tests since they did not use the a SYCL kernel or the SYCL_EXTERNAL 
macro. Code is
emitted currently in Clang due to missing SYCL support. Additionally some of 
the features tested
like RTTI are illegal constructs in SYCL device code. It is undiagnosed in 
Clang due to incomplete
support again. We are working on improving and adding more SYCL support through 
our implementation
of RFC - 
https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080.

However, since the current SYCL support in Clang is incomplete, I would suggest 
using some other
target with non-zero value for generic address space for these tests if 
required.
---
 .../CodeGenCXX/dynamic-cast-address-space.cpp | 54 ---
 .../template-param-objects-address-space.cpp  | 10 
 ...w-expression-typeinfo-in-address-space.cpp |  2 -
 .../try-catch-with-address-space.cpp  |  3 --
 .../typeid-cxx11-with-address-space.cpp   |  4 --
 .../CodeGenCXX/typeid-with-address-space.cpp  | 11 
 .../typeinfo-with-address-space.cpp   |  7 ---
 .../vtable-assume-load-address-space.cpp  |  1 -
 ...e-pointer-initialization-address-space.cpp |  7 ---
 clang/test/CodeGenCXX/vtt-address-space.cpp   |  7 ---
 10 files changed, 106 deletions(-)

diff --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
index 3d5e32516c7af2..23773def15eecc 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --no-generate-body-for-unused-prefixes --version 4
 // RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
-// RUN: %clang_cc1 -I%S %s -triple spirv64-unknown-unknown -fsycl-is-device 
-emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s 
--check-prefix=WITH-NONZERO-DEFAULT-AS
 
 struct A { virtual void f(); };
 struct B : A { };
@@ -15,13 +14,6 @@ B fail;
 // CHECK: @_ZTI1B = linkonce_odr addrspace(1) constant { ptr addrspace(1), ptr 
addrspace(1), ptr addrspace(1) } { ptr addrspace(1) getelementptr inbounds (ptr 
addrspace(1), ptr addrspace(1) @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 
2), ptr addrspace(1) @_ZTS1B, ptr addrspace(1) @_ZTI1A }, comdat, align 8
 // CHECK: @__oclc_ABI_version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 500
 //.
-// WITH-NONZERO-DEFAULT-AS: @_ZTV1B = linkonce_odr unnamed_addr addrspace(1) 
constant { [3 x ptr addrspace(1)] } { [3 x ptr addrspace(1)] [ptr addrspace(1) 
null, ptr addrspace(1) @_ZTI1B, ptr addrspace(1) addrspacecast (ptr @_ZN1A1fEv 
to ptr addrspace(1))] }, comdat, align 8
-// WITH-NONZERO-DEFAULT-AS: @fail = addrspace(1) global { ptr addrspace(1) } { 
ptr addrspace(1) getelementptr inbounds inrange(-16, 8) ({ [3 x ptr 
addrspace(1)] }, ptr addrspace(1) @_ZTV1B, i32 0, i32 0, i32 2) }, align 8
-// WITH-NONZERO-DEFAULT-AS: @_ZTI1A = external addrspace(1) constant ptr 
addrspace(1)
-// WITH-NONZERO-DEFAULT-AS: @_ZTVN10__cxxabiv120__si_class_type_infoE = 
external addrspace(1) global [0 x ptr addrspace(1)]
-// WITH-NONZERO-DEFAULT-AS: @_ZTS1B = linkonce_odr addrspace(1) constant [3 x 
i8] c"1B\00", comdat, align 1
-// WITH-NONZERO-DEFAULT-AS: @_ZTI1B = linkonce_odr addrspace(1) constant { ptr 
addrspace(1), ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) 
getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) 
@_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr addrsp

[clang] [clang/AST] Make it possible to use SwiftAttr in type context (PR #108631)

2024-09-18 Thread Pavel Yaskevich via cfe-commits


@@ -6037,13 +6038,24 @@ class AttributedType : public Type, public 
llvm::FoldingSetNode {
 private:
   friend class ASTContext; // ASTContext creates these
 
+  const Attr *Attribute;
+
   QualType ModifiedType;
   QualType EquivalentType;
 
   AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
  QualType equivalent)
+  : AttributedType(canon, attrKind, nullptr, modified, equivalent) {}
+
+  AttributedType(QualType canon, const Attr *attr, QualType modified,
+ QualType equivalent);
+
+private:
+  AttributedType(QualType canon, attr::Kind attrKind, const Attr *attr,
+ QualType modified, QualType equivalent)
   : Type(Attributed, canon, equivalent->getDependence()),
-ModifiedType(modified), EquivalentType(equivalent) {
+Attribute(attr), ModifiedType(modified),
+EquivalentType(equivalent) {
 AttributedTypeBits.AttrKind = attrKind;

xedin wrote:

Sure!

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


[clang] [Clang][NFC] Remove incorrect SYCL tests (PR #109182)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (elizabethandrews)


Changes

The tests added for SYCL device compilation in 
https://github.com/llvm/llvm-project/pull/88182 are incorrect SYCL tests. Code 
technically should not have been emitted in SYCL device compilation for these 
tests since they did not use the a SYCL kernel or the SYCL_EXTERNAL macro. Code 
is emitted currently in Clang due to missing SYCL support. Additionally some of 
the features tested like RTTI are illegal constructs in SYCL device code. It is 
undiagnosed in Clang due to incomplete support again. We are working on 
improving and adding more SYCL support through our implementation of RFC - 
https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080.

However, since the current SYCL support in Clang is incomplete, I would suggest 
using some other target with non-zero value for generic address space for these 
tests if required.

---

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


10 Files Affected:

- (modified) clang/test/CodeGenCXX/dynamic-cast-address-space.cpp (-54) 
- (modified) clang/test/CodeGenCXX/template-param-objects-address-space.cpp 
(-10) 
- (modified) 
clang/test/CodeGenCXX/throw-expression-typeinfo-in-address-space.cpp (-2) 
- (modified) clang/test/CodeGenCXX/try-catch-with-address-space.cpp (-3) 
- (modified) clang/test/CodeGenCXX/typeid-cxx11-with-address-space.cpp (-4) 
- (modified) clang/test/CodeGenCXX/typeid-with-address-space.cpp (-11) 
- (modified) clang/test/CodeGenCXX/typeinfo-with-address-space.cpp (-7) 
- (modified) clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp (-1) 
- (modified) 
clang/test/CodeGenCXX/vtable-pointer-initialization-address-space.cpp (-7) 
- (modified) clang/test/CodeGenCXX/vtt-address-space.cpp (-7) 


``diff
diff --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
index 3d5e32516c7af2..23773def15eecc 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -1,6 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals all --no-generate-body-for-unused-prefixes --version 4
 // RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm 
-fcxx-exceptions -fexceptions -o - | FileCheck %s
-// RUN: %clang_cc1 -I%S %s -triple spirv64-unknown-unknown -fsycl-is-device 
-emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s 
--check-prefix=WITH-NONZERO-DEFAULT-AS
 
 struct A { virtual void f(); };
 struct B : A { };
@@ -15,13 +14,6 @@ B fail;
 // CHECK: @_ZTI1B = linkonce_odr addrspace(1) constant { ptr addrspace(1), ptr 
addrspace(1), ptr addrspace(1) } { ptr addrspace(1) getelementptr inbounds (ptr 
addrspace(1), ptr addrspace(1) @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 
2), ptr addrspace(1) @_ZTS1B, ptr addrspace(1) @_ZTI1A }, comdat, align 8
 // CHECK: @__oclc_ABI_version = weak_odr hidden local_unnamed_addr 
addrspace(4) constant i32 500
 //.
-// WITH-NONZERO-DEFAULT-AS: @_ZTV1B = linkonce_odr unnamed_addr addrspace(1) 
constant { [3 x ptr addrspace(1)] } { [3 x ptr addrspace(1)] [ptr addrspace(1) 
null, ptr addrspace(1) @_ZTI1B, ptr addrspace(1) addrspacecast (ptr @_ZN1A1fEv 
to ptr addrspace(1))] }, comdat, align 8
-// WITH-NONZERO-DEFAULT-AS: @fail = addrspace(1) global { ptr addrspace(1) } { 
ptr addrspace(1) getelementptr inbounds inrange(-16, 8) ({ [3 x ptr 
addrspace(1)] }, ptr addrspace(1) @_ZTV1B, i32 0, i32 0, i32 2) }, align 8
-// WITH-NONZERO-DEFAULT-AS: @_ZTI1A = external addrspace(1) constant ptr 
addrspace(1)
-// WITH-NONZERO-DEFAULT-AS: @_ZTVN10__cxxabiv120__si_class_type_infoE = 
external addrspace(1) global [0 x ptr addrspace(1)]
-// WITH-NONZERO-DEFAULT-AS: @_ZTS1B = linkonce_odr addrspace(1) constant [3 x 
i8] c"1B\00", comdat, align 1
-// WITH-NONZERO-DEFAULT-AS: @_ZTI1B = linkonce_odr addrspace(1) constant { ptr 
addrspace(1), ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) 
getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) 
@_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr addrspace(1) @_ZTS1B, 
ptr addrspace(1) @_ZTI1A }, comdat, align 8
-//.
 // CHECK-LABEL: define dso_local noundef nonnull align 8 dereferenceable(8) 
ptr @_Z1fP1A(
 // CHECK-SAME: ptr noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] personality ptr 
@__gxx_personality_v0 {
 // CHECK-NEXT:  entry:
@@ -59,43 +51,6 @@ B fail;
 // CHECK:   try.cont:
 // CHECK-NEXT:ret ptr addrspacecast (ptr addrspace(1) @fail to ptr)
 //
-// WITH-NONZERO-DEFAULT-AS-LABEL: define spir_func noundef align 8 
dereferenceable(8) ptr addrspace(4) @_Z1fP1A(
-// WITH-NONZERO-DEFAULT-AS-SAME: ptr addrspace(4) noundef [[A:%.*]]) 
#[[ATTR0:[0-9]+]] personality ptr @__gxx_personality_v0 {
-// WITH-NONZERO-DEFAULT-AS-NEXT:  entry:
-// WITH-NONZERO-DEFAULT-AS-NEXT:[[RETVAL:%

[clang] [lld] [llvm] [clang][MIPS] Add support for mipsel-windows-* targets (PR #107744)

2024-09-18 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> > For the Mips backend itself, I would ask the Mips backend code 
> > maintainer... but we don't have a maintainer for Mips. And we don't have 
> > any buildbots. I'm really not sure about adding complexity to a backend 
> > which is already suffering from a lack of anyone that has any experience 
> > with it. (People familiar with other backends can sort of step in to review 
> > changes to Mips, but it's hard to do a good review for anything 
> > non-trivial.)
> 
> FWIW, I've seen @wzssyqa do some amount of work around MIPS, should we ask 
> them about whether want to take up the role as MIPS backend maintainer?

Ping @wzssyqa - what's your take on this, both about the maintainance state of 
the MIPS target overall, and if you have concerns around accepting patches in 
this area?

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


[clang] [llvm] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED (PR #79942)

2024-09-18 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/79942

>From 2a5a3f2f55bd2b7479278fa72f6f05e54033532c Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Wed, 19 Jul 2023 20:30:29 -0700
Subject: [PATCH] [Clang][CMake] Add CSSPGO support to LLVM_BUILD_INSTRUMENTED

Build on Clang-BOLT infrastructure to collect sample profiles for CSSPGO.
Add clang/cmake/caches/CSSPGO.cmake to automate CSSPGO Clang build.

Differential Revision: https://reviews.llvm.org/D155419
---
 clang/CMakeLists.txt   | 12 -
 clang/cmake/caches/CSSPGO.cmake|  3 ++
 clang/utils/perf-training/CMakeLists.txt   | 28 ++-
 clang/utils/perf-training/lit.cfg  |  6 +++
 clang/utils/perf-training/lit.site.cfg.in  |  1 +
 clang/utils/perf-training/perf-helper.py   | 56 ++
 llvm/CMakeLists.txt|  3 ++
 llvm/cmake/modules/HandleLLVMOptions.cmake | 26 +-
 8 files changed, 121 insertions(+), 14 deletions(-)
 create mode 100644 clang/cmake/caches/CSSPGO.cmake

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index c6496167d3828b..46e1412c0727aa 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -744,11 +744,21 @@ if (CLANG_ENABLE_BOOTSTRAP)
   if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps llvm-profdata)
 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+string(TOUPPER "${BOOTSTRAP_LLVM_BUILD_INSTRUMENTED}" 
BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
+if (BOOTSTRAP_LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  add_dependencies(clang-bootstrap-deps llvm-profgen)
+  list(APPEND PGO_OPT 
-DLLVM_PROFGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profgen)
+endif()
   endif()
 
   if(LLVM_BUILD_INSTRUMENTED)
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
 add_dependencies(clang-bootstrap-deps generate-profdata)
-set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PGO_OPT 
-DLLVM_SPROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+else()
+  set(PGO_OPT 
-DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+endif()
 # Use the current tools for LTO instead of the instrumented ones
 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
   CMAKE_CXX_COMPILER
diff --git a/clang/cmake/caches/CSSPGO.cmake b/clang/cmake/caches/CSSPGO.cmake
new file mode 100644
index 00..34159068d5ea3f
--- /dev/null
+++ b/clang/cmake/caches/CSSPGO.cmake
@@ -0,0 +1,3 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED "CSSPGO" CACHE STRING "")
+include(${CMAKE_CURRENT_LIST_DIR}/PGO.cmake)
diff --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 49673790ff6e84..91883a21182340 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -20,6 +20,7 @@ if(LLVM_BUILD_INSTRUMENTED)
 
   add_custom_target(clear-profraw
 COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/ profraw
+COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py 
clean ${CMAKE_CURRENT_BINARY_DIR} perf.data
 COMMENT "Clearing old profraw data")
 
   if(NOT LLVM_PROFDATA)
@@ -39,10 +40,33 @@ if(LLVM_BUILD_INSTRUMENTED)
   # Therefor we call the generate-profraw target manually as part of this 
custom
   # command, which will only run if clang or ${CLANG_PGO_TRAINING_DEPS} 
are updated.
   COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target 
generate-profraw
-  COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py merge ${LLVM_PROFDATA} 
${CMAKE_CURRENT_BINARY_DIR}/clang.profdata ${CMAKE_CURRENT_BINARY_DIR} 
${CMAKE_BINARY_DIR}/profiles/
-  COMMENT "Merging profdata"
   DEPENDS clang ${CLANG_PGO_TRAINING_DEPS}
 )
+string(TOUPPER "${LLVM_BUILD_INSTRUMENTED}" LLVM_BUILD_INSTRUMENTED)
+if (LLVM_BUILD_INSTRUMENTED STREQUAL "CSSPGO")
+  set(PROFDATA_SAMPLE "--sample")
+  if(NOT LLVM_PROFGEN)
+find_program(LLVM_PROFGEN llvm-profgen)
+  endif()
+
+  if(NOT LLVM_PROFGEN)
+message(STATUS "To enable converting CSSPGO samples LLVM_PROFGEN has 
to point to llvm-profgen")
+  endif()
+
+  # Convert perf profiles into profraw
+  add_custom_command(
+OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clang.profdata
+COMMAND "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/perf-helper.py perf2prof ${LLVM_PROFGEN} 
$ ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}/profiles/
+COMMENT "Converting perf profiles into profraw"
+APPEND
+  )
+endif()
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clang.p

[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)

2024-09-18 Thread Florian Mayer via cfe-commits


@@ -84,6 +84,14 @@ void test_macro_expansion4() {
 #undef MY_NULL
 }
 
+template  struct pear {
+  T x;
+};
+void test_templated() {
+  pear p = { NULL };

fmayer wrote:

Doesn't this need some `CHECK` or `CHECK-NOT`?

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Remove feature sha1 from FMV. (PR #108383)

2024-09-18 Thread Andrew Carlotti via cfe-commits


@@ -33,7 +33,6 @@ enum CPUFeatures {
   FEAT_FP,
   FEAT_SIMD,
   FEAT_CRC,
-  FEAT_SHA1,

andrewcarlotti wrote:

> And the clang and gcc implementations of FMV are already ABI incompatible for 
> other reasons.
Are they? I'm not currently aware of any incompatibilities.

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


[clang-tools-extra] [clang-tidy][readability-container-contains] Use hasOperands when possible (PR #109178)

2024-09-18 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank created 
https://github.com/llvm/llvm-project/pull/109178


Simplifies two cases and matches two new cases previously missing, 
`container.end() [!=]= container.find(...)`.

I had split this change from #107521 for easier review.


>From a8b8ce089e9eeadf1b8b424e426f7372d0a97662 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 18 Sep 2024 14:59:51 -0400
Subject: [PATCH] [clang-tidy][readability-container-contains] Use hasOperands
 when possible

Simplifies two cases and matches two new cases previously missing, 
`container.end() [!=]= container.find(...)`.

I had split this change from #107521 for easier review.
---
 .../readability/ContainerContainsCheck.cpp| 14 +++---
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++-
 .../readability/container-contains.cpp| 27 +++
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index 698231d777d2d4..05d4c87bc73cef 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -62,10 +62,7 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
  .bind("positiveComparison"),
  this);
   AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), hasOperatorName("!="), 
hasRHS(Literal0))
-  .bind("positiveComparison"));
-  AddSimpleMatcher(
-  binaryOperator(hasLHS(Literal0), hasOperatorName("!="), 
hasRHS(CountCall))
+  binaryOperator(hasOperatorName("!="), hasOperands(CountCall, Literal0))
   .bind("positiveComparison"));
   AddSimpleMatcher(
   binaryOperator(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
@@ -82,10 +79,7 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Find inverted membership tests which use `count()`.
   AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), hasOperatorName("=="), 
hasRHS(Literal0))
-  .bind("negativeComparison"));
-  AddSimpleMatcher(
-  binaryOperator(hasLHS(Literal0), hasOperatorName("=="), 
hasRHS(CountCall))
+  binaryOperator(hasOperatorName("=="), hasOperands(CountCall, Literal0))
   .bind("negativeComparison"));
   AddSimpleMatcher(
   binaryOperator(hasLHS(CountCall), hasOperatorName("<="), 
hasRHS(Literal0))
@@ -102,10 +96,10 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Find membership tests based on `find() == end()`.
   AddSimpleMatcher(
-  binaryOperator(hasLHS(FindCall), hasOperatorName("!="), hasRHS(EndCall))
+  binaryOperator(hasOperatorName("!="), hasOperands(FindCall, EndCall))
   .bind("positiveComparison"));
   AddSimpleMatcher(
-  binaryOperator(hasLHS(FindCall), hasOperatorName("=="), hasRHS(EndCall))
+  binaryOperator(hasOperatorName("=="), hasOperands(FindCall, EndCall))
   .bind("negativeComparison"));
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 82a761bd7f40ab..c125223adcdf64 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,7 +167,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-container-contains
   ` check to let it work on
-  any class that has a ``contains`` method.
+  any class that has a ``contains`` method. Also now match previously missing
+  cases with uncommon operand ordering.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
index 906515b075d4de..9a9b233e07229b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -426,3 +426,30 @@ void testBox() {
   // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
   // CHECK-FIXES: if (Set.contains(0)) {};
 }
+
+void testOperandPermutations(std::map& Map) {
+  if (Map.count(0) != 0) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (Map.contains(0)) {};
+  if (0 != Map.count(0)) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (Map.contains(0)) {};
+  if (Map.count(0) == 0) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (!Map.contains(0)) {};
+  if (0 == Map.count(0)) {};
+  //

[clang-tools-extra] [clang-tidy][readability-container-contains] Use hasOperands when possible (PR #109178)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




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

Author: Nicolas van Kempen (nicovank)


Changes


Simplifies two cases and matches two new cases previously missing, 
`container.end() [!=]= container.find(...)`.

I had split this change from #107521 for easier review.


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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp (+4-10) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
(+27) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index 698231d777d2d4..05d4c87bc73cef 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -62,10 +62,7 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
  .bind("positiveComparison"),
  this);
   AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), hasOperatorName("!="), 
hasRHS(Literal0))
-  .bind("positiveComparison"));
-  AddSimpleMatcher(
-  binaryOperator(hasLHS(Literal0), hasOperatorName("!="), 
hasRHS(CountCall))
+  binaryOperator(hasOperatorName("!="), hasOperands(CountCall, Literal0))
   .bind("positiveComparison"));
   AddSimpleMatcher(
   binaryOperator(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
@@ -82,10 +79,7 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Find inverted membership tests which use `count()`.
   AddSimpleMatcher(
-  binaryOperator(hasLHS(CountCall), hasOperatorName("=="), 
hasRHS(Literal0))
-  .bind("negativeComparison"));
-  AddSimpleMatcher(
-  binaryOperator(hasLHS(Literal0), hasOperatorName("=="), 
hasRHS(CountCall))
+  binaryOperator(hasOperatorName("=="), hasOperands(CountCall, Literal0))
   .bind("negativeComparison"));
   AddSimpleMatcher(
   binaryOperator(hasLHS(CountCall), hasOperatorName("<="), 
hasRHS(Literal0))
@@ -102,10 +96,10 @@ void ContainerContainsCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Find membership tests based on `find() == end()`.
   AddSimpleMatcher(
-  binaryOperator(hasLHS(FindCall), hasOperatorName("!="), hasRHS(EndCall))
+  binaryOperator(hasOperatorName("!="), hasOperands(FindCall, EndCall))
   .bind("positiveComparison"));
   AddSimpleMatcher(
-  binaryOperator(hasLHS(FindCall), hasOperatorName("=="), hasRHS(EndCall))
+  binaryOperator(hasOperatorName("=="), hasOperands(FindCall, EndCall))
   .bind("negativeComparison"));
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 82a761bd7f40ab..c125223adcdf64 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,7 +167,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-container-contains
   ` check to let it work on
-  any class that has a ``contains`` method.
+  any class that has a ``contains`` method. Also now match previously missing
+  cases with uncommon operand ordering.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
index 906515b075d4de..9a9b233e07229b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -426,3 +426,30 @@ void testBox() {
   // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
   // CHECK-FIXES: if (Set.contains(0)) {};
 }
+
+void testOperandPermutations(std::map& Map) {
+  if (Map.count(0) != 0) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (Map.contains(0)) {};
+  if (0 != Map.count(0)) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (Map.contains(0)) {};
+  if (Map.count(0) == 0) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (!Map.contains(0)) {};
+  if (0 == Map.count(0)) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'contains' to check 
for membership [readability-container-contains]
+  // CHECK-FIXES: if (!Map.contains(0)) {};
+  if (Map.find(0) != Map.end()) {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use 'c

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits

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


[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)

2024-09-18 Thread Alex Voicu via cfe-commits


@@ -766,8 +766,19 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*Expr, Address Dest,
   // LLVM atomic instructions always have synch scope. If clang atomic
   // expression has no scope operand, use default LLVM synch scope.
   if (!ScopeModel) {
+llvm::SyncScope::ID SS;
+if (CGF.getLangOpts().OpenCL)
+  // OpenCL approach is: "The functions that do not have memory_scope
+  // argument have the same semantics as the corresponding functions with
+  // the memory_scope argument set to memory_scope_device." See ref.:
+  // 
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#atomic-functions
+  SS = CGF.getTargetHooks().getLLVMSyncScopeID(CGF.getLangOpts(),
+   SyncScope::OpenCLDevice,
+   Order, 
CGF.getLLVMContext());
+else
+  SS = CGF.getLLVMContext().getOrInsertSyncScopeID("");

AlexVlx wrote:

Done.

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

It's one thing that we might tweak the rules to account for redundant 
parenthesis.
But the more complete example shows there is no way to order these unrelated 
things.

Note that we hadn't so far implemented these rules for partial ordering of 
function templates, but the same issue should already exist for all 
implementations when you convert this example to class templates partial 
specializations, so the approach Eigen is taking here is not standing on solid 
ground.

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits


@@ -69,29 +69,25 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, 
StringRef FS) {
 CPU = "v3";
   if (CPU == "probe")
 CPU = sys::detail::getHostCPUNameForBPF();
-  if (CPU == "generic" || CPU == "v1")
+  if (CPU.empty() || CPU == "generic" || CPU == "v1")

eddyz87 wrote:

Nitpick: `CPU` can't be empty at this point.

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits


@@ -621,6 +642,16 @@ let Predicates = [BPFHasLdsx] in {
 
 def LDD : LOADi64;
 
+class acquiring_load
+: PatFrag<(ops node:$ptr), (base node:$ptr)> {
+  let IsAtomic = 1;

eddyz87 wrote:

Note: in #107343 we decided to fallback to more strong orderings if there is no 
direct instruction available. However, for this pull request I get:

```
$ cat test4.c 
char load_acquire_i8(char *p) { return __atomic_load_n(p, __ATOMIC_RELAXED); }

$ clang -O2 -mcpu=v5 --target=bpf test4.c -c -o - | llvm-objdump -d -
fatal error: error in backend: Cannot select: t8: i32,ch = AtomicLoad<(load 
monotonic (s8) from %ir.p), zext from i8> t0, t2
  t2: i64,ch = CopyFromReg t0, Register:i64 %0
t1: i64 = Register %0
In function: load_acquire_i8
...
```

While `consume` appears to work:

```
$ cat test4.c 
char load_acquire_i8(char *p) { return __atomic_load_n(p, __ATOMIC_CONSUME); }

$ clang -O2 -mcpu=v5 --target=bpf test4.c -c -o - | llvm-objdump -d -

:file format elf64-bpf

Disassembly of section .text:

 :
   0:   f1 10 00 00 00 00 00 00 w0 = load_acquire((u8 *)(r1 + 0x0))
   1:   95 00 00 00 00 00 00 00 exit
```

(Although, in the light of #107343 I think this should be a `lock ...` 
instruction).

Also, the error message for `SEQ_CST` should be more user friendly, at the 
moment it is:

```
$ cat test4.c 
char load_acquire_i8(char *p) { return __atomic_load_n(p, __ATOMIC_SEQ_CST); }

$ clang -O2 -mcpu=v5 --target=bpf test4.c -c -o - | llvm-objdump -d -
fatal error: error in backend: Cannot select: t8: i32,ch = AtomicLoad<(load 
seq_cst (s8) from %ir.p), zext from i8> t0, t2
  t2: i64,ch = CopyFromReg t0, Register:i64 %0
t1: i64 = Register %0
In function: load_acquire_i8
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
...
```

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-18 Thread via cfe-commits

https://github.com/eddyz87 commented:

I think this looks fine, but syntax seems like it adds to zoo we already have.
E.g. there are already instructions like `lock *(u32 *)(r1 + 0x0) &= w2` and we 
treat these as having `monotonic` / `memory_order_relaxed` semantics (see 
#107343).
It seems, to me at-least, that it is more logical to build on top of already 
existing syntax, e.g.:

lock *(u64 *)(r1 + 0x0) = r2 release
lock r2 = *(u64 *)(r1 + 0x0) acquire

Also a question regarding 3 commits in one pull request.
As far as I understand [current](https://llvm.org/docs/GitHub.html) policy, the 
idea is to have a separate pull request for each commit (and fork branches from 
one another to build a stack). Otherwise the commits are squashed. What's the 
idea with current pull request?

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Remove feature sha1 from FMV. (PR #108383)

2024-09-18 Thread Eli Friedman via cfe-commits


@@ -33,7 +33,6 @@ enum CPUFeatures {
   FEAT_FP,
   FEAT_SIMD,
   FEAT_CRC,
-  FEAT_SHA1,

efriedma-quic wrote:

We've generally been more conservative with compiler-rt.builtins compared with 
other parts of compiler-rt, like  sanitizers.  People do ship static libraries 
to other people, and we don't want them to silently break.

Even if you still consider the ABI "beta", it's not clear to me how we expect 
users to know; is the "beta" status mentioned anywhere in LLVM/clang 
documentation?

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

Wow, I would never have thought it was a problem. Making these the same type 
removes the compilation error. Can you explain why this is a problem from the 
C++ standard PoV?

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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-09-18 Thread via cfe-commits

goldsteinn wrote:

ping5

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


[clang] [llvm] [AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (PR #94647)

2024-09-18 Thread Jun Wang via cfe-commits


@@ -434,6 +434,15 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
   indicatePessimisticFixpoint();
   return;
 }
+
+for (Instruction &I : instructions(F)) {
+  if (isa(I) &&

jwanggit86 wrote:

@arsenm Following constants to see if they contain addrSpaceCast is now done. 
An example is: `store i32 7, ptr addrspace(3) addrspacecast (ptr addrspace(5) 
null to ptr addrspace(3))`. 
However, I'm not sure it's required or even correct. For the above example, opt 
with -O2 would optimize away the addrspacecast, and the result would be the 
opposite.

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Richard Smith via cfe-commits

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


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-x86_64-debian-fast` 
running on `gribozavr4` while building `clang` at step 4 "cmake-configure".

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


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

```
Step 4 (cmake-configure) failure: cmake (failure)
...
-- Failed to find LLVM FileCheck
-- Google Benchmark version: v0.0.0, normalized to 0.0.0
-- Looking for shm_open in rt
-- Looking for shm_open in rt - found
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST - Success
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Enabling additional flags: 
-DINCLUDE_DIRECTORIES=/b/1/clang-x86_64-debian-fast/llvm.src/third-party/benchmark/include
-- Compiling and running to test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- success
-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Compiling and running to test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Compiling and running to test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Compiling and running to test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring incomplete, errors occurred!
See also "/b/1/clang-x86_64-debian-fast/llvm.obj/CMakeFiles/CMakeOutput.log".
See also "/b/1/clang-x86_64-debian-fast/llvm.obj/CMakeFiles/CMakeError.log".

```



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


[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-18 Thread Eli Friedman via cfe-commits


@@ -870,6 +904,15 @@ bool ConstStructBuilder::Build(const APValue &Val, const 
RecordDecl *RD,
 if (!EltInit)
   return false;
 
+if (ZeroInitPadding) {
+  if (!DoZeroInitPadding(Layout, FieldNo, *Field, SizeSoFar,
+ IsFlexibleArray, AllowOverwrite))
+return false;
+  if (IsFlexibleArray)

efriedma-quic wrote:

I think I've figured out the way IsFlexibleArray works, but it's sort of 
awkward.  Do you really need to use a different codepath for flexible-array 
fields, vs. ordinary fields?  It seems like it would be simpler to just use 
getTypeAllocSize() in both cases.  And the name "IsFlexibleArray" is a bit 
confusing because isn't really reliably detecting flexible arrays; there are 
other zero-size fields.

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


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` 
running on `gribozavr4` while building `clang` at step 4 "cmake-configure".

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


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

```
Step 4 (cmake-configure) failure: cmake (failure)
...
-- Failed to find LLVM FileCheck
-- Google Benchmark version: v0.0.0, normalized to 0.0.0
-- Looking for shm_open in rt
-- Looking for shm_open in rt - found
-- Performing Test HAVE_CXX_FLAG_WALL
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST
-- Performing Test HAVE_CXX_FLAG_WOLD_STYLE_CAST - Success
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_FLAG_WSUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_CXX_FLAG_WNO_DEPRECATED_DECLARATIONS - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Enabling additional flags: 
-DINCLUDE_DIRECTORIES=/b/1/llvm-x86_64-debian-dylib/llvm-project/third-party/benchmark/include
-- Compiling and running to test HAVE_THREAD_SAFETY_ATTRIBUTES
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- success
-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Compiling and running to test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Compiling and running to test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Compiling and running to test HAVE_STEADY_CLOCK
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring incomplete, errors occurred!
See also "/b/1/llvm-x86_64-debian-dylib/build/CMakeFiles/CMakeOutput.log".
See also "/b/1/llvm-x86_64-debian-dylib/build/CMakeFiles/CMakeError.log".

```



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


[clang] Revert update-verify-tests.py (PR #109171)

2024-09-18 Thread Henrik G. Olsson via cfe-commits

https://github.com/hnrklssn created 
https://github.com/llvm/llvm-project/pull/109171

This reverts commits c96ee0ffaf5ee7afa1f4b0be0662852f57b47244 and 
9ceb9676678ad979a0b767450855d7852ce6a553.

Discussion in github PR #108658.

>From 0c8a40ed24b0b5f319fd2fb49a27703dc7f1 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" 
Date: Wed, 18 Sep 2024 10:23:53 -0700
Subject: [PATCH] Revert update-verify-tests.py

This reverts commits c96ee0ffaf5ee7afa1f4b0be0662852f57b47244
and 9ceb9676678ad979a0b767450855d7852ce6a553.

Discussion in github PR #108658.
---
 .../Inputs/duplicate-diag.c   |   8 -
 .../Inputs/duplicate-diag.c.expected  |   8 -
 .../Inputs/infer-indentation.c|   8 -
 .../Inputs/infer-indentation.c.expected   |  11 -
 .../Inputs/leave-existing-diags.c |  11 -
 .../Inputs/leave-existing-diags.c.expected|  12 -
 .../Inputs/multiple-errors.c  |   6 -
 .../Inputs/multiple-errors.c.expected |   9 -
 .../multiple-missing-errors-same-line.c   |   8 -
 ...ltiple-missing-errors-same-line.c.expected |  13 -
 .../update-verify-tests/Inputs/no-checks.c|   3 -
 .../Inputs/no-checks.c.expected   |   4 -
 .../update-verify-tests/Inputs/no-diags.c |   5 -
 .../Inputs/no-diags.c.expected|   5 -
 .../Inputs/no-expected-diags.c|   4 -
 .../Inputs/no-expected-diags.c.expected   |   4 -
 .../Inputs/non-default-prefix.c   |   5 -
 .../Inputs/non-default-prefix.c.expected  |   5 -
 .../Inputs/update-same-line.c |   4 -
 .../Inputs/update-same-line.c.expected|   4 -
 .../Inputs/update-single-check.c  |   4 -
 .../Inputs/update-single-check.c.expected |   4 -
 .../update-verify-tests/duplicate-diag.test   |   4 -
 .../infer-indentation.test|   3 -
 .../leave-existing-diags.test |   4 -
 .../utils/update-verify-tests/lit.local.cfg   |  28 --
 .../update-verify-tests/multiple-errors.test  |   3 -
 .../multiple-missing-errors-same-line.test|   3 -
 .../utils/update-verify-tests/no-checks.test  |   3 -
 .../utils/update-verify-tests/no-diags.test   |   4 -
 .../no-expected-diags.test|   4 -
 .../non-default-prefix.test   |   4 -
 .../update-verify-tests/update-same-line.test |   4 -
 .../update-single-check.test  |   3 -
 clang/utils/UpdateVerifyTests/core.py | 452 --
 clang/utils/update-verify-tests.py|  38 --
 36 files changed, 702 deletions(-)
 delete mode 100644 clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c.expected
 delete mode 100644 clang/test/utils/update-verify-tests/Inputs/no-checks.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/no-checks.c.expected
 delete mode 100644 clang/test/utils/update-verify-tests/Inputs/no-diags.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/no-diags.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/update-same-line.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/update-same-line.c.expected
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/update-single-check.c
 delete mode 100644 
clang/test/utils/update-verify-tests/Inputs/update-single-check.c.expected
 delete mode 100644 clang/test/utils/update-verify-tests/duplicate-diag.test
 delete mode 100644 clang/test/utils/update-verify-tests/infer-indentation.test
 delete mode 100644 
clang/test/utils/update-verify-tests/leave-existing-diags.test
 delete mode 100644 clang/test/utils/update-verify-tests/lit.local.cfg
 delete mode 100644 clang/test/utils/update-verify-tests/multiple-errors.test
 delete mode 100644 
clang/test/utils/update-ver

[clang] Revert update-verify-tests.py (PR #109171)

2024-09-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Henrik G. Olsson (hnrklssn)


Changes

This reverts commits c96ee0ffaf5ee7afa1f4b0be0662852f57b47244 and 
9ceb9676678ad979a0b767450855d7852ce6a553.

Discussion in github PR #108658.

---

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


36 Files Affected:

- (removed) clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c (-8) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected (-8) 
- (removed) clang/test/utils/update-verify-tests/Inputs/infer-indentation.c 
(-8) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected (-11) 
- (removed) clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c 
(-11) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c.expected 
(-12) 
- (removed) clang/test/utils/update-verify-tests/Inputs/multiple-errors.c (-6) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c.expected (-9) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c 
(-8) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c.expected
 (-13) 
- (removed) clang/test/utils/update-verify-tests/Inputs/no-checks.c (-3) 
- (removed) clang/test/utils/update-verify-tests/Inputs/no-checks.c.expected 
(-4) 
- (removed) clang/test/utils/update-verify-tests/Inputs/no-diags.c (-5) 
- (removed) clang/test/utils/update-verify-tests/Inputs/no-diags.c.expected 
(-5) 
- (removed) clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c 
(-4) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c.expected (-4) 
- (removed) clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c 
(-5) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c.expected (-5) 
- (removed) clang/test/utils/update-verify-tests/Inputs/update-same-line.c (-4) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/update-same-line.c.expected (-4) 
- (removed) clang/test/utils/update-verify-tests/Inputs/update-single-check.c 
(-4) 
- (removed) 
clang/test/utils/update-verify-tests/Inputs/update-single-check.c.expected (-4) 
- (removed) clang/test/utils/update-verify-tests/duplicate-diag.test (-4) 
- (removed) clang/test/utils/update-verify-tests/infer-indentation.test (-3) 
- (removed) clang/test/utils/update-verify-tests/leave-existing-diags.test (-4) 
- (removed) clang/test/utils/update-verify-tests/lit.local.cfg (-28) 
- (removed) clang/test/utils/update-verify-tests/multiple-errors.test (-3) 
- (removed) 
clang/test/utils/update-verify-tests/multiple-missing-errors-same-line.test 
(-3) 
- (removed) clang/test/utils/update-verify-tests/no-checks.test (-3) 
- (removed) clang/test/utils/update-verify-tests/no-diags.test (-4) 
- (removed) clang/test/utils/update-verify-tests/no-expected-diags.test (-4) 
- (removed) clang/test/utils/update-verify-tests/non-default-prefix.test (-4) 
- (removed) clang/test/utils/update-verify-tests/update-same-line.test (-4) 
- (removed) clang/test/utils/update-verify-tests/update-single-check.test (-3) 
- (removed) clang/utils/UpdateVerifyTests/core.py (-452) 
- (removed) clang/utils/update-verify-tests.py (-38) 


``diff
diff --git a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
deleted file mode 100644
index 8c7e46c6eca9c1..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-b = 2; b = 2;
-// expected-error@+1 3{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-// expected-error 2{{asdf}}
-}
diff --git 
a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
deleted file mode 100644
index 6214ff382f4495..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1 2{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-// expected-error@+1 2{{use of undeclared identifier 'b'}}
-b = 2; b = 2;
-// expected-error@+1 2{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-}
diff --git a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c 
b/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
deleted file mode 100644
index 0210ac35fd5cd1..00
--- a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
- // expected-error@+12  {{use of undeclared identifier 
'a'}}
-a = 2; a = 2; b = 2; b = 2; c = 2;
- // expected-error@+12  {{asdf}}
-d = 2;
-

[clang] [clang-tools-extra] [clang-tidy] Fix performance-unnecessary-value-param (PR #109145)

2024-09-18 Thread Kazu Hirata via cfe-commits




kazutakahirata wrote:

I cannot immediately think of common ways in which an iterator stays valid, but 
if you don't enable assertions or `LLVM_ENABLE_ABI_BREAKING_CHECKS`, you may be 
able to avoid a crash although that doesn't necessarily mean that clang-tidy is 
working correctly.

If you would like a more reliable way to detect potential iterator 
invalidation, you could check the size of the data structure before and after 
calling `new FunctionParmMutationAnalyzer(...)`:

```
auto OldSize = Memorized.FuncParmAnalyzer.size();
NewValue = std::unique_ptr(
  new FunctionParmMutationAnalyzer(Func, Context, Memorized));
auto NewSize = Memorized.FuncParmAnalyzer.size();
assert(OldSize == NewSize);
it->second = NewValue;
```


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


[clang-tools-extra] Add clang-tidy external examples (PR #106675)

2024-09-18 Thread via cfe-commits

https://github.com/MichelleCDjunaidi updated 
https://github.com/llvm/llvm-project/pull/106675

>From 08324e3586acb16cbf010fd6013c21f2b5faa64e Mon Sep 17 00:00:00 2001
From: MichelleCDjunaidi <87893361+michellecdjuna...@users.noreply.github.com>
Date: Fri, 30 Aug 2024 14:55:16 +0800
Subject: [PATCH 1/8] Add clang-tidy external examples

---
 .../clang-tidy/ExternalClang-TidyExamples.rst | 31 +++
 1 file changed, 31 insertions(+)
 create mode 100644 
clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst

diff --git a/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst 
b/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst
new file mode 100644
index 00..735f99b30c7b7d
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst
@@ -0,0 +1,31 @@
+===
+External Clang-Tidy Examples
+===
+
+Introduction
+
+
+This page provides examples of what people have done with clang-tidy that 
+might serve as useful guides (or starting points) to develop your own checks. 
+They may be helpful even for necessary things such as how to write 
CMakeLists.txt 
+for an out-of-tree plugin of clang-tidy checks.
+
+If you know of (or wrote!) a tool or project using clang-tidy, please post on
+`the Discourse forums (Clang Frontend category)
+`_ to have it added.
+(or if you are already a clang-tidy contributor, feel free to directly commit
+additions). Since the primary purpose of this page is to provide examples
+that can help developers, generally they must have code available.
+
+As clang-tidy shares C++ AST Matchers with Clang diagnostics, `External Clang 
Examples`_ 
+may also be useful to look at.
+
+.. _External Clang Examples: 
https://clang.llvm.org/docs/ExternalClangExamples.html
+
+https://clang.llvm.org/docs/ExternalClangExamples.html
+
+List of projects and tools
+==
+
+``_
+"This folder contains clang-tidy plugins."
\ No newline at end of file

>From b47792347dd6ebab3ac49bc55b0c812db0ee5ba3 Mon Sep 17 00:00:00 2001
From: MichelleCDjunaidi <87893361+michellecdjuna...@users.noreply.github.com>
Date: Fri, 30 Aug 2024 21:22:55 +0800
Subject: [PATCH 2/8] update wording to invite PR

---
 .../clang-tidy/ExternalClang-TidyExamples.rst | 23 ++-
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst 
b/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst
index 735f99b30c7b7d..2355b6f119b760 100644
--- a/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst
+++ b/clang-tools-extra/docs/clang-tidy/ExternalClang-TidyExamples.rst
@@ -5,21 +5,22 @@ External Clang-Tidy Examples
 Introduction
 
 
-This page provides examples of what people have done with clang-tidy that 
+This page provides examples of what people have done with `clang-tidy`` that 
 might serve as useful guides (or starting points) to develop your own checks. 
-They may be helpful even for necessary things such as how to write 
CMakeLists.txt 
-for an out-of-tree plugin of clang-tidy checks.
+They may be helpful for necessary things such as how to write CMakeLists.txt 
+for an out-of-tree plugin of `clang-tidy` checks.
 
-If you know of (or wrote!) a tool or project using clang-tidy, please post on
-`the Discourse forums (Clang Frontend category)
-`_ to have it added.
-(or if you are already a clang-tidy contributor, feel free to directly commit
-additions). Since the primary purpose of this page is to provide examples
-that can help developers, generally they must have code available.
+If you know of (or wrote!) a tool or project using clang-tidy, please share it 
+on `the Discourse forums (Clang Frontend category)
+`_ for wider visibility and open a 
+pull-request on `LLVM Github`_ to have it added here. Since the primary 
purpose of 
+this page is to provide examples that can help developers, generally they must 
have 
+code available.
 
-As clang-tidy shares C++ AST Matchers with Clang diagnostics, `External Clang 
Examples`_ 
-may also be useful to look at.
+As `clang-tidy` shares C++ AST Matchers with Clang diagnostics, `External 
Clang Examples`_ 
+may also be useful to look at for examples.
 
+.. _LLVM Github: https://github.com/llvm/llvm-project
 .. _External Clang Examples: 
https://clang.llvm.org/docs/ExternalClangExamples.html
 
 https://clang.llvm.org/docs/ExternalClangExamples.html

>From dab57a6a65b9fcc4fd24d7fd0838f428ad675cd5 Mon Sep 17 00:00:00 2001
From: MichelleCDjunaidi <87893361+michellecdjuna...@users.noreply.github.com>
Date: Fri, 30 Aug 2024 21:38:24 +0800
Subject: [PATCH 3/8] cleanup formatting and wording

---
 .../docs/clang-tidy/ExternalClang-TidyExamples.rst  | 6 +

[clang-tools-extra] Add clang-tidy external examples (PR #106675)

2024-09-18 Thread via cfe-commits

MichelleCDjunaidi wrote:

I will need help to merge this once approved. Thank you so much!

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


[clang] 13502c7 - Revert update-verify-tests.py (#109171)

2024-09-18 Thread via cfe-commits

Author: Henrik G. Olsson
Date: 2024-09-18T10:51:53-07:00
New Revision: 13502c7f2c053b2a060f7b9926328cfda46404de

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

LOG: Revert update-verify-tests.py (#109171)

This reverts commits c96ee0ffaf5ee7afa1f4b0be0662852f57b47244 and
9ceb9676678ad979a0b767450855d7852ce6a553.

Discussion in github PR #108658.

Added: 


Modified: 


Removed: 
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c.expected

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c.expected
clang/test/utils/update-verify-tests/Inputs/no-checks.c
clang/test/utils/update-verify-tests/Inputs/no-checks.c.expected
clang/test/utils/update-verify-tests/Inputs/no-diags.c
clang/test/utils/update-verify-tests/Inputs/no-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c.expected
clang/test/utils/update-verify-tests/Inputs/update-same-line.c
clang/test/utils/update-verify-tests/Inputs/update-same-line.c.expected
clang/test/utils/update-verify-tests/Inputs/update-single-check.c
clang/test/utils/update-verify-tests/Inputs/update-single-check.c.expected
clang/test/utils/update-verify-tests/duplicate-diag.test
clang/test/utils/update-verify-tests/infer-indentation.test
clang/test/utils/update-verify-tests/leave-existing-diags.test
clang/test/utils/update-verify-tests/lit.local.cfg
clang/test/utils/update-verify-tests/multiple-errors.test
clang/test/utils/update-verify-tests/multiple-missing-errors-same-line.test
clang/test/utils/update-verify-tests/no-checks.test
clang/test/utils/update-verify-tests/no-diags.test
clang/test/utils/update-verify-tests/no-expected-diags.test
clang/test/utils/update-verify-tests/non-default-prefix.test
clang/test/utils/update-verify-tests/update-same-line.test
clang/test/utils/update-verify-tests/update-single-check.test
clang/utils/UpdateVerifyTests/core.py
clang/utils/update-verify-tests.py



diff  --git a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
deleted file mode 100644
index 8c7e46c6eca9c1..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-b = 2; b = 2;
-// expected-error@+1 3{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-// expected-error 2{{asdf}}
-}

diff  --git 
a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
deleted file mode 100644
index 6214ff382f4495..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1 2{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-// expected-error@+1 2{{use of undeclared identifier 'b'}}
-b = 2; b = 2;
-// expected-error@+1 2{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-}

diff  --git a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c 
b/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
deleted file mode 100644
index 0210ac35fd5cd1..00
--- a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
- // expected-error@+12  {{use of undeclared identifier 
'a'}}
-a = 2; a = 2; b = 2; b = 2; c = 2;
- // expected-error@+12  {{asdf}}
-d = 2;
-e = 2; f = 2; // expected-error2  {{use of 
undeclared identifier 'e'}}
-}
-

diff  --git 
a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected 
b/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected
deleted file mode 100644
index 5c5aaeee

[clang] f212826 - [HLSL][NFC] Remove RegisterBindingFlags struct (#108924)

2024-09-18 Thread via cfe-commits

Author: Helena Kotas
Date: 2024-09-18T10:51:30-07:00
New Revision: f2128267c26e548bef59209e7a351ff94d343bf3

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

LOG: [HLSL][NFC] Remove RegisterBindingFlags struct (#108924)

When diagnosing register bindings we just need to make sure there is a
resource that matches the provided register type. We can emit the
diagnostics right away instead of collecting flags in the
RegisterBindingFlags struct. That also enables early exit when scanning
user defined types because we can return as soon as we find a matching
resource for the given register type.

Added: 


Modified: 
clang/lib/Sema/SemaHLSL.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index a303f211501348..03b7c2edb605fe 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -40,6 +40,48 @@
 #include 
 
 using namespace clang;
+using llvm::dxil::ResourceClass;
+
+enum class RegisterType { SRV, UAV, CBuffer, Sampler, C, I, Invalid };
+
+static RegisterType getRegisterType(ResourceClass RC) {
+  switch (RC) {
+  case ResourceClass::SRV:
+return RegisterType::SRV;
+  case ResourceClass::UAV:
+return RegisterType::UAV;
+  case ResourceClass::CBuffer:
+return RegisterType::CBuffer;
+  case ResourceClass::Sampler:
+return RegisterType::Sampler;
+  }
+  llvm_unreachable("unexpected ResourceClass value");
+}
+
+static RegisterType getRegisterType(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+  case 'T':
+return RegisterType::SRV;
+  case 'u':
+  case 'U':
+return RegisterType::UAV;
+  case 'b':
+  case 'B':
+return RegisterType::CBuffer;
+  case 's':
+  case 'S':
+return RegisterType::Sampler;
+  case 'c':
+  case 'C':
+return RegisterType::C;
+  case 'i':
+  case 'I':
+return RegisterType::I;
+  default:
+return RegisterType::Invalid;
+  }
+}
 
 SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S) {}
 
@@ -586,8 +628,7 @@ bool clang::CreateHLSLAttributedResourceType(
 LocEnd = A->getRange().getEnd();
 switch (A->getKind()) {
 case attr::HLSLResourceClass: {
-  llvm::dxil::ResourceClass RC =
-  cast(A)->getResourceClass();
+  ResourceClass RC = cast(A)->getResourceClass();
   if (HasResourceClass) {
 S.Diag(A->getLocation(), ResAttrs.ResourceClass == RC
  ? diag::warn_duplicate_attribute_exact
@@ -672,7 +713,7 @@ bool SemaHLSL::handleResourceTypeAttr(const ParsedAttr &AL) 
{
 SourceLocation ArgLoc = Loc->Loc;
 
 // Validate resource class value
-llvm::dxil::ResourceClass RC;
+ResourceClass RC;
 if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
   Diag(ArgLoc, diag::warn_attribute_type_not_supported)
   << "ResourceClass" << Identifier;
@@ -750,28 +791,6 @@ SemaHLSL::TakeLocForHLSLAttribute(const 
HLSLAttributedResourceType *RT) {
   return LocInfo;
 }
 
-struct RegisterBindingFlags {
-  bool Resource = false;
-  bool UDT = false;
-  bool Other = false;
-  bool Basic = false;
-
-  bool SRV = false;
-  bool UAV = false;
-  bool CBV = false;
-  bool Sampler = false;
-
-  bool ContainsNumeric = false;
-  bool DefaultGlobals = false;
-
-  // used only when Resource == true
-  std::optional ResourceClass;
-};
-
-static bool isDeclaredWithinCOrTBuffer(const Decl *TheDecl) {
-  return TheDecl && isa(TheDecl->getDeclContext());
-}
-
 // get the record decl from a var decl that we expect
 // represents a resource
 static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
@@ -786,24 +805,6 @@ static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl 
*VD) {
   return TheRecordDecl;
 }
 
-static void updateResourceClassFlagsFromDeclResourceClass(
-RegisterBindingFlags &Flags, llvm::hlsl::ResourceClass DeclResourceClass) {
-  switch (DeclResourceClass) {
-  case llvm::hlsl::ResourceClass::SRV:
-Flags.SRV = true;
-break;
-  case llvm::hlsl::ResourceClass::UAV:
-Flags.UAV = true;
-break;
-  case llvm::hlsl::ResourceClass::CBuffer:
-Flags.CBV = true;
-break;
-  case llvm::hlsl::ResourceClass::Sampler:
-Flags.Sampler = true;
-break;
-  }
-}
-
 const HLSLAttributedResourceType *
 findAttributedResourceTypeOnField(VarDecl *VD) {
   assert(VD != nullptr && "expected VarDecl");
@@ -817,8 +818,10 @@ findAttributedResourceTypeOnField(VarDecl *VD) {
   return nullptr;
 }
 
-static void updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
-   const RecordType *RT) {
+// Iterate over RecordType fields and return true if any of them matched the
+// register type
+static bool ContainsResourceForRegisterType(Sema &S, const RecordType *RT,
+Re

[clang] [HLSL][NFC] Remove RegisterBindingFlags struct (PR #108924)

2024-09-18 Thread Helena Kotas via cfe-commits

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


[clang] Revert update-verify-tests.py (PR #109171)

2024-09-18 Thread Henrik G. Olsson via cfe-commits

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


[clang] [clang] Increase VecLib bitfield size to 4 bits in CodeGenOptions.def (PR #108804)

2024-09-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` 
running on `premerge-linux-1` while building `clang` at step 5 
"cmake-configure".

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


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

```
Step 5 (cmake-configure) failure: cmake (failure)
...
-- Performing Test CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG - Success
-- Performing Test CXX_SUPPORTS_NO_CTAD_MAYBE_UNSUPPORTED_FLAG
-- Performing Test CXX_SUPPORTS_NO_CTAD_MAYBE_UNSUPPORTED_FLAG - Success
-- Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS
-- Not copying omp_lib.h, no OpenMP runtime in LLVM_ENABLED_PROJECTS
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Targeting AArch64 in llvm-bolt
-- Targeting X86 in llvm-bolt
-- Targeting RISCV in llvm-bolt
-- Building BOLT runtime libraries for X86
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- ISL version: isl-0.25-193-g8621c60c
-- Registering Polly as a pass plugin (static build: ON)
-- Found Python3: /usr/bin/python3.10 (found version "3.10.12") found 
components: Interpreter 
-- libclc target 'amdgcn--' is enabled
--   device: tahiti ( 
pitcairn;verde;oland;hainan;bonaire;kabini;kaveri;hawaii;mullins;tonga;tongapro;iceland;carrizo;fiji;stoney;polaris10;polaris11;gfx602;gfx705;gfx805;gfx900;gfx902;gfx904;gfx906;gfx908;gfx909;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx1010;gfx1011;gfx1012;gfx1013;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201
 )
-- libclc target 'amdgcn--amdhsa' is enabled
--   device: none (  )
-- libclc target 'amdgcn-mesa-mesa3d' is enabled
--   device: tahiti ( 
pitcairn;verde;oland;hainan;bonaire;kabini;kaveri;hawaii;mullins;tonga;tongapro;iceland;carrizo;fiji;stoney;polaris10;polaris11;gfx602;gfx705;gfx805;gfx900;gfx902;gfx904;gfx906;gfx908;gfx909;gfx90a;gfx90c;gfx940;gfx941;gfx942;gfx1010;gfx1011;gfx1012;gfx1013;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201
 )
-- libclc target 'clspv--' is enabled
--   device: none (  )
-- libclc target 'clspv64--' is enabled
--   device: none (  )
-- libclc target 'nvptx--' is enabled
--   device: none (  )
-- libclc target 'nvptx--nvidiacl' is enabled
--   device: none (  )
-- libclc target 'nvptx64--' is enabled
--   device: none (  )
-- libclc target 'nvptx64--nvidiacl' is enabled
--   device: none (  )
-- libclc target 'r600--' is enabled
--   device: cedar ( palm;sumo;sumo2;redwood;juniper )
--   device: cypress ( hemlock )
--   device: barts ( turks;caicos )
--   device: cayman ( aruba )
-- Registering ExampleIRTransforms as a pass plugin (static build: OFF)
-- Registering Bye as a pass plugin (static build: OFF)
-- Failed to find LLVM FileCheck
-- Google Benchmark version: v0.0.0, normalized to 0.0.0
-- Enabling additional flags: 
-DINCLUDE_DIRECTORIES=/build/buildbot/premerge-monolithic-linux/llvm-project/third-party/benchmark/include
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- success
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- success
-- Configuring incomplete, errors occurred!
See also 
"/build/buildbot/premerge-monolithic-linux/build/CMakeFiles/CMakeOutput.log".
See also 
"/build/buildbot/premerge-monolithic-linux/build/CMakeFiles/CMakeError.log".

```



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


[clang] [clang-tools-extra] [clang-tidy] Fix performance-unnecessary-value-param (PR #109145)

2024-09-18 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata updated 
https://github.com/llvm/llvm-project/pull/109145

>From c230f7e30e60f11c5675ec1dd9f49f5f6378dc6f Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 18 Sep 2024 00:19:25 -0700
Subject: [PATCH 1/2] [clang-tidy] Fix performance-unnecessary-value-param

This patch essentially reverts #108674 while adding a testcase that
triggers a crash in clang-tidy.

Fixes #108963.
---
 .../unnecessary-value-param-crash.cpp | 23 +++
 .../Analysis/Analyses/ExprMutationAnalyzer.h  | 17 ++
 2 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
new file mode 100644
index 00..99c2fe905bdf37
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-crash.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy  -std=c++14-or-later %s 
performance-unnecessary-value-param %t
+
+// The test case used to crash clang-tidy.
+// https://github.com/llvm/llvm-project/issues/108963
+
+struct A
+{
+  template A(T&&) {}
+};
+
+struct B
+{
+  ~B();
+};
+
+struct C
+{
+  A a;
+  C(B, int i) : a(i) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: the parameter #1 is copied for 
each invocation but only used as a const reference; consider making it a const 
reference
+};
+
+C c(B(), 0);
diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index b7b84852168e2e..d7d0d80ee8cd8c 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -118,10 +118,19 @@ class FunctionParmMutationAnalyzer {
   static FunctionParmMutationAnalyzer *
   getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext 
&Context,
   ExprMutationAnalyzer::Memoized &Memorized) {
-auto [it, Inserted] = Memorized.FuncParmAnalyzer.try_emplace(&Func);
-if (Inserted)
-  it->second = std::unique_ptr(
-  new FunctionParmMutationAnalyzer(Func, Context, Memorized));
+auto it = Memorized.FuncParmAnalyzer.find(&Func);
+if (it == Memorized.FuncParmAnalyzer.end())
+  // We call try_emplace here, repeating a hash lookup on the same key. 
Note
+  // that creating a new instance of FunctionParmMutationAnalyzer below may
+  // add additional elements to FuncParmAnalyzer and invalidate iterators.
+  // That means that we cannot call try_emplace above and update the value
+  // portion (i.e. it->second) here.
+  it =
+  Memorized.FuncParmAnalyzer
+  .try_emplace(&Func, 
std::unique_ptr(
+  new FunctionParmMutationAnalyzer(
+  Func, Context, Memorized)))
+  .first;
 return it->getSecond().get();
   }
 

>From ef2522bb8fc645a0db77130a33a0b392cc1fadae Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 18 Sep 2024 10:53:46 -0700
Subject: [PATCH 2/2] Add curly braces.  Adjust comments.

---
 .../clang/Analysis/Analyses/ExprMutationAnalyzer.h   | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index d7d0d80ee8cd8c..c7a5b016c949d0 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -119,18 +119,18 @@ class FunctionParmMutationAnalyzer {
   getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext 
&Context,
   ExprMutationAnalyzer::Memoized &Memorized) {
 auto it = Memorized.FuncParmAnalyzer.find(&Func);
-if (it == Memorized.FuncParmAnalyzer.end())
-  // We call try_emplace here, repeating a hash lookup on the same key. 
Note
-  // that creating a new instance of FunctionParmMutationAnalyzer below may
-  // add additional elements to FuncParmAnalyzer and invalidate iterators.
-  // That means that we cannot call try_emplace above and update the value
-  // portion (i.e. it->second) here.
+if (it == Memorized.FuncParmAnalyzer.end()) {
+  // Creating a new instance of FunctionParmMutationAnalyzer below may add
+  // additional elements to FuncParmAnalyzer. If we did try_emplace before
+  // creating a new instance, the returned iterator of try_emplace could be
+  // invalidated.
   it =
   Memorized.FuncParmAnalyzer
   .try_emplace(&Func, 
std::unique_ptr(
   new FunctionParmMutationAnalyzer(
  

[clang] [clang-tools-extra] [clang-tidy] Fix performance-unnecessary-value-param (PR #109145)

2024-09-18 Thread Kazu Hirata via cfe-commits


@@ -118,10 +118,19 @@ class FunctionParmMutationAnalyzer {
   static FunctionParmMutationAnalyzer *
   getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext 
&Context,
   ExprMutationAnalyzer::Memoized &Memorized) {
-auto [it, Inserted] = Memorized.FuncParmAnalyzer.try_emplace(&Func);
-if (Inserted)
-  it->second = std::unique_ptr(
-  new FunctionParmMutationAnalyzer(Func, Context, Memorized));
+auto it = Memorized.FuncParmAnalyzer.find(&Func);
+if (it == Memorized.FuncParmAnalyzer.end())
+  // We call try_emplace here, repeating a hash lookup on the same key. 
Note
+  // that creating a new instance of FunctionParmMutationAnalyzer below may
+  // add additional elements to FuncParmAnalyzer and invalidate iterators.

kazutakahirata wrote:

Updated the comment accordingly.  Thanks!

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Timm Baeder via cfe-commits


@@ -96,6 +96,8 @@ def note_constexpr_pointer_constant_comparison : Note<
   "at runtime">;
 def note_constexpr_literal_comparison : Note<
   "comparison of addresses of literals has unspecified value">;
+def note_constexpr_opaque_call_comparison : Note<
+  "comparison against opaque constant has unspecified value">;

tbaederr wrote:

I can't imagine a normal person knows what's meant by "opaque constant"

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Timm Baeder via cfe-commits


@@ -2061,15 +2063,21 @@ static bool EvaluateIgnoredValue(EvalInfo &Info, const 
Expr *E) {
   return true;
 }
 
-/// Should this call expression be treated as a no-op?
-static bool IsNoOpCall(const CallExpr *E) {
+/// Should this call expression be treated as forming an opaque constant?
+static bool IsOpaqueConstantCall(const CallExpr *E) {
   unsigned Builtin = E->getBuiltinCallee();
   return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
   Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
   Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
   Builtin == Builtin::BI__builtin_function_start);
 }
 
+static bool IsOpaqueConstantCall(const LValue &LVal) {
+  auto *BaseExpr =
+  llvm::dyn_cast_or_null(LVal.Base.dyn_cast());

tbaederr wrote:

```suggestion
  const auto *BaseExpr =
  llvm::dyn_cast_if_present(LVal.Base.dyn_cast());
```

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


[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

2024-09-18 Thread Timm Baeder via cfe-commits


@@ -2142,11 +2150,81 @@ static const ValueDecl *GetLValueBaseDecl(const LValue 
&LVal) {
   return LVal.Base.dyn_cast();
 }
 
-static bool IsLiteralLValue(const LValue &Value) {
-  if (Value.getLValueCallIndex())
+// Information about an LValueBase that is some kind of string.
+struct LValueBaseString {
+  std::string ObjCEncodeStorage;
+  StringRef Bytes;
+  int CharWidth;
+};
+
+// Gets the lvalue base of LVal as a string.
+static bool GetLValueBaseAsString(const EvalInfo &Info, const LValue &LVal,
+  LValueBaseString &AsString) {
+  const auto *BaseExpr = LVal.Base.dyn_cast();
+  if (!BaseExpr)
+return false;
+
+  // For ObjCEncodeExpr, we need to compute and store the string.
+  if (const auto *EE = dyn_cast(BaseExpr)) {
+Info.Ctx.getObjCEncodingForType(EE->getEncodedType(),
+AsString.ObjCEncodeStorage);
+AsString.Bytes = AsString.ObjCEncodeStorage;
+AsString.CharWidth = 1;
+return true;
+  }
+
+  // Otherwise, we have a StringLiteral.
+  const auto *Lit = dyn_cast(BaseExpr);
+  if (const auto *PE = dyn_cast(BaseExpr))
+Lit = PE->getFunctionName();
+
+  if (!Lit)
+return false;
+
+  AsString.Bytes = Lit->getBytes();
+  AsString.CharWidth = Lit->getCharByteWidth();
+  return true;
+}
+
+// Determine whether two string literals potentially overlap. This will be the
+// case if they agree on the values of all the bytes on the overlapping region
+// between them.

tbaederr wrote:

"The overlapping region" means they share some prefix?

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


  1   2   3   4   5   >