[PATCH] D145302: [clangd] Add library for clangd main function

2023-03-04 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko created this revision.
ivanmurashko added reviewers: sammccall, kadircet, ilya-biryukov.
Herald added a subscriber: arphaman.
Herald added a project: All.
ivanmurashko requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

The diff adds a library for clangd main function. That change allows to create 
custom builds for clangd outside the main LLVM repo. The main reason for such 
builds is an ability to use custom clang-tidy modules (created outside LLVM 
repo).

Note: The possibility for the custom clang-tidy modules was added recently at 
https://reviews.llvm.org/D73300. The header installation for clangd was also 
added as a separate diff: https://reviews.llvm.org/D145228

Test Plan:

  ninja clangd

also check that necessary libs are installed aka

  ninja install
  ...
  ls /lib/libclangdMain.a


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145302

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/tool/ClangdMain.h
  clang-tools-extra/clangd/tool/ClangdToolMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdToolMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangdMain.h"
+
+int main(int argc, char **argv) {
+  return clang::clangd::clangdMain(argc, argv);
+}
Index: clang-tools-extra/clangd/tool/ClangdMain.h
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,27 @@
+//===--- ClangdMain.h - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+#include "ClangdLSPServer.h"
+
+namespace clang {
+namespace clangd {
+// Check functon that simulates opening a file
+// (determining compile command, parsing, indexing)
+// and then running features at many locations.
+bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
+   const ClangdLSPServer::Options &Opts);
+
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangdMain.h"
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
@@ -60,10 +61,6 @@
 namespace clang {
 namespace clangd {
 
-// Implemented in Check.cpp.
-bool check(const llvm::StringRef File, const ThreadsafeFS &TFS,
-   const ClangdLSPServer::Options &Opts);
-
 namespace {
 
 using llvm::cl::cat;
@@ -710,8 +707,6 @@
   }
 };
 } // namespace
-} // namespace clangd
-} // namespace clang
 
 enum class ErrorResultCode : int {
   NoShutdownRequest = 1,
@@ -719,10 +714,7 @@
   CheckFailed = 3
 };
 
-int main(int argc, char *argv[]) {
-  using namespace clang;
-  using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
@@ -1041,3 +1033,6 @@
 
   return ExitCode;
 }
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,6 +1,13 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdMain.cpp ClangdToolMain.cpp Check.cpp)
+
+add_clang_library(clangdMain
   ClangdMain.cpp
   Check.cpp
+  )
+
+add_clang_tool(clangd
+  ClangdToolMain.cpp
   $
   )
 
@@ -13,8 +20,32 @@
   list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
 endif()
 
+clang_target_link_libraries(clangdMain
+  PRIVAT

[PATCH] D145303: clang-tidy altera-id-dependent-backward-branch: print notes after warning

2023-03-04 Thread Egor Suvorov via Phabricator via cfe-commits
yeputons-gh created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
yeputons-gh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In Clang notes are typically printed after a corresponding warning, not before.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145303

Files:
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -27,8 +27,8 @@
   int ThreadID = get_local_id(0);
 
   while (j < ThreadID) {
-// CHECK-NOTES: :[[@LINE-3]]:3: note: assignment of ID-dependent variable 
ThreadID
-// CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent variable 
ThreadID
 accumulator++;
   }
 
@@ -45,34 +45,34 @@
   };
 
   for (int i = 0; i < ThreadID2; i++) {
-// CHECK-NOTES: :[[@LINE-9]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
-// CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-10]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
 accumulator++;
   }
 
   do {
 accumulator++;
   } while (j < ThreadID);
-  // CHECK-NOTES: :[[@LINE-29]]:3: note: assignment of ID-dependent variable 
ThreadID
-  // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+  // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+  // CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent variable 
ThreadID
 
   for (int i = 0; i < Example.IDDepField; i++) {
-// CHECK-NOTES: :[[@LINE-24]]:3: note: assignment of ID-dependent field 
IDDepField
-// CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-25]]:3: note: assignment of ID-dependent field 
IDDepField
 accumulator++;
   }
 
   while (j < Example.IDDepField) {
-// CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent field 
IDDepField
-// CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-31]]:3: note: assignment of ID-dependent field 
IDDepField
 accumulator++;
   }
 
   do {
 accumulator++;
   } while (j < Example.IDDepField);
-  // CHECK-NOTES: :[[@LINE-38]]:3: note: assignment of ID-dependent field 
IDDepField
-  // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+  // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+  // CHECK-NOTES: :[[@LINE-39]]:3: note: assignment of ID-dependen

[PATCH] D145304: clang-tidy altera-id-dependent-backward-branch: refactor test

2023-03-04 Thread Egor Suvorov via Phabricator via cfe-commits
yeputons-gh created this revision.
Herald added a project: All.
yeputons-gh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- Put all "Inferred Assignments" testing at the end
- Group together ID-dependent variable/member testing
- Group together unused inferred assignments
- Use a literal instead of `get_local_size` which may have special meaning
- Create a new `struct` for each variable because analysis is done per field, 
not per field per instance.

Depends on D145303 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145304

Files:
  
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -1,9 +1,5 @@
 // RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c
 
-typedef struct ExampleStruct {
-  int IDDepField;
-} ExampleStruct;
-
 void error() {
   //  Conditional Expressions 
   int accumulator = 0;
@@ -32,39 +28,24 @@
 accumulator++;
   }
 
-  ExampleStruct Example;
-  Example.IDDepField = get_local_id(0);
-
-  //  Inferred Assignments 
-  int ThreadID2 = ThreadID * get_local_size(0);
-
-  int ThreadID3 = Example.IDDepField; // OK: not used in any loops
-
-  ExampleStruct UnusedStruct = {
-  ThreadID * 2 // OK: not used in any loops
-  };
-
-  for (int i = 0; i < ThreadID2; i++) {
-// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
-// CHECK-NOTES: :[[@LINE-10]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
-accumulator++;
-  }
-
   do {
 accumulator++;
   } while (j < ThreadID);
   // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is 
ID-dependent due to variable reference to 'ThreadID' and may cause performance 
degradation [altera-id-dependent-backward-branch]
-  // CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent variable 
ThreadID
+  // CHECK-NOTES: :[[@LINE-12]]:3: note: assignment of ID-dependent variable 
ThreadID
+
+  struct { int IDDepField; } Example;
+  Example.IDDepField = get_local_id(0);
 
   for (int i = 0; i < Example.IDDepField; i++) {
 // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
-// CHECK-NOTES: :[[@LINE-25]]:3: note: assignment of ID-dependent field 
IDDepField
+// CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent field 
IDDepField
 accumulator++;
   }
 
   while (j < Example.IDDepField) {
 // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
-// CHECK-NOTES: :[[@LINE-31]]:3: note: assignment of ID-dependent field 
IDDepField
+// CHECK-NOTES: :[[@LINE-10]]:3: note: assignment of ID-dependent field 
IDDepField
 accumulator++;
   }
 
@@ -72,7 +53,22 @@
 accumulator++;
   } while (j < Example.IDDepField);
   // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is 
ID-dependent due to member reference to 'IDDepField' and may cause performance 
degradation [altera-id-dependent-backward-branch]
-  // CHECK-NOTES: :[[@LINE-39]]:3: note: assignment of ID-dependent field 
IDDepField
+  // CHECK-NOTES: :[[@LINE-18]]:3: note: assignment of ID-dependent field 
IDDepField
+
+  //  Inferred Assignments 
+  int ThreadID2 = ThreadID * 2;
+
+  for (int i = 0; i < ThreadID2; i++) {
+// CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is 
ID-dependent due to variable reference to 'ThreadID2' and may cause performance 
degradation [altera-id-dependent-backward-branch]
+// CHECK-NOTES: :[[@LINE-4]]:3: note: inferred assignment of ID-dependent 
value from ID-dependent variable ThreadID
+accumulator++;
+  }
+
+  //  Unused Inferred Assignments 
+  int UnusedThreadID = Example.IDDepField; // OK: not used in any loops
+
+  struct { int IDDepField; } UnusedStruct;
+  UnusedStruct.IDDepField = ThreadID * 2; // OK: not used in any loops
 }
 
 void success() {


Index: clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cp

[PATCH] D145305: clang-tidy altera-id-dependent-backward-branch: fix #52790

2023-03-04 Thread Egor Suvorov via Phabricator via cfe-commits
yeputons-gh created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
yeputons-gh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Mark variables/fields as ID-dependent when initializing from ID-dependent
expressions only, not any expressions.

Depends on D145304 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145305

Files:
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -71,6 +71,8 @@
   UnusedStruct.IDDepField = ThreadID * 2; // OK: not used in any loops
 }
 
+int foo(int);
+
 void success() {
   int accumulator = 0;
 
@@ -79,4 +81,57 @@
   accumulator++;
 }
   }
+
+  //  Conditional Expressions 
+  for (int i = 0; i < foo(0); i++) {
+accumulator++;
+  }
+
+  int j = 0;
+  while (j < foo(0)) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < foo(0));
+
+  //  Assignments 
+  int NotThreadID = foo(0);
+
+  while (j < NotThreadID) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < NotThreadID);
+
+  struct { int NotIDDepField; } Example;
+  Example.NotIDDepField = foo(0);
+
+  for (int i = 0; i < Example.NotIDDepField; i++) {
+accumulator++;
+  }
+
+  while (j < Example.NotIDDepField) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < Example.NotIDDepField);
+
+  //  Inferred Assignments 
+  int NotThreadID2 = NotThreadID * 2;
+
+  for (int i = 0; i < NotThreadID2; i++) {
+accumulator++;
+  }
+
+  //  Unused Inferred Assignments 
+  int UnusedNotThreadID = Example.NotIDDepField;
+
+  struct { int NotIDDepField; } UnusedStruct;
+  UnusedStruct.NotIDDepField = NotThreadID * 2;
 }
Index: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
===
--- clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
+++ clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
@@ -56,12 +56,12 @@
   void saveIdDepField(const Stmt *Statement, const FieldDecl *Field);
   /// Stores the location an ID-dependent variable is created from a reference
   /// to another ID-dependent variable or field in IdDepVarsMap.
-  void saveIdDepVarFromReference(const DeclRefExpr *RefExpr,
+  void saveIdDepVarFromPotentialReference(const DeclRefExpr *RefExpr,
  const MemberExpr *MemExpr,
  const VarDecl *PotentialVar);
   /// Stores the location an ID-dependent field is created from a reference to
   /// another ID-dependent variable or field in IdDepFieldsMap.
-  void saveIdDepFieldFromReference(const DeclRefExpr *RefExpr,
+  void saveIdDepFieldFromPotentialReference(const DeclRefExpr *RefExpr,
const MemberExpr *MemExpr,
const FieldDecl *PotentialField);
   /// Returns the loop type.
Index: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -127,7 +127,7 @@
   Twine("assignment of ID-dependent field ") + Field->getNameAsString());
 }
 
-void IdDependentBackwardBranchCheck::saveIdDepVarFromReference(
+void IdDependentBackwardBranchCheck::saveIdDepVarFromPotentialReference(
 const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
 const VarDecl *PotentialVar) {
   // If the variable is already in IdDepVarsMap, ignore it.
@@ -140,20 +140,26 @@
   if (RefExpr) {
 const auto *RefVar = dyn_cast(RefExpr->getDecl());
 // If variable isn't ID-dependent, but RefVar is.
-if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
+if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end()) {
   StringStream << "variable " << RefVar->getNameAsString();
+  IdDepVarsMap[PotentialVar] = IdDependencyRecord(
+  PotentialVar, PotentialVar->getBeginLoc(), Message);
+  return; // Optional, as we only match only one of `RefExpr` or `MemExpr`
+}
   }
   if (MemExpr) {
 const auto *RefField = dyn_cast(MemExpr->getMemberDecl());
 // If variable isn't ID-dependent, but RefField is.
-if (IdDepFieldsMap.find(RefField) != IdDepFields

[PATCH] D144509: [CMake] Bumps minimum version to 3.20.0.

2023-03-04 Thread Mark de Wever 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 rG44c6b905f852: [CMake] Bumps minimum version to 3.20.0. 
(authored by Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144509

Files:
  bolt/runtime/CMakeLists.txt
  clang/CMakeLists.txt
  clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/crt/CMakeLists.txt
  flang/CMakeLists.txt
  flang/lib/Decimal/CMakeLists.txt
  flang/runtime/CMakeLists.txt
  libc/CMakeLists.txt
  libc/examples/hello_world/CMakeLists.txt
  libclc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/tools/debugserver/CMakeLists.txt
  llvm-libgcc/CMakeLists.txt
  llvm/CMakeLists.txt
  llvm/docs/CMake.rst
  llvm/docs/GettingStarted.rst
  llvm/docs/ReleaseNotes.rst
  mlir/CMakeLists.txt
  mlir/examples/standalone/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/cmake/DetectTestCompiler/CMakeLists.txt
  openmp/docs/SupportAndFAQ.rst
  openmp/libompd/src/CMakeLists.txt
  openmp/libomptarget/plugins/remote/src/CMakeLists.txt
  openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
  openmp/tools/Modules/FindOpenMPTarget.cmake
  openmp/tools/Modules/README.rst
  polly/CMakeLists.txt
  pstl/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -1,12 +1,5 @@
 # This file handles building LLVM runtime sub-projects.
-cmake_minimum_required(VERSION 3.13.4)
-if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-  message(WARNING
-"Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-"minimum version of CMake required to build LLVM will become 3.20.0, and "
-"using an older CMake will become an error. Please upgrade your CMake to "
-"at least 3.20.0 now to avoid issues in the future!")
-endif()
+cmake_minimum_required(VERSION 3.20.0)
 project(Runtimes C CXX ASM)
 
 # Add path for custom and the LLVM build's modules to the CMake module path.
Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 #
 #===--===##
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
Index: polly/CMakeLists.txt
===
--- polly/CMakeLists.txt
+++ polly/CMakeLists.txt
@@ -1,14 +1,7 @@
 # Check if this is a in tree build.
 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
   project(Polly)
-  cmake_minimum_required(VERSION 3.13.4)
-  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-message(WARNING
-  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-  "minimum version of CMake required to build LLVM will become 3.20.0, and "
-  "using an older CMake will become an error. Please upgrade your CMake to "
-  "at least 3.20.0 now to avoid issues in the future!")
-  endif()
+  cmake_minimum_required(VERSION 3.20.0)
   set(POLLY_STANDALONE_BUILD TRUE)
 endif()
 
Index: openmp/tools/Modules/README.rst
===
--- openmp/tools/Modules/README.rst
+++ openmp/tools/Modules/README.rst
@@ -26,7 +26,7 @@
 
 .. code-block:: cmake
 
-  cmake_minimum_required(VERSION 3.13.4)
+  cmake_minimum_required(VERSION 3.20.0)
   project(offloadTest VERSION 1.0 LANGUAGES CXX)
 
   list(APPEND CMAKE_MODULE_PATH "${PATH_TO_OPENMP_INSTALL}/lib/cmake/openmp")
@@ -37,7 +37,7 @@
   target_link_libraries(offload PRIVATE OpenMPTarget::OpenMPTarget_NVPTX)
   target_sources(offload PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp)
 
-Using this module requires at least CMake version 3.13.4. Supported languages
+Using this module requires at least CMake version 3.20.0. Supported languages
 are C and C++ with Fortran support planned in the future. If your application
 requires building for a specific device architecture you can set the
 ``OpenMPTarget__ARCH=`` variable. Compiler support is best for
Index: openmp/tools/Modules/FindOpenMPTarget.cmake
===
--- openmp/tools/Modules/FindOpenMPTarget.cmake
+++ openmp/tools/Modules/FindOpenMPTarget.cmake
@@ -79,7 +79,7 @@
 # TODO: Test more compilers
 
 cmake_policy(PUSH)
-cmake_policy(

[PATCH] D129507: [OffloadPackager] Add option to extract files from images

2023-03-04 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/Driver/offload-packager.c:2-3
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
+// UNSUPPORTED: system-windows

bader wrote:
> Are nvptx and amdgpu target required for this test?
> Latest version of the test invokes clang only for x86 target and 
> clang-offload-packager just adds triple as metadata string without using llvm 
> target. Right?
You're right, we could get rid of those. Also this made me realize that the 
test for the bitcode file isn't actually using bitcode, I should probably fix 
that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129507

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


[PATCH] D145305: clang-tidy altera-id-dependent-backward-branch: fix #52790

2023-03-04 Thread Egor Suvorov via Phabricator via cfe-commits
yeputons-gh updated this revision to Diff 502372.
yeputons-gh added a comment.

Applied clang-format to the header as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145305

Files:
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -71,6 +71,8 @@
   UnusedStruct.IDDepField = ThreadID * 2; // OK: not used in any loops
 }
 
+int foo(int);
+
 void success() {
   int accumulator = 0;
 
@@ -79,4 +81,57 @@
   accumulator++;
 }
   }
+
+  //  Conditional Expressions 
+  for (int i = 0; i < foo(0); i++) {
+accumulator++;
+  }
+
+  int j = 0;
+  while (j < foo(0)) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < foo(0));
+
+  //  Assignments 
+  int NotThreadID = foo(0);
+
+  while (j < NotThreadID) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < NotThreadID);
+
+  struct { int NotIDDepField; } Example;
+  Example.NotIDDepField = foo(0);
+
+  for (int i = 0; i < Example.NotIDDepField; i++) {
+accumulator++;
+  }
+
+  while (j < Example.NotIDDepField) {
+accumulator++;
+  }
+
+  do {
+accumulator++;
+  } while (j < Example.NotIDDepField);
+
+  //  Inferred Assignments 
+  int NotThreadID2 = NotThreadID * 2;
+
+  for (int i = 0; i < NotThreadID2; i++) {
+accumulator++;
+  }
+
+  //  Unused Inferred Assignments 
+  int UnusedNotThreadID = Example.NotIDDepField;
+
+  struct { int NotIDDepField; } UnusedStruct;
+  UnusedStruct.NotIDDepField = NotThreadID * 2;
 }
Index: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
===
--- clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
+++ clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
@@ -56,14 +56,14 @@
   void saveIdDepField(const Stmt *Statement, const FieldDecl *Field);
   /// Stores the location an ID-dependent variable is created from a reference
   /// to another ID-dependent variable or field in IdDepVarsMap.
-  void saveIdDepVarFromReference(const DeclRefExpr *RefExpr,
- const MemberExpr *MemExpr,
- const VarDecl *PotentialVar);
+  void saveIdDepVarFromPotentialReference(const DeclRefExpr *RefExpr,
+  const MemberExpr *MemExpr,
+  const VarDecl *PotentialVar);
   /// Stores the location an ID-dependent field is created from a reference to
   /// another ID-dependent variable or field in IdDepFieldsMap.
-  void saveIdDepFieldFromReference(const DeclRefExpr *RefExpr,
-   const MemberExpr *MemExpr,
-   const FieldDecl *PotentialField);
+  void saveIdDepFieldFromPotentialReference(const DeclRefExpr *RefExpr,
+const MemberExpr *MemExpr,
+const FieldDecl *PotentialField);
   /// Returns the loop type.
   LoopType getLoopType(const Stmt *Loop);
 
Index: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -127,7 +127,7 @@
   Twine("assignment of ID-dependent field ") + Field->getNameAsString());
 }
 
-void IdDependentBackwardBranchCheck::saveIdDepVarFromReference(
+void IdDependentBackwardBranchCheck::saveIdDepVarFromPotentialReference(
 const DeclRefExpr *RefExpr, const MemberExpr *MemExpr,
 const VarDecl *PotentialVar) {
   // If the variable is already in IdDepVarsMap, ignore it.
@@ -140,20 +140,26 @@
   if (RefExpr) {
 const auto *RefVar = dyn_cast(RefExpr->getDecl());
 // If variable isn't ID-dependent, but RefVar is.
-if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end())
+if (IdDepVarsMap.find(RefVar) != IdDepVarsMap.end()) {
   StringStream << "variable " << RefVar->getNameAsString();
+  IdDepVarsMap[PotentialVar] = IdDependencyRecord(
+  PotentialVar, PotentialVar->getBeginLoc(), Message);
+  return; // Optional, as we only match only one of `RefExpr` or `MemExpr`
+}
   }
   if (MemExpr) {
 const auto *RefField = dyn_cast(MemExpr->getMemberDecl());
 // If variable i

[clang] 2708869 - Re-land "[clang][Interp] Implement C++ Range-for loops"

2023-03-04 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-04T15:17:44+01:00
New Revision: 2708869801ae00f4681f6b2d9d69b25b3fce26b6

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

LOG: Re-land "[clang][Interp] Implement C++ Range-for loops"

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/test/AST/Interp/loops.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index ff2727cc4d354..a4be86c0e0639 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -172,6 +172,8 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
 return visitDoStmt(cast(S));
   case Stmt::ForStmtClass:
 return visitForStmt(cast(S));
+  case Stmt::CXXForRangeStmtClass:
+return visitCXXForRangeStmt(cast(S));
   case Stmt::BreakStmtClass:
 return visitBreakStmt(cast(S));
   case Stmt::ContinueStmtClass:
@@ -369,6 +371,58 @@ bool ByteCodeStmtGen::visitForStmt(const ForStmt 
*S) {
   return true;
 }
 
+template 
+bool ByteCodeStmtGen::visitCXXForRangeStmt(const CXXForRangeStmt *S) {
+  const Stmt *Init = S->getInit();
+  const Expr *Cond = S->getCond();
+  const Expr *Inc = S->getInc();
+  const Stmt *Body = S->getBody();
+  const Stmt *BeginStmt = S->getBeginStmt();
+  const Stmt *RangeStmt = S->getRangeStmt();
+  const Stmt *EndStmt = S->getEndStmt();
+  const VarDecl *LoopVar = S->getLoopVariable();
+
+  LabelTy EndLabel = this->getLabel();
+  LabelTy CondLabel = this->getLabel();
+  LabelTy IncLabel = this->getLabel();
+  LoopScope LS(this, EndLabel, IncLabel);
+  {
+ExprScope ES(this);
+
+// Emit declarations needed in the loop.
+if (Init && !this->visitStmt(Init))
+  return false;
+if (!this->visitStmt(RangeStmt))
+  return false;
+if (!this->visitStmt(BeginStmt))
+  return false;
+if (!this->visitStmt(EndStmt))
+  return false;
+
+// Now the condition as well as the loop variable assignment.
+this->emitLabel(CondLabel);
+if (!this->visitBool(Cond))
+  return false;
+if (!this->jumpFalse(EndLabel))
+  return false;
+
+if (!this->visitVarDecl(LoopVar))
+  return false;
+
+// Body.
+if (!this->visitStmt(Body))
+  return false;
+this->emitLabel(IncLabel);
+if (!this->discard(Inc))
+  return false;
+if (!this->jump(CondLabel))
+  return false;
+  }
+
+  this->emitLabel(EndLabel);
+  return true;
+}
+
 template 
 bool ByteCodeStmtGen::visitBreakStmt(const BreakStmt *S) {
   if (!BreakLabel)

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 7a30f7b69470a..6b3644ad13469 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -60,6 +60,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen 
{
   bool visitWhileStmt(const WhileStmt *S);
   bool visitDoStmt(const DoStmt *S);
   bool visitForStmt(const ForStmt *S);
+  bool visitCXXForRangeStmt(const CXXForRangeStmt *S);
   bool visitBreakStmt(const BreakStmt *S);
   bool visitContinueStmt(const ContinueStmt *S);
   bool visitSwitchStmt(const SwitchStmt *S);

diff  --git a/clang/test/AST/Interp/loops.cpp b/clang/test/AST/Interp/loops.cpp
index d0386e3ac759a..2e235123af76e 100644
--- a/clang/test/AST/Interp/loops.cpp
+++ b/clang/test/AST/Interp/loops.cpp
@@ -3,10 +3,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 
-verify=expected-cpp20 %s
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
-// ref-no-diagnostics
-// expected-no-diagnostics
-// expected-cpp20-no-diagnostics
-
 namespace WhileLoop {
   constexpr int f() {
 int i = 0;
@@ -274,3 +270,57 @@ namespace ForLoop {
 #endif
 
 };
+
+namespace RangeForLoop {
+  constexpr int localArray() {
+int a[] = {1,2,3,4};
+int s = 0;
+for(int i : a) {
+  s += i;
+}
+return s;
+  }
+  static_assert(localArray() == 10, "");
+
+  constexpr int localArray2() {
+int a[] = {1,2,3,4};
+int s = 0;
+for(const int &i : a) {
+  s += i;
+}
+return s;
+  }
+  static_assert(localArray2() == 10, "");
+
+  constexpr int nested() {
+int s = 0;
+for (const int i : (int[]){1,2,3,4}) {
+  int a[] = {i, i};
+  for(int m : a) {
+s += m;
+  }
+}
+return s;
+  }
+  static_assert(nested() == 20, "");
+
+  constexpr int withBreak() {
+int s = 0;
+for (const int &i: (bool[]){false, true}) {
+  if (i)
+break;
+  s++;
+}
+return s;
+  }
+  static_assert(withBreak() == 1, "");
+
+  constexpr void NoBody() {
+for (const int &i: (bool[]){false, true}); // expected-warning {{empty 
body}

[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-04 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

This patch also fixes: https://github.com/llvm/llvm-project/issues/56111, 
https://github.com/llvm/llvm-project/issues/58696, and 
https://github.com/llvm/llvm-project/issues/54730 (some of those could probably 
be made duplicates but it seems they're all going down in one blow anyway)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D145098: [clang][deps] Preserve input ordering in the full output

2023-03-04 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

Thanks for addressing this. Unfortunately the test is still failing after the 
fix and a clean build

https://lab.llvm.org/buildbot/#/builders/214/builds/6170/steps/6/logs/FAIL__Clang__modules-full-output-tu-order_c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145098

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-04 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added inline comments.



Comment at: clang/unittests/Format/QualifierFixerTest.cpp:523
+  // TODO: Something strange is going on with this formating.
+  verifyFormat("Bar < Foo, Foo const >> ;", "Bar < Foo, const Foo >> ;", 
Style);
+

(see below)



Comment at: clang/unittests/Format/QualifierFixerTest.cpp:733
+  // TODO: Something strange is going on with this formating.
+  verifyFormat("Bar < Foo, const Foo >> ;", "Bar < Foo, Foo const >> ;", 
Style);
+

This... isn't valid syntax? an opening < is missing.
Perhaps you could adapt https://github.com/llvm/llvm-project/issues/56111 into 
a test, it seems to be fixed by the patch, but there might still be corner-cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-04 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D144709#4169219 , @rymiel wrote:

> This patch also fixes: https://github.com/llvm/llvm-project/issues/56111, 
> https://github.com/llvm/llvm-project/issues/58696, and 
> https://github.com/llvm/llvm-project/issues/54730 (some of those could 
> probably be made duplicates but it seems they're all going down in one blow 
> anyway)
>
> In D144709#4165962 , 
> @MyDeveloperDay wrote:
>
>> Firstly let me say thank you for this review, your perseverance demonstrates 
>> to me that there is a desire to make this capability better
>
> +1, I certainly wouldn't have such perseverance, which is why I stick to bug 
> reports

any @rymiel we thank you for those efforts too! it just as important.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-04 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added inline comments.



Comment at: clang/unittests/Format/QualifierFixerTest.cpp:733
+  // TODO: Something strange is going on with this formating.
+  verifyFormat("Bar < Foo, const Foo >> ;", "Bar < Foo, Foo const >> ;", 
Style);
+

rymiel wrote:
> This... isn't valid syntax? an opening < is missing.
> Perhaps you could adapt https://github.com/llvm/llvm-project/issues/56111 
> into a test, it seems to be fixed by the patch, but there might still be 
> corner-cases
Right, I must've focused too much on the missing right >. What is the procedure 
now that the review is accepted. Can I still upload a fix to this and to 
include that issue in the tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D131306: [llvm][misexpect] Track provenance of branch weights

2023-03-04 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Sorry for the slow response. Looks pretty good, just a few minor suggestions 
and questions.




Comment at: llvm/include/llvm/IR/MDBuilder.h:61
 
   /// Return metadata containing two branch weights.
+  MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight,

Update comment to mention new parameter in this and the below methods.

Also, I wonder if it would be better to make the IsExpected non-optional, to 
force any new callers to think about whether they need that and help avoid 
issues where it gets dropped incorrectly?



Comment at: llvm/include/llvm/IR/ProfDataUtils.h:58
 
+/// Check if Branch Weight Metadata has an "expected" field
+bool hasExpectedProvenance(const Instruction &I);

Maybe note the meaning of the expected field (i.e. had an llvm.expect 
intrinsic).



Comment at: llvm/lib/Analysis/BranchProbabilityInfo.cpp:394
+  // Ensure there are weights for all of the successors. Note that the first
+  // operand to the metadata node is a name, not a weight.
+  if (WeightsNode->getNumOperands() !=

Isn't it now the first 1 or 2 are a name?



Comment at: llvm/lib/Analysis/BranchProbabilityInfo.cpp:397
+  TI->getNumSuccessors() + getBranchWeightOffset(WeightsNode))
+return false;
+

Should this be an assert?



Comment at: llvm/lib/IR/Instructions.cpp:732
   ProfileData->getNumOperands() > 0) {
+auto Offset = getBranchWeightOffset(ProfileData);
 // Using APInt::div may be expensive, but most cases should fit 64 bits.

I guess we don't have to worry about pushing the expect provenance because this 
is a call and it shouldn't have one. Maybe add an assert that the offset is 1?



Comment at: llvm/lib/IR/Verifier.cpp:4553
   StringRef ProfName = MDS->getString();
+  unsigned Offset = getBranchWeightOffset(I);
 

Related to an earlier comment regarding calls - maybe the verifier should 
ensure that "expected" only shows up on certain instruction types?



Comment at: llvm/lib/Transforms/Utils/MisExpect.cpp:156
+  // weights are being added multiple times, as is the case for SampleProfiling
+  // under ThinLTO. We gate all known entry paths to verifyMisExpect() by first
+  // checking for the presence of the "expected" tag in the metadata, which is

Why not check it within verifyMisExpect, seems less error prone than requiring 
callers to check?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131306

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-04 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added inline comments.



Comment at: clang/unittests/Format/QualifierFixerTest.cpp:733
+  // TODO: Something strange is going on with this formating.
+  verifyFormat("Bar < Foo, const Foo >> ;", "Bar < Foo, Foo const >> ;", 
Style);
+

AlexanderHederstaf wrote:
> rymiel wrote:
> > This... isn't valid syntax? an opening < is missing.
> > Perhaps you could adapt https://github.com/llvm/llvm-project/issues/56111 
> > into a test, it seems to be fixed by the patch, but there might still be 
> > corner-cases
> Right, I must've focused too much on the missing right >. What is the 
> procedure now that the review is accepted. Can I still upload a fix to this 
> and to include that issue in the tests?
> What is the procedure now that the review is accepted
No different to the usual! The patch will stay accepted, and reviewers can just 
re-approve anyways.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D143418: [libclang] Add API to override preamble storage path

2023-03-04 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy updated this revision to Diff 502376.
vedgy added a comment.

Replace `clang_getDefaultGlobalOptions()` with `CXChoice` as discussed.
A few unrelated small improvements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143418

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Frontend/PrecompiledPreamble.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexer.h
  clang/tools/libclang/libclang.map
  clang/unittests/Frontend/ASTUnitTest.cpp
  clang/unittests/libclang/LibclangTest.cpp
  clang/unittests/libclang/TestUtils.h

Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -22,11 +22,11 @@
 #include 
 
 class LibclangParseTest : public ::testing::Test {
-  // std::greater<> to remove files before their parent dirs in TearDown().
-  std::set> Files;
   typedef std::unique_ptr fixed_addr_string;
   std::map UnsavedFileContents;
 public:
+  // std::greater<> to remove files before their parent dirs in TearDown().
+  std::set> FilesAndDirsToRemove;
   std::string TestDir;
   bool RemoveTestDirRecursivelyDuringTeardown = false;
   CXIndex Index;
@@ -40,7 +40,7 @@
 TestDir = std::string(Dir.str());
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
   clang_defaultEditingTranslationUnitOptions();
-Index = clang_createIndex(0, 0);
+CreateIndex();
 ClangTU = nullptr;
   }
   void TearDown() override {
@@ -48,7 +48,7 @@
 clang_disposeIndex(Index);
 
 namespace fs = llvm::sys::fs;
-for (const std::string &Path : Files)
+for (const std::string &Path : FilesAndDirsToRemove)
   EXPECT_FALSE(fs::remove(Path, /*IgnoreNonExisting=*/false));
 if (RemoveTestDirRecursivelyDuringTeardown)
   EXPECT_FALSE(fs::remove_directories(TestDir, /*IgnoreErrors=*/false));
@@ -63,7 +63,7 @@
FileI != FileEnd; ++FileI) {
 ASSERT_NE(*FileI, ".");
 path::append(Path, *FileI);
-Files.emplace(Path.str());
+FilesAndDirsToRemove.emplace(Path.str());
   }
   Filename = std::string(Path.str());
 }
@@ -101,6 +101,9 @@
 return string;
   };
 
+protected:
+  virtual void CreateIndex() { Index = clang_createIndex(0, 0); }
+
 private:
   template
   static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "TestUtils.h"
 #include "clang-c/Index.h"
 #include "clang-c/Rewrite.h"
 #include "llvm/ADT/StringRef.h"
@@ -14,7 +15,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
-#include "TestUtils.h"
+#include 
 #include 
 #include 
 #include 
@@ -355,6 +356,168 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
+TEST_F(LibclangParseTest, GlobalOptions) {
+  EXPECT_EQ(clang_CXIndex_getGlobalOptions(Index), CXGlobalOpt_None);
+}
+
+class LibclangIndexOptionsTest : public LibclangParseTest {
+  virtual void AdjustOptions(CXIndexOptions &Opts) {}
+
+protected:
+  void CreateIndex() override {
+CXIndexOptions Opts;
+memset(&Opts, 0, sizeof(Opts));
+Opts.Size = sizeof(CXIndexOptions);
+AdjustOptions(Opts);
+Index = clang_createIndexWithOptions(&Opts);
+ASSERT_TRUE(Index);
+  }
+};
+
+TEST_F(LibclangIndexOptionsTest, GlobalOptions) {
+  EXPECT_EQ(clang_CXIndex_getGlobalOptions(Index), CXGlobalOpt_None);
+}
+
+class LibclangIndexingEnabledIndexOptionsTest
+: public LibclangIndexOptionsTest {
+  void AdjustOptions(CXIndexOptions &Opts) override {
+Opts.ThreadBackgroundPriorityForIndexing = CXChoice_Enabled;
+  }
+};
+
+TEST_F(LibclangIndexingEnabledIndexOptionsTest, GlobalOptions) {
+  EXPECT_EQ(clang_CXIndex_getGlobalOptions(Index),
+CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
+}
+
+class LibclangIndexingDisabledEditingEnabledIndexOptionsTest
+: public LibclangIndexOptionsTest {
+  void AdjustOptions(CXIndexOptions &Opts) override {
+Opts.ThreadBackgroundPriorityForIndexing = CXChoice_Disabled;
+Opts.ThreadBackgroundPriorityForEditing = CXChoice_Enabled;
+  }
+};
+
+TEST_F(LibclangIndexingDisabledEditingEnabledIndexOptionsTest, GlobalOptions) {
+  EXPECT_EQ(clang_CXIndex_getGlobalOptions(Index),
+CXGlobalOpt_ThreadBackgroundPriorityForEditing);
+}
+
+class LibclangBothEnabledIndexOptionsTest : public LibclangInd

[PATCH] D145305: clang-tidy altera-id-dependent-backward-branch: fix #52790

2023-03-04 Thread Egor Suvorov via Phabricator via cfe-commits
yeputons-gh added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp:128
+
+  for (int i = 0; i < NotThreadID2; i++) {
+accumulator++;

This line previously yielded a false positive. Now it does not. More tests are 
created in upcoming patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145305

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


[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 502385.
mikecrowe edited the summary of this revision.
mikecrowe added a comment.

This new version uses size_t and size_type rather than the annoyingly-named 
"size" type that the old implementation in redundant-string-cstr.cpp used and 
is the basis for using the new  header in four further checks to be 
submitted as separate changes.


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

https://reviews.llvm.org/D144216

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -1,71 +1,5 @@
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
-
-typedef unsigned __INT16_TYPE__ char16;
-typedef unsigned __INT32_TYPE__ char32;
-typedef __SIZE_TYPE__ size;
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template 
-struct basic_string {
-  typedef basic_string _Type;
-  basic_string();
-  basic_string(const C *p, const A &a = A());
-
-  ~basic_string();
-
-  const C *c_str() const;
-  const C *data() const;
-
-  _Type& append(const C *s);
-  _Type& append(const C *s, size n);
-  _Type& assign(const C *s);
-  _Type& assign(const C *s, size n);
-
-  int compare(const _Type&) const;
-  int compare(const C* s) const;
-  int compare(size pos, size len, const _Type&) const;
-  int compare(size pos, size len, const C* s) const;
-
-  size find(const _Type& str, size pos = 0) const;
-  size find(const C* s, size pos = 0) const;
-  size find(const C* s, size pos, size n) const;
-
-  _Type& insert(size pos, const _Type& str);
-  _Type& insert(size pos, const C* s);
-  _Type& insert(size pos, const C* s, size n);
-
-  _Type& operator+=(const _Type& str);
-  _Type& operator+=(const C* s);
-  _Type& operator=(const _Type& str);
-  _Type& operator=(const C* s);
-};
-
-typedef basic_string, std::allocator> string;
-typedef basic_string, std::allocator> wstring;
-typedef basic_string, std::allocator> u16string;
-typedef basic_string, std::allocator> u32string;
-
-template 
-struct basic_string_view {
-  basic_string_view(const C* s);
-};
-typedef basic_string_view> string_view;
-typedef basic_string_view> wstring_view;
-typedef basic_string_view> u16string_view;
-typedef basic_string_view> u32string_view;
-}
-
-std::string operator+(const std::string&, const std::string&);
-std::string operator+(const std::string&, const char*);
-std::string operator+(const char*, const std::string&);
-
-bool operator==(const std::string&, const std::string&);
-bool operator==(const std::string&, const char*);
-bool operator==(const char*, const std::string&);
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -isystem %clang_tidy_headers
+#include 
 
 namespace llvm {
 struct StringRef {
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -0,0 +1,74 @@
+#ifndef _STRING_
+#define _STRING_
+
+// For size_t
+#include 
+
+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template 
+struct basic_string {
+  typedef size_t size_type;
+  typedef basic_string _Type;
+  basic_string();
+  basic_string(const C *p, const A &a = A());
+
+  ~basic_string();
+
+  const C *c_str() const;
+  const C *data() const;
+
+  _Type& append(const C *s);
+  _Type& append(const C *s, size_type n);
+  _Type& assign(const C *s);
+  _Type& assign(const C *s, size_type n);
+
+  int compare(const _Type&) const;
+  int compare(const C* s) const;
+  int compare(size_type pos, size_type len, const _Type&) const;
+  int compare(size_type pos, size_type len, const C* s) const;
+
+  size_type find(const _Type& str, size_type pos = 0) const;
+  size_type find(const C* s, size_type pos = 0) const;
+  size_type find(const C* s, size_type pos, size_type n) const;
+
+  _Type& insert(size_type pos, const _Type& str);
+  _Type& insert(size_type pos, const C* s);
+  _Type& insert(size_type pos, const C* s, size_type n);
+
+  _Type& operator+=(const _Type& str);
+  _Type& operator+=(const C* s);
+  _Type& operator=(const _Type& str);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+typedef basic_string, std::allocator> u16string;
+typedef basic_string, std::allocator> u32string;
+
+template 
+struct basic_string_view {
+  basic_string_view(const C* s);
+};
+typedef b

[PATCH] D145310: [clang-tidy] Make readability-container-data-pointer use header

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This requires operator[] to be added to the std::basic_string
implementation.


https://reviews.llvm.org/D145310

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- 
-isystem %clang_tidy_headers -fno-delayed-template-parsing
+#include 
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -17,22 +18,6 @@
   const T &operator[](size_type) const;
 };
 
-template 
-struct basic_string {
-  using size_type = size_t;
-
-  basic_string();
-
-  T *data();
-  const T *data() const;
-
-  T &operator[](size_t);
-  const T &operator[](size_type) const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 template 
 struct is_integral;
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -42,6 +42,9 @@
   _Type& insert(size_type pos, const C* s);
   _Type& insert(size_type pos, const C* s, size_type n);
 
+  _Type& operator[](size_type);
+  const _Type& operator[](size_type) const;
+
   _Type& operator+=(const _Type& str);
   _Type& operator+=(const C* s);
   _Type& operator=(const _Type& str);


Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s readability-container-data-pointer %t -- -- -isystem %clang_tidy_headers -fno-delayed-template-parsing
+#include 
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -17,22 +18,6 @@
   const T &operator[](size_type) const;
 };
 
-template 
-struct basic_string {
-  using size_type = size_t;
-
-  basic_string();
-
-  T *data();
-  const T *data() const;
-
-  T &operator[](size_t);
-  const T &operator[](size_type) const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 template 
 struct is_integral;
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -42,6 +42,9 @@
   _Type& insert(size_type pos, const C* s);
   _Type& insert(size_type pos, const C* s, size_type n);
 
+  _Type& operator[](size_type);
+  const _Type& operator[](size_type) const;
+
   _Type& operator+=(const _Type& str);
   _Type& operator+=(const C* s);
   _Type& operator=(const _Type& str);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145311: Make abseil-redundant-strcat-calls checker use header

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: carlosgalvezp.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

It's unclear where the "string" in no namespace comes from in this
check. The inheritance from __gnu_cxx implies that it's supposed to be
from libstdc++ but having string outside namespace std hasn't been a
thing in libstdc++ for over twenty years!

The comment says: "Here we mimic the hierarchy of ::string. We need to
do so because we are matching on the fully qualified name of the
methods." However, this doesn't appear to be true since just using the
implementation in Inputs/Headers/string, which lacks any inheritance,
doesn't cause any of the tests to fail.

I don't use Abseil, and have no idea whether this change is appropriate,
but the check does still pass provided all uses of string are changed to
std::string!

Depends on D145310 


https://reviews.llvm.org/D145311

Files:
  clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp
@@ -1,92 +1,8 @@
-// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t
+// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers
+#include 
 
 int strlen(const char *);
 
-// Here we mimic the hierarchy of ::string.
-// We need to do so because we are matching on the fully qualified name of the
-// methods.
-struct __sso_string_base {};
-namespace __gnu_cxx {
-template 
-class __versa_string {
- public:
-  const char *c_str() const;
-  const char *data() const;
-  int size() const;
-  int capacity() const;
-  int length() const;
-  bool empty() const;
-  char &operator[](int);
-  void clear();
-  void resize(int);
-  int compare(const __versa_string &) const;
-};
-}  // namespace __gnu_cxx
-
-namespace std {
-template 
-class char_traits {};
-template 
-class allocator {};
-}  // namespace std
-
-template ,
-  typename C = std::allocator>
-class basic_string : public __gnu_cxx::__versa_string {
- public:
-  basic_string();
-  basic_string(const basic_string &);
-  basic_string(const char *, C = C());
-  basic_string(const char *, int, C = C());
-  basic_string(const basic_string &, int, int, C = C());
-  ~basic_string();
-
-  basic_string &operator+=(const basic_string &);
-};
-
-template 
-basic_string operator+(const basic_string &,
-const basic_string &);
-template 
-basic_string operator+(const basic_string &, const char *);
-
-typedef basic_string string;
-
-bool operator==(const string &, const string &);
-bool operator==(const string &, const char *);
-bool operator==(const char *, const string &);
-
-bool operator!=(const string &, const string &);
-bool operator<(const string &, const string &);
-bool operator>(const string &, const string &);
-bool operator<=(const string &, const string &);
-bool operator>=(const string &, const string &);
-
-namespace std {
-template ,
-  typename _Alloc = allocator<_CharT>>
-class basic_string;
-
-template 
-class basic_string {
- public:
-  basic_string();
-  basic_string(const basic_string &);
-  basic_string(const char *, const _Alloc & = _Alloc());
-  basic_string(const char *, int, const _Alloc & = _Alloc());
-  basic_string(const basic_string &, int, int, const _Alloc & = _Alloc());
-  ~basic_string();
-
-  basic_string &operator+=(const basic_string &);
-
-  unsigned size() const;
-  unsigned length() const;
-  bool empty() const;
-};
-
-typedef basic_string string;
-}  // namespace std
-
 namespace absl {
 
 class string_view {
@@ -95,12 +11,12 @@
 
   string_view();
   string_view(const char *);
-  string_view(const string &);
+  string_view(const std::string &);
   string_view(const char *, int);
   string_view(string_view, int);
 
   template 
-  explicit operator ::basic_string() const;
+  explicit operator std::basic_string() const;
 
   const char *data() const;
   int size() const;
@@ -113,7 +29,7 @@
   AlphaNum(int i);
   AlphaNum(double f);
   AlphaNum(const char *c_str);
-  AlphaNum(const string &str);
+  AlphaNum(const std::string &str);
   AlphaNum(const string_view &pc);
 
  private:
@@ -121,28 +37,28 @@
   AlphaNum &operator=(const AlphaNum &);
 };
 
-string StrCat();
-string StrCat(const AlphaNum &A);
-string StrCat(const AlphaNum &A, const AlphaNum &B);
-string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C);
-string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C,
-  const AlphaNum &D);
+std::string StrCat();
+std::string StrCat(const AlphaNum &A);
+std::string StrCat(const

[PATCH] D145312: [clang-tidy] Make readability-string-compare check use header

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Improve the generic  header by adding another constructor,
std::basic_string::empty and operator!= overload set so that it can be
used to replace the custom implementation in the
readability-string-compare check.


https://reviews.llvm.org/D145312

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template , typename A = 
std::allocator>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string &str) const;
-  bool empty();
-};
-bool operator==(const basic_string &lhs, const basic_string &rhs);
-bool operator!=(const basic_string &lhs, const basic_string &rhs);
-bool operator==(const basic_string &lhs, const char *&rhs);
-typedef basic_string string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem 
%clang_tidy_headers
+#include 
 
 void func(bool b);
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@
   typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_


Index: clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/string-compare.cpp
@@ -1,25 +1,5 @@
-// RUN: %check_clang_tidy %s readability-string-compare %t
-
-namespace std {
-template 
-class allocator {};
-template 
-class char_traits {};
-template , typename A = std::allocator>
-class basic_string {
-public:
-  basic_string();
-  basic_string(const C *, unsigned int size);
-  int compare(const basic_string &str) const;
-  int compare(const C *) const;
-  int compare(int, int, const basic_string &str) const;
-  bool empty();
-};
-bool operator==(const basic_string &lhs, const basic_string &rhs);
-bool operator!=(const basic_string &lhs, const basic_string &rhs);
-bool operator==(const basic_string &lhs, const char *&rhs);
-typedef basic_string string;
-}
+// RUN: %check_clang_tidy %s readability-string-compare %t -- -- -isystem %clang_tidy_headers
+#include 
 
 void func(bool b);
 
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
@@ -18,12 +18,15 @@
   typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+  basic_string(const C *p, size_type count);
 
   ~basic_string();
 
   const C *c_str() const;
   const C *data() const;
 
+  bool empty() const;
+
   _Type& append(const C *s);
   _Type& append(const C *s, size_type n);
   _Type& assign(const C *s);
@@ -72,6 +75,10 @@
 bool operator==(const std::string&, const std::string&);
 bool operator==(const std::string&, const char*);
 bool operator==(const char*, const std::string&);
+
+bool operator!=(const std::string&, const std::string&);
+bool operator!=(const std::string&, const char*);
+bool operator!=(const char*, const std::string&);
 }
 
 #endif // _STRING_
___

[PATCH] D145313: [clang-tidy] Make readability-container-size-empty check using header

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Improve the generic  header by adding the size() method so that
it can be used to replace the custom implementation in the
readability-container-size-empty check.

This requires fixing an incorrect comparison of a std::wstring with a
char string literal.

Unfortunately, removing the custom basic_string implementation means
fixing the line numbers for many of the checks.

Depends on D145312 


https://reviews.llvm.org/D145313

Files:
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,6 +1,7 @@
 // RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: [{key: readability-container-size-empty.ExcludedComparisonTypes , value: '::std::array;::IgnoredDummyType'}]}" \
-// RUN: -- -fno-delayed-template-parsing
+// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
+#include 
 
 namespace std {
 template  struct vector {
@@ -11,20 +12,6 @@
   bool empty() const;
 };
 
-template  struct basic_string {
-  basic_string();
-  bool operator==(const basic_string& other) const;
-  bool operator!=(const basic_string& other) const;
-  bool operator==(const char *) const;
-  bool operator!=(const char *) const;
-  basic_string operator+(const basic_string& other) const;
-  unsigned long size() const;
-  bool empty() const;
-};
-
-typedef basic_string string;
-typedef basic_string wstring;
-
 inline namespace __v2 {
 template  struct set {
   set();
@@ -125,12 +112,12 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (intSet == std::set())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
-  // CHECK-MESSAGES: :34:8: note: method 'set'::empty() defined here
+  // CHECK-MESSAGES: :21:8: note: method 'set'::empty() defined here
   if (s_func() == "")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
@@ -155,7 +142,7 @@
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
-  if (wstr == "")
+  if (wstr == L"")
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
@@ -452,7 +439,7 @@
 public:
   ConstructWithBoolField(const std::vector &C) : B(C.size()) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:57: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}ConstructWithBoolField(const std::vector &C) : B(!C.empty()) {}
 };
 
@@ -460,21 +447,21 @@
   std::vector C;
   bool B = C.size();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}bool B = !C.empty();
 };
 
 int func(const std::vector &C) {
   return C.size() ? 0 : 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :11:8: note: method 'vector'::empty() defined here
+// CHECK-MESSAGES: :12:8: note: method 'vector'::empty() defined here
 // CHECK-FIXES: {{^  }}return !C.empty() ? 0 : 1;
 }
 
 constexpr Lazy L;
 static_assert(!L.size(), "");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: the 'empty' method should be used
-// CHECK-MESSAGES: :103:18: note: method 'Lazy'::empty() defined here
+// CHECK-MESSAGES: :90:18: note: method 'Lazy'::empty() defined here
 // CHECK-FIXES: {{^}}static_assert(L.empty(), "");
 
 struct StructWithLazyNoexcept {
@@ -489,7 +476,7 @@
   if (v.size())
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
-  // CHECK-MESSAGES: :11:8: note: method 'vector'::emp

[PATCH] D144216: [clang-tidy] Extract string header from redundant-string-cstr checker

2023-03-04 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

The changes that extend the  header further and use it in a few more 
checks are:

- https://reviews.llvm.org/D145310
- https://reviews.llvm.org/D145311
- https://reviews.llvm.org/D145312
- https://reviews.llvm.org/D145313

and of course my original change:

- https://reviews.llvm.org/D143342


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

https://reviews.llvm.org/D144216

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

2023-03-04 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 502390.
jaredgrubb added a comment.

Create unit-tests for the patch (and remove the proposed non-unit test "test").


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

https://reviews.llvm.org/D145262

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestObjC.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1292,6 +1292,34 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GenericSelectionColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
+  // '__attribute__' has special handling.
+  auto Tokens = annotate("__attribute__(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw___attribute, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  // 'TT_FunctionAnnotationRParen' doesn't seem right; fix?
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_FunctionAnnotationRParen);
+
+  // Add a custom AttributeMacro. Test that it has the same behavior.
+  FormatStyle Style = getLLVMStyle();
+  Style.AttributeMacros.push_back("A");
+
+  // An "AttributeMacro" gets annotated like '__attribute__'.
+  Tokens = annotate("A(X) void Foo(void);", Style);
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_AttributeMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_AttributeParen);
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_AttributeParen);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1489,6 +1489,9 @@
 }
 
 TEST_F(FormatTestObjC, Attributes) {
+  Style.AttributeMacros.push_back("ATTRIBUTE_MACRO");
+
+  // Check '__attribute__' macro directly.
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@interface Foo\n"
"@end");
@@ -1498,6 +1501,41 @@
   verifyFormat("__attribute__((objc_subclassing_restricted))\n"
"@implementation Foo\n"
"@end");
+
+  // Check AttributeMacro gets treated the same, with or without parentheses.
+  verifyFormat("ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
+
+  // Indenter also needs to understand multiple attribute macros.
+  verifyFormat("ATTRIBUTE_MACRO(X) ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("ATTRIBUTE_MACRO ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
+
+  Style.ColumnLimit = 30;
+  verifyFormat("ATTRIBUTE_MACRO(X)\n"
+   "ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  // Note: the following -should- break across multiple lines, but doesn't.
+  // This is added to acknowledge the behavior, but it should be improved.
+  verifyFormat("ATTRIBUTE_MACRO ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
+
+  Style.ColumnLimit = 0;
+  verifyFormat("ATTRIBUTE_MACRO(X) ATTRIBUTE_MACRO\n"
+   "@interface Foo\n"
+   "@end");
+  verifyFormat("ATTRIBUTE_MACRO ATTRIBUTE_MACRO(X)\n"
+   "@interface Foo\n"
+   "@end");
 }
 
 } // end namespace
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,7 +369,7 @@
 // Infer the role of the l_paren based on the previous token if we haven't
 // detected one yet.
 if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
-  if (PrevNonComment->is(tok::kw___attribute)) {
+  if (PrevNonComment->isOneOf(tok::kw___attribute, TT_AttributeMacro)) {
 OpeningParen.setType(TT_AttributeParen);
   } else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
  tok::kw_typeof,
@@ -4889,8 +4889,10 @@
   }
 
   // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.is(TT_AttributeParen) &&

[clang] fc10715 - Fix broken link on Clang documentation page

2023-03-04 Thread Roy Jacobson via cfe-commits

Author: Tulio Leao
Date: 2023-03-05T00:58:48+02:00
New Revision: fc10715f9bb39741fcfd5373134767481235aa14

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

LOG: Fix broken link on Clang documentation page

While browsing the latest [clang 
manual](https://clang.llvm.org/docs/ReleaseNotes.html), I came across this 
warning and clicked, but it leads to a broken page, apparently because it's 
missing the trailing `/`. Seems to be the only place where it's missing in the 
whole of LLVM monorepo.

{F26690053}
{F26690057}

Reviewed By: brenoguim, royjacobson

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c152cab15c6..988bcf186098 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@ Written by the `LLVM Team `_
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 



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


[PATCH] D145047: Fix broken link on Clang documentation page

2023-03-04 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc10715f9bb3: Fix broken link on Clang documentation page 
(authored by tupaschoal, committed by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145047

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144823: [Driver][FreeBSD] Simplify ARM handling

2023-03-04 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144823

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


[PATCH] D144823: [Driver][FreeBSD] Simplify ARM handling

2023-03-04 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

I think this is fine. @emaste can you think of any objections? 8 and 9 are long 
gone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144823

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


[PATCH] D145214: [TSAN] add support for riscv64

2023-03-04 Thread Alex Fan via Phabricator via cfe-commits
alexfanqi updated this revision to Diff 502397.
alexfanqi added a comment.

remove libatomic link


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145214

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  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_riscv64.S
  compiler-rt/test/tsan/map32bit.cpp
  compiler-rt/test/tsan/mmap_large.cpp
  compiler-rt/test/tsan/test.h

Index: compiler-rt/test/tsan/test.h
===
--- compiler-rt/test/tsan/test.h
+++ compiler-rt/test/tsan/test.h
@@ -73,6 +73,8 @@
 const int kPCInc = 1;
 #elif defined(__sparc__) || defined(__mips__)
 const int kPCInc = 8;
+#elif defined(__riscv) && __riscv_xlen == 64
+const int kPCInc = 2;
 #else
 const int kPCInc = 4;
 #endif
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,8 @@
 int main() {
 #ifdef __x86_64__
   const size_t kLog2Size = 39;
-#elif defined(__mips64) || defined(__aarch64__) || defined(__loongarch_lp64)
+#elif defined(__mips64) || defined(__aarch64__) || \
+defined(__loongarch_lp64) || (defined(__riscv) && __riscv_xlen == 64)
   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
@@ -13,6 +13,7 @@
 // XFAIL: target=powerpc64{{.*}}
 // XFAIL: target=s390x{{.*}}
 // XFAIL: target=loongarch64{{.*}}
+// XFAIL: target=riscv64{{.*}}
 
 // MAP_32BIT doesn't exist on OS X and NetBSD.
 // UNSUPPORTED: darwin,target={{.*netbsd.*}}
Index: compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S
===
--- /dev/null
+++ compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S
@@ -0,0 +1,203 @@
+#include "sanitizer_common/sanitizer_asm.h"
+
+.section .text
+
+.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 sp, sp, -32
+  sd ra, 24(sp)
+  sd s0, 16(sp)
+  CFI_DEF_CFA_OFFSET (32)
+  CFI_OFFSET (1, -8)
+  CFI_OFFSET (8, -16)
+
+  // Adjust the SP for previous frame
+  addi s0, sp, 32
+  CFI_DEF_CFA_REGISTER (8)
+
+  // Save env parameter
+  sd a0, 8(sp)
+  CFI_OFFSET (10, -24)
+
+  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
+  addi  a0, s0, 0
+
+  // call tsan interceptor
+  call ASM_SYMBOL(__tsan_setjmp)
+
+  // Restore env parameter
+  ld a0, 8(sp)
+  CFI_RESTORE (10)
+
+  // Restore frame/link register
+  ld s0, 16(sp)
+  ld ra, 24(sp)
+  addi sp, sp, 32
+  CFI_RESTORE (8)
+  CFI_RESTORE (1)
+  CFI_DEF_CFA (2, 0)
+
+  // tail jump to libc setjmp
+  la t1, _ZN14__interception11real_setjmpE
+  ld t1, 0(t1)
+  jr t1
+
+  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 sp, sp, -32
+  sd ra, 24(sp)
+  sd s0, 16(sp)
+  CFI_DEF_CFA_OFFSET (32)
+  CFI_OFFSET (1, -8)
+  CFI_OFFSET (8, -16)
+
+  // Adjust the SP for previous frame
+  addi s0, sp, 32
+  CFI_DEF_CFA_REGISTER (8)
+
+  // Save env parameter
+  sd a0, 8(sp)
+  CFI_OFFSET (10, -24)
+
+  // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
+  addi  a0, s0, 0
+
+  // call tsan interceptor
+  call ASM_SYMBOL(__tsan_setjmp)
+
+  // Restore env parameter
+  ld a0, 8(sp)
+  CFI_RESTORE (10)
+
+  // Restore frame/link register
+  ld s0, 16(sp)
+  ld ra, 24(sp)
+  addi sp, sp, 32
+  CFI_RESTORE (8)
+  CFI_RESTORE (1)
+  CFI_DEF_CFA (2, 0)
+
+  // tail jump to libc setjmp
+  la t1, _ZN14__interception12real__setjmpE
+  ld t1, 0(t1)
+  jr t1
+
+  CFI_ENDPROC
+ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp))
+
+.comm _ZN14__interception14real_sigsetjmpE,8,8
+.globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp)
+ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
+ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
+  CFI_STARTPROC
+
+  // Save frame pointer and return address register
+  addi sp, sp, -32
+  sd ra, 24(sp)
+  sd s0, 16(sp)
+  CFI_DEF_CFA_OFFSET (32)
+  CFI_OFFSET (1, -8)
+  CFI_OFFSET (8, -16)
+
+  // Adjust the SP for previous frame
+  addi s0, sp, 32
+  CFI_DEF_CFA_REGISTER (8)
+
+  // Save env parameter
+  sd a0, 8(s

[PATCH] D145214: [TSAN] add support for riscv64

2023-03-04 Thread Alex Fan via Phabricator via cfe-commits
alexfanqi added inline comments.



Comment at: compiler-rt/lib/tsan/rtl/tsan_platform.h:971
 };
-const uptr indicator = 0x0e00ull;
+const uptr indicator = 0x0f00ull;
 const uptr ind_lsb = 1ull << LeastSignificantSetBitIndex(indicator);

jrtc27 wrote:
> ?
This is changed for sv48. Tsan compresses the address to 44 bits and uses the 
top 3 bits (42-44) to uncompress it by comparing with the corresponding bits in 
the mapping. So the 42-44th bits of each app mapping range must be all 
different from each other.  But 3 bits are not enough to distinguish mappings 
in this scheme of MappingRiscv64_48, so I increment it to 4 bits. An 
alternative of this would be reducing app mapping size by half.



Comment at: compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp:270-271
+#elif SANITIZER_RISCV64
+  // the bottom half of vma is allocated for userspace
+  vmaSize = vmaSize + 1;
+# if !SANITIZER_GO

jrtc27 wrote:
> Why don't other architectures need the +1?
I am not too sure about other architectures. Perhaps, because riscv kernel 
divides vma range further by 2. 
https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/pgtable.h#L785
By https://docs.kernel.org/riscv/vm-layout.html, botton half is exposed for 
userspace, top half is for kernel.
The available userspace virtual address size for arm64 with same bit size is 
exactly double of riscv. For example, 39bit -> 0x40(riscv) vs 
0x80(arm64) 




Comment at: compiler-rt/test/tsan/test.h:77
+#elif defined(__riscv) && __riscv_xlen == 64
+const int kPCInc = 2;
 #else

jrtc27 wrote:
> What's this the length of? RVC is optional.
The same length as in GetPreviousInstructionPc. Without it, I got java_race_pc, 
race_range_pc test failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145214

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


[PATCH] D145316: [Clang][Lex] Generate an annotation token for clang-repl

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patches adds a new annotation token called annot_input_end, which
can be used to capture expression in value printing. It works somewhat
like annot_end_of_module token we already have.

This approach is proposed by Richard Smith, thanks!

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145316

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp

Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::annot_input_end))
+ConsumeAnyToken();
 
   Result = nullptr;
   switch (Tok.getKind()) {
@@ -697,6 +698,7 @@
 return false;
 
   case tok::eof:
+  case tok::annot_input_end:
 // Check whether -fmax-tokens= was reached.
 if (PP.getMaxTokens() != 0 && PP.getTokenCount() > PP.getMaxTokens()) {
   PP.Diag(Tok.getLocation(), diag::warn_max_tokens_total)
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2061,6 +2061,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   return;
 
 default:
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -836,6 +836,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Ran out of tokens.
   return false;
 
@@ -1242,6 +1243,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Ran out of tokens.
   return false;
 
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -535,13 +535,19 @@
   return LeavingSubmodule;
 }
   }
-
   // If this is the end of the main file, form an EOF token.
   assert(CurLexer && "Got EOF but no current lexer set!");
   const char *EndPos = getCurLexerEndPos();
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
-  CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
+
+  if (isIncrementalProcessingEnabled()) {
+CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_input_end);
+Result.setAnnotationEndLoc(Result.getLocation());
+Result.setAnnotationValue(nullptr);
+  } else {
+CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
+  }
 
   if (isCodeCompletionEnabled()) {
 // Inserting the code-completion point increases the source buffer by 1,
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -158,8 +158,8 @@
   LastPTU.TUPart = C.getTranslationUnitDecl();
 
   // Skip previous eof due to last incremental input.
-  if (P->getCurToken().is(tok::eof)) {
-P->ConsumeToken();
+  if (P->getCurToken().is(tok::annot_input_end)) {
+P->ConsumeAnyToken();
 // FIXME: Clang does not call ExitScope on finalizing the regular TU, we
 // might want to do that around HandleEndOfTranslationUnit.
 P->ExitScope();
@@ -259,12 +259,12 @@
 Token Tok;
 do {
   PP.Lex(Tok);
-} while (Tok.isNot(tok::eof));
+} while (Tok.isNot(tok::annot_input_end));
   }
 
   Token AssertTok;
   PP.Lex(AssertTok);
-  assert(AssertTok.is(tok::eof) &&
+  assert(AssertTok.is(tok::annot_input_end) &&
  "Lexer must be EOF when starting incremental parse!");
 
   if (CodeGenerator *CG = getCodeGen(Act.get())) {
Index: clang/lib/Frontend/PrintP

[PATCH] D141215: [clang-repl] Introduce Value and implement pretty printing

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 502402.
junaire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -66,6 +66,32 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, bool);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, signed char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long "
+  "long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, float);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, double);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, void*);",
+  "void* __InterpreterSetValueWithAlloc(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+  llvm::cantFail(Interp.ParseAndExecute("#include "));
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:0x.*]]
+
+%quit
+
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -543,8 +543,16 @@
 return ParseCaseStatement(StmtCtx, /*MissingCase=*/true, Expr);
   }
 
-  // Otherwise, eat the semicolon.
-  ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::annot_input_end)) {
+// If we're parsing an ExprStmt and the last semicolon is missing and the
+// incremental externsion is enabled and we're reaching the end, consider we
+// want to do value printing.
+ConsumeAnyToken();
+setPrettyPrintMode();
+  } else {
+// Otherwise, eat the semicolon.
+ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+  }
   return handleExprStmt(Expr, StmtCtx);
 }
 
Index: clang/lib/Interpreter/Value.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/Value.cpp

[PATCH] D141215: [clang-repl] Introduce Value and implement pretty printing

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 502405.
junaire added a comment.

Prefer one patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -66,6 +66,32 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, bool);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, signed char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long "
+  "long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, float);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, double);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, void*);",
+  "void* __InterpreterSetValueWithAlloc(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+  llvm::cantFail(Interp.ParseAndExecute("#include "));
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:0x.*]]
+
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok:

[PATCH] D145316: [Clang][Lex] Generate an annotation token for clang-repl

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire abandoned this revision.
junaire added a comment.

Merged changes into the child revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145316

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


[PATCH] D141215: [clang-repl] Introduce Value and implement pretty printing

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 502406.
junaire added a comment.

Fix patch application failed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -66,6 +66,32 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, bool);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, signed char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long "
+  "long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, float);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, double);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, void*);",
+  "void* __InterpreterSetValueWithAlloc(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+  llvm::cantFail(Interp.ParseAndExecute("#include "));
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:0x.*]]
+
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() &&

[PATCH] D141215: [clang-repl] Introduce Value and implement pretty printing

2023-03-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 502407.
junaire added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -66,6 +66,32 @@
   return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+static void DeclareMagicFunctions(clang::Interpreter &Interp) {
+  std::vector MagicFunctions = {
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, bool);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, signed char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, long long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned char);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned short);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned int);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, unsigned long "
+  "long);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, float);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, double);",
+  "void __InterpreterSetValueNoAlloc(void*, void*, void*, void*);",
+  "void* __InterpreterSetValueWithAlloc(void*, void*, void*);"};
+
+  for (llvm::StringRef Function : MagicFunctions) {
+llvm::cantFail(Interp.ParseAndExecute(Function));
+  }
+  llvm::cantFail(Interp.ParseAndExecute("#include "));
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -110,6 +136,7 @@
 
   bool HasError = false;
 
+  DeclareMagicFunctions(*Interp);
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) a
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.21
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:0x.*]]
+
+%quit
+
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::annot_inp