[PATCH] D138511: [CodeGen][AArch64] Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

2022-11-25 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

pin~


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138511/new/

https://reviews.llvm.org/D138511

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


[PATCH] D137838: [RFC][Support] Move TargetParsers to new component

2022-11-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

The name `llvm/lib/TargetParser` LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137838/new/

https://reviews.llvm.org/D137838

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


[PATCH] D138520: [clangd] Make decision forest model optional

2022-11-25 Thread Arfrever Frehtes Taifersar Arahesis via Phabricator via cfe-commits
Arfrever added a comment.

In `clang-tools-extra/clangd/unittests/CMakeLists.txt`, usage of 
`CompletionModel.cmake` probably also should be dependent on 
`CLANGD_DECISION_FOREST`.

In `clang-tools-extra/clangd/CMakeLists.txt` and 
`clang-tools-extra/clangd/unittests/CMakeLists.txt`, calls to 
`target_include_directories()` for directories with generated Completion Model 
headers can be also made dependent on `CLANGD_DECISION_FOREST`.

  --- clang-tools-extra/clangd/unittests/CMakeLists.txt
  +++ clang-tools-extra/clangd/unittests/CMakeLists.txt
  @@ -146,10 +146,12 @@
 omp_gen
 )
   
  -# Include generated CompletionModel headers.
  -target_include_directories(clangDaemon PUBLIC
  -  $
  -)
  +if(CLANGD_DECISION_FOREST)
  +  # Include generated Completion Model header.
  +  target_include_directories(clangDaemon PUBLIC
  +$
  +  )
  +endif()
   
   clang_target_link_libraries(clangDaemon
 PRIVATE
  --- clang-tools-extra/clangd/unittests/CMakeLists.txt
  +++ clang-tools-extra/clangd/unittests/CMakeLists.txt
  @@ -19,8 +19,12 @@
 set(REMOTE_TEST_SOURCES remote/MarshallingTests.cpp)
   endif()
   
  -include(${CMAKE_CURRENT_SOURCE_DIR}/../quality/CompletionModel.cmake)
  -gen_decision_forest(${CMAKE_CURRENT_SOURCE_DIR}/decision_forest_model 
DecisionForestRuntimeTest ::ns1::ns2::test::Example)
  +set(DECISIONFORESTRUNTIMETEST_SOURCES)
  +if(CLANGD_DECISION_FOREST)
  +  include(${CMAKE_CURRENT_SOURCE_DIR}/../quality/CompletionModel.cmake)
  +  gen_decision_forest(${CMAKE_CURRENT_SOURCE_DIR}/decision_forest_model 
DecisionForestRuntimeTest ::ns1::ns2::test::Example)
  +  list(APPEND DECISIONFORESTRUNTIMETEST_SOURCES 
${CMAKE_CURRENT_BINARY_DIR}/DecisionForestRuntimeTest.cpp)
  +endif()
   
   add_custom_target(ClangdUnitTests)
   add_unittest(ClangdUnitTests ClangdTests
  @@ -95,7 +99,7 @@
 TypeHierarchyTests.cpp
 URITests.cpp
 XRefsTests.cpp
  -  ${CMAKE_CURRENT_BINARY_DIR}/DecisionForestRuntimeTest.cpp
  +  ${DECISIONFORESTRUNTIMETEST_SOURCES}
   
 support/CancellationTests.cpp
 support/ContextTests.cpp
  @@ -134,10 +138,12 @@
 $
 )
   
  -# Include generated ComletionModel headers.
  -target_include_directories(ClangdTests PUBLIC
  -  $
  -)
  +if(CLANGD_DECISION_FOREST)
  +  # Include generated Completion Model header.
  +  target_include_directories(ClangdTests PUBLIC
  +$
  +  )
  +endif()
   
   clang_target_link_libraries(ClangdTests
 PRIVATE


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138520/new/

https://reviews.llvm.org/D138520

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


[PATCH] D138693: [clang] [MinGW] Improve detection of libstdc++ headers on Fedora

2022-11-25 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 accepted this revision.
mati865 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138693/new/

https://reviews.llvm.org/D138693

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


[PATCH] D138692: [clang] [MinGW] Improve/extend the gcc/sysroot detection logic

2022-11-25 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 accepted this revision.
mati865 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138692/new/

https://reviews.llvm.org/D138692

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


[clang] 20ba079 - [StaticAnalyzer] Don't use Optional::create (NFC)

2022-11-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-11-25T15:38:53-08:00
New Revision: 20ba079dda7be1a72d64cebc9f55d909bf29f6c1

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

LOG: [StaticAnalyzer] Don't use Optional::create (NFC)

Note that std::optional does not offer create().

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 4528dbc0cc36..f99ef04584a7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -480,9 +480,8 @@ ProgramStateRef ExprEngine::setIndexOfElementToConstruct(
 Optional ExprEngine::getPendingInitLoop(ProgramStateRef State,
   const CXXConstructExpr *E,
   const LocationContext *LCtx) 
{
-
-  return Optional::create(
-  State->get({E, LCtx->getStackFrame()}));
+  const unsigned *V = State->get({E, LCtx->getStackFrame()});
+  return V ? Optional(*V) : std::nullopt;
 }
 
 ProgramStateRef ExprEngine::removePendingInitLoop(ProgramStateRef State,
@@ -509,9 +508,9 @@ Optional
 ExprEngine::getIndexOfElementToConstruct(ProgramStateRef State,
  const CXXConstructExpr *E,
  const LocationContext *LCtx) {
-
-  return Optional::create(
-  State->get({E, LCtx->getStackFrame()}));
+  const unsigned *V =
+  State->get({E, LCtx->getStackFrame()});
+  return V ? Optional(*V) : std::nullopt;
 }
 
 ProgramStateRef
@@ -529,8 +528,9 @@ ExprEngine::getPendingArrayDestruction(ProgramStateRef 
State,
const LocationContext *LCtx) {
   assert(LCtx && "LocationContext shouldn't be null!");
 
-  return Optional::create(
-  State->get(LCtx->getStackFrame()));
+  const unsigned *V =
+  State->get(LCtx->getStackFrame());
+  return V ? Optional(*V) : std::nullopt;
 }
 
 ProgramStateRef ExprEngine::setPendingArrayDestruction(
@@ -599,7 +599,8 @@ ExprEngine::getObjectUnderConstruction(ProgramStateRef 
State,
const ConstructionContextItem ,
const LocationContext *LC) {
   ConstructedObjectKey Key(Item, LC->getStackFrame());
-  return Optional::create(State->get(Key));
+  const SVal *V = State->get(Key);
+  return V ? Optional(*V) : std::nullopt;
 }
 
 ProgramStateRef



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


[PATCH] D138274: Add version to all LLVM cmake package

2022-11-25 Thread Thomas Preud'homme via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGecfa2d3d9943: Add version to all LLVM cmake package 
(authored by thopre).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138274/new/

https://reviews.llvm.org/D138274

Files:
  clang/cmake/modules/CMakeLists.txt
  clang/cmake/modules/ClangConfig.cmake.in
  clang/cmake/modules/ClangConfigVersion.cmake.in
  flang/cmake/modules/CMakeLists.txt
  flang/cmake/modules/FlangConfig.cmake.in
  flang/cmake/modules/FlangConfigVersion.cmake.in
  lld/cmake/modules/CMakeLists.txt
  lld/cmake/modules/LLDConfig.cmake.in
  lld/cmake/modules/LLDConfigVersion.cmake.in
  mlir/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/MLIRConfig.cmake.in
  mlir/cmake/modules/MLIRConfigVersion.cmake.in
  polly/cmake/CMakeLists.txt
  polly/cmake/PollyConfig.cmake.in
  polly/cmake/PollyConfigVersion.cmake.in

Index: polly/cmake/PollyConfigVersion.cmake.in
===
--- /dev/null
+++ polly/cmake/PollyConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+  "${PACKAGE_FIND_VERSION_PATCH}")
+set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()
Index: polly/cmake/PollyConfig.cmake.in
===
--- polly/cmake/PollyConfig.cmake.in
+++ polly/cmake/PollyConfig.cmake.in
@@ -2,7 +2,8 @@
 
 @POLLY_CONFIG_CODE@
 
-find_package(LLVM REQUIRED CONFIG
+set(LLVM_VERSION @LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@.@LLVM_VERSION_PATCH@)
+find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
  HINTS "@POLLY_CONFIG_LLVM_CMAKE_DIR@")
 
 set(Polly_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -82,6 +82,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
   ${polly_cmake_builddir}/PollyConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
+  ${polly_cmake_builddir}/PollyConfigVersion.cmake
+  @ONLY)
 
 file(GENERATE
   OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
@@ -138,6 +142,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake
+  @ONLY)
 file(GENERATE OUTPUT
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
   CONTENT "${POLLY_EXPORTS}")
@@ -146,6 +154,7 @@
   install(
 FILES
 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
+"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake"
 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
 DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
 endif ()
Index: mlir/cmake/modules/MLIRConfigVersion.cmake.in
===
--- /dev/null
+++ mlir/cmake/modules/MLIRConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+  "${PACKAGE_FIND_VERSION_PATCH}")
+set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()
Index: mlir/cmake/modules/MLIRConfig.cmake.in
===
--- mlir/cmake/modules/MLIRConfig.cmake.in
+++ mlir/cmake/modules/MLIRConfig.cmake.in
@@ -2,7 +2,8 @@
 
 @MLIR_CONFIG_CODE@
 
-find_package(LLVM REQUIRED CONFIG
+set(LLVM_VERSION @LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@.@LLVM_VERSION_PATCH@)
+find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
  HINTS "@MLIR_CONFIG_LLVM_CMAKE_DIR@")
 
 set(MLIR_EXPORTED_TARGETS "@MLIR_EXPORTS@")
Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -41,6 +41,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
   

[clang] ecfa2d3 - Add version to all LLVM cmake package

2022-11-25 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2022-11-25T21:57:58Z
New Revision: ecfa2d3d9943a48411d04a4b3103c42b4653d9af

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

LOG: Add version to all LLVM cmake package

Add a version to non-LLVM cmake package so that users needing an exact
version match can use the version parameter to find_package. Also adjust
the find_package(LLVM) to use an exact version match as well.

Reviewed By: arsenm, stellaraccident, mceier

Differential Revision: https://reviews.llvm.org/D138274

Added: 
clang/cmake/modules/ClangConfigVersion.cmake.in
flang/cmake/modules/FlangConfigVersion.cmake.in
lld/cmake/modules/LLDConfigVersion.cmake.in
mlir/cmake/modules/MLIRConfigVersion.cmake.in
polly/cmake/PollyConfigVersion.cmake.in

Modified: 
clang/cmake/modules/CMakeLists.txt
clang/cmake/modules/ClangConfig.cmake.in
flang/cmake/modules/CMakeLists.txt
flang/cmake/modules/FlangConfig.cmake.in
lld/cmake/modules/CMakeLists.txt
lld/cmake/modules/LLDConfig.cmake.in
mlir/cmake/modules/CMakeLists.txt
mlir/cmake/modules/MLIRConfig.cmake.in
polly/cmake/CMakeLists.txt
polly/cmake/PollyConfig.cmake.in

Removed: 




diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index 880d51f5aef7..749ef672c34f 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -32,6 +32,10 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfigVersion.cmake.in
+  ${clang_cmake_builddir}/ClangConfigVersion.cmake
+  @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
@@ -59,6 +63,10 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfigVersion.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfigVersion.cmake
+  @ONLY)
 set(CLANG_CONFIG_CODE)
 set(CLANG_CONFIG_CMAKE_DIR)
 
@@ -67,6 +75,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
 
   install(FILES
 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
+${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfigVersion.cmake
 ${CMAKE_CURRENT_SOURCE_DIR}/AddClang.cmake
 DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}
 COMPONENT clang-cmake-exports)

diff  --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 2a254463d6f5..5f67681649c6 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -2,7 +2,8 @@
 
 @CLANG_CONFIG_CODE@
 
-find_package(LLVM REQUIRED CONFIG
+set(LLVM_VERSION 
@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@.@LLVM_VERSION_PATCH@)
+find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
  HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
 
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")

diff  --git a/clang/cmake/modules/ClangConfigVersion.cmake.in 
b/clang/cmake/modules/ClangConfigVersion.cmake.in
new file mode 100644
index ..e9ac4ed2da78
--- /dev/null
+++ b/clang/cmake/modules/ClangConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+  "${PACKAGE_FIND_VERSION_PATCH}")
+set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()

diff  --git a/flang/cmake/modules/CMakeLists.txt 
b/flang/cmake/modules/CMakeLists.txt
index 31a6c3c83e48..bf50bcaa18d5 100644
--- a/flang/cmake/modules/CMakeLists.txt
+++ b/flang/cmake/modules/CMakeLists.txt
@@ -28,8 +28,8 @@ set(FLANG_CONFIG_INCLUDE_DIRS
   "${FLANG_BINARY_DIR}/include"
   )
 configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
-  ${flang_cmake_builddir}/FlangConfig.cmake
+  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfigVersion.cmake.in
+  ${flang_cmake_builddir}/FlangConfigVersion.cmake
   @ONLY)
 set(FLANG_CONFIG_CMAKE_DIR)
 set(FLANG_CONFIG_LLVM_CMAKE_DIR)
@@ -46,6 +46,10 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfigVersion.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfigVersion.cmake
+  @ONLY)
 
 set(FLANG_CONFIG_CODE)
 set(FLANG_CONFIG_CMAKE_DIR)
@@ -56,6 +60,7 @@ if 

[PATCH] D138210: [clang] Require parameter pack to be last argument in concepts.

2022-11-25 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google updated this revision to Diff 478019.
luken-google added a comment.

Strengthen assert.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138210/new/

https://reviews.llvm.org/D138210

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -766,3 +766,24 @@
   __iterator_traits_member_pointer_or_arrow_or_void> f;
 }
 }// namespace InheritedFromPartialSpec
+
+namespace GH48182 {
+template // expected-error{{template 
parameter pack must be the last template parameter}}
+concept invalid = true;
+
+template requires invalid // expected-error{{use of undeclared 
identifier 'invalid'}}
+no errors are printed
+;
+
+static_assert(invalid also here ; // expected-error{{use of undeclared 
identifier 'invalid'}}
+
+int foo() {
+bool b;
+b = invalid not just in declarations; // expected-error{{expected ';' 
after expression}}
+   // expected-error@-1{{use of 
undeclared identifier 'invalid'}}
+   // expected-error@-2{{expected 
';' after expression}}
+   // expected-error@-3{{use of 
undeclared identifier 'just'}}
+   // expected-error@-4{{unknown 
type name 'in'}}
+return b;
+}
+} // namespace GH48182
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5981,8 +5981,12 @@
   // A non-expanded parameter pack before the end of the parameter list
   // only occurs for an ill-formed template parameter list, unless we've
   // got a partial argument list for a function template, so just bail out.
-  if (Param + 1 != ParamEnd)
+  if (Param + 1 != ParamEnd) {
+assert(
+(Template->getMostRecentDecl()->getKind() != Decl::Kind::Concept) 
&&
+"Concept templates must have parameter packs at the end.");
 return true;
+  }
 
   SugaredConverted.push_back(
   TemplateArgument::CreatePackCopy(Context, SugaredArgumentPack));
@@ -8922,17 +8926,33 @@
 return nullptr;
   }
 
-  if (TemplateParameterLists.front()->size() == 0) {
+  TemplateParameterList *Params = TemplateParameterLists.front();
+
+  if (Params->size() == 0) {
 Diag(NameLoc, diag::err_concept_no_parameters);
 return nullptr;
   }
 
+  // Ensure that the parameter pack, if present, is the last parameter in the
+  // template.
+  for (TemplateParameterList::const_iterator ParamIt = Params->begin(),
+ ParamEnd = Params->end();
+   ParamIt != ParamEnd; ++ParamIt) {
+Decl const *Param = *ParamIt;
+if (Param->isParameterPack()) {
+  if (++ParamIt == ParamEnd)
+break;
+  Diag(Param->getLocation(),
+   diag::err_template_param_pack_must_be_last_template_parameter);
+  return nullptr;
+}
+  }
+
   if (DiagnoseUnexpandedParameterPack(ConstraintExpr))
 return nullptr;
 
-  ConceptDecl *NewDecl = ConceptDecl::Create(Context, DC, NameLoc, Name,
- TemplateParameterLists.front(),
- ConstraintExpr);
+  ConceptDecl *NewDecl =
+  ConceptDecl::Create(Context, DC, NameLoc, Name, Params, ConstraintExpr);
 
   if (NewDecl->hasAssociatedConstraints()) {
 // C++2a [temp.concept]p4:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -648,6 +648,8 @@
   ([temp.func.order]p6.2.1 is not implemented, matching GCC).
 - Implemented `P0857R0 
`_,
   which specifies constrained lambdas and constrained template 
*template-parameter*\s.
+- Required parameter pack to be provided at the end of the concept parameter 
list. This
+  fixes `Issue 48182 `_.
 
 - Do not hide templated base members introduced via using-decl in derived class
   (useful specially for constrained members). Fixes `GH50886 
`_.


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -766,3 +766,24 @@
   __iterator_traits_member_pointer_or_arrow_or_void> f;
 }
 }// namespace InheritedFromPartialSpec
+
+namespace GH48182 {
+template // expected-error{{template parameter pack must be the last template parameter}}
+concept 

[PATCH] D138210: [clang] Require parameter pack to be last argument in concepts.

2022-11-25 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google added a comment.

There is logic in the template expansion that returns an error state if the 
template parameter pack was not at the end of the template parameter list. It 
returns `true` but does not generate any diagnostics, but the outer code error 
machinery assumes that diagnostics have already been generated and so considers 
the expression invalid and moves on.

As this fix no longer accepts these ill-formed templates as valid, that code no 
longer fires. I have strengthened the check there to an assert. PTAL.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138210/new/

https://reviews.llvm.org/D138210

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


[PATCH] D138552: [docs] Document that the modules can improve the linking time

2022-11-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

> And another problem here is, without LTO, the function definitions in other 
> TU can't be inlined. But now, the function definitions in the module 
> interface can be imported to the importee as AvaialableExternally linkage 
> with optimization. The AvaialableExternally linkage is a special linkage 
> which aims for the IPO. And the AvaialableExternally entities would be 
> removed in the middle end after inlining. (I know there are arguments to 
> remove the function definition in the module file.) So if we move not 
> directly used things in .cpp files, the performance will be hurt. But it is 
> not the case for modules (at least for now).

Yeah, I think if we're planning to minimize pcms to the point where they can't 
do code generation I guess we'll probably remove the indirect function 
definitions/not use available externally, and rely on (Thin)LTO to provide 
whole program optimization - so the guidance that modules reduces link time 
wouldn't be true in that case.

I think it's probably best to abandon this patch/not document/suggest that this 
is a benefit people should expect from modules if it's one that'd go away in 
the future anyway.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138552/new/

https://reviews.llvm.org/D138552

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/3)

2022-11-25 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:197
+llvm::cl::opt P1689TargetedCommand(
+"p1689-targeted-command", llvm::cl::Optional,
+llvm::cl::desc("Only supported for P1689, the targeted command of which "

ChuanqiXu wrote:
> ben.boeckel wrote:
> > Can this be something like `--` so that I don't have to figure out how to 
> > quote the thing (for the shell and whatever parsing Clang does internally)?
> Yeah, it can. Both `-` and `--` are accepted. I've updated the test to 
> disambiguate.
I don't mean the flag using `--` as a prefix. I don't care about that. What I 
*do* care about is having to quote everything I'd give to `clang` here. I'd 
vastly prefer something like:

```
clang-scan-deps -p1689-targeted-file-name=… -p1689-use-command -- -flags --for 
---clang --go --here
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137534/new/

https://reviews.llvm.org/D137534

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.

One thought about returning -1 but otherwise LGTM




Comment at: llvm/lib/Support/Threading.cpp:59
   if (MaxThreadCount <= 0)
 MaxThreadCount = 1;
   if (ThreadsRequested == 0)

It looks like this is the only place `get_physical_cores` is used, and if the 
number is unknown or threading is disabled `MaxThreadCount` is just set to 1. 
Would it not make sense to change `get_physical_cores` to return 1, like 
`compute_thread_count`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138579: [AArch64] Assembly support for FEAT_LRCPC3

2022-11-25 Thread Tomas Matheson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6aaa969f7ca: [AArch64] Assembly support for FEAT_LRCPC3 
(authored by tmatheson).

Changed prior to commit:
  https://reviews.llvm.org/D138579?vs=478001=478005#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138579/new/

https://reviews.llvm.org/D138579

Files:
  clang/test/Driver/aarch64-lrcpc3.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/test/MC/AArch64/arm64-memory.s
  llvm/test/MC/AArch64/armv8.9a-lrcpc3.s
  llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1606,7 +1606,8 @@
   AArch64::AEK_SME, AArch64::AEK_SMEF64F64, AArch64::AEK_SMEI16I64,
   AArch64::AEK_SME2,AArch64::AEK_HBC,  AArch64::AEK_MOPS,
   AArch64::AEK_PERFMON, AArch64::AEK_SVE2p1,   AArch64::AEK_SME2p1,
-  AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC};
+  AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC,
+  AArch64::AEK_RCPC3};
 
   std::vector Features;
 
@@ -1672,6 +1673,7 @@
   EXPECT_TRUE(llvm::is_contained(Features, "+mops"));
   EXPECT_TRUE(llvm::is_contained(Features, "+perfmon"));
   EXPECT_TRUE(llvm::is_contained(Features, "+cssc"));
+  EXPECT_TRUE(llvm::is_contained(Features, "+rcpc3"));
 
   // Assuming we listed every extension above, this should produce the same
   // result. (note that AEK_NONE doesn't have a name so it won't be in the
Index: llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
@@ -0,0 +1,113 @@
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding   -mattr=+rcpc3 < %s | FileCheck %s
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding -mattr=+v8.9a -mattr=+rcpc3 < %s | FileCheck %s
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding -mattr=+v9.4a -mattr=+rcpc3 < %s | FileCheck %s
+
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble   < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble -mattr=+v8.9a < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble -mattr=+v9.4a < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+
+[0x18,0x0a,0x00,0x99]
+# CHECK:  stilp   w24, w0, [x16, #-8]! // encoding: [0x18,0x0a,0x00,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x18,0x0a,0x00,0x99]
+# CHECK:  stilp   w24, w0, [x16, #-8]! // encoding: [0x18,0x0a,0x00,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x39,0x0a,0x01,0xd9]
+# CHECK:  stilp   x25, x1, [x17, #-16]!// encoding: [0x39,0x0a,0x01,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x39,0x0a,0x01,0xd9]
+# CHECK:  stilp   x25, x1, [x17, #-16]!// encoding: [0x39,0x0a,0x01,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x5a,0x1a,0x02,0x99]
+# CHECK:  stilp   w26, w2, [x18]   // encoding: [0x5a,0x1a,0x02,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xfb,0x1b,0x03,0xd9]
+# CHECK:  stilp   x27, x3, [sp]// encoding: [0xfb,0x1b,0x03,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x9c,0x0a,0x44,0x99]
+# CHECK:  ldiapp  w28, w4, [x20], #8   // encoding: [0x9c,0x0a,0x44,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x9c,0x0a,0x44,0x99]
+# CHECK:  ldiapp  w28, w4, [x20], #8   // encoding: [0x9c,0x0a,0x44,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xbd,0x0a,0x45,0xd9]
+# CHECK:  ldiapp  x29, x5, [x21], #16  // encoding: [0xbd,0x0a,0x45,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xbd,0x0a,0x45,0xd9]
+# CHECK:  ldiapp  x29, x5, [x21], #16  // encoding: [0xbd,0x0a,0x45,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xfe,0x1b,0x46,0x99]
+# CHECK:  ldiapp  w30, w6, [sp]// encoding: [0xfe,0x1b,0x46,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding

[clang] a6aaa96 - [AArch64] Assembly support for FEAT_LRCPC3

2022-11-25 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-11-25T18:59:07Z
New Revision: a6aaa969f7caec58a994142f8d855861cf3a1463

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

LOG: [AArch64] Assembly support for FEAT_LRCPC3

This patch implements assembly support for the 2022 A-Profile Architecture
extension FEAT_LRCPC3. FEAT_LRCPC3 is AArch64 only and introduces new
variants of load/store instructions with release consistency ordering.

Specs for individual instructions can be found here:
https://developer.arm.com/documentation/ddi0602/2022-09/Base-Instructions/

This feature is optionally available from v8.2a and therefore not enabled by
default.

Contributors:
  Lucas Prates
  Sam Elliot
  Son Tuan Vu
  Tomas Matheson

Differential Revision: https://reviews.llvm.org/D138579

Added: 
clang/test/Driver/aarch64-lrcpc3.c
llvm/test/MC/AArch64/armv8.9a-lrcpc3.s
llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt

Modified: 
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrFormats.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/test/MC/AArch64/arm64-memory.s
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/aarch64-lrcpc3.c 
b/clang/test/Driver/aarch64-lrcpc3.c
new file mode 100644
index 0..27b522d74c5f8
--- /dev/null
+++ b/clang/test/Driver/aarch64-lrcpc3.c
@@ -0,0 +1,26 @@
+// Test that target feature FEAT_RCPC3 is implemented and available correctly
+
+// FEAT_RCPC3 is optional for v8.2a onwards, and can be enabled with +rcpc3
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.9-a %s 
2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.9-a+rcpc3   %s 
2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.9-a+norcpc3 %s 
2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9.4-a %s 
2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9.4-a+rcpc3   %s 
2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9.4-a+norcpc3 %s 
2>&1 | FileCheck %s --check-prefix=DISABLED
+
+// FEAT_RCPC3 is optional (off by default) for v8.8a/9.3a and older, and can 
be enabled using +rcpc3
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2-a %s 
2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2-a+rcpc3   %s 
2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv8.2-a+norcpc3 %s 
2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9-a %s 
2>&1 | FileCheck %s --check-prefix=NOT_ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9-a+rcpc3   %s 
2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -target aarch64-none-none-eabi -march=armv9-a+norcpc3 %s 
2>&1 | FileCheck %s --check-prefix=DISABLED
+
+// FEAT_RCPC3 is invalid before v8
+// RUN: %clang -### -target arm-none-none-eabi -march=armv7-a+rcpc3 %s 
2>&1 | FileCheck %s --check-prefix=INVALID
+
+// INVALID: error: unsupported argument 'armv7-a+rcpc3' to option '-march='
+// ENABLED: "-target-feature" "+rcpc3"
+// NOT_ENABLED-NOT: "-target-feature" "+rcpc3"
+// DISABLED: "-target-feature" "-rcpc3"
+

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index f016c9147a7bb..6fd68872e96c1 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser.def
@@ -152,6 +152,7 @@ AARCH64_ARCH_EXT_NAME("hbc",  AArch64::AEK_HBC, 
"+hbc",
 AARCH64_ARCH_EXT_NAME("mops", AArch64::AEK_MOPS,"+mops",   
  "-mops")
 AARCH64_ARCH_EXT_NAME("pmuv3",AArch64::AEK_PERFMON, "+perfmon",
  "-perfmon")
 AARCH64_ARCH_EXT_NAME("cssc", AArch64::AEK_CSSC,"+cssc",   
  "-cssc")
+AARCH64_ARCH_EXT_NAME("rcpc3",AArch64::AEK_RCPC3,   "+rcpc3",  
  "-rcpc3")
 #undef AARCH64_ARCH_EXT_NAME
 
 #ifndef AARCH64_CPU_NAME

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.h 
b/llvm/include/llvm/Support/AArch64TargetParser.h
index 4d069a6b67831..3261e3f5b5eae 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.h
+++ b/llvm/include/llvm/Support/AArch64TargetParser.h
@@ -77,6 +77,7 @@ enum 

[PATCH] D138579: [AArch64] Assembly support for FEAT_LRCPC3

2022-11-25 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson updated this revision to Diff 478001.
tmatheson marked 3 inline comments as done.
tmatheson added a comment.

Address comments and change instruction names


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138579/new/

https://reviews.llvm.org/D138579

Files:
  clang/test/Driver/aarch64-lrcpc3.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/test/MC/AArch64/arm64-memory.s
  llvm/test/MC/AArch64/armv8.9a-lrcpc3.s
  llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1606,7 +1606,8 @@
   AArch64::AEK_SME, AArch64::AEK_SMEF64F64, AArch64::AEK_SMEI16I64,
   AArch64::AEK_SME2,AArch64::AEK_HBC,  AArch64::AEK_MOPS,
   AArch64::AEK_PERFMON, AArch64::AEK_SVE2p1,   AArch64::AEK_SME2p1,
-  AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC};
+  AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC,
+  AArch64::AEK_RCPC3};
 
   std::vector Features;
 
@@ -1672,6 +1673,7 @@
   EXPECT_TRUE(llvm::is_contained(Features, "+mops"));
   EXPECT_TRUE(llvm::is_contained(Features, "+perfmon"));
   EXPECT_TRUE(llvm::is_contained(Features, "+cssc"));
+  EXPECT_TRUE(llvm::is_contained(Features, "+rcpc3"));
 
   // Assuming we listed every extension above, this should produce the same
   // result. (note that AEK_NONE doesn't have a name so it won't be in the
Index: llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/AArch64/armv8.9a-lrcpc3.txt
@@ -0,0 +1,113 @@
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding   -mattr=+rcpc3 < %s | FileCheck %s
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding -mattr=+v8.9a -mattr=+rcpc3 < %s | FileCheck %s
+# RUN: llvm-mc -triple aarch64-none-linux-gnu -disassemble -show-encoding -mattr=+v9.4a -mattr=+rcpc3 < %s | FileCheck %s
+
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble   < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble -mattr=+v8.9a < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+# RUN: not llvm-mc -triple aarch64-none-linux-gnu -disassemble -mattr=+v9.4a < %s 2>&1 | FileCheck --check-prefix=ERROR-NO-RCPC3 %s
+
+[0x18,0x0a,0x00,0x99]
+# CHECK:  stilp   w24, w0, [x16, #-8]! // encoding: [0x18,0x0a,0x00,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x18,0x0a,0x00,0x99]
+# CHECK:  stilp   w24, w0, [x16, #-8]! // encoding: [0x18,0x0a,0x00,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x39,0x0a,0x01,0xd9]
+# CHECK:  stilp   x25, x1, [x17, #-16]!// encoding: [0x39,0x0a,0x01,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x39,0x0a,0x01,0xd9]
+# CHECK:  stilp   x25, x1, [x17, #-16]!// encoding: [0x39,0x0a,0x01,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x5a,0x1a,0x02,0x99]
+# CHECK:  stilp   w26, w2, [x18]   // encoding: [0x5a,0x1a,0x02,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xfb,0x1b,0x03,0xd9]
+# CHECK:  stilp   x27, x3, [sp]// encoding: [0xfb,0x1b,0x03,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x9c,0x0a,0x44,0x99]
+# CHECK:  ldiapp  w28, w4, [x20], #8   // encoding: [0x9c,0x0a,0x44,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0x9c,0x0a,0x44,0x99]
+# CHECK:  ldiapp  w28, w4, [x20], #8   // encoding: [0x9c,0x0a,0x44,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xbd,0x0a,0x45,0xd9]
+# CHECK:  ldiapp  x29, x5, [x21], #16  // encoding: [0xbd,0x0a,0x45,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xbd,0x0a,0x45,0xd9]
+# CHECK:  ldiapp  x29, x5, [x21], #16  // encoding: [0xbd,0x0a,0x45,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xfe,0x1b,0x46,0x99]
+# CHECK:  ldiapp  w30, w6, [sp]// encoding: [0xfe,0x1b,0x46,0x99]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid instruction encoding
+[0xff,0x1a,0x47,0xd9]
+# CHECK:  ldiapp  xzr, x7, [x23]   // encoding: [0xff,0x1a,0x47,0xd9]
+# ERROR-NO-RCPC3: [[@LINE-2]]:2: warning: invalid 

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-25 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:215
"-bugprone-use-after-move",
+   // Using an CFG and might crash on invalid code:
+   "-performance-unnecessary-copy-on-last-use",

kadircet wrote:
> comment seems half-finished here. is there any other reason than trying to 
> analyze `CFG` for invalid code?
Thanks, the "and" does not belong here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-25 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe updated this revision to Diff 477997.
Febbe marked 3 inline comments as done.
Febbe added a comment.

Fixed typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyOnLastUseCheck.h
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-copy-on-last-use.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp
@@ -0,0 +1,270 @@
+// RUN: %check_clang_tidy %s -std=c++17 performance-unnecessary-copy-on-last-use %t
+// RUN: %check_clang_tidy %s -std=c++11 performance-unnecessary-copy-on-last-use %t
+// CHECK-FIXES: #include 
+
+struct Movable {
+  Movable() = default;
+  Movable(Movable const &) = default;
+  Movable(Movable &&) = default;
+  Movable =(Movable const &) = default;
+  Movable =(Movable &&) = default;
+  ~Movable();
+
+  void memberUse() {}
+};
+
+struct Copyable {
+  Copyable() = default;
+  Copyable(Copyable const &) = default;
+  Copyable(Copyable &&) = default;
+  Copyable =(Copyable const &) = default;
+  Copyable =(Copyable &&) = default;
+  ~Copyable() = default; 
+
+  void memberUse() {}
+};
+// static_assert(!std::is_trivially_copyable_v, "Movable must not be trivially copyable");
+
+void valueReceiver(Movable Mov);
+void constRefReceiver(Movable const );
+
+void valueTester() {
+  Movable Mov{};
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void testUsageInBranch(bool Splitter) {
+  Movable Mov{};
+
+  valueReceiver(Mov);
+  if(Splitter){
+Mov.memberUse();
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+
+  if(Splitter){
+Mov = Movable{};
+  } else {
+Mov = Movable{};
+  }
+  valueReceiver(Mov);
+  Mov.memberUse();
+}
+
+void testExplicitCopy() {
+  Movable Mov{};
+  constRefReceiver(Movable{Mov});
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: constRefReceiver(Movable{std::move(Mov)});
+}
+
+Movable testReturn() {
+  Movable Mov{};
+  return Mov; // no warning, copy elision
+}
+
+Movable testReturn2(Movable && Mov, bool F) {
+  return F? Mov: Movable{}; 
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use] 
+  // CHECK-FIXES: return F? std::move(Mov): Movable{};
+}
+
+void rValReferenceTester(Movable&& Mov) {
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+  Mov = Movable{};
+  valueReceiver(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
+  // CHECK-FIXES: valueReceiver(std::move(Mov));
+}
+
+void referenceTester(Movable& Mov) {
+  valueReceiver(Mov);
+  valueReceiver(Mov);
+  Mov = Movable{};
+  valueReceiver(Mov);
+}
+
+void pointerTester(Movable* Mov) {
+  valueReceiver(*Mov);
+  valueReceiver(*Mov);
+  *Mov = Movable{};
+  valueReceiver(*Mov);
+}
+
+// Replacements in expansions from macros or of their parameters are buggy, so we don't fix them.
+// Todo (future): The source location of macro parameters might be fixed in the future
+#define FUN(Mov) valueReceiver((Mov))
+void falseMacroExpansion() {
+  Movable Mov;
+  FUN(Mov);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Parameter 'Mov' is copied on last use, consider moving it instead. 

[clang-tools-extra] 9c8a6a1 - [include-cleaner] Fix a warning

2022-11-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-11-25T09:51:25-08:00
New Revision: 9c8a6a1627480b30b54b4ffc691beebb8554e124

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

LOG: [include-cleaner] Fix a warning

This patch fixes:

  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp:240:51: error:
  missing field 'Locations' initializer
  [-Werror,-Wmissing-field-initializers]

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index fc9b00dc572df..cd43a27e5fc5b 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -146,11 +146,11 @@ class Reporter {
 unsigned Offset;
 RefType Type;
 Symbol Sym;
-SmallVector Locations;
-SmallVector Headers;
-SmallVector Includes;
-bool Satisfied = false; // Is the include present?
-std::string Insert; // If we had no includes, what would we insert?
+SmallVector Locations = {};
+SmallVector Headers = {};
+SmallVector Includes = {};
+bool Satisfied = false;  // Is the include present?
+std::string Insert = {}; // If we had no includes, what would we insert?
   };
   std::vector Refs;
   llvm::DenseMap> IncludeRefs;



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


[PATCH] D137838: [RFC][Support] Move TargetParsers to new component

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

> As for the name TargetParser. @arsenm came up with the name 
> SubtargetRegistry. I am fine with either names.

@fpetrogalli I'm going to stick with TargetParser, because I think this is less 
confusing, given that TargetRegistry is already a component.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137838/new/

https://reviews.llvm.org/D137838

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


[PATCH] D137838: [RFC][Support] Move TargetParsers to new component

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added inline comments.



Comment at: clang/lib/Lex/CMakeLists.txt:3
 
-set(LLVM_LINK_COMPONENTS support)
+set(LLVM_LINK_COMPONENTS
+  Support

fpetrogalli wrote:
> I wonder how `support` was not being detected as a linking error...
Not sure, but I still think getting the case right is useful in this patch.



Comment at: flang/tools/bbc/CMakeLists.txt:2-4
+  Passes
+  TargetParser
+  )

fpetrogalli wrote:
> nit: extra tabs
I've undone the re-indent here.



Comment at: flang/unittests/Optimizer/CMakeLists.txt:14
   ${dialect_libs}
 )
 

fpetrogalli wrote:
> Why not add `LLVMTargetParser` here?
That's better, done.



Comment at: llvm/include/llvm/ADT/Triple.h:1
-//===-- llvm/ADT/Triple.h - Target triple helper class --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_ADT_TRIPLE_H
-#define LLVM_ADT_TRIPLE_H
-
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/VersionTuple.h"
-
-// Some system headers or GCC predefined macros conflict with identifiers in
-// this file.  Undefine them here.
-#undef NetBSD
-#undef mips
-#undef sparc
-
-namespace llvm {
-
-/// Triple - Helper class for working with autoconf configuration names. For
-/// historical reasons, we also call these 'triples' (they used to contain
-/// exactly three fields).
-///
-/// Configuration names are strings in the canonical form:
-///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
-/// or
-///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
-///
-/// This class is used for clients which want to support arbitrary
-/// configuration names, but also want to implement certain special
-/// behavior for particular configurations. This class isolates the mapping
-/// from the components of the configuration name to well known IDs.
-///
-/// At its core the Triple class is designed to be a wrapper for a triple
-/// string; the constructor does not change or normalize the triple string.
-/// Clients that need to handle the non-canonical triples that users often
-/// specify should use the normalize method.
-///
-/// See autoconf/config.guess for a glimpse into what configuration names
-/// look like in practice.
-class Triple {
-public:
-  enum ArchType {
-UnknownArch,
-
-arm,// ARM (little endian): arm, armv.*, xscale
-armeb,  // ARM (big endian): armeb
-aarch64,// AArch64 (little endian): aarch64
-aarch64_be, // AArch64 (big endian): aarch64_be
-aarch64_32, // AArch64 (little endian) ILP32: aarch64_32
-arc,// ARC: Synopsys ARC
-avr,// AVR: Atmel AVR microcontroller
-bpfel,  // eBPF or extended BPF or 64-bit BPF (little endian)
-bpfeb,  // eBPF or extended BPF or 64-bit BPF (big endian)
-csky,   // CSKY: csky
-dxil,   // DXIL 32-bit DirectX bytecode
-hexagon,// Hexagon: hexagon
-loongarch32,// LoongArch (32-bit): loongarch32
-loongarch64,// LoongArch (64-bit): loongarch64
-m68k,   // M68k: Motorola 680x0 family
-mips,   // MIPS: mips, mipsallegrex, mipsr6
-mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el
-mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
-mips64el,   // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
-msp430, // MSP430: msp430
-ppc,// PPC: powerpc
-ppcle,  // PPCLE: powerpc (little endian)
-ppc64,  // PPC64: powerpc64, ppu
-ppc64le,// PPC64LE: powerpc64le
-r600,   // R600: AMD GPUs HD2XXX - HD6XXX
-amdgcn, // AMDGCN: AMD GCN GPUs
-riscv32,// RISC-V (32-bit): riscv32
-riscv64,// RISC-V (64-bit): riscv64
-sparc,  // Sparc: sparc
-sparcv9,// Sparcv9: Sparcv9
-sparcel,// Sparc: (endianness = little). NB: 'Sparcle' is a CPU 
variant
-systemz,// SystemZ: s390x
-tce,// TCE (http://tce.cs.tut.fi/): tce
-tcele,  // TCE little endian (http://tce.cs.tut.fi/): tcele
-thumb,  // Thumb (little endian): thumb, thumbv.*
-thumbeb,// Thumb (big endian): thumbeb
-x86,// X86: i[3-9]86
-x86_64, // X86-64: amd64, x86_64
-xcore,  // XCore: xcore
-nvptx,  // NVPTX: 32-bit
-nvptx64,// NVPTX: 64-bit
-le32,   // le32: generic little-endian 32-bit CPU (PNaCl)
-le64,   // le64: generic little-endian 64-bit CPU (PNaCl)
-amdil,  // AMDIL
-amdil64,// AMDIL with 64-bit pointers
-hsail,  // AMD HSAIL
-

[PATCH] D138727: [clang] Skip defaulted functions in zero-as-null-pointer-constant.

2022-11-25 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: ilya-biryukov.
Herald added a project: All.
massberg requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The zero-as-null-pointer-constant check should not fire if it is inside
a defaulted function, e.g. defaulted spaceship operators.
Add C++20 tests with spaceship operators.

Fixes #50221


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138727

Files:
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -isystem %S/Inputs 
-Wzero-as-null-pointer-constant -std=c++20
+
+#include 
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A ) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null 
pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2)); // 
expected-warning{{zero as null pointer constant}}
+}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -597,6 +597,13 @@
   CodeSynthesisContext::RewritingOperatorAsSpaceship)
 return;
 
+  // Ignore null pointers in defaulted functions, e.g. defaulted comparison
+  // operators.
+  FunctionDecl *FD =  getCurFunctionDecl();
+  if (FD && FD->isDefaulted()) {
+return;
+  }
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();


Index: clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-zero-nullptr-cxx20.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -isystem %S/Inputs -Wzero-as-null-pointer-constant -std=c++20
+
+#include 
+
+namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
+struct strong_ordering {
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A ) const = default;
+};
+
+void test_cxx_rewritten_binary_ops() {
+  A a1, a2;
+  bool result;
+  result = (a1 < a2);
+  result = (a1 >= a2);
+  int *ptr = 0; // expected-warning{{zero as null pointer constant}}
+  result = (a1 > (ptr == 0 ? a1 : a2)); // expected-warning{{zero as null pointer constant}}
+  result = (a1 > ((a1 > (ptr == 0 ? 

[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-25 Thread Fabian Keßler via Phabricator via cfe-commits
Febbe added a comment.

In D137205#3950722 , @kadircet wrote:

> another thing that i noticed is usage of east consts in the implementation 
> files. no one seem to have brought it up so far (at least none that i can 
> see).
> in theory there are no explicit guidelines about it in LLVM coding style, but 
> rest of the codebase uses west const convention. so i am not sure if straying 
> away from it here will make much sense.

I think this should be regulated / enforced via clang-format if it is relevant 
at all to somebody.
In terms of consistency, the east-const I use is more consistent. Not to the 
previous written code, but to the language.
It is also completely irrelevant, because a new programmer will not understand 
that `const T const *` is actually `T const*` and not `T const * const`. An 
experienced programmer can understand it well either way.

In my eyes it should therefore always be east-const and also be taught in such 
a way, since such irritations do not arise thereby at all.

When it is ok for you to keep the east-const I would like to leave it as is, 
because it is on top a lot of work to manually search and replace those 
occurrences.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-11-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I haven't looked at the implementation. I only checked the tests and something 
is not quite right there. See my comments inline.
BTW the line-coverage is good. I found only two branches which I want to have 
tests for - see inline.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1624
+  if (LHS.isEmpty() || RHS.isEmpty())
+return RangeFactory.getEmptySet();
+

This branch is uncovered by tests.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1633
+APSIntType CastingType(std::max(LHS.getBitWidth(), RHS.getBitWidth()),
+   LHS.isUnsigned() || RHS.isUnsigned());
+

Although the `RHS.isUnsigned()` is covered 2 times in the 
`check-clang-analysis`target, I think it would make sense to have a dedicated 
test for this case in the `constant-folding.c`.



Comment at: clang/test/Analysis/constant-folding.c:289-301
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+1, INT_MIN+2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+

These two hunks seem to be the same. We should probably keep one.
In addition to that, clang thinks the answer for `u1 != s1` depends on the 
operands.
We should probably return `UNKNOWN` for such cases. 
https://godbolt.org/z/aG1oY5Mr4



Comment at: clang/test/Analysis/constant-folding.c:315-319
+  if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-5, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }

Clang thinks it depends on the operands if `u1 != s1` is true.
https://godbolt.org/z/Pf3eYKnzd



Comment at: clang/test/Analysis/constant-folding.c:321-325
+  if (s1 < 1 && s1 > -7 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-6, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }

Clang thinks it depends on the operands if `u1 != s1` is true.
https://godbolt.org/z/1YYcd1EY8



Comment at: clang/test/Analysis/constant-folding.c:328-332
+  if (((u1 >= 1 && u1 <= 2) || (u1 >= 8 && u1 <= 9)) &&
+  u2 >= 5 && u2 <= 6) {
+// u1: [1, 2]U[8, 9], u2: [5, 6]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }

Clang thinks it depends on the operands if `u1 != u2` is true.
I believe, in such cases we should have returned `UNKNOWN`: 
https://godbolt.org/z/fxaT7YYob



Comment at: clang/test/Analysis/constant-folding.c:404-407
+  if (uch > 1 && sch < 1) {
+// uch: [2, CHAR_MAX], sch: [SCHAR_MIN, 0]
+clang_analyzer_eval(uch != sch); // expected-warning{{UNKNOWN}}
+  }

Shouldn't it print `TRUE`?
Clang will optimize this to `return true`. https://godbolt.org/z/6c6EPYofY
We should probably conclude the same here.



Comment at: clang/test/Analysis/constant-folding.c:420-423
+  if (ush > 1 && ssh < 1) {
+// ush: [2, USHRT_MAX], ssh: [SHRT_MIN, 0]
+clang_analyzer_eval(ush != ssh); // expected-warning{{UNKNOWN}}
+  }

It should return `TRUE`. https://godbolt.org/z/44Pax16d1


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a subscriber: MaskRay.
lenary added a comment.

New version, which changes how the move works a bit. I've updated the 
description with the caveats, so this is now definitely not NFC.

I'm looking for re-review, and maybe input from @MaskRay who has made some 
minor cleanups in this code recently.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary edited the summary of this revision.
lenary updated this revision to Diff 477975.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

Files:
  clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
  llvm/include/llvm/Support/Host.h
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/Threading.cpp
  llvm/lib/Support/Unix/Threading.inc
  llvm/lib/Support/Windows/Threading.inc
  llvm/unittests/Support/Host.cpp
  llvm/unittests/Support/Threading.cpp

Index: llvm/unittests/Support/Threading.cpp
===
--- llvm/unittests/Support/Threading.cpp
+++ llvm/unittests/Support/Threading.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "llvm/Support/Threading.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/thread.h"
 #include "gtest/gtest.h"
 
@@ -17,6 +19,18 @@
 
 namespace {
 
+static bool isThreadingSupportedArchAndOS() {
+  Triple Host(Triple::normalize(sys::getProcessTriple()));
+
+  // Initially this is only testing detection of the number of
+  // physical cores, which is currently only supported/tested on
+  // some systems.
+  return (Host.isOSWindows() && llvm_is_multithreaded()) ||
+  Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
+  (Host.isOSLinux() && !Host.isAndroid()) ||
+  (Host.isSystemZ() && Host.isOSzOS());
+}
+
 TEST(Threading, PhysicalConcurrency) {
   auto Num = heavyweight_hardware_concurrency();
   // Since Num is unsigned this will also catch us trying to
@@ -25,6 +39,20 @@
 hardware_concurrency().compute_thread_count());
 }
 
+TEST(Threading, NumPhysicalCoresSupported) {
+  if (!isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_GT(Num, 0);
+}
+
+TEST(Threading, NumPhysicalCoresUnsupported) {
+  if (isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_EQ(Num, -1);
+}
+
 #if LLVM_ENABLE_THREADS
 
 class Notification {
Index: llvm/unittests/Support/Host.cpp
===
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -30,37 +30,6 @@
 
 using namespace llvm;
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
-
 TEST(getLinuxHostCPUName, ARM) {
   StringRef CortexA9ProcCpuinfo = R"(
 processor   : 0
@@ -439,13 +408,13 @@
   return Success;
 }
 
-TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
+TEST(HostTest, DummyRunAndGetCommandOutputUse) {
   // Suppress defined-but-not-used warnings when the tests using the helper are
   // disabled.
   (void)
 }
 
-TEST_F(HostTest, getMacOSHostVersion) {
+TEST(HostTest, getMacOSHostVersion) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (!HostTriple.isMacOSX())
 GTEST_SKIP();
@@ -491,7 +460,7 @@
   .getOSVersion();
 }
 
-TEST_F(HostTest, AIXHostVersionDetect) {
+TEST(HostTest, AIXHostVersionDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -517,7 +486,7 @@
   ASSERT_EQ(SysMinor, HostVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXTargetVersionDetect) {
+TEST(HostTest, AIXTargetVersionDetect) {
   llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
   if (TargetTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -535,7 +504,7 @@
   ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXHostCPUDetect) {
+TEST(HostTest, AIXHostCPUDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
Index: llvm/lib/Support/Windows/Threading.inc
===
--- llvm/lib/Support/Windows/Threading.inc
+++ llvm/lib/Support/Windows/Threading.inc
@@ -238,8 +238,7 @@
   return I;
 }
 
-// for sys::getHostNumPhysicalCores
-int 

[PATCH] D138722: Overload all llvm.annotation intrinsics for globals argument

2022-11-25 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson created this revision.
arichardson added reviewers: arsenm, bader, Tyker, nikic.
Herald added subscribers: jrtc27, hiraditya.
Herald added a project: All.
arichardson requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, wdng.
Herald added projects: clang, LLVM.

The global constant arguments could be in a different address space
than the first argument, so we have to add another overloaded argument.
This patch was originally made for CHERI LLVM (where globals can be in
address space 200), but it also appears to be useful for in-tree targets
as can be seen from the test diffs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138722

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypeCache.h
  clang/test/CodeGen/annotations-field.c
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGen/annotations-loc.c
  clang/test/CodeGen/annotations-var.c
  clang/test/CodeGenCXX/attr-annotate.cpp
  clang/test/CodeGenCXX/attr-annotate2.cpp
  clang/test/CodeGenSYCL/field-annotate-addr-space.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/test/Analysis/CostModel/X86/free-intrinsics.ll
  llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll
  llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll
  llvm/test/Analysis/ScalarEvolution/annotation-intrinsics.ll
  llvm/test/Assembler/opaque-ptr-intrinsic-remangling.ll
  llvm/test/Bitcode/upgrade-annotation.ll
  llvm/test/Bitcode/upgrade-annotation.ll.bc
  llvm/test/Bitcode/upgrade-ptr-annotation.ll
  llvm/test/Bitcode/upgrade-var-annotation.ll
  llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
  llvm/test/Transforms/InstCombine/assume_inevitable.ll

Index: llvm/test/Transforms/InstCombine/assume_inevitable.ll
===
--- llvm/test/Transforms/InstCombine/assume_inevitable.ll
+++ llvm/test/Transforms/InstCombine/assume_inevitable.ll
@@ -10,11 +10,11 @@
 ; CHECK-NEXT:[[M:%.*]] = alloca i64, align 8
 ; CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A:%.*]], align 32
 ; CHECK-NEXT:[[LOADRES:%.*]] = load i32, ptr [[B:%.*]], align 4
-; CHECK-NEXT:[[LOADRES2:%.*]] = call i32 @llvm.annotation.i32(i32 [[LOADRES]], ptr nonnull @.str, ptr nonnull @.str1, i32 2)
+; CHECK-NEXT:[[LOADRES2:%.*]] = call i32 @llvm.annotation.i32.p0(i32 [[LOADRES]], ptr nonnull @.str, ptr nonnull @.str1, i32 2)
 ; CHECK-NEXT:store i32 [[LOADRES2]], ptr [[A]], align 32
 ; CHECK-NEXT:[[DUMMY_EQ:%.*]] = icmp ugt i32 [[LOADRES]], 42
 ; CHECK-NEXT:tail call void @llvm.assume(i1 [[DUMMY_EQ]])
-; CHECK-NEXT:[[M_A:%.*]] = call ptr @llvm.ptr.annotation.p0(ptr nonnull [[M]], ptr nonnull @.str, ptr nonnull @.str1, i32 2, ptr null)
+; CHECK-NEXT:[[M_A:%.*]] = call ptr @llvm.ptr.annotation.p0.p0(ptr nonnull [[M]], ptr nonnull @.str, ptr nonnull @.str1, i32 2, ptr null)
 ; CHECK-NEXT:[[OBJSZ:%.*]] = call i64 @llvm.objectsize.i64.p0(ptr [[C:%.*]], i1 false, i1 false, i1 false)
 ; CHECK-NEXT:store i64 [[OBJSZ]], ptr [[M_A]], align 4
 ; CHECK-NEXT:[[PTRINT:%.*]] = ptrtoint ptr [[A]] to i64
Index: llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
===
--- llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
+++ llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
@@ -12,7 +12,7 @@
 ; CHECK-LABEL: @annotated(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[C:%.*]], align 4
-; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.annotation.i32(i32 [[TMP0]], ptr undef, ptr undef, i32 undef)
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.annotation.i32.p0(i32 [[TMP0]], ptr undef, ptr undef, i32 undef)
 ; CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
 ; CHECK-NEXT:ret i32 [[ADD]]
 ;
Index: llvm/test/Bitcode/upgrade-var-annotation.ll
===
--- llvm/test/Bitcode/upgrade-var-annotation.ll
+++ llvm/test/Bitcode/upgrade-var-annotation.ll
@@ -1,15 +1,16 @@
 ; Test upgrade of var.annotation intrinsics.
 ;
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
 ; RUN: llvm-dis < %s.bc | FileCheck %s
 
 
 define void @f(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3) {
 ;CHECK: @f(i8* [[ARG0:%.*]], i8* [[ARG1:%.*]], i8* [[ARG2:%.*]], i32 [[ARG3:%.*]])
   call void @llvm.var.annotation(i8* %arg0, i8* %arg1, i8* %arg2, i32 %arg3)
-;CHECK:  call void @llvm.var.annotation(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
+;CHECK:  call void @llvm.var.annotation.p0i8.p0i8(i8* [[ARG0]], i8* [[ARG1]], i8* [[ARG2]], i32 [[ARG3]], i8* null)
   ret void
 }
 
 ; Function Attrs: nofree nosync nounwind willreturn
 declare void @llvm.var.annotation(i8*, i8*, i8*, i32)
-; CHECK: declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*)
+; CHECK: declare 

[clang] 38f5ab4 - Revert "[clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation"

2022-11-25 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2022-11-25T17:04:31+01:00
New Revision: 38f5ab4d44e3fa826006022aad377bb23ed357ca

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

LOG: Revert "[clang][modules] NFCI: Pragma diagnostic mappings: write/read 
FileID instead of SourceLocation"

This reverts commit f61c135a69084e470b73c26a8134785808ee246f. The commit affects
some build setups. See https://reviews.llvm.org/D137213#3939959.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index ceaade4a6e1e8..591eb34ec8839 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 24;
+const unsigned VERSION_MAJOR = 23;
 
 /// AST file minor version number supported by this version of
 /// Clang.

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8f7cb38c6a9f5..4c0395cc4107b 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6361,15 +6361,17 @@ void 
ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine ) {
 while (NumLocations--) {
   assert(Idx < Record.size() &&
  "Invalid data, missing pragma diagnostic states");
-  FileID FID = ReadFileID(F, Record, Idx);
-  assert(FID.isValid() && "invalid FileID for transition");
+  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
+  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
+  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
+  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
   unsigned Transitions = Record[Idx++];
 
   // Note that we don't need to set up Parent/ParentOffset here, because
   // we won't be changing the diagnostic state within imported FileIDs
   // (other than perhaps appending to the main source file, which has no
   // parent).
-  auto  = Diag.DiagStatesByLoc.Files[FID];
+  auto  = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
   F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
   for (unsigned I = 0; I != Transitions; ++I) {
 unsigned Offset = Record[Idx++];

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 220b2b9aca3fb..197bbe1b477ac 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3006,7 +3006,9 @@ void ASTWriter::WritePragmaDiagnosticMappings(const 
DiagnosticsEngine ,
   continue;
 ++NumLocations;
 
-AddFileID(FileIDAndFile.first, Record);
+SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 
0);
+assert(!Loc.isInvalid() && "start loc for valid FileID is invalid");
+AddSourceLocation(Loc, Record);
 
 Record.push_back(FileIDAndFile.second.StateTransitions.size());
 for (auto  : FileIDAndFile.second.StateTransitions) {



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


[PATCH] D119138: [clang-format] Further improve support for requires expressions

2022-11-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.
Herald added a project: All.

Hey ho, sorry for the late comment here, but adding peekNextToken(n) is 
problematic, as this gets in the way of future changes we want to do to handle 
macros better.
Usually we want to use X = Tokens->getPosition() and FormatTok = 
Tokens->setPosition(X) pairs when doing look-ahead.
I did a quick attempt at fixing this, but ran into infinite loops later in the 
annotator :(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119138/new/

https://reviews.llvm.org/D119138

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477960.
VitaNuo added a comment.

Apply the local changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -346,18 +346,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -233,14 +233,18 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
-Out->IWYUPublic.insert(
-{FE->getLastRef().getUniqueID(),
- save(Pragma->startswith("<") || Pragma->startswith("\"")
-  ? (*Pragma)
-  : ("\"" + *Pragma + "\"").str())});
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE)
+return false;
+  StringRef PublicHeader;
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
+PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
+? (*Pragma)
+: ("\"" + *Pragma + "\"").str());
+  }
+  Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader});
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ -346,6 +350,10 @@
   return !NonSelfContainedFiles.contains(FE->getUniqueID());
 }
 
+bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
+  return IWYUPublic.find(FE->getUniqueID()) != IWYUPublic.end();
+}
+
 std::unique_ptr RecordedAST::record() {
   class Recorder : public ASTConsumer {
 RecordedAST *Out;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
@@ -17,16 +17,15 @@
 #ifndef CLANG_INCLUDE_CLEANER_RECORD_H
 #define CLANG_INCLUDE_CLEANER_RECORD_H
 
+#include "clang-include-cleaner/Types.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
-#include "clang-include-cleaner/Types.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/StringMap.h"
 #include 
 #include 
 
@@ -73,6 +72,9 @@
   /// Returns true if the given file is a self-contained file.
   bool isSelfContained(const FileEntry *File) const;
 
+  /// Returns true if the given file is marked with the IWYU private pragma.
+  bool isPrivate(const FileEntry *File) const;
+
 private:
   class RecordPragma;
   /// 1-based Line numbers for the #include directives of the main file that
@@ -80,7 +82,8 @@
   /// export` right after).
   llvm::DenseSet ShouldKeep;
 
-  /// The public header mapping by the IWYU private pragma.
+  /// The public header mapping by the IWYU private pragma. For private pragmas
+  //  without public mapping an empty StringRef is stored.
   //
   

[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2022-11-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

It'll be better to expand existing `init-variables.cpp` test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138655/new/

https://reviews.llvm.org/D138655

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477958.
VitaNuo added a comment.

Fix history.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
@@ -257,27 +256,6 @@
   EXPECT_THAT(RefOffsets, ElementsAreArray(MainFile.points()));
 }
 
-TEST_F(RecordPPTest, CapturesIfDefMacroRefs) {
-  llvm::Annotations MainFile(R"cpp(
-#define X 1
-#ifdef $def^X
- #define Y 2
-#endif
-  )cpp");
-
-  Inputs.Code = MainFile.code();
-  auto AST = build();
-  ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
-
-  SourceManager  = AST.sourceManager();
-  SourceLocation Def = SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
-
-  SymbolReference XRef = Recorded.MacroReferences.front();
-  EXPECT_EQ(XRef.RT, RefType::Ambiguous);
-  EXPECT_EQ("X", XRef.Target.macro().Name->getName());
-  EXPECT_EQ(XRef.RefLocation, Def);
-}
-
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
 
@@ -368,18 +346,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -53,7 +53,7 @@
 SourceRange Range, const MacroArgs *Args) override {
 if (!Active)
   return;
-recordMacroRef(MacroName, *MD.getMacroInfo(), RefType::Explicit);
+recordMacroRef(MacroName, *MD.getMacroInfo());
   }
 
   void MacroDefined(const Token , const MacroDirective *MD) override {
@@ -71,7 +71,7 @@
   llvm::is_contained(MI->params(), II))
 continue;
   if (const MacroInfo *MI = PP.getMacroInfo(II))
-recordMacroRef(Tok, *MI, RefType::Explicit);
+recordMacroRef(Tok, *MI);
 }
   }
 
@@ -80,11 +80,11 @@
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
-  recordMacroRef(MacroName, *MI, RefType::Explicit);
+  recordMacroRef(MacroName, *MI);
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
- const MacroDefinition ) override {
+ const MacroDefinition ) override {
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
@@ -124,13 +124,13 @@
   }
 
 private:
-  void recordMacroRef(const Token , const MacroInfo , RefType RT) {
+  void recordMacroRef(const Token , const MacroInfo ,
+  RefType RT = RefType::Explicit) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(
-SymbolReference{Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
-RT});
+Recorded.MacroReferences.push_back(SymbolReference{
+Tok.getLocation(),
+Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
   }
 
   bool Active = false;
@@ -233,14 +233,18 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
-Out->IWYUPublic.insert(
-   

[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477956.
VitaNuo marked 2 inline comments as done.
VitaNuo added a comment.

Fix build.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -346,18 +346,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -53,7 +53,7 @@
 SourceRange Range, const MacroArgs *Args) override {
 if (!Active)
   return;
-recordMacroRef(MacroName, *MD.getMacroInfo());
+recordMacroRef(MacroName, *MD.getMacroInfo(), RefType::Explicit);
   }
 
   void MacroDefined(const Token , const MacroDirective *MD) override {
@@ -71,7 +71,7 @@
   llvm::is_contained(MI->params(), II))
 continue;
   if (const MacroInfo *MI = PP.getMacroInfo(II))
-recordMacroRef(Tok, *MI);
+recordMacroRef(Tok, *MI, RefType::Explicit);
 }
   }
 
@@ -80,7 +80,7 @@
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
-  recordMacroRef(MacroName, *MI);
+  recordMacroRef(MacroName, *MI, RefType::Explicit);
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
@@ -124,8 +124,7 @@
   }
 
 private:
-  void recordMacroRef(const Token , const MacroInfo ,
-  RefType RT = RefType::Explicit) {
+  void recordMacroRef(const Token , const MacroInfo , RefType RT) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
 Recorded.MacroReferences.push_back(SymbolReference{
@@ -233,14 +232,18 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
-Out->IWYUPublic.insert(
-{FE->getLastRef().getUniqueID(),
- save(Pragma->startswith("<") || Pragma->startswith("\"")
-  ? (*Pragma)
-  : ("\"" + *Pragma + "\"").str())});
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE)
+return false;
+  StringRef PublicHeader;
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
+PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
+? (*Pragma)
+: ("\"" + *Pragma + "\"").str());
+  }
+  Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader});
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ -346,6 +349,10 @@
   return !NonSelfContainedFiles.contains(FE->getUniqueID());
 }
 
+bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
+  return IWYUPublic.find(FE->getUniqueID()) != IWYUPublic.end();
+}
+
 std::unique_ptr RecordedAST::record() {
   class Recorder : public ASTConsumer {
 RecordedAST *Out;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
@@ -17,16 +17,15 @@
 #ifndef 

[PATCH] D138713: Fix assertion failure "PathDiagnosticSpotPiece's must have a valid location." in ReturnPtrRange checker on builtin functions

2022-11-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal resigned from this revision.
steakhal added a comment.
Herald added a subscriber: steakhal.

I already reviewed this internally. For me, it looks great.

@arseniy-sonar consider adding the `Fixes #55347` marker to the summary, so the 
commit will auto-reference the fixed issue.
Also mention the commit author sign to which we should accredit this revision 
if accepted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138713/new/

https://reviews.llvm.org/D138713

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:237
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE) {
+return false;

kadircet wrote:
> nit: you can drop the braces here. LLVM convention is to not have braces when 
> a condition/loop body has only a single statement.
Ah ok, thank you. It's a bit funny, my whole life until now I've been 
rigorously taught to never do this ;-)



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:240
+  }
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.

kadircet wrote:
> nit: you can also rewrite this as:
> ```
> StringRef PublicHeader;
> if (Pragma->consume_front(", include ")) {
>   PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
>   ? (*Pragma)
>   : ("\"" + *Pragma + "\"").str());
> }
> Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader});
> ```
Yeah this is good, thanks.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:381
+// IWYU pragma: private
+class Private {};
+  )cpp";

kadircet wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > nit: no need for the declaration of `Private` here (nor in `private.h`). 
> > > it's actually introducing a double definition error into TU now.
> > Out of curiosity: what's TU?
> it means `translation unit`, it's the source file provided to the compiler 
> after all preprocessor directives are processed.
Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477954.
VitaNuo added a comment.

Small refactoring.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
@@ -257,27 +256,6 @@
   EXPECT_THAT(RefOffsets, ElementsAreArray(MainFile.points()));
 }
 
-TEST_F(RecordPPTest, CapturesIfDefMacroRefs) {
-  llvm::Annotations MainFile(R"cpp(
-#define X 1
-#ifdef $def^X
- #define Y 2
-#endif
-  )cpp");
-
-  Inputs.Code = MainFile.code();
-  auto AST = build();
-  ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
-
-  SourceManager  = AST.sourceManager();
-  SourceLocation Def = SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
-
-  SymbolReference XRef = Recorded.MacroReferences.front();
-  EXPECT_EQ(XRef.RT, RefType::Ambiguous);
-  EXPECT_EQ("X", XRef.Target.macro().Name->getName());
-  EXPECT_EQ(XRef.RefLocation, Def);
-}
-
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
 
@@ -368,18 +346,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -84,7 +84,7 @@
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
- const MacroDefinition ) override {
+ const MacroDefinition ) override {
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
@@ -127,10 +127,9 @@
   void recordMacroRef(const Token , const MacroInfo , RefType RT) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(
-SymbolReference{Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
-RT});
+Recorded.MacroReferences.push_back(SymbolReference{
+Tok.getLocation(),
+Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
   }
 
   bool Active = false;
@@ -233,14 +232,18 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
-Out->IWYUPublic.insert(
-{FE->getLastRef().getUniqueID(),
- save(Pragma->startswith("<") || Pragma->startswith("\"")
-  ? (*Pragma)
-  : ("\"" + *Pragma + "\"").str())});
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE)
+return false;
+  StringRef PublicHeader;
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
+PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
+? (*Pragma)
+: ("\"" + *Pragma + "\"").str());
+  }
+  Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader});
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ 

[PATCH] D138713: Fix assertion failure "PathDiagnosticSpotPiece's must have a valid location." in ReturnPtrRange checker on builtin functions

2022-11-25 Thread Arseniy Zaostrovnykh via Phabricator via cfe-commits
arseniy-sonar created this revision.
arseniy-sonar added reviewers: xazax.hun, martong, NoQ, Szelethus, steakhal.
arseniy-sonar added a project: clang.
Herald added a subscriber: rnkovacs.
Herald added a project: All.
arseniy-sonar requested review of this revision.
Herald added a subscriber: cfe-commits.

This fixes https://github.com/llvm/llvm-project/issues/55347
Builtin functions (such ast `std::move`, `std::forward`, `std::as_const`) have 
a body generated during the analysis not related to any source file so their 
statements have no valid source locations.
ReturnPtrRange checker should not report issues for these builtin functions 
because they only forward its parameter and do not create any new pointers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138713

Files:
  clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
  clang/test/Analysis/return-ptr-range.cpp


Index: clang/test/Analysis/return-ptr-range.cpp
===
--- clang/test/Analysis/return-ptr-range.cpp
+++ clang/test/Analysis/return-ptr-range.cpp
@@ -115,3 +115,14 @@
 
 }
 
+namespace std {
+// A builtin function with the body generated on the fly.
+template  T&& move(T &&) noexcept;
+} // namespace std
+
+char buf[2];
+
+void top() {
+  // see https://github.com/llvm/llvm-project/issues/55347
+  (void)std::move(*(buf + 3)); // no-crash
+}
Index: clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
@@ -41,6 +41,13 @@
   if (!RetE)
 return;
 
+  // Skip calls to built-in functions because such functions might feature
+  // a return statement with no valid source location.
+  if (const CallExpr *CE =
+  dyn_cast_or_null(C.getStackFrame()->getCallSite());
+  CE && CE->getBuiltinCallee() != 0)
+return;
+
   SVal V = C.getSVal(RetE);
   const MemRegion *R = V.getAsRegion();
 


Index: clang/test/Analysis/return-ptr-range.cpp
===
--- clang/test/Analysis/return-ptr-range.cpp
+++ clang/test/Analysis/return-ptr-range.cpp
@@ -115,3 +115,14 @@
 
 }
 
+namespace std {
+// A builtin function with the body generated on the fly.
+template  T&& move(T &&) noexcept;
+} // namespace std
+
+char buf[2];
+
+void top() {
+  // see https://github.com/llvm/llvm-project/issues/55347
+  (void)std::move(*(buf + 3)); // no-crash
+}
Index: clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
@@ -41,6 +41,13 @@
   if (!RetE)
 return;
 
+  // Skip calls to built-in functions because such functions might feature
+  // a return statement with no valid source location.
+  if (const CallExpr *CE =
+  dyn_cast_or_null(C.getStackFrame()->getCallSite());
+  CE && CE->getBuiltinCallee() != 0)
+return;
+
   SVal V = C.getSVal(RetE);
   const MemRegion *R = V.getAsRegion();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D137836#3950883 , @lenary wrote:

> In D137836#3950846 , @fhahn wrote:
>
>> (it looks like this job should have sent an email: 
>> https://green.lab.llvm.org/green/job/clang-stage1-RA/32031/console)
>
> Yeah, sorry, no email. I'll check with colleagues to see if other people do 
> get emails from this CI instance.

Thanks for confirming, I'll let the maintainers know.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[clang-tools-extra] db335d0 - [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr

2022-11-25 Thread Ilya Biryukov via cfe-commits

Author: Jens Massberg
Date: 2022-11-25T15:45:37+01:00
New Revision: db335d02a5e7d98c24f7006e42129856ba1cd695

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

LOG: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls 
in modernize-use-nullptr

The check has produced false positives when checking the default implementation 
of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix 
and add another test case.

Fixes #53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index 5ca2be2eb556d..220a310a0d4e4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -62,7 +62,9 @@ StatementMatcher makeCastSequenceMatcher() {
 ImplicitCastToNull,
 hasAncestor(cxxRewrittenBinaryOperator().bind(
 "checkBinopOperands")))
-.bind(CastSequence));
+.bind(CastSequence))),
+// Skip defaulted comparison operators.
+unless(hasAncestor(functionDecl(isDefaulted()));
 }
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
index b00cb5787ea07..be59d4ed1d056 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@ constexpr strong_ordering strong_ordering::less = {-1};
 } // namespace std
 
 class A {
+  int a;
 public:
   auto operator<=>(const A ) const = default;
+  // CHECK-FIXES: auto operator<=>(const A ) const = default;
 };
 
 void test_cxx_rewritten_binary_ops() {
@@ -32,3 +58,14 @@ void test_cxx_rewritten_binary_ops() {
   result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
   // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : 
a2));
 }
+
+template
+struct P {
+  T1 x1;
+  T2 x2;
+  friend auto operator<=>(const P&, const P&) = default;
+  // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;
+};
+
+bool foo(P x, P y) { return x < y; }
+// CHECK-FIXES: bool foo(P x, P y) { return x < y; }



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


[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.

2022-11-25 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb335d02a5e7: [clang-tidy] Ignore cxxRewrittenBinaryOperator 
in defaulted function decls in… (authored by massberg, committed by 
ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138701/new/

https://reviews.llvm.org/D138701

Files:
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@
 } // namespace std
 
 class A {
+  int a;
 public:
   auto operator<=>(const A ) const = default;
+  // CHECK-FIXES: auto operator<=>(const A ) const = default;
 };
 
 void test_cxx_rewritten_binary_ops() {
@@ -32,3 +58,14 @@
   result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
   // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : 
a2));
 }
+
+template
+struct P {
+  T1 x1;
+  T2 x2;
+  friend auto operator<=>(const P&, const P&) = default;
+  // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;
+};
+
+bool foo(P x, P y) { return x < y; }
+// CHECK-FIXES: bool foo(P x, P y) { return x < y; }
Index: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -62,7 +62,9 @@
 ImplicitCastToNull,
 hasAncestor(cxxRewrittenBinaryOperator().bind(
 "checkBinopOperands")))
-.bind(CastSequence));
+.bind(CastSequence))),
+// Skip defaulted comparison operators.
+unless(hasAncestor(functionDecl(isDefaulted()));
 }
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@
 } // namespace std
 
 class A {
+  int a;
 public:
 

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D137836#3950846 , @fhahn wrote:

> (it looks like this job should have sent an email: 
> https://green.lab.llvm.org/green/job/clang-stage1-RA/32031/console)

Yeah, sorry, no email. I'll check with colleagues to see if other people do get 
emails from this CI instance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:237
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE) {
+return false;

nit: you can drop the braces here. LLVM convention is to not have braces when a 
condition/loop body has only a single statement.



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:240
+  }
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.

nit: you can also rewrite this as:
```
StringRef PublicHeader;
if (Pragma->consume_front(", include ")) {
  PublicHeader = save(Pragma->startswith("<") || Pragma->startswith("\"")
  ? (*Pragma)
  : ("\"" + *Pragma + "\"").str());
}
Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), PublicHeader});
```



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:381
+// IWYU pragma: private
+class Private {};
+  )cpp";

VitaNuo wrote:
> kadircet wrote:
> > nit: no need for the declaration of `Private` here (nor in `private.h`). 
> > it's actually introducing a double definition error into TU now.
> Out of curiosity: what's TU?
it means `translation unit`, it's the source file provided to the compiler 
after all preprocessor directives are processed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477946.
VitaNuo added a comment.

Fix comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
@@ -257,27 +256,6 @@
   EXPECT_THAT(RefOffsets, ElementsAreArray(MainFile.points()));
 }
 
-TEST_F(RecordPPTest, CapturesIfDefMacroRefs) {
-  llvm::Annotations MainFile(R"cpp(
-#define X 1
-#ifdef $def^X
- #define Y 2
-#endif
-  )cpp");
-
-  Inputs.Code = MainFile.code();
-  auto AST = build();
-  ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
-
-  SourceManager  = AST.sourceManager();
-  SourceLocation Def = SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
-
-  SymbolReference XRef = Recorded.MacroReferences.front();
-  EXPECT_EQ(XRef.RT, RefType::Ambiguous);
-  EXPECT_EQ("X", XRef.Target.macro().Name->getName());
-  EXPECT_EQ(XRef.RefLocation, Def);
-}
-
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
 
@@ -368,18 +346,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -84,7 +84,7 @@
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
- const MacroDefinition ) override {
+ const MacroDefinition ) override {
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
@@ -127,10 +127,9 @@
   void recordMacroRef(const Token , const MacroInfo , RefType RT) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(
-SymbolReference{Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
-RT});
+Recorded.MacroReferences.push_back(SymbolReference{
+Tok.getLocation(),
+Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
   }
 
   bool Active = false;
@@ -233,14 +232,21 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE) {
+return false;
+  }
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
 Out->IWYUPublic.insert(
 {FE->getLastRef().getUniqueID(),
  save(Pragma->startswith("<") || Pragma->startswith("\"")
   ? (*Pragma)
   : ("\"" + *Pragma + "\"").str())});
+  } else {
+Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), StringRef()});
+  }
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ -346,6 +352,10 @@
   return !NonSelfContainedFiles.contains(FE->getUniqueID());
 }
 
+bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
+  return IWYUPublic.find(FE->getUniqueID()) != 

[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477944.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Fix build.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -256,6 +256,28 @@
   EXPECT_THAT(RefOffsets, ElementsAreArray(MainFile.points()));
 }
 
+TEST_F(RecordPPTest, CapturesIfDefMacroRefs) {
+  llvm::Annotations MainFile(R"cpp(
+#define X 1
+#ifdef $def^X
+ #define Y 2
+#endif
+  )cpp");
+
+  Inputs.Code = MainFile.code();
+  auto AST = build();
+  ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
+
+  SourceManager  = AST.sourceManager();
+  SourceLocation Def =
+  SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
+
+  SymbolReference XRef = Recorded.MacroReferences.front();
+  EXPECT_EQ(XRef.RT, RefType::Ambiguous);
+  EXPECT_EQ("X", XRef.Target.macro().Name->getName());
+  EXPECT_EQ(XRef.RefLocation, Def);
+}
+
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
 
@@ -346,18 +368,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -53,7 +53,7 @@
 SourceRange Range, const MacroArgs *Args) override {
 if (!Active)
   return;
-recordMacroRef(MacroName, *MD.getMacroInfo());
+recordMacroRef(MacroName, *MD.getMacroInfo(), RefType::Explicit);
   }
 
   void MacroDefined(const Token , const MacroDirective *MD) override {
@@ -71,7 +71,7 @@
   llvm::is_contained(MI->params(), II))
 continue;
   if (const MacroInfo *MI = PP.getMacroInfo(II))
-recordMacroRef(Tok, *MI);
+recordMacroRef(Tok, *MI, RefType::Explicit);
 }
   }
 
@@ -80,7 +80,7 @@
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
-  recordMacroRef(MacroName, *MI);
+  recordMacroRef(MacroName, *MI, RefType::Explicit);
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
@@ -124,8 +124,7 @@
   }
 
 private:
-  void recordMacroRef(const Token , const MacroInfo ,
-  RefType RT = RefType::Explicit) {
+  void recordMacroRef(const Token , const MacroInfo , RefType RT) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
 Recorded.MacroReferences.push_back(SymbolReference{
@@ -233,14 +232,21 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE) {
+return false;
+  }
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
 Out->IWYUPublic.insert(
 {FE->getLastRef().getUniqueID(),
  save(Pragma->startswith("<") || Pragma->startswith("\"")
   ? (*Pragma)
   : ("\"" + *Pragma + "\"").str())});
+  } else {
+Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), StringRef()});
+  }
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ -346,6 +352,10 @@
   return 

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

(it looks like this job should have sent an email: 
https://green.lab.llvm.org/green/job/clang-stage1-RA/32031/console)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[clang] d65019b - [NFC] Clean up printing of UnwrappedLines.

2022-11-25 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-11-25T14:26:47Z
New Revision: d65019bbcb0a33502ebfc3cfc492e4d3cee9c7b7

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

LOG: [NFC] Clean up printing of UnwrappedLines.

Move print functions to start of UnwarppedLineParser so they can be
used from everywhere in the file.
Pull out function that doesn't hard-code the stream.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4dc70e2d56c70..3bc7d2454c93a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -64,6 +64,39 @@ class FormatTokenSource {
 
 namespace {
 
+void printLine(llvm::raw_ostream , const UnwrappedLine ,
+   StringRef Prefix = "", bool PrintText = false) {
+  OS << Prefix << "Line(" << Line.Level << ", FSC=" << Line.FirstStartColumn
+ << ")" << (Line.InPPDirective ? " MACRO" : "") << ": ";
+  bool NewLine = false;
+  for (std::list::const_iterator I = Line.Tokens.begin(),
+E = Line.Tokens.end();
+   I != E; ++I) {
+if (NewLine) {
+  OS << Prefix;
+  NewLine = false;
+}
+OS << I->Tok->Tok.getName() << "["
+   << "T=" << (unsigned)I->Tok->getType()
+   << ", OC=" << I->Tok->OriginalColumn << ", \"" << I->Tok->TokenText
+   << "\"] ";
+for (SmallVectorImpl::const_iterator
+ CI = I->Children.begin(),
+ CE = I->Children.end();
+ CI != CE; ++CI) {
+  OS << "\n";
+  printLine(OS, *CI, (Prefix + "  ").str());
+  NewLine = true;
+}
+  }
+  if (!NewLine)
+OS << "\n";
+}
+
+LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine ) {
+  printLine(llvm::dbgs(), Line);
+}
+
 class ScopedDeclarationState {
 public:
   ScopedDeclarationState(UnwrappedLine , llvm::BitVector ,
@@ -4314,23 +4347,6 @@ void UnwrappedLineParser::parseVerilogCaseLabel() {
   Line->Level = OrigLevel;
 }
 
-LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine ,
- StringRef Prefix = "") {
-  llvm::dbgs() << Prefix << "Line(" << Line.Level
-   << ", FSC=" << Line.FirstStartColumn << ")"
-   << (Line.InPPDirective ? " MACRO" : "") << ": ";
-  for (const auto  : Line.Tokens) {
-llvm::dbgs() << Node.Tok->Tok.getName() << "["
- << "T=" << static_cast(Node.Tok->getType())
- << ", OC=" << Node.Tok->OriginalColumn << "] ";
-  }
-  for (const auto  : Line.Tokens)
-for (const auto  : Node.Children)
-  printDebugInfo(ChildNode, "\nChild: ");
-
-  llvm::dbgs() << "\n";
-}
-
 void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
   if (Line->Tokens.empty())
 return;



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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D137836#3950825 , @lenary wrote:

> In D137836#3950815 , @fhahn wrote:
>
>> Unfortunately it looks like this commit breaks building on ARM64 macOS. I 
>> reverted the change for now and added more details on the error in the 
>> revert commit.
>
> Thanks for reverting. I hadn't seen any buildbot messages about this until 
> now. It's annoying there's no mac pre-merge testing.

FYI macOS testing is happening on https://green.lab.llvm.org. The failing build 
is 
https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/32875/console.
 From the log it looks like the bot didn't send an email though. Just to double 
check, you didn't receive an email notification about this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138709: Reland "[Lex] Fix suggested spelling of /usr/bin/../include/foo"

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: clang/lib/Lex/HeaderSearch.cpp:1936
+  path::remove_dots(FilePath, /*remove_dot_dot=*/true);
+  path::native(FilePath, path::Style::posix);
+  File = FilePath;

might be worth adding a comment like `we can't pass posix as style to 
remove_dots, because it won't canonicalize "a\.\b.h"`



Comment at: clang/unittests/Lex/HeaderSearchTest.cpp:155
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/x/../y/z",
+   /*WorkingDir=*/"",

can you also add a new test that looks like:
```
addSearchDir("x/");
EXPECT(suggestForDiag("x\y\z.h"), "y/z.h");
```

as in theory that's the new behaviour we're adding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138709/new/

https://reviews.llvm.org/D138709

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


[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.

2022-11-25 Thread Jens Massberg via Phabricator via cfe-commits
massberg marked 2 inline comments as done.
massberg added a comment.

Thanks for the comments!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138701/new/

https://reviews.llvm.org/D138701

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

In D137836#3950815 , @fhahn wrote:

> Unfortunately it looks like this commit breaks building on ARM64 macOS. I 
> reverted the change for now and added more details on the error in the revert 
> commit.

Thanks for reverting. I hadn't seen any buildbot messages about this until now. 
It's annoying there's no mac pre-merge testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.

2022-11-25 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 477941.
massberg added a comment.

Add comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138701/new/

https://reviews.llvm.org/D138701

Files:
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@
 } // namespace std
 
 class A {
+  int a;
 public:
   auto operator<=>(const A ) const = default;
+  // CHECK-FIXES: auto operator<=>(const A ) const = default;
 };
 
 void test_cxx_rewritten_binary_ops() {
@@ -32,3 +58,14 @@
   result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
   // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : 
a2));
 }
+
+template
+struct P {
+  T1 x1;
+  T2 x2;
+  friend auto operator<=>(const P&, const P&) = default;
+  // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;
+};
+
+bool foo(P x, P y) { return x < y; }
+// CHECK-FIXES: bool foo(P x, P y) { return x < y; }
Index: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -62,7 +62,9 @@
 ImplicitCastToNull,
 hasAncestor(cxxRewrittenBinaryOperator().bind(
 "checkBinopOperands")))
-.bind(CastSequence));
+.bind(CastSequence))),
+// Skip defaulted comparison operators.
+unless(hasAncestor(functionDecl(isDefaulted()));
 }
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@
 } // namespace std
 
 class A {
+  int a;
 public:
   auto operator<=>(const A ) const = default;
+  // CHECK-FIXES: auto operator<=>(const A ) const = default;
 };
 
 void test_cxx_rewritten_binary_ops() {
@@ -32,3 +58,14 @@
   result = (a1 > ((a1 > (ptr == 

[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked 4 inline comments as done.
VitaNuo added a comment.

The formatting has introduced a bit of unrelated diff. It's not much, so I hope 
that's fine.




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:95
+  /// Contains all files marked with IWYU private pragmas that
+  /// do not have public header mapping. This uses the UniqueID similar to
+  /// the IWYU private pragmas with public mapping.

hokein wrote:
> It should collect files with mapping IWYU private pragmas.
> 
> and I think the last sentence can be removed (the intention of using UniqueID 
> is clear from other comments).
I've followed Kadir's suggestion below now and merged the private pragmas with 
the IWYUPublic map.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:97
+  /// the IWYU private pragmas with public mapping.
+  llvm::DenseSet IWYUPrivate;
+

kadircet wrote:
> i'd actually merge this with the previous map, and store empty verbatim 
> spellings. semantics of `getPublic` is to return empty path when there are no 
> mappings anyway.
Sounds reasonable. I wasn't sure which of the options to pick in the first 
place.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:381
+// IWYU pragma: private
+class Private {};
+  )cpp";

kadircet wrote:
> nit: no need for the declaration of `Private` here (nor in `private.h`). it's 
> actually introducing a double definition error into TU now.
Out of curiosity: what's TU?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Unfortunately it looks like this commit breaks building on ARM64 macOS. I 
reverted the change for now and added more details on the error in the revert 
commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 477940.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
@@ -270,7 +269,8 @@
   ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
 
   SourceManager  = AST.sourceManager();
-  SourceLocation Def = SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
+  SourceLocation Def =
+  SM.getComposedLoc(SM.getMainFileID(), MainFile.point("def"));
 
   SymbolReference XRef = Recorded.MacroReferences.front();
   EXPECT_EQ(XRef.RT, RefType::Ambiguous);
@@ -368,18 +368,29 @@
   Inputs.Code = R"cpp(
 #include "public.h"
   )cpp";
-  Inputs.ExtraFiles["public.h"] = "#include \"private.h\"";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h"
+  )cpp";
   Inputs.ExtraFiles["private.h"] = R"cpp(
 // IWYU pragma: private, include "public2.h"
-class Private {};
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
   )cpp";
   TestAST Processed = build();
   auto PrivateFE = Processed.fileManager().getFile("private.h");
   assert(PrivateFE);
+  EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
+
   EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
   auto PublicFE = Processed.fileManager().getFile("public.h");
   assert(PublicFE);
   EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
+
+  auto Private2FE = Processed.fileManager().getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExport) {
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -84,7 +84,7 @@
   }
 
   void Ifdef(SourceLocation Loc, const Token ,
- const MacroDefinition ) override {
+ const MacroDefinition ) override {
 if (!Active)
   return;
 if (const auto *MI = MD.getMacroInfo())
@@ -127,10 +127,9 @@
   void recordMacroRef(const Token , const MacroInfo , RefType RT) {
 if (MI.isBuiltinMacro())
   return; // __FILE__ is not a reference.
-Recorded.MacroReferences.push_back(
-SymbolReference{Tok.getLocation(),
-Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()},
-RT});
+Recorded.MacroReferences.push_back(SymbolReference{
+Tok.getLocation(),
+Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT});
   }
 
   bool Active = false;
@@ -233,14 +232,21 @@
 if (!Pragma)
   return false;
 
-if (Pragma->consume_front("private, include ")) {
-  // We always insert using the spelling from the pragma.
-  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
+if (Pragma->consume_front("private")) {
+  auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin()));
+  if (!FE) {
+return false;
+  }
+  if (Pragma->consume_front(", include ")) {
+// We always insert using the spelling from the pragma.
 Out->IWYUPublic.insert(
 {FE->getLastRef().getUniqueID(),
  save(Pragma->startswith("<") || Pragma->startswith("\"")
   ? (*Pragma)
   : ("\"" + *Pragma + "\"").str())});
+  } else {
+Out->IWYUPublic.insert({FE->getLastRef().getUniqueID(), StringRef()});
+  }
   return false;
 }
 FileID CommentFID = SM.getFileID(Range.getBegin());
@@ -346,6 +352,10 @@
   return !NonSelfContainedFiles.contains(FE->getUniqueID());
 }
 
+bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
+  return IWYUPublic.find(FE->getUniqueID()) != IWYUPublic.end();
+}
+
 std::unique_ptr RecordedAST::record() {
   class Recorder : public ASTConsumer {
 RecordedAST *Out;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
+++ 

[clang-tools-extra] 07ca9cc - Revert "[Support] Move getHostNumPhysicalCores to Threading.h"

2022-11-25 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2022-11-25T14:11:56Z
New Revision: 07ca9cc04bc2d57730507ad5ab444a1fd56cae11

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

LOG: Revert "[Support] Move getHostNumPhysicalCores to Threading.h"

This reverts commit 5577207d6d3e0642ea047a8dfbfcf3ad372a7f25.

This breaks building LLVM on recent macOS. Error messages below:

llvm/lib/Support/Threading.cpp:190:3: error: use of undeclared
identifier 'sysctlbyname'
  sysctlbyname("hw.physicalcpu", , , NULL, 0);
^

llvm/lib/Support/Threading.cpp:193:13: error: use of undeclared
identifier 'CTL_HW'
nm[0] = CTL_HW;
^

llvm/lib/Support/Threading.cpp:194:13: error: use of undeclared identifier 
'HW_AVAILCPU'
nm[1] = HW_AVAILCPU;
^

llvm/lib/Support/Threading.cpp:195:5: error: use of undeclared identifier 
'sysctl'
sysctl(nm, 2, , , NULL, 0);
^

Added: 


Modified: 
clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
llvm/include/llvm/Support/Host.h
llvm/include/llvm/Support/Threading.h
llvm/lib/Support/Host.cpp
llvm/lib/Support/Threading.cpp
llvm/unittests/Support/Host.cpp
llvm/unittests/Support/Threading.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h 
b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
index bf760e367ff78..3b7620adafb10 100644
--- a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
+++ b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
@@ -7,7 +7,11 @@ class Dex;
 } // namespace clang
 
 namespace llvm {
-int get_physical_cores();
+namespace sys {
+
+int getHostNumPhysicalCores();
+
+} // namespace sys
 } // namespace llvm
 
 namespace {

diff  --git a/llvm/include/llvm/Support/Host.h 
b/llvm/include/llvm/Support/Host.h
index dcebebdca6cb7..369d6745db5ae 100644
--- a/llvm/include/llvm/Support/Host.h
+++ b/llvm/include/llvm/Support/Host.h
@@ -54,6 +54,11 @@ namespace sys {
   /// \return - True on success.
   bool getHostCPUFeatures(StringMap );
 
+  /// Get the number of physical cores (as opposed to logical cores returned
+  /// from thread::hardware_concurrency(), which includes hyperthreads).
+  /// Returns -1 if unknown for the current host system.
+  int getHostNumPhysicalCores();
+
   namespace detail {
   /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
   StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent);

diff  --git a/llvm/include/llvm/Support/Threading.h 
b/llvm/include/llvm/Support/Threading.h
index f3f7c44bd439a..7f2708ddbb467 100644
--- a/llvm/include/llvm/Support/Threading.h
+++ b/llvm/include/llvm/Support/Threading.h
@@ -231,11 +231,6 @@ constexpr bool llvm_is_multithreaded() { return 
LLVM_ENABLE_THREADS; }
   /// Returns how many physical CPUs or NUMA groups the system has.
   unsigned get_cpus();
 
-  /// Returns how many physical cores (as opposed to logical cores returned 
from
-  /// thread::hardware_concurrency(), which includes hyperthreads).
-  /// Returns -1 if unknown for the current host system.
-  int get_physical_cores();
-
   enum class ThreadPriority {
 /// Lower the current thread's priority as much as possible. Can be used
 /// for long-running tasks that are not time critical; more energy-

diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index c87d9644d0979..713227c4b088c 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1576,6 +1576,128 @@ VendorSignatures getVendorSignature(unsigned *MaxLeaf) {
 } // namespace llvm
 #endif
 
+#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
+// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
+// using the number of unique physical/core id pairs. The following
+// implementation reads the /proc/cpuinfo format on an x86_64 system.
+static int computeHostNumPhysicalCores() {
+  // Enabled represents the number of physical id/core id pairs with at least
+  // one processor id enabled by the CPU affinity mask.
+  cpu_set_t Affinity, Enabled;
+  if (sched_getaffinity(0, sizeof(Affinity), ) != 0)
+return -1;
+  CPU_ZERO();
+
+  // Read /proc/cpuinfo as a stream (until EOF reached). It cannot be
+  // mmapped because it appears to have 0 size.
+  llvm::ErrorOr> Text =
+  llvm::MemoryBuffer::getFileAsStream("/proc/cpuinfo");
+  if (std::error_code EC = Text.getError()) {
+llvm::errs() << "Can't read "
+ << "/proc/cpuinfo: " << EC.message() << "\n";
+return -1;
+  }
+  SmallVector strs;
+  (*Text)->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
+ /*KeepEmpty=*/false);
+  int CurProcessor = -1;
+  int CurPhysicalId = -1;
+  int CurSiblings = -1;
+  int CurCoreId = -1;
+  for (StringRef Line : strs) {
+

[PATCH] D124351: [Clang][WIP] Implement Change scope of lambda trailing-return-type - Take 2

2022-11-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 477938.
cor3ntin added a comment.

Rebase. This is still a bit rough, I have a few tests to fix
and some dead code to remove.

---

@erichkeanne I wouldn't mind picking your brain on this.
Consider:

  template 
  void dependent_init_capture(T x = 0) {
[y = x] () requires (decltype(y){1}) {
  return y;
}();
  }
  
  void test_dependent() {
dependent_init_capture(0);
  }

This used to ""work"" in the previous iteration of the patch,
but with the late concept checking it seems more involved.

My understanding so far is that in `CheckFunctionConstraints` 
we can't find an instanciated declaration of `y` (so it asserts in 
`LocalInstantiationScope::findInstantiationOf`).

I'm not 100% sure of what's the correct approach here would be. 
My guess is that we might need to retransform the captures  in the 
instanciation scope used 
for constraint checking? 
I'm not actually sure whether an instanciation of the lambda does exist at that 
point in some other scope, 
though. Ideally we would not instannciate lambdas more times than needed.

Another issue is that there is no way to walk back from a call expression to a 
lambda expression,
so we might need to add that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124351/new/

https://reviews.llvm.org/D124351

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1358,7 +1358,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3;>P2036R3
-  No
+  Clang 16
 
 
   https://wg21.link/P2579R0;>P2579R0
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,248 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [ = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+
+  static_assert(noexcept([&] mutable noexcept(!is_same) {}())); // expected-error {{static_assert failed due}}
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  []() requires 

[PATCH] D138709: Reland "[Lex] Fix suggested spelling of /usr/bin/../include/foo"

2022-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 1dc0a1e5d220b83c1074204bd3afd54f3bac4270 
.

Failures were caused by unintentional conversion to native slashes by
remove_dots, so undo that: we always suggest posix slashes for includes.

This could potentially be a change in behavior on windows if people were
spelling headers with backslashes and headermaps contained backslashes,
but that's all underspecified and I don't think anyone uses headermaps
on windows.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138709

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -150,6 +150,14 @@
 "z");
 }
 
+TEST_F(HeaderSearchTest, BothDotDots) {
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/x/../y/z",
+   /*WorkingDir=*/"",
+   /*MainFile=*/""),
+"z");
+}
+
 TEST_F(HeaderSearchTest, IncludeFromSameDirectory) {
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z/t.h",
/*WorkingDir=*/"",
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1928,32 +1928,27 @@
 llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile,
 bool *IsSystem) {
   using namespace llvm::sys;
+  
+  llvm::SmallString<32> FilePath = File;
+  // remove_dots switches to backslashes on windows as a side-effect!
+  // We always want to suggest forward slashes for includes.
+  path::remove_dots(FilePath, /*remove_dot_dot=*/true);
+  path::native(FilePath, path::Style::posix);
+  File = FilePath;
 
   unsigned BestPrefixLength = 0;
   // Checks whether `Dir` is a strict path prefix of `File`. If so and that's
   // the longest prefix we've seen so for it, returns true and updates the
   // `BestPrefixLength` accordingly.
-  auto CheckDir = [&](llvm::StringRef Dir) -> bool {
-llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
+  auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool {
 if (!WorkingDir.empty() && !path::is_absolute(Dir))
-  fs::make_absolute(WorkingDir, DirPath);
-path::remove_dots(DirPath, /*remove_dot_dot=*/true);
-Dir = DirPath;
+  fs::make_absolute(WorkingDir, Dir);
+path::remove_dots(Dir, /*remove_dot_dot=*/true);
 for (auto NI = path::begin(File), NE = path::end(File),
   DI = path::begin(Dir), DE = path::end(Dir);
- /*termination condition in loop*/; ++NI, ++DI) {
-  // '.' components in File are ignored.
-  while (NI != NE && *NI == ".")
-++NI;
-  if (NI == NE)
-break;
-
-  // '.' components in Dir are ignored.
-  while (DI != DE && *DI == ".")
-++DI;
+ NI != NE; ++NI, ++DI) {
   if (DI == DE) {
-// Dir is a prefix of File, up to '.' components and choice of path
-// separators.
+// Dir is a prefix of File, up to choice of path separators.
 unsigned PrefixLength = NI - path::begin(File);
 if (PrefixLength > BestPrefixLength) {
   BestPrefixLength = PrefixLength;


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -150,6 +150,14 @@
 "z");
 }
 
+TEST_F(HeaderSearchTest, BothDotDots) {
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/x/../y/z",
+   /*WorkingDir=*/"",
+   /*MainFile=*/""),
+"z");
+}
+
 TEST_F(HeaderSearchTest, IncludeFromSameDirectory) {
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z/t.h",
/*WorkingDir=*/"",
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1928,32 +1928,27 @@
 llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile,
 bool *IsSystem) {
   using namespace llvm::sys;
+  
+  llvm::SmallString<32> FilePath = File;
+  // remove_dots switches to backslashes on windows as a side-effect!
+  // We always want to suggest forward slashes for includes.
+  

[PATCH] D137213: [clang][modules] NFCI: Pragma diagnostic mappings: write/read FileID instead of SourceLocation

2022-11-25 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:6343
  "Invalid data, missing pragma diagnostic states");
-  SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
-  auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
-  assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
-  assert(IDAndOffset.second == 0 && "not a start location for a FileID");
+  FileID FID = ReadFileID(F, Record, Idx);
+  assert(FID.isValid() && "invalid FileID for transition");

dexonsmith wrote:
> eaeltsin wrote:
> > This doesn't work as before, likely because ReadFileID doesn't do 
> > TranslateSourceLocation.
> > 
> > Our tests fail.
> > 
> > I tried calling TranslateSourceLocation here and the tests passed:
> > ```
> >   SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FID, 0);
> >   SourceLocation Loc2 = TranslateSourceLocation(F, Loc);
> >   auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc2);
> > 
> >   // Note that we don't need to set up Parent/ParentOffset here, because
> >   // we won't be changing the diagnostic state within imported FileIDs
> >   // (other than perhaps appending to the main source file, which has no
> >   // parent).
> >   auto  = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
> > ```
> > 
> > Sorry I don't know the codebase, so this fix is definitely ugly :) But it 
> > shows the problem.
> > 
> I don't think that's the issue, since `ReadFileID()` calls `TranslateFileID`, 
> which should seems like it should be equivalent.
> 
> However, I notice that the post-increment for `Idx` got dropped! Can you try 
> replacing the line of code with the following and see if that fixes your 
> tests (without any extra TranslateSourceLocation logic)?
> ```
> lang=c++
> FileID FID = ReadFileID(F, Record, Idx++);
> ```
> 
> If so, maybe you can contribute that fix with a reduced testcase? I suggest 
> adding me, @vsapsai, @Bigcheese, and @jansvoboda11 as reviewers.
> 
> @alexfh, maybe you can check if this fixes your tests as well?
> 
> (If this is the issue, it's a bit surprising we don't have existing tests 
> covering this case... and embarrassing I missed it when reviewing initially!)
I've noticed the dropped `Idx` post-increment as well, but I went a step 
further and looked at the `ReadFileID` implementation, which is actually doing 
a post-increment itself, and accepts `Idx` by reference:
```
  FileID ReadFileID(ModuleFile , const RecordDataImpl ,
unsigned ) const {
return TranslateFileID(F, FileID::get(Record[Idx++]));
  }
```

Thus, it seems to be correct. But what @eaeltsin  has found is actually a 
problem for us.  I'm currently trying to make an isolated test case, but it's 
quite tricky (as header modules are =\). It may be the case that our build 
setup relies on something clang doesn't explicitly promises, but the fact is 
that the behavior (as observed by our build setup) has changed. I'll try to 
revert the commit for now to get us unblocked and provide a test case as soon 
as I can.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137213/new/

https://reviews.llvm.org/D137213

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


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-11-25 Thread Manuel Klimek via cfe-commits
Fixed in ca8c6156f27003ffa0e24bace2be7c25307f50a3.

On Thu, Jul 21, 2022 at 3:21 PM Manuel Klimek  wrote:

> Ping :)
>
> On Mon, Jul 18, 2022 at 1:22 PM Manuel Klimek  wrote:
>
>> Ping :)
>>
>> On Wed, Jul 13, 2022 at 11:43 AM Manuel Klimek  wrote:
>>
>>> This is a functional change, as it removes the debug output when the
>>> tokens do not match, which is important for understanding test failures.
>>>
>>> On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>

 Author: Jorge Gorbe Moya
 Date: 2022-07-12T16:46:58-07:00
 New Revision: ee88c0cf09969ba44307068797e12533b94768a6

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

 LOG: [NFCI] Fix unused variable/function warnings in
 MacroCallReconstructorTest.cpp when asserts are disabled.

 Added:


 Modified:
 clang/unittests/Format/MacroCallReconstructorTest.cpp

 Removed:




 
 diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
 b/clang/unittests/Format/MacroCallReconstructorTest.cpp
 index 2bda62aa42be..3abe0383aeae 100644
 --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
 +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
 @@ -91,14 +91,6 @@ struct Chunk {
llvm::SmallVector Children;
  };

 -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
 -  if (Left->getType() == Right->getType() &&
 -  Left->TokenText == Right->TokenText)
 -return true;
 -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText <<
 "\n";
 -  return false;
 -}
 -
  // Allows to produce chunks of a token list by typing the code of
 equal tokens.
  //
  // Created from a list of tokens, users call "consume" to get the next
 chunk
 @@ -110,7 +102,9 @@ struct Matcher {
Chunk consume(StringRef Tokens) {
  TokenList Result;
  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
 -  assert(tokenMatches(*It, Token));
 +  (void)Token;  // Fix unused variable warning when asserts are
 disabled.
 +  assert((*It)->getType() == Token->getType() &&
 + (*It)->TokenText == Token->TokenText);
Result.push_back(*It);
++It;
  }



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

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-11-25 Thread Manas Gupta via Phabricator via cfe-commits
manas updated this revision to Diff 477934.
manas added a comment.

Fix test cases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constant-folding.c

Index: clang/test/Analysis/constant-folding.c
===
--- clang/test/Analysis/constant-folding.c
+++ clang/test/Analysis/constant-folding.c
@@ -281,3 +281,149 @@
 clang_analyzer_eval((b % a) < x + 10); // expected-warning{{TRUE}}
   }
 }
+
+void testDisequalityRules(unsigned int u1, unsigned int u2, unsigned int u3,
+  int s1, int s2, int s3, unsigned char uch,
+  signed char sch, short ssh, unsigned short ush) {
+  // Checks for overflowing values
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+1, INT_MIN+2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (u1 > INT_MAX && u1 <= UINT_MAX / 2 + 4 && u1 != UINT_MAX / 2 + 2 &&
+  u1 != UINT_MAX / 2 + 3 && s1 >= INT_MIN + 1 && s1 <= INT_MIN + 2) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+1, INT_MIN+2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (u1 >= INT_MIN && u1 <= INT_MIN + 2 &&
+  s1 > INT_MIN + 2 && s1 < INT_MIN + 4) {
+// u1: [INT_MAX+1, INT_MAX+1]U[INT_MAX+4, INT_MAX+4],
+// s1: [INT_MIN+3, INT_MIN+3]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 0 && s1 > -4 && u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 < 1 && s1 > -6 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-5, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  if (s1 < 1 && s1 > -7 && s1 != -4 && s1 != -3 &&
+  u1 > UINT_MAX - 4 && u1 < UINT_MAX - 1) {
+// s1: [-6, -5]U[-2, 0], u1: [UINT_MAX - 3, UINT_MAX - 2]
+clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}
+  }
+
+  // Check when RHS is in between two Ranges in LHS
+  if (((u1 >= 1 && u1 <= 2) || (u1 >= 8 && u1 <= 9)) &&
+  u2 >= 5 && u2 <= 6) {
+// u1: [1, 2]U[8, 9], u2: [5, 6]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  // Checks for concrete value with same type
+  if (u1 > 1 && u1 < 3 && u2 > 1 && u2 < 3) {
+// u1: [2, 2], u2: [2, 2]
+clang_analyzer_eval(u1 != u2); // expected-warning{{FALSE}}
+  }
+
+  // Check for concrete value with different types
+  if (u1 > 4 && u1 < 6 && s1 > 4 && s1 < 6) {
+// u1: [5, 5], s1: [5, 5]
+clang_analyzer_eval(u1 != s1); // expected-warning{{FALSE}}
+  }
+
+  // Checks when ranges are not overlapping
+  if (u1 <= 10 && u2 >= 20) {
+// u1: [0,10], u2: [20,UINT_MAX]
+clang_analyzer_eval(u1 != u2); // expected-warning{{TRUE}}
+  }
+
+  if (s1 <= INT_MIN + 10 && s2 >= INT_MAX - 10) {
+// s1: [INT_MIN,INT_MIN + 10], s2: [INT_MAX - 10,INT_MAX]
+clang_analyzer_eval(s1 != s2); // expected-warning{{TRUE}}
+  }
+
+  // Checks when ranges are completely overlapping and have more than one point
+  if (u1 >= 20 && u1 <= 50 && u2 >= 20 && u2 <= 50) {
+// u1: [20,50], u2: [20,50]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -20 && s1 <= 20 && s2 >= -20 && s2 <= 20) {
+// s1: [-20,20], s2: [-20,20]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks when ranges are partially overlapping
+  if (u1 >= 100 && u1 <= 200 && u2 >= 150 && u2 <= 300) {
+// u1: [100,200], u2: [150,300]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -80 && s1 <= -50 && s2 >= -100 && s2 <= -75) {
+// s1: [-80,-50], s2: [-100,-75]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for ranges which are subset of one-another
+  if (u1 >= 500 && u1 <= 1000 && u2 >= 750 && u2 <= 1000) {
+// u1: [500,1000], u2: [750,1000]
+clang_analyzer_eval(u1 != u2); // expected-warning{{UNKNOWN}}
+  }
+
+  if (s1 >= -1000 && s1 <= -500 && s2 >= -750 && s2 <= -500) {
+// s1: [-1000,-500], s2: [-750, -500]
+clang_analyzer_eval(s1 != s2); // expected-warning{{UNKNOWN}}
+  }
+
+  // Checks for comparison between different types
+  // Using different variables as previous constraints may interfere in the
+  // reasoning.
+  if (u3 <= 255 && s3 < 0) {
+// u3: [0, 255], s3: [INT_MIN, -1]
+clang_analyzer_eval(u3 != s3); // expected-warning{{TRUE}}
+  }
+
+  // Checks for char-uchar 

[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-11-25 Thread Manas Gupta via Phabricator via cfe-commits
manas added a comment.



In D112621#3949400 , @steakhal wrote:

> `Analysis/constant-folding.c` seems to fail.
> Please run the `check-clang-analysis` build target to see what fails and 
> investigate it.

@steakhal thank you for reviewing this! I investigated about the failing tests.

  // s1: [-3, -1], u1: [UINT_MAX - 3, UINT_MAX - 2]
  clang_analyzer_eval(u1 != s1); // expected-warning{{TRUE}}# Line: 312
  
  // uch: [2, CHAR_MAX], sch: [SCHAR_MIN, 0]
  clang_analyzer_eval(uch != sch); // expected-warning{{TRUE}}  # Line: 406
  
  // ush: [2, USHRT_MAX], ssh: [SHRT_MIN, 0]
  clang_analyzer_eval(ush != ssh); // expected-warning{{TRUE}}  # Line: 422

Above tests are failing.

Previously, it was discussed that a good strategy is to "cast both [LHS and 
RHS] to the biggest type or unsigned one."

And for example, in the first failing test case, casting both rangesets,
`s1 = [-3,-1] -> [UINT_MAX-2, UINT_MAX]` and `u1 = [UINT_MAX-3, UINT_MAX-2] 
->(unchanged) [UINT_MAX-3, UINT_MAX-2]`

`UINT_MAX -2` is overlapping  in both RangeSets.

Casting signed types to unsigned ones can leave us with overlapping values as 
shown above. Essentially, these tests were wrongly written. So, I am correcting 
these tests accordingly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

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


[clang] ca8c615 - Fix test output regression from ee88c0cf09969ba44307068797e12533b94768a6.

2022-11-25 Thread Manuel Klimek via cfe-commits

Author: Manuel Klimek
Date: 2022-11-25T13:53:34Z
New Revision: ca8c6156f27003ffa0e24bace2be7c25307f50a3

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

LOG: Fix test output regression from ee88c0cf09969ba44307068797e12533b94768a6.

The unused variable fix also remove the test output of the tokens
that do not match, making debugging tests harder. Undo the semantic
changes of the build fix.

Added: 


Modified: 
clang/unittests/Format/MacroCallReconstructorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index 2b880d75b514f..eee980bae8d8b 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -97,12 +97,20 @@ struct Matcher {
   Matcher(const TokenList , TestLexer )
   : Tokens(Tokens), It(this->Tokens.begin()), Lex(Lex) {}
 
+  bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
+if (Left->getType() == Right->getType() &&
+Left->TokenText == Right->TokenText) {
+  return true;
+}
+llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
+return false;
+  }
+
   Chunk consume(StringRef Tokens) {
 TokenList Result;
 for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
   (void)Token; // Fix unused variable warning when asserts are disabled.
-  assert((*It)->getType() == Token->getType() &&
- (*It)->TokenText == Token->TokenText);
+  assert(tokenMatches(*It, Token));
   Result.push_back(*It);
   ++It;
 }



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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

another thing that i noticed is usage of east consts in the implementation 
files. no one seem to have brought it up so far (at least none that i can see).
in theory there are no explicit guidelines about it in LLVM coding style, but 
rest of the codebase uses west const convention. so i am not sure if straying 
away from it here will make much sense.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:215
"-bugprone-use-after-move",
+   // Using an CFG and might crash on invalid code:
+   "-performance-unnecessary-copy-on-last-use",

comment seems half-finished here. is there any other reason than trying to 
analyze `CFG` for invalid code?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137205/new/

https://reviews.llvm.org/D137205

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


[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-11-25 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:76
   ConstructorOrDestructor,
+  UserProvided,
 

sammccall wrote:
> ckandeler wrote:
> > sammccall wrote:
> > > sammccall wrote:
> > > > nridge wrote:
> > > > > ckandeler wrote:
> > > > > > ckandeler wrote:
> > > > > > > sammccall wrote:
> > > > > > > > sammccall wrote:
> > > > > > > > > sammccall wrote:
> > > > > > > > > > Can you give some background here or on the bug tracker 
> > > > > > > > > > about what kind of distinction you're trying to draw here 
> > > > > > > > > > and why it's important?
> > > > > > > > > > (Most clients are never going to benefit from nonstandard 
> > > > > > > > > > modifiers so they should be pretty compelling)
> > > > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > > > 
> > > > > > > > > If we need this and can't get away with reusing 
> > > > > > > > > `defaultLibrary` (which would include `std::`) then maybe we 
> > > > > > > > > should add something like `builtin` which seems quite 
> > > > > > > > > reusable.
> > > > > > > > Since we often can't say whether an operator is user-provided 
> > > > > > > > or not (in templates), we should consider what we want the 
> > > > > > > > highlighting to be in these cases.
> > > > > > > > (If templates should be highlighted as built-in, we should 
> > > > > > > > prefer a modifier like `UserProvided`, if they should be 
> > > > > > > > highlighted as user-provided, we should prefer a modifier like 
> > > > > > > > `Builtin`)
> > > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > > 
> > > > > > > > If we need this and can't get away with reusing 
> > > > > > > > `defaultLibrary` (which would include `std::`) then maybe we 
> > > > > > > > should add something like `builtin` which seems quite reusable.
> > > > > > > 
> > > > > > > I use "userProvided" here in the sense of "not built-in" or 
> > > > > > > "overloaded". I do not cling to the term, and have also suggested 
> > > > > > > the opposite default of using "builtin" in another comment.
> > > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > > not (in templates), we should consider what we want the 
> > > > > > > highlighting to be in these cases.
> > > > > > 
> > > > > > True, I have not considered this.
> > > > > > 
> > > > > > > (If templates should be highlighted as built-in, we should prefer 
> > > > > > > a modifier like `UserProvided`, if they should be highlighted as 
> > > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > > 
> > > > > > Intuitively, it seems we should be conservative and not claim the 
> > > > > > operator is overloaded unless we know it is. So "built-in" might 
> > > > > > then mean "we can't prove it's not a built-in". It's probably not 
> > > > > > worth to introduce a modifier CouldBeEitherWay just to explicitly 
> > > > > > express ambiguity ;)
> > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > not (in templates), we should consider what we want the 
> > > > > > highlighting to be in these cases.
> > > > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > 
> > > > > In my mind, "go-to-definition on this operator symbol will take me to 
> > > > > a function declaration/definition" is a good match for "I want this 
> > > > > colored differently". (Which would imply treating dependent operator 
> > > > > calls where we can't figure out an overloaded operator target even 
> > > > > heuristically, as "built-in".)
> > > > > Can you give some background here or on the bug tracker about what 
> > > > > kind of distinction you're trying to draw here and why it's important?
> > > > > (Most clients are never going to benefit from nonstandard modifiers 
> > > > > so they should be pretty compelling)
> > > > 
> > > > This was one of the biggest questions I had about this patch - just 
> > > > hoping it doesn't get missed.
> > > > Intuitively, it seems we should be conservative and not claim the 
> > > > operator is overloaded unless we know it is. 
> > > 
> > > This feels a bit circular, if we agree we're not going to introduce a 
> 

[PATCH] D138489: [tsan] Add tsan support for loongarch64

2022-11-25 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1543
+"r"(__fn), "r"(__arg), "r"(nr_clone), "i"(__NR_exit)
+  : "memory");
+  return res;

xry111 wrote:
> xry111 wrote:
> > SixWeining wrote:
> > > tangyouling wrote:
> > > > SixWeining wrote:
> > > > > Shall we list $t0-$t8 here? Ref D137396.
> > > > > Shall we list $t0-$t8 here? Ref D137396.
> > > > 
> > > > I will add the missing $t0-$t8.
> > > As this inline asm is almost at the end of the function, it's sure `$t*` 
> > > would not be used any more. So I think we could not add them to the 
> > > clobber list. Just keep current approach.
> > It's hard to tell: the compiler may decide to inline this function of 
> > perform some inter-procedural analysis.  So IMO we should add t0-t8 here.
> > It's hard to tell: the compiler may decide to inline this function of 
> > perform some inter-procedural analysis.  So IMO we should add t0-t8 here.
> 
> "or perform", not "of perform".
Make sense. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138489/new/

https://reviews.llvm.org/D138489

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


[clang] 1dc0a1e - Revert "[Lex] Fix suggested spelling of /usr/bin/../include/foo"

2022-11-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-11-25T14:01:39+01:00
New Revision: 1dc0a1e5d220b83c1074204bd3afd54f3bac4270

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

LOG: Revert "[Lex] Fix suggested spelling of /usr/bin/../include/foo"

This reverts commit 8bed59c7e7da2fea41a9167e15c15a8f58a5ede7.

Breaks bots e.g. https://lab.llvm.org/buildbot/#/builders/216/builds/13282

Added: 


Modified: 
clang/lib/Lex/HeaderSearch.cpp
clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 




diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 0615002734e94..e6af122949709 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1928,24 +1928,32 @@ std::string 
HeaderSearch::suggestPathToFileForDiagnostics(
 llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile,
 bool *IsSystem) {
   using namespace llvm::sys;
-  
-  llvm::SmallString<32> FilePath = File;
-  path::remove_dots(FilePath, /*remove_dot_dot=*/true);
-  File = FilePath;
 
   unsigned BestPrefixLength = 0;
   // Checks whether `Dir` is a strict path prefix of `File`. If so and that's
   // the longest prefix we've seen so for it, returns true and updates the
   // `BestPrefixLength` accordingly.
-  auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool {
+  auto CheckDir = [&](llvm::StringRef Dir) -> bool {
+llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
 if (!WorkingDir.empty() && !path::is_absolute(Dir))
-  fs::make_absolute(WorkingDir, Dir);
-path::remove_dots(Dir, /*remove_dot_dot=*/true);
+  fs::make_absolute(WorkingDir, DirPath);
+path::remove_dots(DirPath, /*remove_dot_dot=*/true);
+Dir = DirPath;
 for (auto NI = path::begin(File), NE = path::end(File),
   DI = path::begin(Dir), DE = path::end(Dir);
- NI != NE; ++NI, ++DI) {
+ /*termination condition in loop*/; ++NI, ++DI) {
+  // '.' components in File are ignored.
+  while (NI != NE && *NI == ".")
+++NI;
+  if (NI == NE)
+break;
+
+  // '.' components in Dir are ignored.
+  while (DI != DE && *DI == ".")
+++DI;
   if (DI == DE) {
-// Dir is a prefix of File, up to choice of path separators.
+// Dir is a prefix of File, up to '.' components and choice of path
+// separators.
 unsigned PrefixLength = NI - path::begin(File);
 if (PrefixLength > BestPrefixLength) {
   BestPrefixLength = PrefixLength;

diff  --git a/clang/unittests/Lex/HeaderSearchTest.cpp 
b/clang/unittests/Lex/HeaderSearchTest.cpp
index 939f5a7210d8a..5024f0d3d6b00 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -150,14 +150,6 @@ TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
 "z");
 }
 
-TEST_F(HeaderSearchTest, BothDotDots) {
-  addSearchDir("/x/../y/");
-  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/x/../y/z",
-   /*WorkingDir=*/"",
-   /*MainFile=*/""),
-"z");
-}
-
 TEST_F(HeaderSearchTest, IncludeFromSameDirectory) {
   EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z/t.h",
/*WorkingDir=*/"",



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


[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:76
   ConstructorOrDestructor,
+  UserProvided,
 

ckandeler wrote:
> sammccall wrote:
> > sammccall wrote:
> > > nridge wrote:
> > > > ckandeler wrote:
> > > > > ckandeler wrote:
> > > > > > sammccall wrote:
> > > > > > > sammccall wrote:
> > > > > > > > sammccall wrote:
> > > > > > > > > Can you give some background here or on the bug tracker about 
> > > > > > > > > what kind of distinction you're trying to draw here and why 
> > > > > > > > > it's important?
> > > > > > > > > (Most clients are never going to benefit from nonstandard 
> > > > > > > > > modifiers so they should be pretty compelling)
> > > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > > 
> > > > > > > > If we need this and can't get away with reusing 
> > > > > > > > `defaultLibrary` (which would include `std::`) then maybe we 
> > > > > > > > should add something like `builtin` which seems quite reusable.
> > > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > > not (in templates), we should consider what we want the 
> > > > > > > highlighting to be in these cases.
> > > > > > > (If templates should be highlighted as built-in, we should prefer 
> > > > > > > a modifier like `UserProvided`, if they should be highlighted as 
> > > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > 
> > > > > > > If we need this and can't get away with reusing `defaultLibrary` 
> > > > > > > (which would include `std::`) then maybe we should add something 
> > > > > > > like `builtin` which seems quite reusable.
> > > > > > 
> > > > > > I use "userProvided" here in the sense of "not built-in" or 
> > > > > > "overloaded". I do not cling to the term, and have also suggested 
> > > > > > the opposite default of using "builtin" in another comment.
> > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > not (in templates), we should consider what we want the 
> > > > > > highlighting to be in these cases.
> > > > > 
> > > > > True, I have not considered this.
> > > > > 
> > > > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > 
> > > > > Intuitively, it seems we should be conservative and not claim the 
> > > > > operator is overloaded unless we know it is. So "built-in" might then 
> > > > > mean "we can't prove it's not a built-in". It's probably not worth to 
> > > > > introduce a modifier CouldBeEitherWay just to explicitly express 
> > > > > ambiguity ;)
> > > > > Since we often can't say whether an operator is user-provided or not 
> > > > > (in templates), we should consider what we want the highlighting to 
> > > > > be in these cases.
> > > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > 
> > > > In my mind, "go-to-definition on this operator symbol will take me to a 
> > > > function declaration/definition" is a good match for "I want this 
> > > > colored differently". (Which would imply treating dependent operator 
> > > > calls where we can't figure out an overloaded operator target even 
> > > > heuristically, as "built-in".)
> > > > Can you give some background here or on the bug tracker about what kind 
> > > > of distinction you're trying to draw here and why it's important?
> > > > (Most clients are never going to benefit from nonstandard modifiers so 
> > > > they should be pretty compelling)
> > > 
> > > This was one of the biggest questions I had about this patch - just 
> > > hoping it doesn't get missed.
> > > Intuitively, it seems we should be conservative and not claim the 
> > > operator is overloaded unless we know it is. 
> > 
> > This feels a bit circular, if we agree we're not going to introduce a 
> > `CouldBeEitherWay` then why is "built-in" a more conservative claim than 
> > "overloaded"?
> > 
> > I'm inclined towards `builtin` as a modifier because I think for language 
> > entities as a whole (types, 

[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-11-25 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.






Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:76
   ConstructorOrDestructor,
+  UserProvided,
 

sammccall wrote:
> sammccall wrote:
> > nridge wrote:
> > > ckandeler wrote:
> > > > ckandeler wrote:
> > > > > sammccall wrote:
> > > > > > sammccall wrote:
> > > > > > > sammccall wrote:
> > > > > > > > Can you give some background here or on the bug tracker about 
> > > > > > > > what kind of distinction you're trying to draw here and why 
> > > > > > > > it's important?
> > > > > > > > (Most clients are never going to benefit from nonstandard 
> > > > > > > > modifiers so they should be pretty compelling)
> > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > 
> > > > > > > If we need this and can't get away with reusing `defaultLibrary` 
> > > > > > > (which would include `std::`) then maybe we should add something 
> > > > > > > like `builtin` which seems quite reusable.
> > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > not (in templates), we should consider what we want the 
> > > > > > highlighting to be in these cases.
> > > > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > > as well as being jargony, "user-provided" has a specific technical 
> > > > > > meaning that I don't think you intend here. For example, `auto 
> > > > > > operator<=>(const S&) const = default` is not user-provided 
> > > > > > (defaulted on first declaration). 
> > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > 
> > > > > > If we need this and can't get away with reusing `defaultLibrary` 
> > > > > > (which would include `std::`) then maybe we should add something 
> > > > > > like `builtin` which seems quite reusable.
> > > > > 
> > > > > I use "userProvided" here in the sense of "not built-in" or 
> > > > > "overloaded". I do not cling to the term, and have also suggested the 
> > > > > opposite default of using "builtin" in another comment.
> > > > > Since we often can't say whether an operator is user-provided or not 
> > > > > (in templates), we should consider what we want the highlighting to 
> > > > > be in these cases.
> > > > 
> > > > True, I have not considered this.
> > > > 
> > > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > 
> > > > Intuitively, it seems we should be conservative and not claim the 
> > > > operator is overloaded unless we know it is. So "built-in" might then 
> > > > mean "we can't prove it's not a built-in". It's probably not worth to 
> > > > introduce a modifier CouldBeEitherWay just to explicitly express 
> > > > ambiguity ;)
> > > > Since we often can't say whether an operator is user-provided or not 
> > > > (in templates), we should consider what we want the highlighting to be 
> > > > in these cases.
> > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > user-provided, we should prefer a modifier like `Builtin`)
> > > 
> > > In my mind, "go-to-definition on this operator symbol will take me to a 
> > > function declaration/definition" is a good match for "I want this colored 
> > > differently". (Which would imply treating dependent operator calls where 
> > > we can't figure out an overloaded operator target even heuristically, as 
> > > "built-in".)
> > > Can you give some background here or on the bug tracker about what kind 
> > > of distinction you're trying to draw here and why it's important?
> > > (Most clients are never going to benefit from nonstandard modifiers so 
> > > they should be pretty compelling)
> > 
> > This was one of the biggest questions I had about this patch - just hoping 
> > it doesn't get missed.
> > Intuitively, it seems we should be conservative and not claim the operator 
> > is overloaded unless we know it is. 
> 
> This feels a bit circular, if we agree we're not going to introduce a 
> `CouldBeEitherWay` then why is "built-in" a more conservative claim than 
> "overloaded"?
> 
> I'm inclined towards `builtin` as a modifier because I think for language 
> entities as a whole (types, functions etc, not just operators) it's the 
> exception. It also seems easier to name and define.
> 
> > In my mind, "go-to-definition on this operator symbol will take me to a 
> > function 

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5577207d6d3e: [Support] Move getHostNumPhysicalCores to 
Threading.h (authored by lenary).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

Files:
  clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
  llvm/include/llvm/Support/Host.h
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/Threading.cpp
  llvm/unittests/Support/Host.cpp
  llvm/unittests/Support/Threading.cpp

Index: llvm/unittests/Support/Threading.cpp
===
--- llvm/unittests/Support/Threading.cpp
+++ llvm/unittests/Support/Threading.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "llvm/Support/Threading.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/thread.h"
 #include "gtest/gtest.h"
 
@@ -17,6 +19,18 @@
 
 namespace {
 
+static bool isThreadingSupportedArchAndOS() {
+  Triple Host(Triple::normalize(sys::getProcessTriple()));
+
+  // Initially this is only testing detection of the number of
+  // physical cores, which is currently only supported/tested on
+  // some systems.
+  return (Host.isOSWindows() && llvm_is_multithreaded()) ||
+  Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
+  (Host.isOSLinux() && !Host.isAndroid()) ||
+  (Host.isSystemZ() && Host.isOSzOS());
+}
+
 TEST(Threading, PhysicalConcurrency) {
   auto Num = heavyweight_hardware_concurrency();
   // Since Num is unsigned this will also catch us trying to
@@ -25,6 +39,20 @@
 hardware_concurrency().compute_thread_count());
 }
 
+TEST(Threading, NumPhysicalCoresSupported) {
+  if (!isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_GT(Num, 0);
+}
+
+TEST(Threading, NumPhysicalCoresUnsupported) {
+  if (isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_EQ(Num, -1);
+}
+
 #if LLVM_ENABLE_THREADS
 
 class Notification {
Index: llvm/unittests/Support/Host.cpp
===
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -30,37 +30,6 @@
 
 using namespace llvm;
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
-
 TEST(getLinuxHostCPUName, ARM) {
   StringRef CortexA9ProcCpuinfo = R"(
 processor   : 0
@@ -439,13 +408,13 @@
   return Success;
 }
 
-TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
+TEST(HostTest, DummyRunAndGetCommandOutputUse) {
   // Suppress defined-but-not-used warnings when the tests using the helper are
   // disabled.
   (void)
 }
 
-TEST_F(HostTest, getMacOSHostVersion) {
+TEST(HostTest, getMacOSHostVersion) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (!HostTriple.isMacOSX())
 GTEST_SKIP();
@@ -491,7 +460,7 @@
   .getOSVersion();
 }
 
-TEST_F(HostTest, AIXHostVersionDetect) {
+TEST(HostTest, AIXHostVersionDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -517,7 +486,7 @@
   ASSERT_EQ(SysMinor, HostVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXTargetVersionDetect) {
+TEST(HostTest, AIXTargetVersionDetect) {
   llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
   if (TargetTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -535,7 +504,7 @@
   ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXHostCPUDetect) {
+TEST(HostTest, AIXHostCPUDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
Index: llvm/lib/Support/Threading.cpp
===
--- llvm/lib/Support/Threading.cpp
+++ llvm/lib/Support/Threading.cpp
@@ -13,8 +13,12 @@
 
 #include 

[clang-tools-extra] 5577207 - [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2022-11-25T12:51:36Z
New Revision: 5577207d6d3e0642ea047a8dfbfcf3ad372a7f25

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

LOG: [Support] Move getHostNumPhysicalCores to Threading.h

This change is focussed on simplifying `Support/Host.h` to only do
target detection. In this case, this function is close in usage to
existing functions in `Support/Threading.h`, so I moved it into there.
The function is also renamed to `llvm::get_physical_cores()` to match
the style of threading's functions.

Differential Revision: https://reviews.llvm.org/D137836

Added: 


Modified: 
clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
llvm/include/llvm/Support/Host.h
llvm/include/llvm/Support/Threading.h
llvm/lib/Support/Host.cpp
llvm/lib/Support/Threading.cpp
llvm/unittests/Support/Host.cpp
llvm/unittests/Support/Threading.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h 
b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
index 3b7620adafb10..bf760e367ff78 100644
--- a/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
+++ b/clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
@@ -7,11 +7,7 @@ class Dex;
 } // namespace clang
 
 namespace llvm {
-namespace sys {
-
-int getHostNumPhysicalCores();
-
-} // namespace sys
+int get_physical_cores();
 } // namespace llvm
 
 namespace {

diff  --git a/llvm/include/llvm/Support/Host.h 
b/llvm/include/llvm/Support/Host.h
index 369d6745db5ae..dcebebdca6cb7 100644
--- a/llvm/include/llvm/Support/Host.h
+++ b/llvm/include/llvm/Support/Host.h
@@ -54,11 +54,6 @@ namespace sys {
   /// \return - True on success.
   bool getHostCPUFeatures(StringMap );
 
-  /// Get the number of physical cores (as opposed to logical cores returned
-  /// from thread::hardware_concurrency(), which includes hyperthreads).
-  /// Returns -1 if unknown for the current host system.
-  int getHostNumPhysicalCores();
-
   namespace detail {
   /// Helper functions to extract HostCPUName from /proc/cpuinfo on linux.
   StringRef getHostCPUNameForPowerPC(StringRef ProcCpuinfoContent);

diff  --git a/llvm/include/llvm/Support/Threading.h 
b/llvm/include/llvm/Support/Threading.h
index 7f2708ddbb467..f3f7c44bd439a 100644
--- a/llvm/include/llvm/Support/Threading.h
+++ b/llvm/include/llvm/Support/Threading.h
@@ -231,6 +231,11 @@ constexpr bool llvm_is_multithreaded() { return 
LLVM_ENABLE_THREADS; }
   /// Returns how many physical CPUs or NUMA groups the system has.
   unsigned get_cpus();
 
+  /// Returns how many physical cores (as opposed to logical cores returned 
from
+  /// thread::hardware_concurrency(), which includes hyperthreads).
+  /// Returns -1 if unknown for the current host system.
+  int get_physical_cores();
+
   enum class ThreadPriority {
 /// Lower the current thread's priority as much as possible. Can be used
 /// for long-running tasks that are not time critical; more energy-

diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 713227c4b088c..c87d9644d0979 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1576,128 +1576,6 @@ VendorSignatures getVendorSignature(unsigned *MaxLeaf) {
 } // namespace llvm
 #endif
 
-#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
-// On Linux, the number of physical cores can be computed from /proc/cpuinfo,
-// using the number of unique physical/core id pairs. The following
-// implementation reads the /proc/cpuinfo format on an x86_64 system.
-static int computeHostNumPhysicalCores() {
-  // Enabled represents the number of physical id/core id pairs with at least
-  // one processor id enabled by the CPU affinity mask.
-  cpu_set_t Affinity, Enabled;
-  if (sched_getaffinity(0, sizeof(Affinity), ) != 0)
-return -1;
-  CPU_ZERO();
-
-  // Read /proc/cpuinfo as a stream (until EOF reached). It cannot be
-  // mmapped because it appears to have 0 size.
-  llvm::ErrorOr> Text =
-  llvm::MemoryBuffer::getFileAsStream("/proc/cpuinfo");
-  if (std::error_code EC = Text.getError()) {
-llvm::errs() << "Can't read "
- << "/proc/cpuinfo: " << EC.message() << "\n";
-return -1;
-  }
-  SmallVector strs;
-  (*Text)->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
- /*KeepEmpty=*/false);
-  int CurProcessor = -1;
-  int CurPhysicalId = -1;
-  int CurSiblings = -1;
-  int CurCoreId = -1;
-  for (StringRef Line : strs) {
-std::pair Data = Line.split(':');
-auto Name = Data.first.trim();
-auto Val = Data.second.trim();
-// These fields are available if the kernel is configured with CONFIG_SMP.
-if (Name == "processor")
-  Val.getAsInteger(10, CurProcessor);
-else if (Name == 

[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.

2022-11-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!
Initially I thought that traversing with `TK_IgnoreUnlessSpelledInSource` might 
be appropriate. But that idea does not seem to work as we do need to match 
implicit casts to find the `nullptr`.

I am also not sure if we should show this warning when the generated code was 
written by hand. The check will keep suggesting to replace `(a <=> b) < 0` with 
`(a <=> b) < nullptr`.
Technically this will compile, but the C++ Standard explicitly mentions the 
comparisons must be implicitly rewritten to `(a <=> b) < 0`, not `nullptr`.
But let's not solve this problem until someone actually reports it.




Comment at: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp:66
+.bind(CastSequence))),
+unless(hasAncestor(functionDecl(isDefaulted()));
 }

NIT: maybe add a comment mentioning that this tries to find defaulted 
comparison operators.
Pre-C++20 one could only put `= default` constructors, destructors and 
assignment operators. So I suspect this might be a useful clarification for 
readers of the code.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp:6
+
+struct _CmpUnspecifiedParam {
+  consteval

NIT: add a comment mentioning that this mocks how STL defined the parameter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138701/new/

https://reviews.llvm.org/D138701

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


[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-11-25 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 477919.
ckandeler added a comment.

Added template example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136594/new/

https://reviews.llvm.org/D136594

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/initialize-params.test
  clang-tools-extra/clangd/test/semantic-tokens.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -113,9 +113,9 @@
   void $Function_def[[foo]](int $Parameter_def[[A]], $Class[[AS]] $Parameter_def[[As]]) {
 $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $LocalVariable_def[[AA]];
-$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
+$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] $Operator[[+]] $Parameter[[A]];
 auto $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
-$LocalVariable[[FN]](12312);
+$LocalVariable[[FN]]$Operator_userProvided[[(]]12312$Operator_userProvided[[)]];
   }
 )cpp",
   R"cpp(
@@ -144,7 +144,7 @@
   struct $Class_def[[B]] {
 $Class_decl_constrDestr[[B]]();
 ~$Class_decl_constrDestr[[B]]();
-void operator<<($Class[[B]]);
+void operator$Operator_decl[[<<]]($Class[[B]]);
 $Class[[AAA]] $Field_decl[[AA]];
   };
   $Class[[B]]::$Class_def_constrDestr[[B]]() {}
@@ -203,20 +203,20 @@
 static double $StaticField_decl_static[[S]];
 static void $StaticMethod_def_static[[bar]]() {}
 void $Method_def[[foo]]() {
-  $Field[[B]] = 123;
-  this->$Field[[B]] = 156;
+  $Field[[B]] $Operator[[=]] 123;
+  this->$Field[[B]] $Operator[[=]] 156;
   this->$Method[[foo]]();
   $Method[[foo]]();
   $StaticMethod_static[[bar]]();
-  $StaticField_static[[S]] = 90.1;
+  $StaticField_static[[S]] $Operator[[=]] 90.1;
 }
   };
   void $Function_def[[foo]]() {
 $Class[[A]] $LocalVariable_def[[AA]];
-$LocalVariable[[AA]].$Field[[B]] += 2;
+$LocalVariable[[AA]].$Field[[B]] $Operator[[+=]] 2;
 $LocalVariable[[AA]].$Method[[foo]]();
 $LocalVariable[[AA]].$Field[[E]].$Field[[C]];
-$Class[[A]]::$StaticField_static[[S]] = 90;
+$Class[[A]]::$StaticField_static[[S]] $Operator[[=]] 90;
   }
 )cpp",
   R"cpp(
@@ -295,10 +295,10 @@
   struct $Class_def[[B]] {};
   struct $Class_def[[A]] {
 $Class[[B]] $Field_decl[[BB]];
-$Class[[A]] =($Class[[A]] &&$Parameter_def[[O]]);
+$Class[[A]] $Operator_decl[[=]]($Class[[A]] &&$Parameter_def[[O]]);
   };
 
-  $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter_def[[O]]) = default;
+  $Class[[A]] &$Class[[A]]::operator$Operator_def[[=]]($Class[[A]] &&$Parameter_def[[O]]) = default;
 )cpp",
   R"cpp(
   enum $Enum_decl[[En]] {
@@ -327,9 +327,9 @@
   $Enum_deduced[[auto]] $Variable_def[[AE]] = $Enum[[E]]::$EnumConstant_readonly[[E]];
   $Class_deduced[[auto]] $Variable_def[[AF]] = $Class[[Foo]]();
   $Class_deduced[[decltype]](auto) $Variable_def[[AF2]] = $Class[[Foo]]();
-  $Class_deduced[[auto]] *$Variable_def[[AFP]] = &$Variable[[AF]];
+  $Class_deduced[[auto]] *$Variable_def[[AFP]] = $Operator[[&]]$Variable[[AF]];
   $Enum_deduced[[auto]] &$Variable_def[[AER]] = $Variable[[AE]];
-  $Primitive_deduced_defaultLibrary[[auto]] $Variable_def[[Form]] = 10.2 + 2 * 4;
+  $Primitive_deduced_defaultLibrary[[auto]] $Variable_def[[Form]] = 10.2 $Operator[[+]] 2 $Operator[[*]] 4;
   $Primitive_deduced_defaultLibrary[[decltype]]($Variable[[Form]]) $Variable_def[[F]] = 10;
   auto $Variable_def[[Fun]] = []()->void{};
 )cpp",
@@ -342,21 +342,21 @@
   template
   class $Class_def[[IP]] {
 void $Method_def[[f]]() {
-  *$TemplateParameter_readonly[[U]] += 5;
+  $Operator[[*]]$TemplateParameter_readonly[[U]] $Operator[[+=]] 5;
 }
   };
   template
   class $Class_def[[Foo]] {
 void $Method_def[[f]]() {
   for(int $LocalVariable_def[[I]] = 0;
-$LocalVariable[[I]] < $TemplateParameter_readonly[[U]];) {}
+$LocalVariable[[I]] $Operator[[<]] $TemplateParameter_readonly[[U]];) {}
 }
   };
 
   $Class[[G]] $Variable_def[[L]];
   void $Function_def[[f]]() {
 

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli accepted this revision.
fpetrogalli added a comment.

LGTM. Thank you @lenary


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138274: Add version to all LLVM cmake package

2022-11-25 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre updated this revision to Diff 477916.
thopre added a comment.

Use LLVM_VERSION as a CMake variable and LLVM_VERSION_* as substitutions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138274/new/

https://reviews.llvm.org/D138274

Files:
  clang/cmake/modules/CMakeLists.txt
  clang/cmake/modules/ClangConfig.cmake.in
  clang/cmake/modules/ClangConfigVersion.cmake.in
  flang/cmake/modules/CMakeLists.txt
  flang/cmake/modules/FlangConfig.cmake.in
  flang/cmake/modules/FlangConfigVersion.cmake.in
  lld/cmake/modules/CMakeLists.txt
  lld/cmake/modules/LLDConfig.cmake.in
  lld/cmake/modules/LLDConfigVersion.cmake.in
  mlir/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/MLIRConfig.cmake.in
  mlir/cmake/modules/MLIRConfigVersion.cmake.in
  polly/cmake/CMakeLists.txt
  polly/cmake/PollyConfig.cmake.in
  polly/cmake/PollyConfigVersion.cmake.in

Index: polly/cmake/PollyConfigVersion.cmake.in
===
--- /dev/null
+++ polly/cmake/PollyConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+  "${PACKAGE_FIND_VERSION_PATCH}")
+set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()
Index: polly/cmake/PollyConfig.cmake.in
===
--- polly/cmake/PollyConfig.cmake.in
+++ polly/cmake/PollyConfig.cmake.in
@@ -2,7 +2,8 @@
 
 @POLLY_CONFIG_CODE@
 
-find_package(LLVM REQUIRED CONFIG
+set(LLVM_VERSION @LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@.@LLVM_VERSION_PATCH@)
+find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
  HINTS "@POLLY_CONFIG_LLVM_CMAKE_DIR@")
 
 set(Polly_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -82,6 +82,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
   ${polly_cmake_builddir}/PollyConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
+  ${polly_cmake_builddir}/PollyConfigVersion.cmake
+  @ONLY)
 
 file(GENERATE
   OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
@@ -138,6 +142,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
   @ONLY)
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake
+  @ONLY)
 file(GENERATE OUTPUT
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
   CONTENT "${POLLY_EXPORTS}")
@@ -146,6 +154,7 @@
   install(
 FILES
 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
+"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake"
 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
 DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
 endif ()
Index: mlir/cmake/modules/MLIRConfigVersion.cmake.in
===
--- /dev/null
+++ mlir/cmake/modules/MLIRConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+  "${PACKAGE_FIND_VERSION_PATCH}")
+set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()
Index: mlir/cmake/modules/MLIRConfig.cmake.in
===
--- mlir/cmake/modules/MLIRConfig.cmake.in
+++ mlir/cmake/modules/MLIRConfig.cmake.in
@@ -2,7 +2,8 @@
 
 @MLIR_CONFIG_CODE@
 
-find_package(LLVM REQUIRED CONFIG
+set(LLVM_VERSION @LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@.@LLVM_VERSION_PATCH@)
+find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
  HINTS "@MLIR_CONFIG_LLVM_CMAKE_DIR@")
 
 set(MLIR_EXPORTED_TARGETS "@MLIR_EXPORTS@")
Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -41,6 +41,10 @@
   ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
   ${mlir_cmake_builddir}/MLIRConfig.cmake
   @ONLY)
+configure_file(
+  

[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added inline comments.



Comment at: llvm/unittests/Support/Host.cpp:33
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
+class HostTest : public testing::Test {};
 

fpetrogalli wrote:
> lenary wrote:
> > fpetrogalli wrote:
> > > Is this needed? 
> > My original intention was to do the minimal changes required to just move 
> > the code.
> > 
> > It's not technically needed, so I will remove it.
> Yeah, I totally get the idea of doing minimal changes. Juts mention in the 
> commit message that you have some extra cleanup that is not strictly needed 
> for the major changes of the patch, so that people blaming the change can 
> understand why that was done.
So, I forgot to submit this comment *before* I submitted the changes. If you're 
happy with how the patch looks now, +2 and I'll land it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D138274: Add version to all LLVM cmake package

2022-11-25 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre reopened this revision.
thopre added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/cmake/modules/ClangConfig.cmake.in:6
+set(LLVM_VERSION 
${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
+find_package(LLVM @LLVM_VERSION@ EXACT REQUIRED CONFIG
  HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")

mceier wrote:
> I think instead of  `@LLVM_VERSION@` it should be `${LLVM_VERSION}` since 
> `@LLVM_VERSION@` can be something like `16.0.0gitfce7a7aa` when 
> LLVM_VERSION_SUFFIX is set and that value is incorrect according to cmake 
> find_package:
> 
> >  find_package called with invalid argument "16.0.0gitfce7a7aa"
> 
> This error message is produced by cmake when configuring standalone build of 
> lldb:
> 
> > CMake Error at /usr/lib/llvm/16/lib64/cmake/clang/ClangConfig.cmake:10 
> > (find_package):
> > find_package called with invalid argument "16.0.0gitfce7a7aa"
> > Call Stack (most recent call first):
> > cmake/modules/LLDBStandalone.cmake:10 (find_package)
> > CMakeLists.txt:30 (include)
> 
> 
> 
Doh, yeah it was meant to use the variable above. I used PACKAGE_VERSION 
initially which is why I had those @@. Weird that it worked on my test despite 
using a git build. I've reverted and will upload a new version here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138274/new/

https://reviews.llvm.org/D138274

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


[PATCH] D138677: [Lex] Fix suggested spelling of /usr/bin/../include/foo

2022-11-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks tests on windows: http://45.33.8.238/win/70650/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138677/new/

https://reviews.llvm.org/D138677

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: llvm/unittests/Support/Host.cpp:33
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
+class HostTest : public testing::Test {};
 

lenary wrote:
> fpetrogalli wrote:
> > Is this needed? 
> My original intention was to do the minimal changes required to just move the 
> code.
> 
> It's not technically needed, so I will remove it.
Yeah, I totally get the idea of doing minimal changes. Juts mention in the 
commit message that you have some extra cleanup that is not strictly needed for 
the major changes of the patch, so that people blaming the change can 
understand why that was done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary added inline comments.



Comment at: llvm/unittests/Support/Host.cpp:33
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
+class HostTest : public testing::Test {};
 

fpetrogalli wrote:
> Is this needed? 
My original intention was to do the minimal changes required to just move the 
code.

It's not technically needed, so I will remove it.



Comment at: llvm/unittests/Support/Host.cpp:401
 
 TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
   // Suppress defined-but-not-used warnings when the tests using the helper are

fpetrogalli wrote:
> I think you can remove the class `HostTest` and convert the test fixture into 
> just `TEST(` instead of `TEST_F(`. It is kind of awkward to have this: `class 
> HostTest : public testing::Test {};`
Yeah, Will do.



Comment at: llvm/unittests/Support/Threading.cpp:30
 
+class ThreadingTest : public testing::Test {
+  Triple Host;

fpetrogalli wrote:
> I don't think you need to derive from `testing:Test`? The functionality of 
> `isSupportedArchAndOS could be achieved just with a function.
Yes, will do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

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


[PATCH] D137836: [Support] Move getHostNumPhysicalCores to Threading.h

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary edited the summary of this revision.
lenary updated this revision to Diff 477912.
lenary marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137836/new/

https://reviews.llvm.org/D137836

Files:
  clang-tools-extra/clangd/test/Inputs/BenchmarkHeader.h
  llvm/include/llvm/Support/Host.h
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/Threading.cpp
  llvm/unittests/Support/Host.cpp
  llvm/unittests/Support/Threading.cpp

Index: llvm/unittests/Support/Threading.cpp
===
--- llvm/unittests/Support/Threading.cpp
+++ llvm/unittests/Support/Threading.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "llvm/Support/Threading.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/thread.h"
 #include "gtest/gtest.h"
 
@@ -17,6 +19,18 @@
 
 namespace {
 
+static bool isThreadingSupportedArchAndOS() {
+  Triple Host(Triple::normalize(sys::getProcessTriple()));
+
+  // Initially this is only testing detection of the number of
+  // physical cores, which is currently only supported/tested on
+  // some systems.
+  return (Host.isOSWindows() && llvm_is_multithreaded()) ||
+  Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
+  (Host.isOSLinux() && !Host.isAndroid()) ||
+  (Host.isSystemZ() && Host.isOSzOS());
+}
+
 TEST(Threading, PhysicalConcurrency) {
   auto Num = heavyweight_hardware_concurrency();
   // Since Num is unsigned this will also catch us trying to
@@ -25,6 +39,20 @@
 hardware_concurrency().compute_thread_count());
 }
 
+TEST(Threading, NumPhysicalCoresSupported) {
+  if (!isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_GT(Num, 0);
+}
+
+TEST(Threading, NumPhysicalCoresUnsupported) {
+  if (isThreadingSupportedArchAndOS())
+GTEST_SKIP();
+  int Num = get_physical_cores();
+  ASSERT_EQ(Num, -1);
+}
+
 #if LLVM_ENABLE_THREADS
 
 class Notification {
Index: llvm/unittests/Support/Host.cpp
===
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -30,37 +30,6 @@
 
 using namespace llvm;
 
-class HostTest : public testing::Test {
-  Triple Host;
-
-protected:
-  bool isSupportedArchAndOS() {
-// Initially this is only testing detection of the number of
-// physical cores, which is currently only supported/tested on
-// some systems.
-return (Host.isOSWindows() && llvm_is_multithreaded()) ||
-   Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
-   (Host.isOSLinux() && !Host.isAndroid()) ||
-   (Host.isSystemZ() && Host.isOSzOS());
-  }
-
-  HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
-};
-
-TEST_F(HostTest, NumPhysicalCoresSupported) {
-  if (!isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_GT(Num, 0);
-}
-
-TEST_F(HostTest, NumPhysicalCoresUnsupported) {
-  if (isSupportedArchAndOS())
-GTEST_SKIP();
-  int Num = sys::getHostNumPhysicalCores();
-  ASSERT_EQ(Num, -1);
-}
-
 TEST(getLinuxHostCPUName, ARM) {
   StringRef CortexA9ProcCpuinfo = R"(
 processor   : 0
@@ -439,13 +408,13 @@
   return Success;
 }
 
-TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
+TEST(HostTest, DummyRunAndGetCommandOutputUse) {
   // Suppress defined-but-not-used warnings when the tests using the helper are
   // disabled.
   (void)
 }
 
-TEST_F(HostTest, getMacOSHostVersion) {
+TEST(HostTest, getMacOSHostVersion) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (!HostTriple.isMacOSX())
 GTEST_SKIP();
@@ -491,7 +460,7 @@
   .getOSVersion();
 }
 
-TEST_F(HostTest, AIXHostVersionDetect) {
+TEST(HostTest, AIXHostVersionDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -517,7 +486,7 @@
   ASSERT_EQ(SysMinor, HostVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXTargetVersionDetect) {
+TEST(HostTest, AIXTargetVersionDetect) {
   llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
   if (TargetTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
@@ -535,7 +504,7 @@
   ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
 }
 
-TEST_F(HostTest, AIXHostCPUDetect) {
+TEST(HostTest, AIXHostCPUDetect) {
   llvm::Triple HostTriple(llvm::sys::getProcessTriple());
   if (HostTriple.getOS() != Triple::AIX)
 GTEST_SKIP();
Index: llvm/lib/Support/Threading.cpp
===
--- llvm/lib/Support/Threading.cpp
+++ llvm/lib/Support/Threading.cpp
@@ -13,8 +13,12 @@
 
 #include "llvm/Support/Threading.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
+#include 

[clang-tools-extra] 9d5e82e - [include-cleaner] Make HTMLReport impl simpler/safer. NFC

2022-11-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-11-25T13:12:20+01:00
New Revision: 9d5e82e75c61df1a79e337770c1d54d83b33d96a

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

LOG: [include-cleaner] Make HTMLReport impl simpler/safer. NFC

Targets and Refs are 1:1, so merge them.

Don't sort Refs array we keep indices into. (Currently we're done using
those indices by the time we sort, but this is fragile)

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index b57bbbdc94910..fc9b00dc572df 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -23,6 +23,7 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -62,7 +63,7 @@ constexpr llvm::StringLiteral CSS = R"css(
 padding-top: 1em;
 border-top: 1px solid #444;
   }
-  .ref.missing #hover .insert { font-weight: bold; }
+  .ref.missing #hover .insert { background-color: #bea; }
   .ref:not(.missing) #hover .insert { font-style: italic; }
 )css";
 
@@ -139,29 +140,18 @@ class Reporter {
   FileID MainFile;
   const FileEntry *MainFE;
 
-  // References to symbols from the main file.
-  // FIXME: should we deduplicate these?
-  struct Target {
-Symbol Sym;
+  // Points within the main file that reference a Symbol.
+  // Implicit refs will be marked with a symbol just before the token.
+  struct Ref {
+unsigned Offset;
 RefType Type;
+Symbol Sym;
 SmallVector Locations;
 SmallVector Headers;
 SmallVector Includes;
 bool Satisfied = false; // Is the include present?
 std::string Insert; // If we had no includes, what would we insert?
   };
-  std::vector Targets;
-  // Points within the main file that reference a Target.
-  // Implicit refs will be marked with a symbol just before the token.
-  struct Ref {
-unsigned Offset;
-bool Implicit;
-size_t TargetIndex;
-bool operator<(const Ref ) const {
-  return std::forward_as_tuple(Offset, !Implicit, TargetIndex) <
- std::forward_as_tuple(Other.Offset, !Other.Implicit, TargetIndex);
-}
-  };
   std::vector Refs;
   llvm::DenseMap> IncludeRefs;
   llvm::StringMap> Insertion;
@@ -171,7 +161,7 @@ class Reporter {
 if (List.empty())
   return "unused";
 if (llvm::any_of(List, [&](unsigned I) {
-  return Targets[Refs[I].TargetIndex].Type == RefType::Explicit;
+  return Refs[I].Type == RefType::Explicit;
 }))
   return "used";
 return "semiused";
@@ -193,43 +183,39 @@ class Reporter {
 llvm_unreachable("Unknown Header kind");
   }
 
-  Target makeTarget(const SymbolReference ) {
-Target T{SR.Target, SR.RT, {}, {}, {}, {}, {}};
-
+  void fillTarget(Ref ) {
 // Duplicates logic from walkUsed(), which doesn't expose SymbolLocations.
 // FIXME: use locateDecl and friends once implemented.
 // This doesn't use stdlib::Recognizer, but locateDecl will soon do that.
-switch (SR.Target.kind()) {
+switch (R.Sym.kind()) {
 case Symbol::Declaration:
-  T.Locations.push_back(SR.Target.declaration().getLocation());
+  R.Locations.push_back(R.Sym.declaration().getLocation());
   break;
 case Symbol::Macro:
-  T.Locations.push_back(SR.Target.macro().Definition);
+  R.Locations.push_back(R.Sym.macro().Definition);
   break;
 }
 
-for (const auto  : T.Locations)
-  T.Headers.append(findHeaders(Loc, SM, PI));
+for (const auto  : R.Locations)
+  R.Headers.append(findHeaders(Loc, SM, PI));
 
-for (const auto  : T.Headers) {
-  T.Includes.append(Includes.match(H));
+for (const auto  : R.Headers) {
+  R.Includes.append(Includes.match(H));
   // FIXME: library should signal main-file refs somehow.
   // Non-physical refs to the main-file should be possible.
   if (H.kind() == Header::Physical && H.physical() == MainFE)
-T.Satisfied = true;
+R.Satisfied = true;
 }
-if (!T.Includes.empty())
-  T.Satisfied = true;
+if (!R.Includes.empty())
+  R.Satisfied = true;
 // Include pointers are meaningfully ordered as they are backed by a 
vector.
-llvm::sort(T.Includes);
-T.Includes.erase(std::unique(T.Includes.begin(), T.Includes.end()),
- T.Includes.end());
-
-if (!T.Headers.empty())
-  // FIXME: library should tell us which header to use.
-  T.Insert = spellHeader(T.Headers.front());
+llvm::sort(R.Includes);
+

[clang] 54ad4d2 - Drop redundant pipe to opt -instnamer in clang tests

2022-11-25 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2022-11-25T11:34:55Z
New Revision: 54ad4d2dd1526c53c3647eee26f8ecc2ff63f30c

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

LOG: Drop redundant pipe to opt -instnamer in clang tests

This used to be required, but the difference between asserts/!asserts
builds no longer exists for %clang_cc1 (only for %clang), so they pass
just fine without this flag.

Added: 


Modified: 
clang/test/CodeGen/X86/avx512-kconstraints-att_inline_asm.c
clang/test/CodeGen/catch-undef-behavior.c
clang/test/CodeGen/exceptions-seh-leave.c
clang/test/CodeGen/fp-atomic-ops.c
clang/test/CodeGenCXX/catch-undef-behavior.cpp
clang/test/CodeGenCXX/for-range-temporaries.cpp
clang/test/CodeGenOpenCL/atomic-ops.cl
clang/test/CodeGenOpenCL/convergent.cl

Removed: 




diff  --git a/clang/test/CodeGen/X86/avx512-kconstraints-att_inline_asm.c 
b/clang/test/CodeGen/X86/avx512-kconstraints-att_inline_asm.c
index be7be25d84af5..b4939bfc2ca83 100644
--- a/clang/test/CodeGen/X86/avx512-kconstraints-att_inline_asm.c
+++ b/clang/test/CodeGen/X86/avx512-kconstraints-att_inline_asm.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -O0 -ffreestanding -triple=x86_64-apple-darwin 
-target-cpu skylake-avx512 -emit-llvm -o - -Wall -Werror | opt 
-passes=instnamer -S | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -ffreestanding -triple=x86_64-apple-darwin 
-target-cpu skylake-avx512 -emit-llvm -o - -Wall -Werror | FileCheck %s
 // This test checks validity of att\gcc style inline assmebly for avx512 k and 
Yk constraints.
 // Also checks mask register allows flexible type (size <= 64 bit)
 

diff  --git a/clang/test/CodeGen/catch-undef-behavior.c 
b/clang/test/CodeGen/catch-undef-behavior.c
index c2035b030f0a2..9f511d54f458c 100644
--- a/clang/test/CodeGen/catch-undef-behavior.c
+++ b/clang/test/CodeGen/catch-undef-behavior.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -no-opaque-pointers 
-fsanitize=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize-recover=alignment,null,object-size,shift-base,shift-exponent,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 -emit-llvm %s -o - -triple x86_64-linux-gnu | opt -passes=instnamer -S | 
FileCheck %s --check-prefix=CHECK-COMMON --check-prefix=CHECK-UBSAN
-// RUN: %clang_cc1 -no-opaque-pointers 
-fsanitize-trap=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize-recover=alignment,null,object-size,shift-base,shift-exponent,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize-recover=alignment,null,object-size,shift-base,shift-exponent,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 -emit-llvm %s -o - -triple x86_64-linux-gnu | opt -passes=instnamer -S | 
FileCheck %s --check-prefix=CHECK-COMMON --check-prefix=CHECK-TRAP
+// RUN: %clang_cc1 -no-opaque-pointers 
-fsanitize=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize-recover=alignment,null,object-size,shift-base,shift-exponent,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s 
--check-prefix=CHECK-COMMON --check-prefix=CHECK-UBSAN
+// RUN: %clang_cc1 -no-opaque-pointers 
-fsanitize-trap=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize-recover=alignment,null,object-size,shift-base,shift-exponent,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 
-fsanitize=alignment,null,object-size,shift-base,shift-exponent,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool,returns-nonnull-attribute,nonnull-attribute
 

[PATCH] D137835: [ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e9b6adfc7ca: [ARM] Move ARM::parseBranchProtection into 
ARMTargetParserCommon (authored by lenary).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137835/new/

https://reviews.llvm.org/D137835

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/Support/ARMTargetParserCommon.h
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/ARMTargetParserCommon.cpp
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -337,51 +337,3 @@
 
 } // namespace RISCV
 } // namespace llvm
-
-// Parse a branch protection specification, which has the form
-//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
-// Returns true on success, with individual elements of the specification
-// returned in `PBP`. Returns false in error, with `Err` containing
-// an erroneous part of the spec.
-bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
-StringRef ) {
-  PBP = {"none", "a_key", false};
-  if (Spec == "none")
-return true; // defaults are ok
-
-  if (Spec == "standard") {
-PBP.Scope = "non-leaf";
-PBP.BranchTargetEnforcement = true;
-return true;
-  }
-
-  SmallVector Opts;
-  Spec.split(Opts, "+");
-  for (int I = 0, E = Opts.size(); I != E; ++I) {
-StringRef Opt = Opts[I].trim();
-if (Opt == "bti") {
-  PBP.BranchTargetEnforcement = true;
-  continue;
-}
-if (Opt == "pac-ret") {
-  PBP.Scope = "non-leaf";
-  for (; I + 1 != E; ++I) {
-StringRef PACOpt = Opts[I + 1].trim();
-if (PACOpt == "leaf")
-  PBP.Scope = "all";
-else if (PACOpt == "b-key")
-  PBP.Key = "b_key";
-else
-  break;
-  }
-  continue;
-}
-if (Opt == "")
-  Err = "";
-else
-  Err = Opt;
-return false;
-  }
-
-  return true;
-}
Index: llvm/lib/Support/ARMTargetParserCommon.cpp
===
--- llvm/lib/Support/ARMTargetParserCommon.cpp
+++ llvm/lib/Support/ARMTargetParserCommon.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "llvm/Support/ARMTargetParserCommon.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace llvm;
@@ -130,3 +131,51 @@
 
   return EndianKind::INVALID;
 }
+
+// Parse a branch protection specification, which has the form
+//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
+// Returns true on success, with individual elements of the specification
+// returned in `PBP`. Returns false in error, with `Err` containing
+// an erroneous part of the spec.
+bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
+StringRef ) {
+  PBP = {"none", "a_key", false};
+  if (Spec == "none")
+return true; // defaults are ok
+
+  if (Spec == "standard") {
+PBP.Scope = "non-leaf";
+PBP.BranchTargetEnforcement = true;
+return true;
+  }
+
+  SmallVector Opts;
+  Spec.split(Opts, "+");
+  for (int I = 0, E = Opts.size(); I != E; ++I) {
+StringRef Opt = Opts[I].trim();
+if (Opt == "bti") {
+  PBP.BranchTargetEnforcement = true;
+  continue;
+}
+if (Opt == "pac-ret") {
+  PBP.Scope = "non-leaf";
+  for (; I + 1 != E; ++I) {
+StringRef PACOpt = Opts[I + 1].trim();
+if (PACOpt == "leaf")
+  PBP.Scope = "all";
+else if (PACOpt == "b-key")
+  PBP.Key = "b_key";
+else
+  break;
+  }
+  continue;
+}
+if (Opt == "")
+  Err = "";
+else
+  Err = Opt;
+return false;
+  }
+
+  return true;
+}
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -182,19 +182,6 @@
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector );
 
 } // namespace RISCV
-
-namespace ARM {
-struct ParsedBranchProtection {
-  StringRef Scope;
-  StringRef Key;
-  bool BranchTargetEnforcement;
-};
-
-bool parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
-   StringRef );
-
-} // namespace ARM
-
 } // namespace llvm
 
 #endif
Index: llvm/include/llvm/Support/ARMTargetParserCommon.h
===
--- llvm/include/llvm/Support/ARMTargetParserCommon.h
+++ llvm/include/llvm/Support/ARMTargetParserCommon.h
@@ -37,6 +37,15 @@
 // Little/Big endian
 

[clang] 3e9b6ad - [ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon

2022-11-25 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2022-11-25T11:33:53Z
New Revision: 3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff

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

LOG: [ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon

This should live with the Arm targets, given they have target-specific
target parsers.

Differential Revision: https://reviews.llvm.org/D137835

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/ARM.h
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/Support/ARMTargetParserCommon.h
llvm/include/llvm/Support/TargetParser.h
llvm/lib/Support/ARMTargetParserCommon.cpp
llvm/lib/Support/TargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d85a21397abc1..1221b84676d9b 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -18,6 +18,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
 
 using namespace clang;
 using namespace clang::targets;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 74c7aad97690d..6d2eb866444d4 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -16,7 +16,6 @@
 #include "OSTargets.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "llvm/Support/AArch64TargetParser.h"
-#include "llvm/Support/TargetParser.h"
 
 namespace clang {
 namespace targets {

diff  --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index e85336b6e32f9..897073eca7eb5 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -17,9 +17,9 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/ARMTargetParser.h"
-#include "llvm/Support/TargetParser.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
+#include "llvm/Support/Compiler.h"
 
 namespace clang {
 namespace targets {

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fcf99c88d4c2c..765e766c39524 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -44,6 +44,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Compression.h"
@@ -51,7 +52,6 @@
 #include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/YAMLParser.h"
 #include 
 

diff  --git a/llvm/include/llvm/Support/ARMTargetParserCommon.h 
b/llvm/include/llvm/Support/ARMTargetParserCommon.h
index 3db8646e26fd8..a21a9d7f1c67c 100644
--- a/llvm/include/llvm/Support/ARMTargetParserCommon.h
+++ b/llvm/include/llvm/Support/ARMTargetParserCommon.h
@@ -37,6 +37,15 @@ ISAKind parseArchISA(StringRef Arch);
 // Little/Big endian
 EndianKind parseArchEndian(StringRef Arch);
 
+struct ParsedBranchProtection {
+  StringRef Scope;
+  StringRef Key;
+  bool BranchTargetEnforcement;
+};
+
+bool parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
+   StringRef );
+
 } // namespace ARM
 } // namespace llvm
 #endif

diff  --git a/llvm/include/llvm/Support/TargetParser.h 
b/llvm/include/llvm/Support/TargetParser.h
index 39222b02e21ad..bf954b909cf2f 100644
--- a/llvm/include/llvm/Support/TargetParser.h
+++ b/llvm/include/llvm/Support/TargetParser.h
@@ -182,19 +182,6 @@ void fillValidTuneCPUArchList(SmallVectorImpl 
, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector 
);
 
 } // namespace RISCV
-
-namespace ARM {
-struct ParsedBranchProtection {
-  StringRef Scope;
-  StringRef Key;
-  bool BranchTargetEnforcement;
-};
-
-bool parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
-   StringRef );
-
-} // namespace ARM
-
 } // namespace llvm
 
 #endif

diff  --git a/llvm/lib/Support/ARMTargetParserCommon.cpp 
b/llvm/lib/Support/ARMTargetParserCommon.cpp
index 1cbf6e1d4818a..8650261cf5f10 100644
--- a/llvm/lib/Support/ARMTargetParserCommon.cpp
+++ b/llvm/lib/Support/ARMTargetParserCommon.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "llvm/Support/ARMTargetParserCommon.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace llvm;

[PATCH] D138702: support for HIP non hostcall printf

2022-11-25 Thread Vikram Hegde via Phabricator via cfe-commits
vikramRH created this revision.
vikramRH added reviewers: sameerds, b-sumner, yaxunl.
vikramRH added a project: LLVM.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, Anastasia, 
jvesely, arsenm.
Herald added a project: All.
vikramRH requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added a project: clang.

The patch essentially ports the existing non-hostcall printf support in OpenCL 
to HIP (to be controlled via new option "-fdelayed-printf"), with following 
changes

1. Code refactoring -> we now use API's "getConstantStringInfo()" to extract 
constant string contents at compile time.
2. Support to print non-const null terminated strings, required in HIP context. 
This is achieved as follows
  - calculate string size using a function "getStrlenWithNull()" and reserve 
the space in printf buffer using __printf_alloc() (as was the case in OpenCL, 
but number of bytes allocated could be dynamic now)
  - copy the string contents to buffer using previously calculated size and the 
pointer to string (a memcpy intrinsic is generated here)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138702

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Builtins.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/test/CodeGen/AMDGPU/hip-delayed-printf.ll
  llvm/test/CodeGen/AMDGPU/opencl-printf.ll

Index: llvm/test/CodeGen/AMDGPU/opencl-printf.ll
===
--- llvm/test/CodeGen/AMDGPU/opencl-printf.ll
+++ llvm/test/CodeGen/AMDGPU/opencl-printf.ll
@@ -9,18 +9,17 @@
 ; R600: call i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str, i32 0, i32 0), i8* %arraydecay, i32 %n)
 ; GCN-LABEL: entry
 ; GCN: call i8 addrspace(1)* @__printf_alloc
-; GCN-LABEL: entry.split
+; GCN-LABEL: strlen.join.split
 ; GCN: icmp ne i8 addrspace(1)* %printf_alloc_fn, null
+; GCN: br i1 %14, label %15, label %16
 ; GCN: %PrintBuffID = getelementptr i8, i8 addrspace(1)* %printf_alloc_fn, i32 0
 ; GCN: %PrintBuffIdCast = bitcast i8 addrspace(1)* %PrintBuffID to i32 addrspace(1)*
-; GCN: store i32 1, i32 addrspace(1)* %PrintBuffIdCast
+; GCN: store i32 1, i32 addrspace(1)* %PrintBuffIdCast, align 4
 ; GCN: %PrintBuffGep = getelementptr i8, i8 addrspace(1)* %printf_alloc_fn, i32 4
-; GCN: %PrintArgPtr = ptrtoint i8* %arraydecay to i64
-; GCN: %PrintBuffPtrCast = bitcast i8 addrspace(1)* %PrintBuffGep to i64 addrspace(1)*
-; GCN: store i64 %PrintArgPtr, i64 addrspace(1)* %PrintBuffPtrCast
-; GCN: %PrintBuffNextPtr = getelementptr i8, i8 addrspace(1)* %PrintBuffGep, i32 8
-; GCN: %PrintBuffPtrCast1 = bitcast i8 addrspace(1)* %PrintBuffNextPtr to i32 addrspace(1)*
-; GCN: store i32 %n, i32 addrspace(1)* %PrintBuffPtrCast1
+; GCN: call void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* %PrintBuffGep, i8* %arraydecay, i64 %9, i1 false)
+; GCN: %PrintBuffNextPtr = getelementptr i8, i8 addrspace(1)* %PrintBuffGep, i64 %11
+; GCN: %PrintBuffPtrCast = bitcast i8 addrspace(1)* %PrintBuffNextPtr to i32 addrspace(1)*
+; GCN: store i32 %n, i32 addrspace(1)* %PrintBuffPtrCast, align 4
 
 @.str = private unnamed_addr addrspace(2) constant [6 x i8] c"%s:%d\00", align 1
 
Index: llvm/test/CodeGen/AMDGPU/hip-delayed-printf.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/hip-delayed-printf.ll
@@ -0,0 +1,57 @@
+; RUN: opt -mtriple=amdgcn--amdhsa -passes=amdgpu-printf-runtime-binding -S < %s | FileCheck --check-prefix=FUNC --check-prefix=GCN --check-prefix=METADATA %s
+
+; FUNC-LABEL: @test_kernel(
+; GCN-LABEL: entry
+; GCN-LABEL: strlen.while
+; GCN: br i1 %6, label %strlen.while.done, label %strlen.while
+; GCN-LABEL: strlen.join
+; GCN: %12 = add i64 %11, 3
+; GCN: %13 = and i64 %12, 4294967292
+; GCN: %14 = add i64 %13, 4
+; GCN: %15 = trunc i64 %14 to i32
+; GCN: %printf_alloc_fn = call ptr addrspace(1) @__printf_alloc(i32 %15)
+; GCN-LABEL: strlen.join.split
+; GCN: %16 = icmp ne ptr addrspace(1) %printf_alloc_fn, null
+; GCN: br i1 %16, label %17, label %18
+; GCN: %PrintBuffID = getelementptr i8, ptr addrspace(1) %printf_alloc_fn, i32 0
+; GCN: %PrintBuffIdCast = bitcast ptr addrspace(1) %PrintBuffID to ptr addrspace(1)
+; GCN: store i32 1, ptr addrspace(1) %PrintBuffIdCast, align 4
+; GCN: %PrintBuffGep = getelementptr i8, ptr addrspace(1) %printf_alloc_fn, i32 4
+; GCN: call void @llvm.memcpy.p1.p0.i64(ptr addrspace(1) %PrintBuffGep, ptr %1, i64 %11, i1 false)
+; GCN: %PrintBuffNextPtr = getelementptr i8, ptr addrspace(1) %PrintBuffGep, i64 %13
+; GCN: br label %18
+
+; METADATA: !llvm.printf.fmts = !{!0}
+; METADATA: !0 = !{!"1:1:8:%s"}
+
+@.str = private unnamed_addr addrspace(4) constant [3 x i8] c"%s\00", align 1
+@.str.1 = private unnamed_addr addrspace(4) constant [6 x i8] 

[PATCH] D137835: [ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon

2022-11-25 Thread Sam Elliott via Phabricator via cfe-commits
lenary updated this revision to Diff 477904.
lenary marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137835/new/

https://reviews.llvm.org/D137835

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/Support/ARMTargetParserCommon.h
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/ARMTargetParserCommon.cpp
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -337,51 +337,3 @@
 
 } // namespace RISCV
 } // namespace llvm
-
-// Parse a branch protection specification, which has the form
-//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
-// Returns true on success, with individual elements of the specification
-// returned in `PBP`. Returns false in error, with `Err` containing
-// an erroneous part of the spec.
-bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
-StringRef ) {
-  PBP = {"none", "a_key", false};
-  if (Spec == "none")
-return true; // defaults are ok
-
-  if (Spec == "standard") {
-PBP.Scope = "non-leaf";
-PBP.BranchTargetEnforcement = true;
-return true;
-  }
-
-  SmallVector Opts;
-  Spec.split(Opts, "+");
-  for (int I = 0, E = Opts.size(); I != E; ++I) {
-StringRef Opt = Opts[I].trim();
-if (Opt == "bti") {
-  PBP.BranchTargetEnforcement = true;
-  continue;
-}
-if (Opt == "pac-ret") {
-  PBP.Scope = "non-leaf";
-  for (; I + 1 != E; ++I) {
-StringRef PACOpt = Opts[I + 1].trim();
-if (PACOpt == "leaf")
-  PBP.Scope = "all";
-else if (PACOpt == "b-key")
-  PBP.Key = "b_key";
-else
-  break;
-  }
-  continue;
-}
-if (Opt == "")
-  Err = "";
-else
-  Err = Opt;
-return false;
-  }
-
-  return true;
-}
Index: llvm/lib/Support/ARMTargetParserCommon.cpp
===
--- llvm/lib/Support/ARMTargetParserCommon.cpp
+++ llvm/lib/Support/ARMTargetParserCommon.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "llvm/Support/ARMTargetParserCommon.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
 
 using namespace llvm;
@@ -130,3 +131,51 @@
 
   return EndianKind::INVALID;
 }
+
+// Parse a branch protection specification, which has the form
+//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
+// Returns true on success, with individual elements of the specification
+// returned in `PBP`. Returns false in error, with `Err` containing
+// an erroneous part of the spec.
+bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
+StringRef ) {
+  PBP = {"none", "a_key", false};
+  if (Spec == "none")
+return true; // defaults are ok
+
+  if (Spec == "standard") {
+PBP.Scope = "non-leaf";
+PBP.BranchTargetEnforcement = true;
+return true;
+  }
+
+  SmallVector Opts;
+  Spec.split(Opts, "+");
+  for (int I = 0, E = Opts.size(); I != E; ++I) {
+StringRef Opt = Opts[I].trim();
+if (Opt == "bti") {
+  PBP.BranchTargetEnforcement = true;
+  continue;
+}
+if (Opt == "pac-ret") {
+  PBP.Scope = "non-leaf";
+  for (; I + 1 != E; ++I) {
+StringRef PACOpt = Opts[I + 1].trim();
+if (PACOpt == "leaf")
+  PBP.Scope = "all";
+else if (PACOpt == "b-key")
+  PBP.Key = "b_key";
+else
+  break;
+  }
+  continue;
+}
+if (Opt == "")
+  Err = "";
+else
+  Err = Opt;
+return false;
+  }
+
+  return true;
+}
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -182,19 +182,6 @@
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector );
 
 } // namespace RISCV
-
-namespace ARM {
-struct ParsedBranchProtection {
-  StringRef Scope;
-  StringRef Key;
-  bool BranchTargetEnforcement;
-};
-
-bool parseBranchProtection(StringRef Spec, ParsedBranchProtection ,
-   StringRef );
-
-} // namespace ARM
-
 } // namespace llvm
 
 #endif
Index: llvm/include/llvm/Support/ARMTargetParserCommon.h
===
--- llvm/include/llvm/Support/ARMTargetParserCommon.h
+++ llvm/include/llvm/Support/ARMTargetParserCommon.h
@@ -37,6 +37,15 @@
 // Little/Big endian
 EndianKind parseArchEndian(StringRef Arch);
 
+struct ParsedBranchProtection {
+  StringRef Scope;
+  StringRef Key;
+  bool BranchTargetEnforcement;
+};
+
+bool 

[PATCH] D138676: [include-cleaner] HTMLReport shows headers that would be inserted

2022-11-25 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a95e67323dd: [include-cleaner] HTMLReport shows headers 
that would be inserted (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138676/new/

https://reviews.llvm.org/D138676

Files:
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -71,8 +71,10 @@
<< ": " << EC.message() << "\n";
   exit(1);
 }
-writeHTMLReport(AST.Ctx->getSourceManager().getMainFileID(), PP.Includes,
-AST.Roots, PP.MacroReferences, *AST.Ctx, , OS);
+writeHTMLReport(
+AST.Ctx->getSourceManager().getMainFileID(), PP.Includes, AST.Roots,
+PP.MacroReferences, *AST.Ctx,
+getCompilerInstance().getPreprocessor().getHeaderSearchInfo(), , OS);
   }
 };
 
Index: clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
===
--- clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/ScopedPrinter.h"
@@ -29,7 +30,7 @@
 constexpr llvm::StringLiteral CSS = R"css(
   body { margin: 0; }
   pre { line-height: 1.5em; counter-reset: line; margin: 0; }
-  pre .line { counter-increment: line; }
+  pre .line:not(.added) { counter-increment: line; }
   pre .line::before {
 content: counter(line);
 display: inline-block;
@@ -37,6 +38,7 @@
 text-align: right;
 width: 3em; padding-right: 0.5em; margin-right: 0.5em;
   }
+  pre .line.added::before { content: '+' }
   .ref, .inc { text-decoration: underline; color: #008; }
   .sel { position: relative; cursor: pointer; }
   .ref.implicit { background-color: #ff8; }
@@ -52,6 +54,7 @@
   #hover .target.implicit, .provides .implicit { background-color: #bbb; }
   #hover .target.ambiguous, .provides .ambiguous { background-color: #caf; }
   .missing, .unused { background-color: #faa !important; }
+  .inserted { background-color: #bea !important; }
   .semiused { background-color: #888 !important; }
   #hover th { color: #008; text-align: right; padding-right: 0.5em; }
   #hover .target:not(:first-child) {
@@ -59,6 +62,8 @@
 padding-top: 1em;
 border-top: 1px solid #444;
   }
+  .ref.missing #hover .insert { font-weight: bold; }
+  .ref:not(.missing) #hover .insert { font-style: italic; }
 )css";
 
 constexpr llvm::StringLiteral JS = R"js(
@@ -128,6 +133,7 @@
   llvm::raw_ostream 
   const ASTContext 
   const SourceManager 
+  HeaderSearch 
   const RecordedPP::RecordedIncludes 
   const PragmaIncludes *PI;
   FileID MainFile;
@@ -142,6 +148,7 @@
 SmallVector Headers;
 SmallVector Includes;
 bool Satisfied = false; // Is the include present?
+std::string Insert; // If we had no includes, what would we insert?
   };
   std::vector Targets;
   // Points within the main file that reference a Target.
@@ -157,6 +164,7 @@
   };
   std::vector Refs;
   llvm::DenseMap> IncludeRefs;
+  llvm::StringMap> Insertion;
 
   llvm::StringRef includeType(const Include *I) {
 auto  = IncludeRefs[I];
@@ -169,8 +177,24 @@
 return "semiused";
   }
 
+  std::string spellHeader(const Header ) {
+switch (H.kind()) {
+case Header::Physical: {
+  bool IsSystem = false;
+  std::string Path = HS.suggestPathToFileForDiagnostics(
+  H.physical(), MainFE->tryGetRealPathName(), );
+  return IsSystem ? "<" + Path + ">" : "\"" + Path + "\"";
+}
+case Header::Standard:
+  return H.standard().name().str();
+case Header::Verbatim:
+  return H.verbatim().str();
+}
+llvm_unreachable("Unknown Header kind");
+  }
+
   Target makeTarget(const SymbolReference ) {
-Target T{SR.Target, SR.RT, {}, {}, {}};
+Target T{SR.Target, SR.RT, {}, {}, {}, {}, {}};
 
 // Duplicates logic from walkUsed(), which doesn't expose SymbolLocations.
 // FIXME: use locateDecl and friends once implemented.
@@ -200,16 +224,21 @@
 llvm::sort(T.Includes);
 T.Includes.erase(std::unique(T.Includes.begin(), T.Includes.end()),
  T.Includes.end());
+
+if (!T.Headers.empty())
+  // FIXME: library should tell us which header to use.
+  T.Insert = 

[clang-tools-extra] 6a95e67 - [include-cleaner] HTMLReport shows headers that would be inserted

2022-11-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-11-25T11:57:35+01:00
New Revision: 6a95e67323dd64e6023c0b5ea89407cac2dbc01b

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

LOG: [include-cleaner] HTMLReport shows headers that would be inserted

Demo: 
https://htmlpreview.github.io/?https://gist.githubusercontent.com/sam-mccall/9730f933a2cf2e003365520b6636f731/raw/7911d8251ceab7c244e0510285105027cd0a9403/PathMapping.cpp.html

Header insertion doesn't actually work that well (not this patch's fault):
- we don't have ranking of locations/headers yet, so inserted header is pretty
  random
- on my system, we get a lot of absolute "/usr/bin/../include/..." paths.
  This is a HeaderSearch bug introduced in D60873 that I'll send a fix for

Differential Revision: https://reviews.llvm.org/D138676

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h 
b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
index 1b85c679f6a7d..7bca824137e42 100644
--- a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
+++ b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
@@ -29,6 +29,7 @@
 namespace clang {
 class ASTContext;
 class Decl;
+class HeaderSearch;
 class NamedDecl;
 namespace include_cleaner {
 
@@ -87,7 +88,8 @@ llvm::SmallVector findHeaders(const SymbolLocation 
,
 void writeHTMLReport(FileID File, const RecordedPP::RecordedIncludes ,
  llvm::ArrayRef Roots,
  llvm::ArrayRef MacroRefs, ASTContext 
,
- PragmaIncludes *PI, llvm::raw_ostream );
+ HeaderSearch , PragmaIncludes *PI,
+ llvm::raw_ostream );
 
 } // namespace include_cleaner
 } // namespace clang

diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index e28a951592c43..b57bbbdc94910 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/Support/ScopedPrinter.h"
@@ -29,7 +30,7 @@ namespace {
 constexpr llvm::StringLiteral CSS = R"css(
   body { margin: 0; }
   pre { line-height: 1.5em; counter-reset: line; margin: 0; }
-  pre .line { counter-increment: line; }
+  pre .line:not(.added) { counter-increment: line; }
   pre .line::before {
 content: counter(line);
 display: inline-block;
@@ -37,6 +38,7 @@ constexpr llvm::StringLiteral CSS = R"css(
 text-align: right;
 width: 3em; padding-right: 0.5em; margin-right: 0.5em;
   }
+  pre .line.added::before { content: '+' }
   .ref, .inc { text-decoration: underline; color: #008; }
   .sel { position: relative; cursor: pointer; }
   .ref.implicit { background-color: #ff8; }
@@ -52,6 +54,7 @@ constexpr llvm::StringLiteral CSS = R"css(
   #hover .target.implicit, .provides .implicit { background-color: #bbb; }
   #hover .target.ambiguous, .provides .ambiguous { background-color: #caf; }
   .missing, .unused { background-color: #faa !important; }
+  .inserted { background-color: #bea !important; }
   .semiused { background-color: #888 !important; }
   #hover th { color: #008; text-align: right; padding-right: 0.5em; }
   #hover .target:not(:first-child) {
@@ -59,6 +62,8 @@ constexpr llvm::StringLiteral CSS = R"css(
 padding-top: 1em;
 border-top: 1px solid #444;
   }
+  .ref.missing #hover .insert { font-weight: bold; }
+  .ref:not(.missing) #hover .insert { font-style: italic; }
 )css";
 
 constexpr llvm::StringLiteral JS = R"js(
@@ -128,6 +133,7 @@ class Reporter {
   llvm::raw_ostream 
   const ASTContext 
   const SourceManager 
+  HeaderSearch 
   const RecordedPP::RecordedIncludes 
   const PragmaIncludes *PI;
   FileID MainFile;
@@ -142,6 +148,7 @@ class Reporter {
 SmallVector Headers;
 SmallVector Includes;
 bool Satisfied = false; // Is the include present?
+std::string Insert; // If we had no includes, what would we insert?
   };
   std::vector Targets;
   // Points within the main file that reference a Target.
@@ -157,6 +164,7 @@ class Reporter {
   };
   std::vector Refs;
   llvm::DenseMap> IncludeRefs;
+  llvm::StringMap> Insertion;
 
   llvm::StringRef includeType(const Include *I) {
 auto  = IncludeRefs[I];
@@ -169,8 +177,24 @@ class Reporter {
 return "semiused";
   }
 
+  std::string 

[PATCH] D138489: [tsan] Add tsan support for loongarch64

2022-11-25 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added inline comments.



Comment at: compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1543
+"r"(__fn), "r"(__arg), "r"(nr_clone), "i"(__NR_exit)
+  : "memory");
+  return res;

xry111 wrote:
> SixWeining wrote:
> > tangyouling wrote:
> > > SixWeining wrote:
> > > > Shall we list $t0-$t8 here? Ref D137396.
> > > > Shall we list $t0-$t8 here? Ref D137396.
> > > 
> > > I will add the missing $t0-$t8.
> > As this inline asm is almost at the end of the function, it's sure `$t*` 
> > would not be used any more. So I think we could not add them to the clobber 
> > list. Just keep current approach.
> It's hard to tell: the compiler may decide to inline this function of perform 
> some inter-procedural analysis.  So IMO we should add t0-t8 here.
> It's hard to tell: the compiler may decide to inline this function of perform 
> some inter-procedural analysis.  So IMO we should add t0-t8 here.

"or perform", not "of perform".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138489/new/

https://reviews.llvm.org/D138489

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


[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-11-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Regarding AugmentsSyntaxTokens:

- in general this seems like a nice thing to support, though I'm not aware of 
"big" `!AugmentsSyntaxTokens` clients so it's not urgent
- I think the right design for that is to (conditionally) run the lexer and 
mark only tokens that haven't been marked yet. If the lexer doesn't provide 
enough info, then it's maybe not "syntactic".
- I think it's OK to "accidentally" produce some "syntactic" tokens in 
semantic-only mode - we shouldn't go out of our way to avoid doing so.

Since `&`, `&&`, `*` aren't always operators, and this is not syntactically 
distinguishable, I think we should just always emit all operator tokens, even 
in the standard `AugmentsSyntaxTokens` mode, and even for tokens that can only 
be operators. (In practice many other "obvious" operators aren't always either: 
`~` (destructor), `^` (objc blocks), `=` (lambda capture), `#` (directive vs 
pasting), `+-` (objc method specifiers)...)

This means AugmentSyntaxTokens doesn't belong in this patch, I think - as 
Nathan said we want to emit these tokens regardless. (Really sorry for the 
churn...)




Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:76
   ConstructorOrDestructor,
+  UserProvided,
 

nridge wrote:
> ckandeler wrote:
> > ckandeler wrote:
> > > sammccall wrote:
> > > > sammccall wrote:
> > > > > sammccall wrote:
> > > > > > Can you give some background here or on the bug tracker about what 
> > > > > > kind of distinction you're trying to draw here and why it's 
> > > > > > important?
> > > > > > (Most clients are never going to benefit from nonstandard modifiers 
> > > > > > so they should be pretty compelling)
> > > > > as well as being jargony, "user-provided" has a specific technical 
> > > > > meaning that I don't think you intend here. For example, `auto 
> > > > > operator<=>(const S&) const = default` is not user-provided 
> > > > > (defaulted on first declaration). 
> > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > 
> > > > > If we need this and can't get away with reusing `defaultLibrary` 
> > > > > (which would include `std::`) then maybe we should add something like 
> > > > > `builtin` which seems quite reusable.
> > > > Since we often can't say whether an operator is user-provided or not 
> > > > (in templates), we should consider what we want the highlighting to be 
> > > > in these cases.
> > > > (If templates should be highlighted as built-in, we should prefer a 
> > > > modifier like `UserProvided`, if they should be highlighted as 
> > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > as well as being jargony, "user-provided" has a specific technical 
> > > > meaning that I don't think you intend here. For example, `auto 
> > > > operator<=>(const S&) const = default` is not user-provided (defaulted 
> > > > on first declaration). https://eel.is/c++draft/dcl.fct.def.default#5
> > > > 
> > > > If we need this and can't get away with reusing `defaultLibrary` (which 
> > > > would include `std::`) then maybe we should add something like 
> > > > `builtin` which seems quite reusable.
> > > 
> > > I use "userProvided" here in the sense of "not built-in" or "overloaded". 
> > > I do not cling to the term, and have also suggested the opposite default 
> > > of using "builtin" in another comment.
> > > Since we often can't say whether an operator is user-provided or not (in 
> > > templates), we should consider what we want the highlighting to be in 
> > > these cases.
> > 
> > True, I have not considered this.
> > 
> > > (If templates should be highlighted as built-in, we should prefer a 
> > > modifier like `UserProvided`, if they should be highlighted as 
> > > user-provided, we should prefer a modifier like `Builtin`)
> > 
> > Intuitively, it seems we should be conservative and not claim the operator 
> > is overloaded unless we know it is. So "built-in" might then mean "we can't 
> > prove it's not a built-in". It's probably not worth to introduce a modifier 
> > CouldBeEitherWay just to explicitly express ambiguity ;)
> > Since we often can't say whether an operator is user-provided or not (in 
> > templates), we should consider what we want the highlighting to be in these 
> > cases.
> > (If templates should be highlighted as built-in, we should prefer a 
> > modifier like `UserProvided`, if they should be highlighted as 
> > user-provided, we should prefer a modifier like `Builtin`)
> 
> In my mind, "go-to-definition on this operator symbol will take me to a 
> function declaration/definition" is a good match for "I want this colored 
> differently". (Which would imply treating dependent operator calls where we 
> can't figure out an overloaded operator target even heuristically, as 
> "built-in".)
> Can you give some background here or on the bug tracker about what kind of 
> distinction you're trying to draw here and why it's important?
> (Most clients are never 

[PATCH] D138489: [tsan] Add tsan support for loongarch64

2022-11-25 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added inline comments.



Comment at: compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1543
+"r"(__fn), "r"(__arg), "r"(nr_clone), "i"(__NR_exit)
+  : "memory");
+  return res;

SixWeining wrote:
> tangyouling wrote:
> > SixWeining wrote:
> > > Shall we list $t0-$t8 here? Ref D137396.
> > > Shall we list $t0-$t8 here? Ref D137396.
> > 
> > I will add the missing $t0-$t8.
> As this inline asm is almost at the end of the function, it's sure `$t*` 
> would not be used any more. So I think we could not add them to the clobber 
> list. Just keep current approach.
It's hard to tell: the compiler may decide to inline this function of perform 
some inter-procedural analysis.  So IMO we should add t0-t8 here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138489/new/

https://reviews.llvm.org/D138489

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


[clang] b62c8d3 - Revert: Add version to all LLVM cmake package

2022-11-25 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2022-11-25T10:54:58Z
New Revision: b62c8d396f7dbef61122e169ef143276e74eff05

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

LOG: Revert: Add version to all LLVM cmake package

Summary: This reverts commit ad485b71b51168ce13282ae159bd8feff48baf84.

Reviewers:

Subscribers:

Added: 


Modified: 
clang/cmake/modules/CMakeLists.txt
clang/cmake/modules/ClangConfig.cmake.in
flang/cmake/modules/CMakeLists.txt
flang/cmake/modules/FlangConfig.cmake.in
lld/cmake/modules/CMakeLists.txt
lld/cmake/modules/LLDConfig.cmake.in
mlir/cmake/modules/CMakeLists.txt
mlir/cmake/modules/MLIRConfig.cmake.in
polly/cmake/CMakeLists.txt
polly/cmake/PollyConfig.cmake.in

Removed: 
clang/cmake/modules/ClangConfigVersion.cmake.in
flang/cmake/modules/FlangConfigVersion.cmake.in
lld/cmake/modules/LLDConfigVersion.cmake.in
mlir/cmake/modules/MLIRConfigVersion.cmake.in
polly/cmake/PollyConfigVersion.cmake.in



diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index 749ef672c34f7..880d51f5aef71 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -32,10 +32,6 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfigVersion.cmake.in
-  ${clang_cmake_builddir}/ClangConfigVersion.cmake
-  @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
@@ -63,10 +59,6 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
   @ONLY)
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfigVersion.cmake.in
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfigVersion.cmake
-  @ONLY)
 set(CLANG_CONFIG_CODE)
 set(CLANG_CONFIG_CMAKE_DIR)
 
@@ -75,7 +67,6 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
 
   install(FILES
 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
-${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfigVersion.cmake
 ${CMAKE_CURRENT_SOURCE_DIR}/AddClang.cmake
 DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}
 COMPONENT clang-cmake-exports)

diff  --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 5596ad669e209..2a254463d6f5e 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -2,8 +2,7 @@
 
 @CLANG_CONFIG_CODE@
 
-set(LLVM_VERSION 
${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
-find_package(LLVM @LLVM_VERSION@ EXACT REQUIRED CONFIG
+find_package(LLVM REQUIRED CONFIG
  HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
 
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")

diff  --git a/clang/cmake/modules/ClangConfigVersion.cmake.in 
b/clang/cmake/modules/ClangConfigVersion.cmake.in
deleted file mode 100644
index e9ac4ed2da786..0
--- a/clang/cmake/modules/ClangConfigVersion.cmake.in
+++ /dev/null
@@ -1,13 +0,0 @@
-set(PACKAGE_VERSION "@PACKAGE_VERSION@")
-
-# LLVM is API-compatible only with matching major.minor versions
-# and patch versions not less than that requested.
-if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
-"${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
-   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
-  set(PACKAGE_VERSION_COMPATIBLE 1)
-  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
-  "${PACKAGE_FIND_VERSION_PATCH}")
-set(PACKAGE_VERSION_EXACT 1)
-  endif()
-endif()

diff  --git a/flang/cmake/modules/CMakeLists.txt 
b/flang/cmake/modules/CMakeLists.txt
index bf50bcaa18d52..31a6c3c83e48b 100644
--- a/flang/cmake/modules/CMakeLists.txt
+++ b/flang/cmake/modules/CMakeLists.txt
@@ -28,8 +28,8 @@ set(FLANG_CONFIG_INCLUDE_DIRS
   "${FLANG_BINARY_DIR}/include"
   )
 configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfigVersion.cmake.in
-  ${flang_cmake_builddir}/FlangConfigVersion.cmake
+  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
+  ${flang_cmake_builddir}/FlangConfig.cmake
   @ONLY)
 set(FLANG_CONFIG_CMAKE_DIR)
 set(FLANG_CONFIG_LLVM_CMAKE_DIR)
@@ -46,10 +46,6 @@ configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfig.cmake
   @ONLY)
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfigVersion.cmake.in
-  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfigVersion.cmake
-  @ONLY)
 
 set(FLANG_CONFIG_CODE)
 set(FLANG_CONFIG_CMAKE_DIR)
@@ -60,7 +56,6 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
 
   install(FILES
 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfig.cmake
-${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfigVersion.cmake
 

[PATCH] D138546: Clangd: Preserve target flags in system includes extractor

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Sorry for noticing this so late. Yes the initial reason we left `sysroot` and 
`std/builtin-inc` related flags were exactly that, in theory they could vary 
but in practice they were applied to all or none of the project.

Regarding this change itself, surely preserving target makes sense and similar 
to sysroot and others, i'd actually expect it to be the same across all files 
in practice. But they're more likely to change without a clangd restart (e.g. 
because user invokes build in a different configuration). So i think they 
should be part of the cache key nevertheless. My main question about this 
change is, you seem to be using a `clang` driver underneath. Why is clang 
driver we have in clangd not able to infer the same search paths etc? Is the 
clang provided in android ndk a custom clang? can you provide logs in the issue 
you've mentioned above, especially the compile flags retrieved from CDB and cc1 
produced by it?

Regarding the mishandling of `-isysroot` vs `-isysroot ` (they still 
both have a single `-`, but expecting an equals in between is a mistake 
apparently), surely we should fix that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138546/new/

https://reviews.llvm.org/D138546

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


[PATCH] D138489: [tsan] Add tsan support for loongarch64

2022-11-25 Thread Youling Tang via Phabricator via cfe-commits
tangyouling updated this revision to Diff 477901.
tangyouling added a comment.

- Fixed the ThreadDescriptorSize calculation on loongarch64.
- Use `__loongarch_lp64` to distinguish loongarch64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138489/new/

https://reviews.llvm.org/D138489

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_linux.h
  compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
  compiler-rt/lib/tsan/rtl/CMakeLists.txt
  compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
  compiler-rt/lib/tsan/rtl/tsan_platform.h
  compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
  compiler-rt/lib/tsan/rtl/tsan_rtl.h
  compiler-rt/lib/tsan/rtl/tsan_rtl_loongarch64.S
  compiler-rt/test/sanitizer_common/print_address.h
  compiler-rt/test/tsan/map32bit.cpp
  compiler-rt/test/tsan/mmap_large.cpp

Index: compiler-rt/test/tsan/mmap_large.cpp
===
--- compiler-rt/test/tsan/mmap_large.cpp
+++ compiler-rt/test/tsan/mmap_large.cpp
@@ -17,7 +17,7 @@
 int main() {
 #ifdef __x86_64__
   const size_t kLog2Size = 39;
-#elif defined(__mips64) || defined(__aarch64__)
+#elif defined(__mips64) || defined(__aarch64__) || defined(__loongarch_lp64)
   const size_t kLog2Size = 32;
 #elif defined(__powerpc64__)
   const size_t kLog2Size = 39;
Index: compiler-rt/test/tsan/map32bit.cpp
===
--- compiler-rt/test/tsan/map32bit.cpp
+++ compiler-rt/test/tsan/map32bit.cpp
@@ -12,6 +12,7 @@
 // XFAIL: aarch64
 // XFAIL: powerpc64
 // XFAIL: s390x
+// XFAIL: loongarch64
 
 // MAP_32BIT doesn't exist on OS X and NetBSD.
 // UNSUPPORTED: darwin,netbsd
Index: compiler-rt/test/sanitizer_common/print_address.h
===
--- compiler-rt/test/sanitizer_common/print_address.h
+++ compiler-rt/test/sanitizer_common/print_address.h
@@ -7,8 +7,9 @@
   va_start(ap, n);
   while (n--) {
 void *p = va_arg(ap, void *);
-#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \
-defined(__s390x__) || (defined(__riscv) && __riscv_xlen == 64)
+#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) ||   \
+defined(__s390x__) || (defined(__riscv) && __riscv_xlen == 64) ||  \
+defined(__loongarch_lp64)
 // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
 // match to the format used in the diagnotic message.
 fprintf(stderr, "0x%012lx ", (unsigned long) p);
Index: compiler-rt/lib/tsan/rtl/tsan_rtl_loongarch64.S
===
--- /dev/null
+++ compiler-rt/lib/tsan/rtl/tsan_rtl_loongarch64.S
@@ -0,0 +1,196 @@
+#include "sanitizer_common/sanitizer_asm.h"
+
+.section .text
+
+ASM_HIDDEN(__tsan_setjmp)
+.comm _ZN14__interception11real_setjmpE,8,8
+.globl ASM_SYMBOL_INTERCEPTOR(setjmp)
+ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
+ASM_SYMBOL_INTERCEPTOR(setjmp):
+  CFI_STARTPROC
+
+  // Save frame pointer and return address register
+  addi.d $sp, $sp, -32
+  st.d $ra, $sp, 24
+  st.d $fp, $sp, 16
+  CFI_DEF_CFA_OFFSET (32)
+  CFI_OFFSET (1, -8)
+  CFI_OFFSET (22, -16)
+
+  // Adjust the SP for previous frame
+  addi.d $fp, $sp, 32
+  CFI_DEF_CFA_REGISTER (22)
+
+  // Save env parameter
+  st.d $a0, $sp, 8
+  CFI_OFFSET (4, -24)
+
+  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
+  addi.d  $a0, $fp, 0
+
+  // call tsan interceptor
+  bl  ASM_SYMBOL(__tsan_setjmp)
+
+  // Restore env parameter
+  ld.d $a0, $sp, 8
+  CFI_RESTORE (4)
+
+  // Restore frame/link register
+  ld.d $fp, $sp, 16
+  ld.d $ra, $sp, 24
+  addi.d $sp, $sp, 32
+  CFI_RESTORE (22)
+  CFI_RESTORE (1)
+  CFI_DEF_CFA (3, 0)
+
+  // tail jump to libc setjmp
+  la.local $a1, _ZN14__interception11real_setjmpE
+  ld.d $a1, $a1, 0
+  jr $a1
+
+  CFI_ENDPROC
+ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp))
+
+.comm _ZN14__interception12real__setjmpE,8,8
+.globl ASM_SYMBOL_INTERCEPTOR(_setjmp)
+ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
+ASM_SYMBOL_INTERCEPTOR(_setjmp):
+  CFI_STARTPROC
+
+  // Save frame pointer and return address register
+  addi.d $sp, $sp, -32
+  st.d $ra, $sp, 24
+  st.d $fp, $sp, 16
+  CFI_DEF_CFA_OFFSET (32)
+  CFI_OFFSET (1, -8)
+  CFI_OFFSET (22, -16)
+
+  // Adjust the SP for previous frame
+  addi.d $fp, $sp, 32
+  CFI_DEF_CFA_REGISTER (22)
+
+  // Save env parameter
+  st.d $a0, $sp, 8
+  CFI_OFFSET (4, -24)
+
+  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
+  addi.d  $a0, $fp, 0
+
+  // call tsan interceptor
+  bl  ASM_SYMBOL(__tsan_setjmp)
+
+  // Restore env parameter
+  ld.d $a0, $sp, 8
+  CFI_RESTORE (4)
+
+  // 

[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:97
+  /// the IWYU private pragmas with public mapping.
+  llvm::DenseSet IWYUPrivate;
+

i'd actually merge this with the previous map, and store empty verbatim 
spellings. semantics of `getPublic` is to return empty path when there are no 
mappings anyway.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:381
+// IWYU pragma: private
+class Private {};
+  )cpp";

nit: no need for the declaration of `Private` here (nor in `private.h`). it's 
actually introducing a double definition error into TU now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

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


[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.

2022-11-25 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: ilya-biryukov.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
massberg requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The check has produced false positives when checking the default implementation 
of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix 
and add another test case.

Fixes #53961


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138701

Files:
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,32 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +35,10 @@
 } // namespace std
 
 class A {
+  int a;
 public:
   auto operator<=>(const A ) const = default;
+  // CHECK-FIXES: auto operator<=>(const A ) const = default;
 };
 
 void test_cxx_rewritten_binary_ops() {
@@ -32,3 +57,14 @@
   result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
   // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : 
a2));
 }
+
+template
+struct P {
+  T1 x1;
+  T2 x2;
+  friend auto operator<=>(const P&, const P&) = default;
+  // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;
+};
+
+bool foo(P x, P y) { return x < y; }
+// CHECK-FIXES: bool foo(P x, P y) { return x < y; }
Index: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -62,7 +62,8 @@
 ImplicitCastToNull,
 hasAncestor(cxxRewrittenBinaryOperator().bind(
 "checkBinopOperands")))
-.bind(CastSequence));
+.bind(CastSequence))),
+unless(hasAncestor(functionDecl(isDefaulted()));
 }
 
 bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,32 @@
 // RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
 
 namespace std {
+class strong_ordering;
+
+struct _CmpUnspecifiedParam {
+  consteval
+  _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
 struct strong_ordering {
-  int n;
-  constexpr operator int() const { return n; }
+  signed char value;
+
+  friend constexpr bool operator==(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value == 0;
+  }
+  friend constexpr bool operator<(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value < 0;
+  }
+  friend constexpr bool operator>(strong_ordering v,
+  _CmpUnspecifiedParam) noexcept {
+return v.value > 0;
+  }
+  friend constexpr bool operator>=(strong_ordering v,
+   _CmpUnspecifiedParam) noexcept {
+return v.value >= 0;
+  }
   static const strong_ordering equal, greater, less;
 };
 constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +35,10 @@
 } // 

[PATCH] D138676: [include-cleaner] HTMLReport shows headers that would be inserted

2022-11-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: kadircet.

nice!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138676/new/

https://reviews.llvm.org/D138676

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


[PATCH] D138678: [include-cleaner] Capture private headers in PragmaIncludes.

2022-11-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:76
+  /// Returns true if the given file is marked with the IWYU private pragma
+  /// without public mapping.
+  bool isPrivate(const FileEntry *File) const;

I think this function should return true if the given file is marked with the 
IWYU private mapping pragma, because conceptually these file are also private.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h:95
+  /// Contains all files marked with IWYU private pragmas that
+  /// do not have public header mapping. This uses the UniqueID similar to
+  /// the IWYU private pragmas with public mapping.

It should collect files with mapping IWYU private pragmas.

and I think the last sentence can be removed (the intention of using UniqueID 
is clear from other comments).



Comment at: clang-tools-extra/include-cleaner/lib/Record.cpp:266
   }
+} else if (Pragma->startswith("private")) {
+  Out->IWYUPrivate.insert(SM.getFileEntryForID(CommentFID)->getUniqueID());

I'd suggest moving this to the above line 236 where we handle the private 
mapping. 



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:372
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h";
+#include "private2.h";

no extra `;` token needed for the `#include`.



Comment at: clang-tools-extra/include-cleaner/unittests/RecordTest.cpp:393
+  assert(Private2FE);
+  EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
 }

add `EXPECT_TRUE(PI.isPrivate(PrivateFE.get()))`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138678/new/

https://reviews.llvm.org/D138678

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


[PATCH] D138698: [clang-repl] Add basic documentation about clang-repl

2022-11-25 Thread Sara Bellei via Phabricator via cfe-commits
sarabellei created this revision.
sarabellei added a reviewer: v.g.vassilev.
Herald added a subscriber: arphaman.
Herald added a project: All.
sarabellei requested review of this revision.

https://reviews.llvm.org/D138698

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ClangRepl_design.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -91,6 +91,7 @@
ClangOffloadBundler
ClangOffloadWrapper
ClangOffloadPackager
+   ClangRepl
 
 Design Documents
 
Index: clang/docs/ClangRepl.rst
===
--- /dev/null
+++ clang/docs/ClangRepl.rst
@@ -0,0 +1,84 @@
+===
+Clang-REPL
+===
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a REPL style,
+compiling the code just-in-time with a JIT approach that reduces the compile-run
+ cycles.
+
+Clang-Repl is suitable for any application where dynamic run-time modifiability
+and good numerical performance are required.
+
+Clang-Repl is a project derived from
+`Cling `_, a LLVM-based C/C++
+interpreter part of the the open-source data analysis framework
+`ROOT `_, an open-source data analysis framework used by
+ high energy physics and others. Clang-Repl represents the effort to eliminate
+Cling’s dependence on ROOT, moving instead closer to the LLVM orbit.
+
+
+
+Why Clang-REPL?
+===
+
+Several advantages arise from being hosted under the LLVM umbrella.
+As part of the larger LLVM project, Clang-Repl comes as part of the LLVM
+release cycles. Therefore, Clang-Repl follows the strict LLVM coding convention,
+and meets Clang’s quality standards, including diagnostic and complete AST
+representations. This has two consequences: 1. it helps in validating the
+quality, functionality, and vitality of Clang-Repl’s development on one side,
+and 2. It facilitates users who approach Clang-Repl, because they will learn
+how Clang-REPL works through the behavior of the compiler. Furthermore, some of
+Cling’s features are tailored specifically to work on
+`ROOT `_, a software developed at
+`CERN `_ to support the storage, analysis, and
+visualization of data from High-Energy Physics’s experiments. Clang-Repl can
+neglect those features that would not be useful outside the ROOT’s framework,
+and leverage the LLVM reduced API surface compared to ROOT’s one.
+
+
+How does Clang-REPL modify the compiling cycle
+==
+
+.. image:: Clang-Repl_design.png
+   :align: center
+   :alt: Clang REPL design
+
+Clang-Repl compiler pipeline is represented by 8 phases:
+
+1. Clang-Repl controls the input infrastructure by interactive prompt or by an
+interface allowing the incremental processing of input.
+
+2. Then it sends the input to the underlying incremental facilities in Clang
+infrastructure (for simplicity libIncremental).
+
+3. Clang compiles the input into an AST representation.
+
+4. When required the AST can be further transformed in order to attach specific
+behavior.
+
+5. The AST representation is then lowered to LLVM IR.
+
+6. The LLVM IR is the input format for LLVM’s just-in-time (JIT) compilation
+infrastructure. The tool will instruct the JIT to run specified functions,
+translating them into machine code targeting the underlying device
+architecture (eg. Intel x86 or NVPTX).
+
+7. and 8. Clang-Repl can be integrated in existing applications or softwares.
+The concept of **Compiler as A Service** (**CaaS**) is now enabled: Clang-Repl
+changes the strategy to build tools in C++, supporting  interactive programming
+in a REPL style, compiling and binding code just-in-time. Offering support for
+a dynamic programming experience in C++ and control of the compiler
+simultaneously, Clang-Repl represents a tight integration between a high level
+dynamic C++ and a low level compiler.
+
+
+
+Related Reading
+===
+`Cling Transitions to LLVM's Clang-Repl `_
+
+`Moving (parts of) the Cling REPL in Clang `_
+
+`GPU Accelerated Automatic Differentiation With Clad `_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >