[clang] 1050560 - [clang][NFC] Add a missing 'override'

2020-07-17 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-17T17:35:59-07:00
New Revision: 105056045d9ab0b1a49781a18129ada48893452e

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

LOG: [clang][NFC] Add a missing 'override'

Added: 


Modified: 
clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Removed: 




diff  --git a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp 
b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
index 5495f27f5b32..4e6fbeee86a3 100644
--- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -29,7 +29,7 @@ class CTUASTConsumer : public clang::ASTConsumer {
   explicit CTUASTConsumer(clang::CompilerInstance &CI, bool *Success)
   : CTU(CI), Success(Success) {}
 
-  void HandleTranslationUnit(ASTContext &Ctx) {
+  void HandleTranslationUnit(ASTContext &Ctx) override {
 auto FindFInTU = [](const TranslationUnitDecl *TU) {
   const FunctionDecl *FD = nullptr;
   for (const Decl *D : TU->decls()) {



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


[clang] 8b6179f - [NFC] Add missing 'override's

2020-07-20 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-20T14:39:36-07:00
New Revision: 8b6179f48c6c6701447b68615fdd3b0345f241a4

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

LOG: [NFC] Add missing 'override's

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h 
b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
index 40679f9143b9..6dab79e6e20a 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -26,7 +26,7 @@ class CGOpenMPRuntimeNVPTX : public CGOpenMPRuntimeGPU {
 
 public:
   explicit CGOpenMPRuntimeNVPTX(CodeGenModule &CGM);
-  llvm::Value *getGPUWarpSize(CodeGenFunction &CGF);
+  llvm::Value *getGPUWarpSize(CodeGenFunction &CGF) override;
 };
 
 } // CodeGen namespace.

diff  --git 
a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
index 651d5056dd9d..dfa70c8ef6c9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -89,14 +89,14 @@ class SuspendedThreadsListLinux : public 
SuspendedThreadsList {
  public:
   SuspendedThreadsListLinux() { thread_ids_.reserve(1024); }
 
-  tid_t GetThreadID(uptr index) const;
-  uptr ThreadCount() const;
+  tid_t GetThreadID(uptr index) override const;
+  uptr ThreadCount() const override;
   bool ContainsTid(tid_t thread_id) const;
   void Append(tid_t tid);
 
   PtraceRegistersStatus GetRegistersAndSP(uptr index, uptr *buffer,
-  uptr *sp) const;
-  uptr RegisterCount() const;
+  uptr *sp) const override;
+  uptr RegisterCount() const override;
 
  private:
   InternalMmapVector thread_ids_;



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


[clang] fc24d1e - [clang][NFC] Add missing 'override's

2020-07-20 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-20T16:43:24-07:00
New Revision: fc24d1eaddd8c0618e3ef3ab395029a0238d4568

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

LOG: [clang][NFC] Add missing 'override's

Added: 


Modified: 
clang/lib/Tooling/Refactoring/RefactoringActions.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Refactoring/RefactoringActions.cpp 
b/clang/lib/Tooling/Refactoring/RefactoringActions.cpp
index 7ac723f67c04..bf98941f568b 100644
--- a/clang/lib/Tooling/Refactoring/RefactoringActions.cpp
+++ b/clang/lib/Tooling/Refactoring/RefactoringActions.cpp
@@ -18,8 +18,8 @@ namespace {
 
 class DeclNameOption final : public OptionalRefactoringOption {
 public:
-  StringRef getName() const { return "name"; }
-  StringRef getDescription() const {
+  StringRef getName() const override { return "name"; }
+  StringRef getDescription() const override {
 return "Name of the extracted declaration";
   }
 };



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


[clang] 865ee64 - [NFC] Add missing 'override's

2020-07-20 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-20T19:52:49-07:00
New Revision: 865ee64bf80ca833548582476202ec8b70987341

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

LOG: [NFC] Add missing 'override's

Added: 


Modified: 
clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp
llvm/include/llvm/Support/CrashRecoveryContext.h

Removed: 




diff  --git a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp 
b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
index dabcd6aa8f15..b91bf798aa7f 100644
--- a/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ b/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -104,7 +104,7 @@ void MapExtDefNamesConsumer::addIfInMain(const 
DeclaratorDecl *DD,
 class MapExtDefNamesAction : public ASTFrontendAction {
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
- llvm::StringRef) {
+ llvm::StringRef) override {
 return std::make_unique(CI.getASTContext());
   }
 };

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 91659e76219a..91d2dc23d861 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -179,12 +179,12 @@ class SingleCommandCompilationDatabase : public 
tooling::CompilationDatabase {
   SingleCommandCompilationDatabase(tooling::CompileCommand Cmd)
   : Command(std::move(Cmd)) {}
 
-  virtual std::vector
-  getCompileCommands(StringRef FilePath) const {
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
 return {Command};
   }
 
-  virtual std::vector getAllCompileCommands() const {
+  std::vector getAllCompileCommands() const override {
 return {Command};
   }
 

diff  --git a/llvm/include/llvm/Support/CrashRecoveryContext.h 
b/llvm/include/llvm/Support/CrashRecoveryContext.h
index 61a1bd405a4d..1529c197a301 100644
--- a/llvm/include/llvm/Support/CrashRecoveryContext.h
+++ b/llvm/include/llvm/Support/CrashRecoveryContext.h
@@ -181,7 +181,7 @@ class CrashRecoveryContextDestructorCleanup : public
   : CrashRecoveryContextCleanupBase<
 CrashRecoveryContextDestructorCleanup, T>(context, resource) {}
 
-  virtual void recoverResources() {
+  void recoverResources() override {
 this->resource->~T();
   }
 };



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


[clang-tools-extra] fa42b7c - [clang-tools-extra] Disable -Wsuggest-override for unittests/

2020-07-21 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-21T09:11:53-07:00
New Revision: fa42b7cf2949802ff0b8a63a2e111a2a68711067

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

LOG: [clang-tools-extra] Disable -Wsuggest-override for unittests/

This avoids massive warning spam due to the unit tests' use of gtest and gmock, 
which do not use the 'override' keyword in their sources.

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

Added: 


Modified: 
clang-tools-extra/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/unittests/CMakeLists.txt 
b/clang-tools-extra/unittests/CMakeLists.txt
index 086a68e63830..751827cd2a0f 100644
--- a/clang-tools-extra/unittests/CMakeLists.txt
+++ b/clang-tools-extra/unittests/CMakeLists.txt
@@ -5,6 +5,10 @@ function(add_extra_unittest test_dirname)
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_definitions("-Wno-suggest-override")
+endif()
+
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-change-namespace)
 add_subdirectory(clang-doc)



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


[clang] a361aa5 - [clang] Disable -Wsuggest-override for unittests/

2020-07-21 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-21T16:38:35-07:00
New Revision: a361aa5249856e333a373df90947dabf34cd6aab

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

LOG: [clang] Disable -Wsuggest-override for unittests/

Added: 


Modified: 
clang/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 4c222e24599f..64168f44f843 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -10,6 +10,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_definitions("-Wno-suggest-override")
+endif()
+
 # add_clang_unittest(test_dirname file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang



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


[clang-tools-extra] 1c7037a - [clangd] Disable -Wsuggest-override for unittests/

2020-07-22 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-22T10:49:09-07:00
New Revision: 1c7037a2a5576d0bb083db10ad947a8308e61f65

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

LOG: [clangd] Disable -Wsuggest-override for unittests/

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index c25e2b7f8103..8a4a0fb37fc6 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -22,6 +22,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_definitions("-Wno-suggest-override")
+endif()
+
 if (CLANGD_ENABLE_REMOTE)
   include_directories(${CMAKE_CURRENT_BINARY_DIR}/../index/remote)
   add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)



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


[clang-tools-extra] 388c9fb - Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories.

2020-07-22 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-22T14:19:34-07:00
New Revision: 388c9fb1af48b059d8b65cb2e002e0992d147aa5

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

LOG: Try enabling -Wsuggest-override again, using add_compile_options instead 
of add_compile_definitions for disabling it in unittests/ directories.

Using add_compile_definitions caused the flag to be passed to rc.exe on Windows 
and thus broke Windows builds.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/unittests/CMakeLists.txt
clang/unittests/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/cmake/config-ix.cmake
flang/unittests/CMakeLists.txt
libcxx/CMakeLists.txt
libcxxabi/CMakeLists.txt
lld/unittests/CMakeLists.txt
lldb/unittests/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/lib/Testing/Support/CMakeLists.txt
llvm/unittests/CMakeLists.txt
llvm/utils/benchmark/CMakeLists.txt
llvm/utils/unittest/CMakeLists.txt
mlir/unittests/CMakeLists.txt
parallel-libs/acxxel/CMakeLists.txt
polly/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index c25e2b7f8103..b4514e95c9e5 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -22,6 +22,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 if (CLANGD_ENABLE_REMOTE)
   include_directories(${CMAKE_CURRENT_BINARY_DIR}/../index/remote)
   add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)

diff  --git a/clang-tools-extra/unittests/CMakeLists.txt 
b/clang-tools-extra/unittests/CMakeLists.txt
index 086a68e63830..72abe0fa6d0c 100644
--- a/clang-tools-extra/unittests/CMakeLists.txt
+++ b/clang-tools-extra/unittests/CMakeLists.txt
@@ -5,6 +5,10 @@ function(add_extra_unittest test_dirname)
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-change-namespace)
 add_subdirectory(clang-doc)

diff  --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 4c222e24599f..f156372cbc4f 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -10,6 +10,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 # add_clang_unittest(test_dirname file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang

diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index dab55707338a..efb660818270 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -403,6 +403,7 @@ set(COMPILER_RT_GMOCK_CFLAGS
 
 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 
COMPILER_RT_UNITTEST_CFLAGS)
 append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG 
-Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
+append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override 
COMPILER_RT_UNITTEST_CFLAGS)
 
 if(MSVC)
   # gtest use a lot of stuff marked as deprecated on Windows.

diff  --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index f535123351d6..0a27910ed494 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -106,6 +106,7 @@ check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor"   
COMPILER_RT_HAS_WNON_VIRT
 check_cxx_compiler_flag("-Werror -Wvariadic-macros"
COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
 check_cxx_compiler_flag("-Werror -Wunused-parameter"   
COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
 check_cxx_compiler_flag("-Werror -Wcovered-switch-default" 
COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
+check_cxx_compiler_flag("-Werror -Wsuggest-override"   
COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
 check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
 
 check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG)

diff  --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index d53d155f2f2b..21da59f3afcb 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -5,6 +5,10 @@ function(add_flang_unittest test_dirname)
   add_unittest(FlangUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 add_subdi

[clang] 388c9fb - Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories.

2020-07-22 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-22T14:19:34-07:00
New Revision: 388c9fb1af48b059d8b65cb2e002e0992d147aa5

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

LOG: Try enabling -Wsuggest-override again, using add_compile_options instead 
of add_compile_definitions for disabling it in unittests/ directories.

Using add_compile_definitions caused the flag to be passed to rc.exe on Windows 
and thus broke Windows builds.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/unittests/CMakeLists.txt
clang/unittests/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/cmake/config-ix.cmake
flang/unittests/CMakeLists.txt
libcxx/CMakeLists.txt
libcxxabi/CMakeLists.txt
lld/unittests/CMakeLists.txt
lldb/unittests/CMakeLists.txt
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/lib/Testing/Support/CMakeLists.txt
llvm/unittests/CMakeLists.txt
llvm/utils/benchmark/CMakeLists.txt
llvm/utils/unittest/CMakeLists.txt
mlir/unittests/CMakeLists.txt
parallel-libs/acxxel/CMakeLists.txt
polly/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index c25e2b7f8103..b4514e95c9e5 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -22,6 +22,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 if (CLANGD_ENABLE_REMOTE)
   include_directories(${CMAKE_CURRENT_BINARY_DIR}/../index/remote)
   add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)

diff  --git a/clang-tools-extra/unittests/CMakeLists.txt 
b/clang-tools-extra/unittests/CMakeLists.txt
index 086a68e63830..72abe0fa6d0c 100644
--- a/clang-tools-extra/unittests/CMakeLists.txt
+++ b/clang-tools-extra/unittests/CMakeLists.txt
@@ -5,6 +5,10 @@ function(add_extra_unittest test_dirname)
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-change-namespace)
 add_subdirectory(clang-doc)

diff  --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 4c222e24599f..f156372cbc4f 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -10,6 +10,10 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 # add_clang_unittest(test_dirname file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang

diff  --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index dab55707338a..efb660818270 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -403,6 +403,7 @@ set(COMPILER_RT_GMOCK_CFLAGS
 
 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 
COMPILER_RT_UNITTEST_CFLAGS)
 append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG 
-Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
+append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override 
COMPILER_RT_UNITTEST_CFLAGS)
 
 if(MSVC)
   # gtest use a lot of stuff marked as deprecated on Windows.

diff  --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index f535123351d6..0a27910ed494 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -106,6 +106,7 @@ check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor"   
COMPILER_RT_HAS_WNON_VIRT
 check_cxx_compiler_flag("-Werror -Wvariadic-macros"
COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
 check_cxx_compiler_flag("-Werror -Wunused-parameter"   
COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
 check_cxx_compiler_flag("-Werror -Wcovered-switch-default" 
COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
+check_cxx_compiler_flag("-Werror -Wsuggest-override"   
COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
 check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
 
 check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG)

diff  --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index d53d155f2f2b..21da59f3afcb 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -5,6 +5,10 @@ function(add_flang_unittest test_dirname)
   add_unittest(FlangUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  add_compile_options("-Wno-suggest-override")
+endif()
+
 add_subdi

[clang] a52aea0 - Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest

2020-07-27 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-27T08:37:01-07:00
New Revision: a52aea0ba624fcf46602bff8463b7b831e87ba55

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

LOG: Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target 
that links to gtest

This cleans up several CMakeLists.txt's where -Wno-suggest-override was 
manually specified. These test targets now inherit this flag from the gtest 
target.

Some unittests CMakeLists.txt's, in particular Flang and LLDB, are not touched 
by this patch. Flang manually adds the gtest sources itself in some 
configurations, rather than linking to LLVM's gtest target, so this fix would 
be insufficient to cover those cases. Similarly, LLDB has subdirectories that 
manually add the gtest headers to their include path without linking to the 
gtest target, so those subdirectories still need -Wno-suggest-override to be 
manually specified to compile without warnings.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/unittests/CMakeLists.txt
clang/unittests/CMakeLists.txt
lld/unittests/CMakeLists.txt
llvm/lib/Testing/Support/CMakeLists.txt
llvm/unittests/CMakeLists.txt
llvm/utils/unittest/CMakeLists.txt
mlir/unittests/CMakeLists.txt
polly/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index 8ede92c16f7a..c25e2b7f8103 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -13,10 +13,6 @@ include_directories(
   ${CLANGD_BINARY_DIR}
   )
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 if(CLANG_BUILT_STANDALONE)
   # LLVMTestingSupport library is needed for clangd tests.
   if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support

diff  --git a/clang-tools-extra/unittests/CMakeLists.txt 
b/clang-tools-extra/unittests/CMakeLists.txt
index 72abe0fa6d0c..086a68e63830 100644
--- a/clang-tools-extra/unittests/CMakeLists.txt
+++ b/clang-tools-extra/unittests/CMakeLists.txt
@@ -5,10 +5,6 @@ function(add_extra_unittest test_dirname)
   add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-change-namespace)
 add_subdirectory(clang-doc)

diff  --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 9a52b9fb0262..4c222e24599f 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -1,10 +1,6 @@
 add_custom_target(ClangUnitTests)
 set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang tests")
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 if(CLANG_BUILT_STANDALONE)
   # LLVMTestingSupport library is needed for some of the unittests.
   if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support

diff  --git a/lld/unittests/CMakeLists.txt b/lld/unittests/CMakeLists.txt
index 88cb85a08401..84d35d43f4e8 100644
--- a/lld/unittests/CMakeLists.txt
+++ b/lld/unittests/CMakeLists.txt
@@ -12,9 +12,5 @@ function(add_lld_unittest test_dirname)
   target_link_libraries(${test_dirname} ${LLVM_COMMON_LIBS})
 endfunction()
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 add_subdirectory(DriverTests)
 add_subdirectory(MachOTests)

diff  --git a/llvm/lib/Testing/Support/CMakeLists.txt 
b/llvm/lib/Testing/Support/CMakeLists.txt
index 595221a105cd..fe460aeefc91 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -1,10 +1,6 @@
 add_definitions(-DGTEST_LANG_CXX11=1)
 add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 add_llvm_library(LLVMTestingSupport
   Annotations.cpp
   Error.cpp

diff  --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index e90f07448c10..d7dbaeaa32fe 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -14,10 +14,6 @@ function(add_llvm_target_unittest test_dir_name)
   add_llvm_unittest(${test_dir_name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
 endfunction()
 
-if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
-  add_compile_options("-Wno-suggest-override")
-endif()
-
 add_subdirectory(ADT)
 add_subdirectory(Analysis)
 add_subdirectory(AsmParser)

diff  --git a/llvm/utils/unittest/CMakeLists.txt 
b/llvm/utils/unittest/CMakeLists.txt
index 36761a60d9f7..bcae36fa150d 100644
--- a/l

[clang] 2c2a297 - [clang][NFC] Add 'override' keyword to virtual function overrides

2020-07-14 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-14T08:59:57-07:00
New Revision: 2c2a297bb6d1ce9752a69c8c18a58eacc6d3f961

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

LOG: [clang][NFC] Add 'override' keyword to virtual function overrides

This patch adds override to several overriding virtual functions that were 
missing the keyword within the clang/ directory. These were found by the new 
-Wsuggest-override.

Added: 


Modified: 
clang/include/clang/AST/DeclOpenMP.h
clang/lib/AST/Interp/InterpFrame.h
clang/lib/AST/OSLog.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclOpenMP.h 
b/clang/include/clang/AST/DeclOpenMP.h
index 437feaba28fb..154ecb977692 100644
--- a/clang/include/clang/AST/DeclOpenMP.h
+++ b/clang/include/clang/AST/DeclOpenMP.h
@@ -129,7 +129,7 @@ class OMPDeclareReductionDecl final : public ValueDecl, 
public DeclContext {
   /// the declare reduction construct is declared inside compound statement.
   LazyDeclPtr PrevDeclInScope;
 
-  virtual void anchor();
+  void anchor() override;
 
   OMPDeclareReductionDecl(Kind DK, DeclContext *DC, SourceLocation L,
   DeclarationName Name, QualType Ty,
@@ -228,7 +228,7 @@ class OMPDeclareMapperDecl final : public ValueDecl, public 
DeclContext {
 
   LazyDeclPtr PrevDeclInScope;
 
-  virtual void anchor();
+  void anchor() override;
 
   OMPDeclareMapperDecl(Kind DK, DeclContext *DC, SourceLocation L,
DeclarationName Name, QualType Ty,

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index b8391b0bcf92..304e2ad66537 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -45,16 +45,16 @@ class InterpFrame final : public Frame {
   void popArgs();
 
   /// Describes the frame with arguments for diagnostic purposes.
-  void describe(llvm::raw_ostream &OS);
+  void describe(llvm::raw_ostream &OS) override;
 
   /// Returns the parent frame object.
-  Frame *getCaller() const;
+  Frame *getCaller() const override;
 
   /// Returns the location of the call to the frame.
-  SourceLocation getCallLocation() const;
+  SourceLocation getCallLocation() const override;
 
   /// Returns the caller.
-  const FunctionDecl *getCallee() const;
+  const FunctionDecl *getCallee() const override;
 
   /// Returns the current function.
   Function *getFunction() const { return Func; }

diff  --git a/clang/lib/AST/OSLog.cpp b/clang/lib/AST/OSLog.cpp
index df2f808728cf..094c0102854b 100644
--- a/clang/lib/AST/OSLog.cpp
+++ b/clang/lib/AST/OSLog.cpp
@@ -55,9 +55,9 @@ class OSLogFormatStringHandler
 ArgsData.reserve(Args.size());
   }
 
-  virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS,
- const char *StartSpecifier,
- unsigned SpecifierLen) {
+  bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS,
+ const char *StartSpecifier,
+ unsigned SpecifierLen) override {
 if (!FS.consumesDataArgument() &&
 FS.getConversionSpecifier().getKind() !=
 clang::analyze_format_string::ConversionSpecifier::PrintErrno)

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index af04b75392f5..cfa362bef1b1 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -821,7 +821,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
 : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const {
+MacroBuilder &Builder) const override {
 // A common platform macro.
 if (Opts.POSIXThreads)
   Builder.defineMacro("_REENTRANT");

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 515a2e9690ed..22bf35dbd0cb 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1066,7 +1066,7 @@ static IsTupleLike isTupleLike(Sema &S, SourceLocation 
Loc, QualType T,
 TemplateArgumentListInfo &Args;
 ICEDiagnoser(LookupResult &R, TemplateArgumentListInfo &Args)
 : R(R), Args(Args) {}
-void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) {
+void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) override {
   S.Diag(Loc, diag::err_decomp_decl_std_tuple_size_not_constant)

[clang] fbb30c3 - [clang] Add 'override' to virtual function overrides generated by ClangAttrEmitter

2020-07-14 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2020-07-14T09:36:43-07:00
New Revision: fbb30c31fefcf992ddb287087e8ca766eeddb59d

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

LOG: [clang] Add 'override' to virtual function overrides generated by 
ClangAttrEmitter

ClangAttrEmitter.cpp generates ParsedAttr derived classes with virtual 
overrides in them (which end up in AttrParsedAttrImpl.inc); this patch ensures 
these generated functions are marked override, and not (redundantly) virtual.

I hesitate to say NFC since this does of course affect the behavior of the 
generator code, but the generated code behaves the same as it did before, so 
it's NFC in that sense.

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

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 1b9fd2d29bf9..bd20e447a950 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2012,10 +2012,10 @@ 
PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,
 return;
   // Generate a function that constructs a set of matching rules that describe
   // to which declarations the attribute should apply to.
-  OS << "virtual void getPragmaAttributeMatchRules("
+  OS << "void getPragmaAttributeMatchRules("
  << "llvm::SmallVectorImpl> &MatchRules, const LangOptions &LangOpts) const {\n";
+ << ", bool>> &MatchRules, const LangOptions &LangOpts) const override 
{\n";
   const Record *SubjectObj = Attr.getValueAsDef("Subjects");
   std::vector Subjects = 
SubjectObj->getValueAsListOfDefs("Subjects");
   for (const auto *Subject : Subjects) {
@@ -3519,8 +3519,8 @@ static void GenerateAppertainsTo(const Record &Attr, 
raw_ostream &OS) {
   // at all (for instance because it was applied to a type), or that the caller
   // has determined that the check should fail (perhaps prior to the creation
   // of the declaration).
-  OS << "virtual bool diagAppertainsToDecl(Sema &S, ";
-  OS << "const ParsedAttr &Attr, const Decl *D) const {\n";
+  OS << "bool diagAppertainsToDecl(Sema &S, ";
+  OS << "const ParsedAttr &Attr, const Decl *D) const override {\n";
   OS << "  if (";
   for (auto I = Subjects.begin(), E = Subjects.end(); I != E; ++I) {
 // If the subject has custom code associated with it, use the generated
@@ -3594,8 +3594,8 @@ static void GenerateLangOptRequirements(const Record &R,
   if (LangOpts.empty())
 return;
 
-  OS << "virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) ";
-  OS << "const {\n";
+  OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) ";
+  OS << "const override {\n";
   OS << "  auto &LangOpts = S.LangOpts;\n";
   OS << "  if (" << GenerateTestExpression(LangOpts) << ")\n";
   OS << "return true;\n\n";
@@ -3639,7 +3639,7 @@ static void GenerateTargetRequirements(const Record &Attr,
   std::string Test;
   bool UsesT = GenerateTargetSpecificAttrChecks(R, Arches, Test, &FnName);
 
-  OS << "virtual bool existsInTarget(const TargetInfo &Target) const {\n";
+  OS << "bool existsInTarget(const TargetInfo &Target) const override {\n";
   if (UsesT)
 OS << "  const llvm::Triple &T = Target.getTriple(); (void)T;\n";
   OS << "  return " << Test << ";\n";
@@ -3664,8 +3664,8 @@ static void GenerateSpellingIndexToSemanticSpelling(const 
Record &Attr,
   std::string Enum = CreateSemanticSpellings(Spellings, 
SemanticToSyntacticMap);
   std::string Name = Attr.getName().str() + "AttrSpellingMap";
 
-  OS << "virtual unsigned spellingIndexToSemanticSpelling(";
-  OS << "const ParsedAttr &Attr) const {\n";
+  OS << "unsigned spellingIndexToSemanticSpelling(";
+  OS << "const ParsedAttr &Attr) const override {\n";
   OS << Enum;
   OS << "  unsigned Idx = Attr.getAttributeSpellingListIndex();\n";
   WriteSemanticSpellingSwitch("Idx", SemanticToSyntacticMap, OS);
@@ -3678,8 +3678,8 @@ static void GenerateHandleDeclAttribute(const Record 
&Attr, raw_ostream &OS) {
 return;
 
   // Generate a function which just converts from ParsedAttr to the Attr type.
-  OS << "virtual AttrHandling handleDeclAttribute(Sema &S, Decl *D,";
-  OS << "const ParsedAttr &Attr) const {\n";
+  OS << "AttrHandling handleDeclAttribute(Sema &S, Decl *D,";
+  OS << "const ParsedAttr &Attr) const override {\n";
   OS << "  D->addAttr(::new (S.Context) " << Attr.getName();
   OS << "Attr(S.Context, Attr));\n";
   OS << "  return AttributeApplied;\n";



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


[clang] a5a3efa - [Sema] Always search the full function scope context if a potential availability violation is encountered

2021-05-24 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-05-24T21:13:30-07:00
New Revision: a5a3efa82a77ab7a1c9787ef97b547a4a81f2440

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

LOG: [Sema] Always search the full function scope context if a potential 
availability violation is encountered

This fixes both https://bugs.llvm.org/show_bug.cgi?id=50309 and 
https://bugs.llvm.org/show_bug.cgi?id=50310.

Previously, lambdas inside functions would mark their own bodies for later 
analysis when encountering a potentially unavailable decl, without taking into 
consideration that the entire lambda itself might be correctly guarded inside 
an @available check. The same applied to inner class member functions. Blocks 
happened to work as expected already, since Sema::getEnclosingFunction() skips 
through block scopes.

This patch instead simply and conservatively marks the entire outermost 
function scope for search, and removes some special-case logic that prevented 
DiagnoseUnguardedAvailabilityViolations from traversing down into lambdas and 
nested functions. This correctly accounts for arbitrarily nested lambdas, inner 
classes, and blocks that may be inside appropriate @available checks at any 
ancestor level. It also treats all potential availability violations inside 
functions consistently, without being overly sensitive to the current 
DeclContext, which previously caused issues where e.g. nested struct members 
were warned about twice.

DiagnoseUnguardedAvailabilityViolations now has more work to do in some cases, 
particularly in functions with many (possibly deeply) nested lambdas and 
classes, but the big-O is the same, and the simplicity of the approach and the 
fact that it fixes at least two bugs feels like a strong win.

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaAvailability.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaObjC/unguarded-availability.m

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ac6471c4f04a..706293fa929ce 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1882,6 +1882,10 @@ class Sema final {
   /// Retrieve the current captured region, if any.
   sema::CapturedRegionScopeInfo *getCurCapturedRegion();
 
+  /// Retrieve the current function, if any, that should be analyzed for
+  /// potential availability violations.
+  sema::FunctionScopeInfo *getCurFunctionAvailabilityContext();
+
   /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
   SmallVectorImpl &WeakTopLevelDecls() { return WeakTopLevelDecl; }
 

diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 74c4b9e16f74e..d69600aaf94ea 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -666,13 +666,6 @@ class DiagnoseUnguardedAvailability
 SemaRef.Context.getTargetInfo().getPlatformMinVersion());
   }
 
-  bool TraverseDecl(Decl *D) {
-// Avoid visiting nested functions to prevent duplicate warnings.
-if (!D || isa(D))
-  return true;
-return Base::TraverseDecl(D);
-  }
-
   bool TraverseStmt(Stmt *S) {
 if (!S)
   return true;
@@ -686,8 +679,6 @@ class DiagnoseUnguardedAvailability
 
   bool TraverseIfStmt(IfStmt *If);
 
-  bool TraverseLambdaExpr(LambdaExpr *E) { return true; }
-
   // for 'case X:' statements, don't bother looking at the 'X'; it can't lead
   // to any useful diagnostics.
   bool TraverseCaseStmt(CaseStmt *CS) { return TraverseStmt(CS->getSubStmt()); 
}
@@ -919,6 +910,17 @@ void Sema::DiagnoseUnguardedAvailabilityViolations(Decl 
*D) {
   DiagnoseUnguardedAvailability(*this, D).IssueDiagnostics(Body);
 }
 
+FunctionScopeInfo *Sema::getCurFunctionAvailabilityContext() {
+  if (FunctionScopes.empty())
+return nullptr;
+
+  // Conservatively search the entire current function scope context for
+  // availability violations. This ensures we always correctly analyze nested
+  // classes, blocks, lambdas, etc. that may or may not be inside 
if(@available)
+  // checks themselves.
+  return FunctionScopes.front();
+}
+
 void Sema::DiagnoseAvailabilityOfDecl(NamedDecl *D,
   ArrayRef Locs,
   const ObjCInterfaceDecl 
*UnknownObjCClass,
@@ -941,11 +943,8 @@ void Sema::DiagnoseAvailabilityOfDecl(NamedDecl *D,
 // We need to know the @available context in the current function to
 // diagnose this use, let DiagnoseUnguardedAvailabilityViolations do that
 // when we're done parsing the current function.
-if (getCurFunctionOrMethodDecl()) {
-  getEnclosingFunction()->HasPotentialAvailabilityViolations = t

[clang-tools-extra] 988c3f5 - [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro identifiers

2022-01-10 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2022-01-10T10:35:04-08:00
New Revision: 988c3f5f96925e3bcd757043314e345b8f65589f

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

LOG: [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro 
identifiers

This behavior was fixed for regular identifiers in
9f3edc323a88c1a179a0a5a9dc9a87a2964c0d48, but the same fix was not applied to
macro fixits. This addresses https://github.com/llvm/llvm-project/issues/52895.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index a0dcca7f9973c..73b47dca20930 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -486,6 +486,9 @@ void RenamerClangTidyCheck::checkMacro(SourceManager 
&SourceMgr,
   NamingCheckFailure &Failure = NamingCheckFailures[ID];
   SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
 
+  if (!isValidAsciiIdentifier(Info.Fixup))
+Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
+
   Failure.Info = std::move(Info);
   addUsage(ID, Range);
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
index 555c673a3f43b..da8a27588611e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
@@ -171,6 +171,11 @@ int _;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', 
which is reserved in the global namespace; cannot be fixed automatically 
[bugprone-reserved-identifier]
 // CHECK-FIXES: {{^}}int _;{{$}}
 
+// https://github.com/llvm/llvm-project/issues/52895
+#define _5_kmph_rpm 459
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier 
'_5_kmph_rpm', which is reserved in the global namespace; cannot be fixed 
automatically [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}#define _5_kmph_rpm 459{{$}}
+
 // these should pass
 #define MACRO(m) int m = 0
 



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


[clang] 715c72b - [NFC][analyzer] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 715c72b4fbf43d00909ebc9677d59ce8bb24bc23

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

LOG: [NFC][analyzer] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h 
b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
index 31a4ed50a7230..48cd3395e936d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
+++ b/clang/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
@@ -32,7 +32,7 @@ class SValExplainer : public FullSValVisitor {
 std::string Str;
 llvm::raw_string_ostream OS(Str);
 S->printPretty(OS, nullptr, PrintingPolicy(ACtx.getLangOpts()));
-return OS.str();
+return Str;
   }
 
   bool isThisObject(const SymbolicRegion *R) {
@@ -69,7 +69,7 @@ class SValExplainer : public FullSValVisitor {
 std::string Str;
 llvm::raw_string_ostream OS(Str);
 OS << "concrete memory address '" << I << "'";
-return OS.str();
+return Str;
   }
 
   std::string VisitNonLocSymbolVal(nonloc::SymbolVal V) {
@@ -82,7 +82,7 @@ class SValExplainer : public FullSValVisitor {
 llvm::raw_string_ostream OS(Str);
 OS << (I.isSigned() ? "signed " : "unsigned ") << I.getBitWidth()
<< "-bit integer '" << I << "'";
-return OS.str();
+return Str;
   }
 
   std::string VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal V) {
@@ -123,7 +123,7 @@ class SValExplainer : public FullSValVisitor {
 OS << "(" << Visit(S->getLHS()) << ") "
<< std::string(BinaryOperator::getOpcodeStr(S->getOpcode())) << " "
<< S->getRHS();
-return OS.str();
+return Str;
   }
 
   // TODO: IntSymExpr doesn't appear in practice.
@@ -177,7 +177,7 @@ class SValExplainer : public FullSValVisitor {
 else
   OS << "'" << Visit(R->getIndex()) << "'";
 OS << " of " + Visit(R->getSuperRegion());
-return OS.str();
+return Str;
   }
 
   std::string VisitNonParamVarRegion(const NonParamVarRegion *R) {

diff  --git a/clang/lib/Analysis/AnalysisDeclContext.cpp 
b/clang/lib/Analysis/AnalysisDeclContext.cpp
index d8466ac34a3d4..06f1f813aeedd 100644
--- a/clang/lib/Analysis/AnalysisDeclContext.cpp
+++ b/clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -387,7 +387,7 @@ std::string AnalysisDeclContext::getFunctionName(const Decl 
*D) {
 OS << ' ' << OMD->getSelector().getAsString() << ']';
   }
 
-  return OS.str();
+  return Str;
 }
 
 LocationContextManager &AnalysisDeclContext::getLocationContextManager() {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
index e3f4be0726c85..6e4801aa8e91b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
@@ -389,7 +389,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent 
&Call,
 llvm::raw_string_ostream OS(SBuf);
 OS << "Function '" << FuncDecl->getDeclName()
<< "' returns an open handle";
-return OS.str();
+return SBuf;
   } else
 return "";
 });
@@ -405,7 +405,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent 
&Call,
 llvm::raw_string_ostream OS(SBuf);
 OS << "Function '" << FuncDecl->getDeclName()
<< "' returns an unowned handle";
-return OS.str();
+return SBuf;
   } else
 return "";
 });
@@ -439,7 +439,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent 
&Call,
   llvm::raw_string_ostream OS(SBuf);
   OS << "Handle released through " << ParamDiagIdx
  << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter";
-  return OS.str();
+  return SBuf;
 } else
   return "";
   });
@@ -453,7 +453,7 @@ void FuchsiaHandleChecker::checkPostCall(const CallEvent 
&Call,
 llvm::raw_string_ostream OS(SBuf);
 OS << "Handle allocated through " << ParamDiagIdx
<< llvm::get

[clang] 08eb614 - [NFC][testing] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 08eb614e309048b695a9eb0d94e636b2324de094

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

LOG: [NFC][testing] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/include/clang/Testing/TestClangConfig.h
clang/unittests/AST/ASTTraverserTest.cpp
clang/unittests/Analysis/MacroExpansionContextTest.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Testing/TestClangConfig.h 
b/clang/include/clang/Testing/TestClangConfig.h
index 5d6be4f65d0ad..92d5cc3cff994 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -73,7 +73,7 @@ struct TestClangConfig {
 std::string Result;
 llvm::raw_string_ostream OS(Result);
 OS << "{ Language=" << Language << ", Target=" << Target << " }";
-return OS.str();
+return Result;
   }
 
   friend std::ostream &operator<<(std::ostream &OS,

diff  --git a/clang/unittests/AST/ASTTraverserTest.cpp 
b/clang/unittests/AST/ASTTraverserTest.cpp
index d633f90b57d2d..b8eff747e3b50 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -111,7 +111,7 @@ template  std::string 
dumpASTString(NodeType &&... N) {
 
   Dumper.Visit(std::forward(N)...);
 
-  return OS.str();
+  return Buffer;
 }
 
 template 
@@ -126,7 +126,7 @@ std::string dumpASTString(TraversalKind TK, NodeType &&... 
N) {
 
   Dumper.Visit(std::forward(N)...);
 
-  return OS.str();
+  return Buffer;
 }
 
 const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,

diff  --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp 
b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 2e86457d276ca..7cee64c1b9b0c 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -95,14 +95,14 @@ class MacroExpansionContextTest : public ::testing::Test {
 std::string Buf;
 llvm::raw_string_ostream OS{Buf};
 Ctx.dumpExpandedTextsToStream(OS);
-return OS.str();
+return Buf;
   }
 
   static std::string dumpExpansionRanges(const MacroExpansionContext &Ctx) {
 std::string Buf;
 llvm::raw_string_ostream OS{Buf};
 Ctx.dumpExpansionRangesToStream(OS);
-return OS.str();
+return Buf;
   }
 };
 

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 06da4e80156a4..d2acd324b9ca9 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -203,7 +203,7 @@ class ListTest : public SyntaxTreeTest {
 
 OS << "]";
 
-return OS.str();
+return Storage;
   }
 
   std::string dumpNodes(ArrayRef Nodes) {
@@ -218,7 +218,7 @@ class ListTest : public SyntaxTreeTest {
 
 OS << "]";
 
-return OS.str();
+return Storage;
   }
 };
 



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


[clang] ad17ea1 - [NFC][AST] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: ad17ea12e70abb05b6984f530618131181be9dad

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

LOG: [NFC][AST] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/AttrImpl.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclarationName.cpp
clang/lib/AST/OpenMPClause.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 4865f3f706b3f..2e512195fd15e 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -335,7 +335,7 @@ ConvertTypeToDiagnosticString(ASTContext &Context, QualType 
Ty,
   OS << "'" << S << "' (vector of " << VTy->getNumElements() << " '"
  << VTy->getElementType().getAsString(Context.getPrintingPolicy())
  << "' " << Values << ")";
-  return OS.str();
+  return DecoratedString;
 }
   }
 

diff  --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index a3b46752c5113..c2f13cf638309 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -60,7 +60,7 @@ std::string LoopHintAttr::getValueString(const PrintingPolicy 
&Policy) const {
   else
 OS << "disable";
   OS << ")";
-  return OS.str();
+  return ValueName;
 }
 
 // Return a string suitable for identifying this attribute in diagnostics.

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c033563592d28..e63560f1b6fea 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1589,7 +1589,7 @@ std::string NamedDecl::getQualifiedNameAsString() const {
   std::string QualName;
   llvm::raw_string_ostream OS(QualName);
   printQualifiedName(OS, getASTContext().getPrintingPolicy());
-  return OS.str();
+  return QualName;
 }
 
 void NamedDecl::printQualifiedName(raw_ostream &OS) const {

diff  --git a/clang/lib/AST/DeclarationName.cpp 
b/clang/lib/AST/DeclarationName.cpp
index 56cf4b457a485..b2232ddfced32 100644
--- a/clang/lib/AST/DeclarationName.cpp
+++ b/clang/lib/AST/DeclarationName.cpp
@@ -236,7 +236,7 @@ std::string DeclarationName::getAsString() const {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << *this;
-  return OS.str();
+  return Result;
 }
 
 void *DeclarationName::getFETokenInfoSlow() const {
@@ -460,7 +460,7 @@ std::string DeclarationNameInfo::getAsString() const {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << *this;
-  return OS.str();
+  return Result;
 }
 
 raw_ostream &clang::operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo) {

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index f721e56f7fdd1..56e140f107105 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2454,7 +2454,7 @@ std::string OMPTraitInfo::getMangledName() const {
 Property.RawString);
 }
   }
-  return OS.str();
+  return MangledName;
 }
 
 OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {



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


[clang] 0cf6f7b - [NFC][clang] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 0cf6f7b128dd457711ba5c0ebfcb8143dc1632f8

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

LOG: [NFC][clang] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
clang/lib/Basic/SourceLocation.cpp
clang/lib/Basic/Version.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/TestModuleFileExtension.cpp
clang/lib/Rewrite/HTMLRewrite.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp 
b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
index ba2f49e6b6238..41ab0ed70fda4 100644
--- a/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Diagnostics.cpp
@@ -204,7 +204,7 @@ std::string Diagnostics::toString() const {
   std::string S;
   llvm::raw_string_ostream OS(S);
   printToStream(OS);
-  return OS.str();
+  return S;
 }
 
 void Diagnostics::printToStreamFull(llvm::raw_ostream &OS) const {
@@ -223,7 +223,7 @@ std::string Diagnostics::toStringFull() const {
   std::string S;
   llvm::raw_string_ostream OS(S);
   printToStreamFull(OS);
-  return OS.str();
+  return S;
 }
 
 }  // namespace dynamic

diff  --git a/clang/lib/Basic/SourceLocation.cpp 
b/clang/lib/Basic/SourceLocation.cpp
index 6986fcd322f26..6e5e55fb09cef 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -90,7 +90,7 @@ SourceLocation::printToString(const SourceManager &SM) const {
   std::string S;
   llvm::raw_string_ostream OS(S);
   print(OS, SM);
-  return OS.str();
+  return S;
 }
 
 LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager &SM) const {
@@ -149,7 +149,7 @@ SourceRange::printToString(const SourceManager &SM) const {
   std::string S;
   llvm::raw_string_ostream OS(S);
   print(OS, SM);
-  return OS.str();
+  return S;
 }
 
 
//===--===//

diff  --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp
index af3118b0f6da4..e205da7adec1d 100644
--- a/clang/lib/Basic/Version.cpp
+++ b/clang/lib/Basic/Version.cpp
@@ -82,7 +82,7 @@ std::string getClangFullRepositoryVersion() {
   OS << LLVMRepo << ' ';
 OS << LLVMRev << ')';
   }
-  return OS.str();
+  return buf;
 }
 
 std::string getClangFullVersion() {
@@ -102,7 +102,7 @@ std::string getClangToolFullVersion(StringRef ToolName) {
 OS << " " << repo;
   }
 
-  return OS.str();
+  return buf;
 }
 
 std::string getClangFullCPPVersion() {
@@ -120,7 +120,7 @@ std::string getClangFullCPPVersion() {
 OS << " " << repo;
   }
 
-  return OS.str();
+  return buf;
 }
 
 } // end namespace clang

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f760eb284e75f..5d795bfd37ae7 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1285,7 +1285,7 @@ static std::string 
serializeXRayInstrumentationBundle(const XRayInstrSet &S) {
   std::string Buffer;
   llvm::raw_string_ostream OS(Buffer);
   llvm::interleave(BundleParts, OS, [&OS](StringRef Part) { OS << Part; }, 
",");
-  return OS.str();
+  return Buffer;
 }
 
 // Set the profile kind using fprofile-instrument-use-path.

diff  --git a/clang/lib/Frontend/TestModuleFileExtension.cpp 
b/clang/lib/Frontend/TestModuleFileExtension.cpp
index ea737e6891bfe..2d5145d0c54c8 100644
--- a/clang/lib/Frontend/TestModuleFileExtension.cpp
+++ b/clang/lib/Frontend/TestModuleFileExtension.cpp
@@ -133,5 +133,5 @@ std::string TestModuleFileExtension::str() const {
   llvm::raw_string_ostream OS(Buffer);
   OS << BlockName << ":" << MajorVersion << ":" << MinorVersion << ":" << 
Hashed
  << ":" << UserInfo;
-  return OS.str();
+  return Buffer;
 }

diff  --git a/clang/lib/Rewrite/HTMLRewrite.cpp 
b/clang/lib/Rewrite/HTMLRewrite.cpp
index 371557a624c9c..e9b678b695946 100644
--- a/clang/lib/Rewrite/HTMLRewrite.cpp
+++ b/clang/lib/Rewrite/HTMLRewrite.cpp
@@ -203,7 +203,7 @@ std::string html::EscapeText(StringRef s, bool 
EscapeSpaces, bool ReplaceTabs) {
 }
   }
 
-  return os.str();
+  return Str;
 }
 
 static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,



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


[clang] 5276002 - [NFC][Sema] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 5276002a89b9aeb4c5f920d627630b1637c68ddc

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

LOG: [NFC][Sema] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/lib/Sema/CodeCompleteConsumer.cpp
clang/lib/Sema/SemaAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/CodeCompleteConsumer.cpp 
b/clang/lib/Sema/CodeCompleteConsumer.cpp
index 6c47cedfccf3f..0a2ca54e244ad 100644
--- a/clang/lib/Sema/CodeCompleteConsumer.cpp
+++ b/clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -335,7 +335,7 @@ std::string CodeCompletionString::getAsString() const {
   break;
 }
   }
-  return OS.str();
+  return Result;
 }
 
 const char *CodeCompletionString::getTypedText() const {
@@ -640,7 +640,7 @@ static std::string getOverloadAsString(const 
CodeCompletionString &CCS) {
   break;
 }
   }
-  return OS.str();
+  return Result;
 }
 
 void PrintingCodeCompleteConsumer::ProcessOverloadCandidates(

diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 100f8e36a9b86..b694927688489 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -792,7 +792,7 @@ 
attrMatcherRuleListToString(ArrayRef Rules) {
   OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
 OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
   }
-  return OS.str();
+  return Result;
 }
 
 } // end anonymous namespace



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


[clang] 5336bef - [NFC][tools] Return underlying strings directly instead of OS.str()

2021-12-09 Thread Logan Smith via cfe-commits

Author: Logan Smith
Date: 2021-12-09T16:05:46-08:00
New Revision: 5336befe8c3cde08cec020583700b4d2ba25ac16

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

LOG: [NFC][tools] Return underlying strings directly instead of OS.str()

This avoids an unnecessary copy required by 'return OS.str()', allowing
instead for NRVO or implicit move. The .str() call (which flushes the
stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d,
which made raw_string_ostream unbuffered by default.

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/Tokens.cpp
clang/lib/Tooling/Syntax/Tree.cpp
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index 8a31e776d0302..e2014f965c900 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -927,5 +927,5 @@ std::string TokenBuffer::dumpForTests() const {
   M.EndExpanded);
 }
   }
-  return OS.str();
+  return Dump;
 }

diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index 1e3a90f3a3167..c813865e95cd8 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -263,7 +263,7 @@ std::string syntax::Node::dumpTokens(const SourceManager 
&SM) const {
   OS << " ";
 }
   });
-  return OS.str();
+  return Storage;
 }
 
 void syntax::Node::assertInvariants() const {

diff  --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp 
b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index beb51bcfe5948..bf694e575a9dc 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -139,7 +139,7 @@ static std::string OptLLVM(const std::string &IR, 
CodeGenOpt::Level OLvl) {
 
   Passes.run(*M);
 
-  return OS.str();
+  return outString;
 }
 
 // Takes a function and runs it on a set of inputs



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