[clang-tools-extra] r365993 - Simplify with llvm::is_contained. NFC

2019-07-13 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Jul 13 00:23:12 2019
New Revision: 365993

URL: http://llvm.org/viewvc/llvm-project?rev=365993&view=rev
Log:
Simplify with llvm::is_contained. NFC

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/AssertSideEffectCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/modularize/Modularize.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/AssertSideEffectCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/AssertSideEffectCheck.cpp?rev=365993&r1=365992&r2=365993&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/AssertSideEffectCheck.cpp Sat 
Jul 13 00:23:12 2019
@@ -108,8 +108,7 @@ void AssertSideEffectCheck::check(const
 StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
 
 // Check if this macro is an assert.
-if (std::find(AssertMacros.begin(), AssertMacros.end(), MacroName) !=
-AssertMacros.end()) {
+if (llvm::is_contained(AssertMacros, MacroName)) {
   AssertMacroName = MacroName;
   break;
 }

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp?rev=365993&r1=365992&r2=365993&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
 Sat Jul 13 00:23:12 2019
@@ -105,7 +105,7 @@ void ForwardingReferenceOverloadCheck::c
   // template as the function parameter of that type. (This implies that type
   // deduction will happen on the type.)
   const TemplateParameterList *Params = FuncTemplate->getTemplateParameters();
-  if (std::find(Params->begin(), Params->end(), TypeParmDecl) == Params->end())
+  if (!llvm::is_contained(*Params, TypeParmDecl))
 return;
 
   // Every parameter after the first must have a default value.

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=365993&r1=365992&r2=365993&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Sat Jul 13 
00:23:12 2019
@@ -242,10 +242,8 @@ public:
   getOutermostMacroName(StartLoc, SM, Context.getLangOpts());
 
   // Check to see if the user wants to replace the macro being expanded.
-  if (std::find(NullMacros.begin(), NullMacros.end(), OutermostMacroName) 
==
-  NullMacros.end()) {
+  if (!llvm::is_contained(NullMacros, OutermostMacroName))
 return skipSubTree();
-  }
 
   StartLoc = SM.getFileLoc(StartLoc);
   EndLoc = SM.getFileLoc(EndLoc);
@@ -327,8 +325,7 @@ private:
 
 StringRef Name =
 Lexer::getImmediateMacroName(OldArgLoc, SM, Context.getLangOpts());
-return std::find(NullMacros.begin(), NullMacros.end(), Name) !=
-   NullMacros.end();
+return llvm::is_contained(NullMacros, Name);
   }
 
   MacroLoc = SM.getExpansionRange(ArgLoc).getBegin();

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=365993&r1=365992&r2=365993&view=diff
==
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Sat Jul 13 00:23:12 2019
@@ -369,7 +369,7 @@ getModularizeArgumentsAdjuster(Dependenc
 // Ignore warnings.  (Insert after "clang_tool" at beginning.)
 NewArgs.insert(NewArgs.begin() + 1, "-w");
 // Since we are compiling .h files, assume C++ unless given a -x option.
-if (std::find(NewArgs.begin(), NewArgs.end(), "-x") == NewArgs.end()) {
+if (!llvm::is_contained(NewArgs, "-x")) {
   NewArgs.insert(NewArgs.begin() + 2, "-x");
   NewArgs.insert(NewArgs.begin() + 3, "c++");
 }


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


[PATCH] D64687: [clang] Revert "Remove __VERSION__"

2019-07-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay closed this revision.
MaskRay added a comment.

In D64687#1584337 , @sylvestre.ledru 
wrote:

> I went ahead and committed your revert in r365992. Thanks!
>
> Next time, please remove the clang/ from your patch
>  arc could not apply it:


I think `clang/` is there just because the patch was created from the 
llvm-project repository (mono-repo), not the clang repository (multi-repo)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64687



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


r365994 - [CMake][Fuchsia] Define asan+noexcept multilib

2019-07-13 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Sat Jul 13 01:07:10 2019
New Revision: 365994

URL: http://llvm.org/viewvc/llvm-project?rev=365994&view=rev
Log:
[CMake][Fuchsia] Define asan+noexcept multilib

Using noexcept multilib with -fno-exceptions can lead to significant
space savings when statically linking libc++abi because we don't need
all the unwinding and demangling code.

When compiling with ASan, we already get a lot of overhead from the
instrumentation itself, when statically linking libc++abi, that overhead
is even larger.

Having the noexcept variant for ASan can help significantly, we've seen
more than 50% size reduction in our system image, which offsets the cost
of having to build another multilib.

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

Added:

cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/asan+noexcept/

cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/asan+noexcept/libc++.so

cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/asan+noexcept/

cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/asan+noexcept/libc++.so
Modified:
cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/test/Driver/fuchsia.cpp

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=365994&r1=365993&r2=365994&view=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Sat Jul 13 01:07:10 2019
@@ -153,13 +153,21 @@ if(FUCHSIA_SDK)
 
set(RUNTIMES_${target}-unknown-fuchsia+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF 
CACHE BOOL "")
 set(RUNTIMES_${target}-unknown-fuchsia+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LLVM_BUILD_COMPILER_RT OFF 
CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LLVM_USE_SANITIZER 
"Address" CACHE STRING "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=365994&r1=365993&r2=365994&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Sat Jul 13 01:07:10 2019
@@ -192,6 +192,11 @@ Fuchsia::Fuchsia(const Driver &D, const
   // ASan has higher priority because we always want the instrumentated 
version.
   Multilibs.push_back(Multilib("asan", {}, {}, 2)
   .flag("+fsanitize=address"));
+  // Use the asan+noexcept variant with ASan and -fno-exceptions.
+  Multilibs.push_back(Multilib("asan+noexcept", {}, {}, 3)
+  .flag("+fsanitize=address")
+  .flag("-fexceptions")
+  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {

Added: 
cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/asan+noexcept/libc++.so
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c%2B%2B/asan%2Bnoexcept/libc%2B%2B.so?rev=365994&view=auto
==
(empty)

Added: 
cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/asan+noexcept/libc++.so
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c%2B%2B/asan%2Bnoexcept/libc%2B%2B.so?rev=365994&view=auto

r365995 - Fix -Wdocumentation warning. NFCI.

2019-07-13 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Jul 13 01:08:43 2019
New Revision: 365995

URL: http://llvm.org/viewvc/llvm-project?rev=365995&view=rev
Log:
Fix -Wdocumentation warning. NFCI.

Modified:
cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h

Modified: cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h?rev=365995&r1=365994&r2=365995&view=diff
==
--- cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h (original)
+++ cfe/trunk/include/clang/DirectoryWatcher/DirectoryWatcher.h Sat Jul 13 
01:08:43 2019
@@ -98,8 +98,7 @@ public:
 : Kind(Kind), Filename(Filename) {}
   };
 
-  /// Returns nullptr if \param Path doesn't exist.
-  /// Returns nullptr if \param Path isn't a directory.
+  /// Returns nullptr if \param Path doesn't exist or isn't a directory.
   /// Returns nullptr if OS kernel API told us we can't start watching. In such
   /// case it's unclear whether just retrying has any chance to succeeed.
   static std::unique_ptr


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


[PATCH] D64140: [CMake][Fuchsia] Define asan+noexcept multilib

2019-07-13 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365994: [CMake][Fuchsia] Define asan+noexcept multilib 
(authored by phosek, committed by ).
Herald added subscribers: llvm-commits, javed.absar.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D64140?vs=207825&id=209679#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64140

Files:
  cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
  
cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/aarch64-fuchsia/c++/asan+noexcept/libc++.so
  
cfe/trunk/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/asan+noexcept/libc++.so
  cfe/trunk/test/Driver/fuchsia.cpp


Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
@@ -192,6 +192,11 @@
   // ASan has higher priority because we always want the instrumentated 
version.
   Multilibs.push_back(Multilib("asan", {}, {}, 2)
   .flag("+fsanitize=address"));
+  // Use the asan+noexcept variant with ASan and -fno-exceptions.
+  Multilibs.push_back(Multilib("asan+noexcept", {}, {}, 3)
+  .flag("+fsanitize=address")
+  .flag("-fexceptions")
+  .flag("+fno-exceptions"));
   Multilibs.FilterOut([&](const Multilib &M) {
 std::vector RD = FilePaths(M);
 return std::all_of(RD.begin(), RD.end(), [&](std::string P) {
Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -153,13 +153,21 @@
 
set(RUNTIMES_${target}-unknown-fuchsia+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF 
CACHE BOOL "")
 set(RUNTIMES_${target}-unknown-fuchsia+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
 
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LLVM_BUILD_COMPILER_RT OFF 
CACHE BOOL "")
+set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LLVM_USE_SANITIZER 
"Address" CACHE STRING "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
+
set(RUNTIMES_${target}-unknown-fuchsia+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}-unknown-fuchsia")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;asan+noexcept" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")
Index: cfe/trunk/test/Driver/fuchsia.cpp
===
--- cfe/trunk/test/Driver/fuchsia.cpp
+++ cfe/trunk/test/Driver/fuchsia.cpp
@@ -70,8 +70,9 @@
 // RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN: -fuse-ld=lld 2>&1\
-// RUN: | FileCheck %s 
-check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-ASAN-X86
+// RUN: | FileCheck %s 
-check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-ASAN-NOEXCEPT-X86
 // CHECK-MULTILIB-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-MULTILIB-ASAN-X86: 
"-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan"
 // CHECK-MULTILIB-NOEXCEPT-X86: 
"-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}noexcept"
+// CHECK-MULTILIB-ASAN-NOEXCEPT-X86: 
"-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan+noexcept"
 // CHECK-MULTILIB-X86: 
"-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++"


Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
@@ -192,6 +192,11 @@
   // ASan has higher priority because we always want the instrumentated version.
   Multilibs.push_back(Multilib("asan", {}, {}, 2)
   .flag("+fsanitize=address"));
+  // Use the asan+noexcept variant 

[PATCH] D64391: [CodeComplete] an option to suppress endings for header completion

2019-07-13 Thread Cai Rijun via Phabricator via cfe-commits
richard9404 added a comment.

I think we should first think about what are participating in a modularised 
development environment. In terms of code completion, there are usually four 
layers:

- a "backend" which knows everything about the language, e.g. ClangSema
- a "frontend" which follows some well-known protocol(s), e.g. clangd
- an adapter which deals with all kinds of quirks of the frontend and editor 
and ensures everyone's happy, e.g. vscode-clangd or some magic configuration 
files for vim lsp plugins
- an editor which the user is accustomed to but knows little about the 
language, e.g. vscode or vim with some lsp plugin

Now, the completion behaviours we care about.

**the default behaviour**
I think ClangSema, as a language backend library, targets more about frontend 
developers rather than end users, and should provide rich but "pure" 
information to ensure flexibility. It doesn't seem necessary for it the decide 
which behaviour is more advantageous, especially for some end user oriented 
behaviours. In this specific case, I suppose it is more reasonable to either 
provide an option or return the raw info and let the upper levels to decide 
what to do.

**the slashes**
Different editors, under different user settings, have differences in 
completion behaviour, which are not always distinguishable from LSP's 
`ClientCapabilities`, e.g.:

- whether some key needs to be hit to commit an completion: If hitting `Enter` 
(or something else) is mandatory and `commitCharacters` are not supported, it 
should be better for clangd to include the ending slashes in the completion 
results; but if committing is implicit, it seems more reasonable to let the 
user hit `/` to trigger another completion, and users of these kinds of editors 
should be unlikely to hit `Enter` after selecting a completion item
- is it easy to forcibly trigger a completion: manually triggering completion 
is uncommon and most editors would bind it to some multi-key shortcuts, which 
makes the completion less fluent, or the user will need to ``->`/` 
if another completion is needed immediately after a directory completion

I think clangd should choose a behaviour suitable for the most usual 
circumstance, while trying to support more cases via options (or init params) 
and leaving the decision to the adapters.

**completion with trailing stuff**
When the suffix of a completion item matches with the prefix of the content 
following the completion point, things get complicated. The backend and 
language server are able to decide the range that should be replaced, and 
everything works perfectly as long as the editor correctly support `textEdit`. 
But an editor without `textEdit` support will turn to `insertText`, and it has 
to decide whether the "duplication" should be eliminated, which is impossible 
for a language-natural editor to implement accurately. The editor will either 
keep them in all cases, or merge them in all cases, producing something like 
`#include "dir/^.h"` -> `#include "dir/foo.h".h"` or `ret = Func1(ns::^);` -> 
`ret = Func1(ns::Func2();`. This is indeed a tricky issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64391



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


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale updated this revision to Diff 209683.
oydale added a comment.

Replaced -emit-obj with -emit-llvm-only in test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp


Index: clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm-only --std=c++17 -fcxx-exceptions -fexceptions %s
+// PR40771: check that this input does not crash or assert
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1495,6 +1495,13 @@
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator &cleanup) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1620,6 +1621,8 @@
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
+  assert((cleanupDominator || cleanups.empty()) &&
+ "Missing cleanupDominator before deactivating cleanup blocks");
   for (unsigned i = cleanups.size(); i != 0; --i)
 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
 


Index: clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm-only --std=c++17 -fcxx-exceptions -fexceptions %s
+// PR40771: check that this input does not crash or assert
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1495,6 +1495,13 @@
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator &cleanup) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_beg

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Sorry, i still don't like the test.
You want to check the produced IR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-13 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan created this revision.
Manikishan added reviewers: cfe-commits, mgorny, christos, MyDeveloperDay.
Herald added a subscriber: krytarowski.
Herald added a project: clang.
Manikishan added subscribers: mgorny, christos.

This new Style rule is made as a part of adding support for NetBSD KNF in 
clang-format. NetBSD have it's own priority of includes which should be 
followed while formatting NetBSD code. This style sorts the Cpp Includes 
according to the priorities of NetBSD, as mentioned in the Style Guide 

 The working of this Style rule shown below:

**Configuration:**
In addition to this commit I am also adding another diff which Introduces 
NetBSD Style in clang-format, The required configurations are already made in 
this patch and can be used by

  clang-format -style=NetBSD ...

(The NetBSD Style is not fully implemented but it supports SortNetBSDIncludes 
for now).

Here is an example how this Style sorts cpp includes according to NetBSD KNF.
**Before Formatting:  **

  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include
  #include 
  #include  
  #include 
  #include 
  #include 
  #include 
  #include "pathnames.h"
  #include 
  #include 
  #include 
  #include 

**After Formatting: **

  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  
  #include "pathnames.h"




Repository:
  rC Clang

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1035,6 +1036,12 @@
   NetBSDStyle.FixNamespaceComments = true;
   NetBSDStyle.IndentCaseLabels = false;
   NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*"

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-13 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209685.
Manikishan added a comment.

This is the squashed commit of both Adding NetBSD Style and adding 
sortNetBSDIncludes


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1023,6 +1024,29 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*", 0}};
+  NetBSDStyle.SortNetBSDIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1071,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1763,7 +1789,163 @@
   }
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
+enum CppIncludeHeadersKind {
+  IHK_KERNELHEADERS,
+  IHK_NETWORKHEADERS,
+  IHK_FILESYSHEADERS,
+  IHK_MACHINESHEADERS,
+  IHK_ARCHHEADERS,
+  IHK_USERHEADERS,
+  IHK_INCLUDESWITHQUOTES,
+};
+
+CppIncludeHeadersKind getHeadersKind(std::string Filename) {
+  SmallVector Matches;
+  const char KernelHeaderPattern[] = R"(^<(sys.*|uvm|dev)/)";
+  const char Network

[PATCH] D41217: [Concepts] Concept Specialization Expressions

2019-07-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 209686.
saar.raz added a comment.
Herald added a subscriber: erik.pilkington.

Rebase onto trunk.


Repository:
  rC Clang

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

https://reviews.llvm.org/D41217

Files:
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/StmtNodes.td
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Frontend/FrontendActions.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/CMakeLists.txt
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  test/Parser/cxx2a-concept-declaration.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -256,6 +256,7 @@
   case Stmt::BinaryConditionalOperatorClass:
   case Stmt::TypeTraitExprClass:
   case Stmt::CoawaitExprClass:
+  case Stmt::ConceptSpecializationExprClass:
   case Stmt::DependentCoawaitExprClass:
   case Stmt::CoyieldExprClass:
   case Stmt::CXXBindTemporaryExprClass:
Index: test/Parser/cxx2a-concept-declaration.cpp
===
--- test/Parser/cxx2a-concept-declaration.cpp
+++ test/Parser/cxx2a-concept-declaration.cpp
@@ -14,8 +14,6 @@
 // expected-error@-2{{template template parameter requires 'class' after the parameter list}}
 // expected-error@-3{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}}
 
-template concept C2 = 0.f; // expected-error {{constraint expression must be of type 'bool' but is of type 'float'}}
-
 struct S1 {
   template concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}}
 };
@@ -26,15 +24,15 @@
 
 template
 template
-concept C4 = true; // expected-error {{extraneous template parameter list in concept definition}}
+concept C2 = true; // expected-error {{extraneous template parameter list in concept definition}}
 
-template concept C5 = true; // expected-note {{previous}} expected-note {{previous}}
-int C5; // expected-error {{redefinition}}
-struct C5 {}; // expected-error {{redefinition}}
+template concept C3 = true; // expected-note {{previous}} expected-note {{previous}}
+int C3; // expected-error {{redefinition}}
+struct C3 {}; // expected-error {{redefinition}}
 
-struct C6 {}; // expected-note{{previous definition is here}}
-template concept C6 = true;
-// expected-error@-1{{redefinition of 'C6' as different kind of symbol}}
+struct C4 {}; // expected-note{{previous definition is here}}
+template concept C4 = true;
+// expected-error@-1{{redefinition of 'C4' as different kind of symbol}}
 
 // TODO: Add test to prevent explicit specialization, partial specialization
 // and explicit instantiation of concepts.
@@ -43,31 +41,55 @@
 struct integral_constant { static constexpr T value = v; };
 
 namespace N {
-  template concept C7 = true;
+  template concept C5 = true;
 }
-using N::C7;
+using N::C5;
 
-template  concept C8 = integral_constant::value;
+template  concept C6 = integral_constant::value;
 // expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}}
 // expected-note@-2{{'word' declared here}}
 
-template concept bool C9 = true;
+template concept bool C7 = true;
 // expected-warning@-1{{ISO C++2a does not permit the 'bool' keyword after 'concept'}}
 
-template<> concept C10 = false;
+template<> concept C8 = false;
 // expected-error@-1{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}}
 
-template<> concept C9 = false;
+template<> concept C7 = false;
 // expected-error@-1{{name defined in concept definition must be an identifier}}
 
-template concept N::C11 = false;
+template concept N::C9 = false;
 // expected-error@-1{{name defined in concept definition must be an identifier}}
 
 class A { };
 // expected-note@-1{{'A' declared here}}
 
-template concept A::C12 = false;
+template concept A::C10 = false;
 // expected-error@-1{{expected namespace name}}
 
 template concept operator int = false;
 // expected-error@-1{{name defined in concept definition must be an identifier}}
+
+template concept C11 = 2; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
+template concept C12 = 2 && x; // expected-error {{atomic constraint

[PATCH] D41284: [Concepts] Associated constraints infrastructure.

2019-07-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 209688.
saar.raz added a comment.

Rebase onto trunk.


Repository:
  rC Clang

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

https://reviews.llvm.org/D41284

Files:
  include/clang/AST/ASTNodeTraverser.h
  include/clang/AST/DeclTemplate.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/temp/concept/p4.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/var-template-decl.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace nodiag {
+
+struct B {
+template  requires bool(T())
+static int A;
+};
+
+template  requires bool(U())
+int B::A = int(U());
+
+} // end namespace nodiag
+
+namespace diag {
+
+struct B {
+template  requires bool(T()) // expected-note{{previous template declaration is here}}
+static int A;
+};
+
+template  requires !bool(U())  // expected-error{{requires clause differs in template redeclaration}}
+int B::A = int(U());
+
+} // end namespace diag
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/func-template-decl.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace nodiag {
+
+template  requires bool(T())
+int A();
+template  requires bool(U())
+int A();
+
+} // end namespace nodiag
+
+namespace diag {
+
+namespace orig {
+  template  requires true
+  int A();
+  template 
+  int B();
+  template  requires true
+  int C();
+}
+
+template 
+int orig::A();
+// expected-error@-1{{out-of-line declaration of 'A' does not match any declaration in namespace 'diag::orig'}}
+template  requires true
+int orig::B();
+// expected-error@-1{{out-of-line declaration of 'B' does not match any declaration in namespace 'diag::orig'}}
+template  requires !0
+int orig::C();
+// expected-error@-1{{out-of-line declaration of 'C' does not match any declaration in namespace 'diag::orig'}}
+
+} // end namespace diag
+
+namespace nodiag {
+
+struct AA {
+  template  requires someFunc(T())
+  int A();
+};
+
+template  requires someFunc(T())
+int AA::A() { return sizeof(T); }
+
+} // end namespace nodiag
+
+namespace diag {
+
+template 
+struct TA {
+  template  class TT> requires TT::happy
+  int A();
+};
+
+template 
+template  class TT> int TA::A() { return sizeof(TT); }
+// expected-error@-1{{out-of-line definition of 'A' does not match any declaration in 'TA'}}
+
+} // end namespace diag
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
===
--- test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
 
 namespace nodiag {
 
@@ -13,15 +13,15 @@
 
 template  requires true // expected-note{{previous template declaration is here}}
 struct A;
-template  struct A; // expected-error{{associated constraints differ in template redeclaration}}
+template  struct A; // expected-error{{requires clause differs in template redeclaration}}
 
 template  struct B; // expected-note{{previous template declaration is here}}
-template  requires true // expected-error{{associated constraints differ in template redeclaration}}
+template  requires true // expected-error{{requires clause differs in template redeclaration}}
 struct B;
 
 template  requires true // expected-note{{previous template declaration is here}}
 struct C;
-template  requires !0 // expected-error{{associated constraints differ in template redeclaration}}
+template  requires !0 // expected-error{{requires clause differs in template redeclaration}}
 struct C;
 
 } // end namespace diag
@@ -33,7 +33,7 @@
   struct A;
 };
 
-template  requires someFunc(T())
+template  requires someFunc(U())
 struct AA::A { };
 
 struct AAF {
@@ -47,18 +47,26 @@
 
 template 
 struct TA {
-  template

[PATCH] D41569: [Concepts] Constraint enforcement and diagnostics

2019-07-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 209689.
saar.raz added a comment.

Create ASTConstraintSatisfaction for correctly storing constraint satisfaction 
data in AST nodes, add support for mangling of ConceptSpecializtationExprs


Repository:
  rC Clang

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

https://reviews.llvm.org/D41569

Files:
  include/clang/AST/ASTConcept.h
  include/clang/AST/ExprCXX.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  include/clang/Sema/SemaConcept.h
  include/clang/Sema/TemplateDeduction.h
  lib/AST/ASTConcept.cpp
  lib/AST/CMakeLists.txt
  lib/AST/Decl.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
  test/CodeGenCXX/mangle-concept.cpp

Index: test/CodeGenCXX/mangle-concept.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-concept.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++2a -fconcepts-ts -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// expected-no-diagnostics
+
+namespace test1 {
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv()
+}
+
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_Z2f0IiE1SIXL_Z1CIT_v()
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace class_templates
+{
+  template requires sizeof(T) >= 4 // expected-note {{because 'sizeof(char) >= 4' (1 >= 4) evaluated to false}}
+  struct is_same { static constexpr bool value = false; };
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  struct is_same { static constexpr bool value = true; };
+
+  static_assert(!is_same::value);
+  static_assert(!is_same::value);
+  static_assert(is_same::value);
+  static_assert(is_same::value); // expected-error {{constraints not satisfied for class template 'is_same' [with T = char, U = char]}}
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  struct B {};
+
+  template requires A::type // expected-note{{in instantiation of template class 'class_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  struct B {};
+
+  template requires T{} // expected-error{{atomic constraint must be of type 'bool' (found 'int')}}
+  struct B {};
+
+  static_assert((B{}, true)); // expected-note{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-1{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-2{{during template argument deduction for class template partial specialization 'B' [with T = int *]}}
+  // expected-note@-3{{during template argument deduction for class template partial specialization 'B' [with T = int]}}
+  // expected-note@-4 2{{in instantiation of template class 'class_templates::B' requested here}}
+}
+
+namespace variable_templates
+{
+  template requires sizeof(T) >= 4
+  constexpr bool is_same_v = false;
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  constexpr bool is_same_v = true;
+
+  static_assert(!is_same_v);
+  static_assert(!is_same_v);
+  static_assert(is_same_v);
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  constexpr bool v1 = false;
+
+  template requires A::type // expected-note{{in instantiation of template class 'variable_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  constexpr bool v1 = true;
+
+  template requires T{} // exp

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale updated this revision to Diff 209690.
oydale added a comment.

Initial attempt at IR output checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp

Index: clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -emit-llvm --std=c++17 -fcxx-exceptions -fexceptions \
+// RUN:   %s -o - | FileCheck %s
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
+
+// CHECK-LABEL: define internal void @__cxx_global_var_init.1() {{.*}} {
+// CHECK-LABEL: entry:
+// CHECK: %cleanup.isactive = alloca i1, align 1
+// CHECK: call void @_ZN1RC1E1Q(%struct.R* %ref.tmp)
+// CHECK: store i1 true, i1* %cleanup.isactive, align 1
+// CHECK: invoke void @_ZN1SC1E1Q(%struct.S* %ref.tmp1)
+// CHECK:   to label %invoke.cont unwind label %lpad
+
+// CHECK-LABEL: invoke.cont:
+// CHECK: store i1 false, i1* %cleanup.isactive, align 1
+// CHECK: call void @_ZN1SD1Ev(%struct.S*
+// CHECK: call void @_ZN1RD1Ev(%struct.R*
+// CHECK: %0 = call i32 @__cxa_atexit(
+// CHECK: ret void
+
+// CHECK-LABEL: lpad:
+// CHECK: %1 = landingpad { i8*, i32 }
+// CHECK:cleanup
+// CHECK: %2 = extractvalue { i8*, i32 } %1, 0
+// CHECK: store i8* %2, i8** %exn.slot, align 8
+// CHECK: %3 = extractvalue { i8*, i32 } %1, 1
+// CHECK: store i32 %3, i32* %ehselector.slot, align 4
+// CHECK: %cleanup.is_active = load i1, i1* %cleanup.isactive, align 1
+// CHECK: br i1 %cleanup.is_active, label %cleanup.action, label %cleanup.done
+
+// CHECK-LABEL: cleanup.action:
+// CHECK: call void @_ZN1RD1Ev(%struct.R*
+// CHECK: br label %cleanup.done
+
+// CHECK-LABEL: cleanup.done:
+// CHECK: call void @_ZN1RD1Ev(%struct.R* %ref.tmp)
+// CHECK: br label %eh.resume
+
+// CHECK-LABEL: eh.resume:
+// CHECK: %exn = load i8*, i8** %exn.slot, align 8
+// CHECK: %sel = load i32, i32* %ehselector.slot, align 4
+// CHECK: %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
+// CHECK: %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
+// CHECK: resume { i8*, i32 } %lpad.val3
+// CHECK: }
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1495,6 +1495,13 @@
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator &cleanup) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1620,6 +1621,8 @@
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
+  assert((cleanupDominator || cleanups.empty()) &&
+ "Missing cleanupDominator before deactivating cleanup blocks");
   for (unsigned i = cleanups.size(); i != 0; --i)
 CGF.DeactivateCleanupBlock(cleanups[i-1], cleanupDominator);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale added a comment.

I have added my initial attempt at verifying the cleanup code generated in this 
scenario, it's probably going to require modifications. The original IR can be 
found at https://reviews.llvm.org/P8156.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Hm, i have a question about this fix.
As it can be seen the C++17 code is successfully codegened by clang to LLVM IR, 
and the actual failure is in LLVM middle-end optimization pass:
https://godbolt.org/z/P3RB23

1. Please file a bug about that pass crash, include that link. It most 
definitively should not crash.
2. Is this fix just workarounding that crash, or is the clang producing 
incorrect IR without this fix, miscompiling it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D64656#1584424 , @lebedev.ri wrote:

> Hm, i have a question about this fix.
>  As it can be seen the C++17 code is successfully codegened by clang to LLVM 
> IR, and the actual failure is in LLVM middle-end optimization pass:
>  https://godbolt.org/z/P3RB23
>
> 1. Please file a bug about that pass crash, include that link. It most 
> definitively should not crash.


As i can now see, there is one in https://bugs.llvm.org/show_bug.cgi?id=40771

> 2. Is this fix just workarounding that crash, or is the clang producing 
> incorrect IR without this fix, miscompiling it?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D41569: [Concepts] Constraint enforcement and diagnostics

2019-07-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 209695.
saar.raz added a comment.

Move ConstraintSatisfaction to ASTConcept.h


Repository:
  rC Clang

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

https://reviews.llvm.org/D41569

Files:
  include/clang/AST/ASTConcept.h
  include/clang/AST/ExprCXX.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  include/clang/Sema/TemplateDeduction.h
  lib/AST/ASTConcept.cpp
  lib/AST/ASTContext.cpp
  lib/AST/CMakeLists.txt
  lib/AST/Decl.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  
test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
  test/CodeGenCXX/mangle-concept.cpp

Index: test/CodeGenCXX/mangle-concept.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-concept.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++2a -fconcepts-ts -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+// expected-no-diagnostics
+
+namespace test1 {
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_ZN5test12f0IiEENS_1SIXL_ZNS_1CIT_EEv()
+}
+
+template  struct S {};
+template  concept C = true;
+template  S> f0() { return S>{}; }
+template S> f0<>();
+// CHECK: void @_Z2f0IiE1SIXL_Z1CIT_v()
\ No newline at end of file
Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ -verify %s
+
+namespace class_templates
+{
+  template requires sizeof(T) >= 4 // expected-note {{because 'sizeof(char) >= 4' (1 >= 4) evaluated to false}}
+  struct is_same { static constexpr bool value = false; };
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  struct is_same { static constexpr bool value = true; };
+
+  static_assert(!is_same::value);
+  static_assert(!is_same::value);
+  static_assert(is_same::value);
+  static_assert(is_same::value); // expected-error {{constraints not satisfied for class template 'is_same' [with T = char, U = char]}}
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  struct B {};
+
+  template requires A::type // expected-note{{in instantiation of template class 'class_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  struct B {};
+
+  template requires T{} // expected-error{{atomic constraint must be of type 'bool' (found 'int')}}
+  struct B {};
+
+  static_assert((B{}, true)); // expected-note{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-1{{while checking constraint satisfaction for class template partial specialization 'B' required here}}
+  // expected-note@-2{{during template argument deduction for class template partial specialization 'B' [with T = int *]}}
+  // expected-note@-3{{during template argument deduction for class template partial specialization 'B' [with T = int]}}
+  // expected-note@-4 2{{in instantiation of template class 'class_templates::B' requested here}}
+}
+
+namespace variable_templates
+{
+  template requires sizeof(T) >= 4
+  constexpr bool is_same_v = false;
+
+  template requires sizeof(T*) >= 4 && sizeof(T) >= 4
+  constexpr bool is_same_v = true;
+
+  static_assert(!is_same_v);
+  static_assert(!is_same_v);
+  static_assert(is_same_v);
+
+  template
+  struct A { using type = typename T::type; }; // expected-error{{type 'int *' cannot be used prior to '::' because it has no members}}
+
+  template
+  constexpr bool v1 = false;
+
+  template requires A::type // expected-note{{in instantiation of template class 'variable_templates::A' requested here}}
+   // expected-note@-1{{while substituting template arguments into constraint expression here}}
+  constexpr bool v1 = true;
+
+  template requires T{} // expected-error{{atomic constraint must be of type 'bool' (found 'int')}}
+  constexpr bool v1 = true;
+
+  static_assert(v1)

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale added a comment.

My understanding of the issue is that clang emits incorrect IR. Without my fix 
and when disabling the assertion mentioned in the commit message by commenting 
it out, llvm-lit gives the following output when executed against the minimal 
test case in the current version of the commit:

  + /home/maestro/llvm/llvm-project/build/bin/clang -cc1 -internal-isystem 
/home/maestro/llvm/llvm-project/build/lib/clang/9.0.0/include -nostdsysteminc 
-emit-obj --std=c++17 -fcxx-exceptions -fexceptions 
/home/maestro/llvm/llvm-project/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
  Instruction referencing instruction not embedded in a basic block!
%cleanup.isactive = alloca i1, align 1
store i1 true, i1* %cleanup.isactive, align 1
  in function __cxx_global_var_init.1
  fatal error: error in backend: Broken function found, compilation aborted!

This is what makes me assume that the IR output is incorrect.

Without my fix and with the assertion still commented out, disabling the LLVM 
verification, and enabling optimizations with -O1, the debug build of clang 
yields a similar crash as what can be observed in release builds such as on 
godbolt:

  ~/llvm/llvm-project/build/bin/clang-9 -cc1 -triple x86_64-pc-linux-gnu 
-emit-obj -disable-free -disable-llvm-verifier -std=c++17 -fexceptions -O1 
-fcxx-exceptions minimal.cpp
  Stack dump:
  0.Program arguments: /home/maestro/llvm/llvm-project/build/bin/clang-9 
-cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier 
-std=c++17 -fexceptions -O1 -fcxx-exceptions minimal.cpp 
  1. parser at end of file
  2.Per-function optimization
  3.Running pass 'SROA' on function '@__cxx_global_var_init.1'
   #0 0x7f2309f7b7a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
   #1 0x7f2309f7b83a PrintStackTraceSignalHandler(void*) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:555:1
   #2 0x7f2309f79834 llvm::sys::RunSignalHandlers() 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Signals.cpp:68:20
   #3 0x7f2309f7b1fd SignalHandler(int) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
   #4 0x7f230929e4d0 __restore_rt (/usr/lib/libpthread.so.0+0x124d0)
   #5 0x7f230be28fda llvm::PointerIntPair*, 1u, 
unsigned int, llvm::PointerLikeTypeTraits*>, 
llvm::PointerIntPairInfo*, 1u, 
llvm::PointerLikeTypeTraits*> > 
>::setPointer(llvm::ilist_node_base*) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:63:32
   #6 0x7f230be267cb 
llvm::ilist_node_base::setPrev(llvm::ilist_node_base*) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_node_base.h:40:75
   #7 0x7f230be3748b 
llvm::ilist_base::removeImpl(llvm::ilist_node_base&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_base.h:34:5
   #8 0x7f230be37725 void 
llvm::ilist_base::remove > 
>(llvm::ilist_node_impl >&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_base.h:80:64
   #9 0x7f230be37166 
llvm::simple_ilist::remove(llvm::Instruction&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/simple_ilist.h:183:77
  #10 0x7f230be36aa2 
llvm::iplist_impl, 
llvm::SymbolTableListTraits 
>::remove(llvm::ilist_iterator, false, false>&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist.h:253:12
  #11 0x7f230be35bf1 
llvm::iplist_impl, 
llvm::SymbolTableListTraits 
>::erase(llvm::ilist_iterator, false, false>) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist.h:266:5
  #12 0x7f230bf7bb5d llvm::Instruction::eraseFromParent() 
/home/maestro/llvm/llvm-project/llvm/lib/IR/Instruction.cpp:69:1
  #13 0x7f230a611a47 
llvm::SROA::deleteDeadInstructions(llvm::SmallPtrSetImpl&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4520:13
  #14 0x7f230a611df1 llvm::SROA::runImpl(llvm::Function&, 
llvm::DominatorTree&, llvm::AssumptionCache&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4564:15
  #15 0x7f230a62979e 
llvm::sroa::SROALegacyPass::runOnFunction(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4620:31
  #16 0x7f230bfc820a llvm::FPPassManager::runOnFunction(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1648:20
  #17 0x7f230bfc7e2c 
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1585:13
  #18 0x7f230bfc7a14 
llvm::legacy::FunctionPassManager::run(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1511:1
  #19 0x7f2307ff5d67 (anonymous 
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, 
std::unique_ptr >) 
/home/maestro/llvm/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:885:25
  #20 0x7f2307ffa457 clang::EmitBackendOutput(clang::DiagnosticsEng

r366007 - Template-related improvements to Visual Studio visualizers

2019-07-13 Thread Mike Spertus via cfe-commits
Author: mps
Date: Sat Jul 13 08:27:53 2019
New Revision: 366007

URL: http://llvm.org/viewvc/llvm-project?rev=366007&view=rev
Log:
Template-related improvements to Visual Studio visualizers

Modified:
cfe/trunk/utils/ClangVisualizers/clang.natvis

Modified: cfe/trunk/utils/ClangVisualizers/clang.natvis
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/ClangVisualizers/clang.natvis?rev=366007&r1=366006&r2=366007&view=diff
==
--- cfe/trunk/utils/ClangVisualizers/clang.natvis (original)
+++ cfe/trunk/utils/ClangVisualizers/clang.natvis Sat Jul 13 08:27:53 2019
@@ -196,7 +196,11 @@ For later versions of Visual Studio, no
 (not yet known if parameter pack) 
 ...
 
-{*this,view(TorC)} 
{*this,view(MaybeEllipses)}{Name,view(cpp)} 
+{(TypeSourceInfo 
*)(DefaultArgument.ValueOrInherited.Val.Value&~3LL),view(cpp)}
+{{InheritedInitializer}}
+= 
{this,view(DefaultArg)na}
+
+{*this,view(TorC)} 
{*this,view(MaybeEllipses)}{Name,view(cpp)} 
{this,view(Initializer)na} 
   
   
 template{TemplateParams,na} 
{*TemplatedDecl};
@@ -288,7 +292,7 @@ For later versions of Visual Studio, no
 
   
   
-{*Replaced,view(cpp)} <= 
{CanonicalType,view(cpp)}
+{{{*Replaced,view(cpp)} <= 
{CanonicalType,view(cpp)}}}
 
   *(clang::Type *)this, view(cmn)
   *Replaced
@@ -353,7 +357,7 @@ For later versions of Visual Studio, no
 
   
   
-{InjectedType,view(cpp)}
+{Decl,view(cpp)}
 
   Decl
   InjectedType
@@ -424,12 +428,21 @@ For later versions of Visual Studio, no
   Ty
 
   
-  
-{Argument}
+  
+{(QualType *)&Ty,na}
 
-  Argument
+  (QualType *)&Ty
+  Data
 
   
+  
+Not 
building anything
+Building a {LastTy}
+  
+  
+{Argument,view(cpp)}
+{Argument}
+  
   
 {*(clang::QualType 
*)&TypeOrValue.V,view(cpp)}
 {(clang::TemplateArgument::ArgKind)TypeOrValue.Kind,en}
 template argument: {*(clang::QualType *)&TypeOrValue.V}
@@ -459,6 +472,21 @@ For later versions of Visual Studio, no
   
 
   
+  
+
+{((TemplateArgumentLoc*)Arguments.BeginX)[0],view(cpp)}{*this,view(elt1)}
+
+, 
{((TemplateArgumentLoc*)Arguments.BeginX)[1],view(cpp)}{*this,view(elt2)}
+
+, 
{((TemplateArgumentLoc*)Arguments.BeginX)[2],view(cpp)}{*this,view(elt3)}
+
+, 
{((TemplateArgumentLoc*)Arguments.BeginX)[3],view(cpp)}{*this,view(elt4)}
+
+, ...
+empty
+<{*this,view(elt0)}>
+Uninitialized
+  
   
 
 {Arguments[0],view(cpp)}{*this,view(arg1)}
@@ -483,6 +511,17 @@ For later versions of Visual Studio, no
 
 , {Data[2],view(cpp)}, 
...
 <{*this,view(arg0)}>
+
+  Length
+  
+
+  
+Length
+Data
+  
+
+  
+
   
   
 
@@ -558,6 +597,7 @@ For later versions of Visual Studio, no
 TemplateSpecializationTypeBits.NumArgs
 (clang::TemplateArgument *)(this+1)
   
+  *(clang::Type *)this, view(cmn)
 
   
   
@@ -745,7 +785,7 @@ For later versions of Visual Studio, no
 {this,view(retType)nand} 
{Name,view(cpp)nd}({*this,view(parm0)nd})
 
   (clang::DeclaratorDecl *)this,nd
-  *this,view(retType)nd
+  ((clang::FunctionProtoType 
*)((clang::ExtQualsTypeCommonBase *)(((uintptr_t)DeclType.Value.Value) & 
~15))->BaseType)->ResultType
   
 {*this,view(parm0)nd}
 
@@ -755,6 +795,7 @@ For later versions of Visual Studio, no
   
 
   
+  TemplateOrSpecialization
 
   
   


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


[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri resigned from this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

In D64656#1584437 , @oydale wrote:

> My understanding of the issue is that clang emits incorrect IR. Without my 
> fix and when disabling the assertion mentioned in the commit message by 
> commenting it out, llvm-lit gives the following output when executed against 
> the minimal test case in the current version of the commit:
>
>   + /home/maestro/llvm/llvm-project/build/bin/clang -cc1 -internal-isystem 
> /home/maestro/llvm/llvm-project/build/lib/clang/9.0.0/include -nostdsysteminc 
> -emit-obj --std=c++17 -fcxx-exceptions -fexceptions 
> /home/maestro/llvm/llvm-project/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
>   Instruction referencing instruction not embedded in a basic block!
> %cleanup.isactive = alloca i1, align 1
> store i1 true, i1* %cleanup.isactive, align 1
>   in function __cxx_global_var_init.1
>   fatal error: error in backend: Broken function found, compilation aborted!
>
>
> This is what makes me assume that the IR output is incorrect.


Aha, this i didn't see before, thank you.
Then i agree the clang fix is needed.

> ...

Since some other assertion (in `-verify` pass?) triggers before the SROA crash 
can be reached, i think may be no middle-end issue here after all.




Comment at: 
clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp:14-18
+// CHECK: %cleanup.isactive = alloca i1, align 1
+// CHECK: call void @_ZN1RC1E1Q(%struct.R* %ref.tmp)
+// CHECK: store i1 true, i1* %cleanup.isactive, align 1
+// CHECK: invoke void @_ZN1SC1E1Q(%struct.S* %ref.tmp1)
+// CHECK:   to label %invoke.cont unwind label %lpad

2 things:
1. These should be `CHECK-NEXT:`.
2. This will immediately break in release build mode, since the value names 
will be discarded.
   You want to follow 
https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-string-substitution-blocks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D64696: Adds a warning when an inline Doxygen comment has no argument

2019-07-13 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: gribozavr, rsmith.
Mordante added a project: clang.

It warns for for comments like
/** \pre \em */

where \em has no argument

This warning is enabled with the -Wdocumentation option.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64696

Files:
  clang/include/clang/Basic/DiagnosticCommentKinds.td
  clang/lib/AST/CommentParser.cpp
  clang/test/Sema/warn-documentation.cpp


Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -1027,6 +1027,49 @@
 template
 void test_attach37::test_attach39(int aaa, int bbb) {}
 
+// The inline comments expect a string after the command.
+// expected-warning@+1 {{'\a' command does not have an argument}}
+/// \a
+int test_inline_no_argument_a_b(int);
+
+/// \a A
+int test_inline_no_argument_a_g(int);
+
+// expected-warning@+1 {{'@b' command does not have an argument}}
+/// @b
+int test_inline_no_argument_b_b(int);
+
+/// @b A
+int test_inline_no_argument_b_g(int);
+
+// expected-warning@+1 {{'\c' command does not have an argument}}
+/// \c
+int test_inline_no_argument_c_b(int);
+
+/// \c A
+int test_inline_no_argument_c_g(int);
+
+// expected-warning@+1 {{'\e' command does not have an argument}}
+/// \e
+int test_inline_no_argument_e_b(int);
+
+/// \e A
+int test_inline_no_argument_e_g(int);
+
+// expected-warning@+1 {{'\em' command does not have an argument}}
+/// \em
+int test_inline_no_argument_em_b(int);
+
+/// \em A
+int test_inline_no_argument_em_g(int);
+
+// expected-warning@+1 {{'\p' command does not have an argument}}
+/// \p
+int test_inline_no_argument_p_b(int);
+
+/// \p A
+int test_inline_no_argument_p_g(int);
+
 // We used to emit warning that parameter 'a' is not found because we parsed
 // the comment in context of the redeclaration which does not have parameter
 // names.
Index: clang/lib/AST/CommentParser.cpp
===
--- clang/lib/AST/CommentParser.cpp
+++ clang/lib/AST/CommentParser.cpp
@@ -422,6 +422,12 @@
 IC = S.actOnInlineCommand(CommandTok.getLocation(),
   CommandTok.getEndLocation(),
   CommandTok.getCommandID());
+
+Diag(CommandTok.getEndLocation().getLocWithOffset(1),
+ diag::warn_doc_inline_contents_no_argument)
+<< CommandTok.is(tok::at_command)
+<< Traits.getCommandInfo(CommandTok.getCommandID())->Name
+<< SourceRange(CommandTok.getLocation(), CommandTok.getEndLocation());
   }
 
   Retokenizer.putBackLeftoverTokens();
Index: clang/include/clang/Basic/DiagnosticCommentKinds.td
===
--- clang/include/clang/Basic/DiagnosticCommentKinds.td
+++ clang/include/clang/Basic/DiagnosticCommentKinds.td
@@ -153,6 +153,12 @@
 def note_add_deprecation_attr : Note<
   "add a deprecation attribute to the declaration to silence this warning">;
 
+// inline contents commands
+
+def warn_doc_inline_contents_no_argument : Warning<
+  "'%select{\\|@}0%1' command does not have an argument">,
+  InGroup, DefaultIgnore;
+
 // verbatim block commands
 
 def warn_verbatim_block_end_without_start : Warning<


Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -1027,6 +1027,49 @@
 template
 void test_attach37::test_attach39(int aaa, int bbb) {}
 
+// The inline comments expect a string after the command.
+// expected-warning@+1 {{'\a' command does not have an argument}}
+/// \a
+int test_inline_no_argument_a_b(int);
+
+/// \a A
+int test_inline_no_argument_a_g(int);
+
+// expected-warning@+1 {{'@b' command does not have an argument}}
+/// @b
+int test_inline_no_argument_b_b(int);
+
+/// @b A
+int test_inline_no_argument_b_g(int);
+
+// expected-warning@+1 {{'\c' command does not have an argument}}
+/// \c
+int test_inline_no_argument_c_b(int);
+
+/// \c A
+int test_inline_no_argument_c_g(int);
+
+// expected-warning@+1 {{'\e' command does not have an argument}}
+/// \e
+int test_inline_no_argument_e_b(int);
+
+/// \e A
+int test_inline_no_argument_e_g(int);
+
+// expected-warning@+1 {{'\em' command does not have an argument}}
+/// \em
+int test_inline_no_argument_em_b(int);
+
+/// \em A
+int test_inline_no_argument_em_g(int);
+
+// expected-warning@+1 {{'\p' command does not have an argument}}
+/// \p
+int test_inline_no_argument_p_b(int);
+
+/// \p A
+int test_inline_no_argument_p_g(int);
+
 // We used to emit warning that parameter 'a' is not found because we parsed
 // the comment in context of the redeclaration which does not have parameter
 // names.
Index: clang/lib/AST/CommentParser.cpp
===
--- clang/lib/AST/Comme

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale updated this revision to Diff 209701.
oydale added a comment.

Changed test to use CHECK-NEXT, -discard-value-names, and pattern matching


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp

Index: clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -emit-llvm --std=c++17 -fcxx-exceptions -fexceptions \
+// RUN:   -discard-value-names %s -o - | FileCheck %s
+
+struct Q { Q(); };
+struct R { R(Q); ~R(); };
+struct S { S(Q); ~S(); };
+struct T : R, S {};
+
+Q q;
+T t { R{q}, S{q} };
+
+// CHECK-LABEL: define internal void @__cxx_global_var_init.1() {{.*}} {
+// CHECK-NEXT: [[TMP_R:%[a-z0-9.]+]] = alloca %struct.R, align 1
+// CHECK-NEXT: [[TMP_Q1:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[TMP_S:%[a-z0-9.]+]] = alloca %struct.S, align 1
+// CHECK-NEXT: [[TMP_Q2:%[a-z0-9.]+]] = alloca %struct.Q, align 1
+// CHECK-NEXT: [[XPT:%[a-z0-9.]+]] = alloca i8*
+// CHECK-NEXT: [[SLOT:%[a-z0-9.]+]] = alloca i32
+// CHECK-NEXT: [[ACTIVE:%[a-z0-9.]+]] = alloca i1, align 1
+// CHECK-NEXT: call void @_ZN1RC1E1Q(%struct.R* [[TMP_R]])
+// CHECK-NEXT: store i1 true, i1* [[ACTIVE]], align 1
+// CHECK-NEXT: invoke void @_ZN1SC1E1Q(%struct.S* [[TMP_S]])
+// CHECK-NEXT:   to label %[[L1:[a-z0-9.]+]] unwind label %[[L2:[a-z0-9.]+]]
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L1]]:
+// CHECK-NEXT: store i1 false, i1* [[ACTIVE]], align 1
+// CHECK-NEXT: call void @_ZN1SD1Ev(%struct.S*
+// CHECK-NEXT: call void @_ZN1RD1Ev(%struct.R*
+// CHECK-NEXT: [[EXIT:%[a-z0-9.]+]] = call i32 @__cxa_atexit(
+// CHECK-NEXT: ret void
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L2]]:
+// CHECK-NEXT: [[LP:%[a-z0-9.]+]] = landingpad { i8*, i32 }
+// CHECK-NEXT:  cleanup
+// CHECK-NEXT: [[X1:%[a-z0-9.]+]] = extractvalue { i8*, i32 } [[LP]], 0
+// CHECK-NEXT: store i8* [[X1]], i8** [[XPT]], align 8
+// CHECK-NEXT: [[X2:%[a-z0-9.]+]] = extractvalue { i8*, i32 } [[LP]], 1
+// CHECK-NEXT: store i32 [[X2]], i32* [[SLOT]], align 4
+// CHECK-NEXT: [[IS_ACT:%[a-z0-9.]+]] = load i1, i1* [[ACTIVE]], align 1
+// CHECK-NEXT: br i1 [[IS_ACT]], label %[[L3:[a-z0-9.]+]], label %[[L4:[a-z0-9.]+]]
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L3]]:
+// CHECK-NEXT: call void @_ZN1RD1Ev(%struct.R*
+// CHECK-NEXT: br label %[[L4]]
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L4]]:
+// CHECK-NEXT: call void @_ZN1RD1Ev(%struct.R* [[TMP_R]])
+// CHECK-NEXT: br label %[[L5:[a-z0-9.]+]]
+// CHECK-EMPTY:
+// CHECK-NEXT: [[L5]]:
+// CHECK-NEXT: [[EXN:%[a-z0-9.]+]] = load i8*, i8** [[XPT]], align 8
+// CHECK-NEXT: [[SEL:%[a-z0-9.]+]] = load i32, i32* [[SLOT]], align 4
+// CHECK-NEXT: [[LV1:%[a-z0-9.]+]] = insertvalue { i8*, i32 } undef, i8* [[EXN]], 0
+// CHECK-NEXT: [[LV2:%[a-z0-9.]+]] = insertvalue { i8*, i32 } [[LV1]], i32 [[SEL]], 1
+// CHECK-NEXT: resume { i8*, i32 } [[LV2]]
+// CHECK-NEXT: }
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1495,6 +1495,13 @@
   // initializers throws an exception.
   SmallVector cleanups;
   llvm::Instruction *cleanupDominator = nullptr;
+  auto addCleanup = [&](const EHScopeStack::stable_iterator &cleanup) {
+cleanups.push_back(cleanup);
+if (!cleanupDominator) // create placeholder once needed
+  cleanupDominator = CGF.Builder.CreateAlignedLoad(
+  CGF.Int8Ty, llvm::Constant::getNullValue(CGF.Int8PtrTy),
+  CharUnits::One());
+  };
 
   unsigned curInitIndex = 0;
 
@@ -1519,7 +1526,7 @@
   if (QualType::DestructionKind dtorKind =
   Base.getType().isDestructedType()) {
 CGF.pushDestroy(dtorKind, V, Base.getType());
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
   }
 }
   }
@@ -1596,15 +1603,9 @@
   = field->getType().isDestructedType()) {
   assert(LV.isSimple());
   if (CGF.needsEHCleanup(dtorKind)) {
-if (!cleanupDominator)
-  cleanupDominator = CGF.Builder.CreateAlignedLoad(
-  CGF.Int8Ty,
-  llvm::Constant::getNullValue(CGF.Int8PtrTy),
-  CharUnits::One()); // placeholder
-
 CGF.pushDestroy(EHCleanup, LV.getAddress(), field->getType(),
 CGF.getDestroyer(dtorKind), false);
-cleanups.push_back(CGF.EHStack.stable_begin());
+addCleanup(CGF.EHStack.stable_begin());
 pushedCleanup = true;
   }
 }
@@ -1620,6 +1621,8 @@
 
   // Deactivate all the partial cleanups in reverse order, which
   // generally means popping them.
+  assert((cleanupDominator || cleanups.empty()) &&
+

[PATCH] D64656: Ensure placeholder instruction for cleanup is created

2019-07-13 Thread Øystein Dale via Phabricator via cfe-commits
oydale accepted this revision.
oydale added a comment.

Feel free to commit this patch on my behalf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64656



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


[PATCH] D64062: Remove __VERSION__

2019-07-13 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

From the failure mode I was seeing, any value at all for __VERSION__ will be 
fine, as long as it is a valid preprocessor string.

It would also solve this particular problem to not define __GNUC__, but I as 
that would create other, more severe, problems, as long as clang identifies 
itself as __GNUC__, we should maintain compatibility with it.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64062



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


[PATCH] D63975: Warn when ScopeDepthOrObjCQuals overflows

2019-07-13 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 209703.
Mordante added a comment.

Addresses @rjmccall's remarks.
Fixes the tests for the nested lambda's.
As suspected the blocks also have the same nesting limit, thus added a test for 
them.


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

https://reviews.llvm.org/D63975

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/nested_blocks_overflow.cpp
  clang/test/Parser/nested_function_prototype_overflow.cpp
  clang/test/Parser/nested_lambda_overflow.cpp

Index: clang/test/Parser/nested_lambda_overflow.cpp
===
--- /dev/null
+++ clang/test/Parser/nested_lambda_overflow.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang %s -fsyntax-only -fbracket-depth=512
+// RUN: not %clang %s -fsyntax-only -fbracket-depth=512 -DFAIL 2>&1 | FileCheck %s
+
+template  int foo(T &&t);
+
+void bar(int x = foo(
+
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+
+[](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo([](int x = foo(
+
+#ifdef FAIL
+[](int x = foo(
+#endif
+
+[](int x = foo(1)){}
+
+#ifdef FAIL
+)){}
+#endif
+
+)){})){})){})){})){})){}
+
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+)){})){})){})){})){})){})){})){}
+));
+
+// CHECK: fatal error: function scope depth exceeded maximum of 127
Index: clang/test/Parser/nested_function_prototype_overflow.cpp
===
--- /dev/null
+++ clang/test/Parser/nested_function_prototype_overflow.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fsyntax-only
+// RUN: not %clang_cc1 %s -fsyntax-only -DFAIL 2>&1 | FileCheck %s
+
+void foo(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(void (*f)(v

[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-07-13 Thread Xiao Shi via Phabricator via cfe-commits
shixiao added a comment.

Could someone please take a look? I think I've addressed all of Jonas's 
comments above. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989



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


[PATCH] D63975: Warn when ScopeDepthOrObjCQuals overflows

2019-07-13 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM!


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

https://reviews.llvm.org/D63975



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


[PATCH] D63975: Warn when ScopeDepthOrObjCQuals overflows

2019-07-13 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Thanks for the review. I don't have SVN access, can you commit these changes?


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

https://reviews.llvm.org/D63975



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


r366010 - Remove extra ';' to silent compiler warning.

2019-07-13 Thread Michael Liao via cfe-commits
Author: hliao
Date: Sat Jul 13 12:49:39 2019
New Revision: 366010

URL: http://llvm.org/viewvc/llvm-project?rev=366010&view=rev
Log:
Remove extra ';' to silent compiler warning.

- Plus extra style formatting.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=366010&r1=366009&r2=366010&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jul 13 12:49:39 2019
@@ -11082,7 +11082,8 @@ bool Sema::DeduceVariableDeclarationType
   return VDecl->isInvalidDecl();
 }
 
-void Sema::checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation 
Loc) {
+void Sema::checkNonTrivialCUnionInInitializer(const Expr *Init,
+  SourceLocation Loc) {
   if (auto *CE = dyn_cast(Init))
 Init = CE->getSubExpr();
 
@@ -3,7 +4,7 @@ void Sema::checkNonTrivialCUnionInInitia
 if (InitType.hasNonTrivialToPrimitiveCopyCUnion())
   checkNonTrivialCUnion(InitType, Loc, NTCUC_CopyInit, NTCUK_Copy);
   }
-};
+}
 
 namespace {
 


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


[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-07-13 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane updated this revision to Diff 209705.
jpakkane added a comment.

Fixed issues found in code review.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D64671

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
  clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp

Index: clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
@@ -0,0 +1,83 @@
+// RUN: %check_clang_tidy %s misc-init-local-variables %t
+
+#include 
+
+#define DO_NOTHING(x) ((void)x)
+
+// Ensure that function declarations are not changed.
+void some_func(int x, double d, bool b, const char *p);
+
+int do_not_modify_me;
+
+typedef struct {
+  int unaltered1;
+  int unaltered2;
+} UnusedStruct;
+
+typedef int my_int_type;
+#define MACRO_INT int
+
+void init_unit_tests() {
+  int x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x = 0;{{$}}
+  int32_t sized_var;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: variable 'sized_var' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int32_t sized_var = 0;{{$}}
+  my_int_type myint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  my_int_type myint = 0;{{$}}
+  MACRO_INT macroint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  MACRO_INT macroint = 0;{{$}}
+  int x0 = 1, x1, x2 = 2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x0 = 1, x1 = 0, x2 = 2;{{$}}
+  int y0, y1 = 1, y2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [misc-init-local-variables]
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int y0 = 0, y1 = 1, y2 = 0;{{$}}
+  int hasval = 42;
+
+  float f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  float f = (0.0/0.0);{{$}}
+  float fval = 85.0;
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  double d = (0.0/0.0);{{$}}
+  double dval = 99.0;
+
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  bool bval = true;
+
+  const char *ptr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  const char *ptr = nullptr;{{$}}
+  const char *ptrval = "a string";
+
+  UnusedStruct u;
+
+  DO_NOTHING(x);
+  DO_NOTHING(sized_var);
+  DO_NOTHING(myint);
+  DO_NOTHING(macroint);
+  DO_NOTHING(x0);
+  DO_NOTHING(x1);
+  DO_NOTHING(x2);
+  DO_NOTHING(y0);
+  DO_NOTHING(y1);
+  DO_NOTHING(y2);
+  DO_NOTHING(hasval);
+  DO_NOTHING(f);
+  DO_NOTHING(fval);
+  DO_NOTHING(d);
+  DO_NOTHING(dval);
+  DO_NOTHING(b);
+  DO_NOTHING(bval);
+  DO_NOTHING(ptr);
+  DO_NOTHING(ptrval);
+  DO_NOTHING(u);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - misc-init-local-variables
+
+misc-init-local-variables
+=
+
+Checks whether there are local variables that are declared without an
+initial value. These may lead to unexpected behaviour if there is a
+code path that reads the variable before assigning to it.
+
+Only integers, booleans, floats, doubles and pointers are checked. The
+fix option initializes all detected values with the value of zero. An
+exception is float and double types, which are initialized to NaN.
+
+As an example a function that looks like this:
+
+.. code-block:: c++
+
+   void function() {
+ int x;
+ char *txt;
+ double d;
+
+ // Rest of the function.
+   }
+
+Would be rewritten to look like this:
+
+.. code-block:: c++
+
+   void function() {
+ int x = 0;
+ char *txt=nullptr;
+ double d = (0.0/0.0);
+
+ // Rest of the function.
+   }
Index: c

[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-07-13 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane marked 10 inline comments as done.
jpakkane added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:26-29
+  if(!MatchedDecl->isLocalVarDecl())
+return;
+  if(MatchedDecl->hasInit())
+return;

lebedev.ri wrote:
> Can make these proper `AST_MATCHER` and do this in `registerMatchers()`.
Init checking is now in the matcher. I did not change isLocalVarDecl because 
according to the documentation there does not seem to be a builtin matcher for 
that. Since the isLocalVarDecl is semantically exactly what is needed here it 
seems a bit silly to reimplement that from scratch from matcher basic blocks.



Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:32-35
+  if(varName.empty() || varName.front() == '_') {
+// Some standard library methods such as "be64toh" are implemented
+// as macros that internally use variable names
+// like __v. Do not touch those.

lebedev.ri wrote:
> This feels brittle.
> 
There's not much else one can do. Also, all variable names that begin with an 
underscore are reserved for the standard library (I think), so we should not be 
changing those in any case.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D64671



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


[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-07-13 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane updated this revision to Diff 209706.
jpakkane marked an inline comment as done.
jpakkane added a comment.

Fix missing spaces in documentation.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D64671

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
  clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp

Index: clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
@@ -0,0 +1,83 @@
+// RUN: %check_clang_tidy %s misc-init-local-variables %t
+
+#include 
+
+#define DO_NOTHING(x) ((void)x)
+
+// Ensure that function declarations are not changed.
+void some_func(int x, double d, bool b, const char *p);
+
+int do_not_modify_me;
+
+typedef struct {
+  int unaltered1;
+  int unaltered2;
+} UnusedStruct;
+
+typedef int my_int_type;
+#define MACRO_INT int
+
+void init_unit_tests() {
+  int x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x = 0;{{$}}
+  int32_t sized_var;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: variable 'sized_var' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int32_t sized_var = 0;{{$}}
+  my_int_type myint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  my_int_type myint = 0;{{$}}
+  MACRO_INT macroint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  MACRO_INT macroint = 0;{{$}}
+  int x0 = 1, x1, x2 = 2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x0 = 1, x1 = 0, x2 = 2;{{$}}
+  int y0, y1 = 1, y2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [misc-init-local-variables]
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int y0 = 0, y1 = 1, y2 = 0;{{$}}
+  int hasval = 42;
+
+  float f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  float f = (0.0/0.0);{{$}}
+  float fval = 85.0;
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  double d = (0.0/0.0);{{$}}
+  double dval = 99.0;
+
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  bool bval = true;
+
+  const char *ptr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  const char *ptr = nullptr;{{$}}
+  const char *ptrval = "a string";
+
+  UnusedStruct u;
+
+  DO_NOTHING(x);
+  DO_NOTHING(sized_var);
+  DO_NOTHING(myint);
+  DO_NOTHING(macroint);
+  DO_NOTHING(x0);
+  DO_NOTHING(x1);
+  DO_NOTHING(x2);
+  DO_NOTHING(y0);
+  DO_NOTHING(y1);
+  DO_NOTHING(y2);
+  DO_NOTHING(hasval);
+  DO_NOTHING(f);
+  DO_NOTHING(fval);
+  DO_NOTHING(d);
+  DO_NOTHING(dval);
+  DO_NOTHING(b);
+  DO_NOTHING(bval);
+  DO_NOTHING(ptr);
+  DO_NOTHING(ptrval);
+  DO_NOTHING(u);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - misc-init-local-variables
+
+misc-init-local-variables
+=
+
+Checks whether there are local variables that are declared without an
+initial value. These may lead to unexpected behaviour if there is a
+code path that reads the variable before assigning to it.
+
+Only integers, booleans, floats, doubles and pointers are checked. The
+fix option initializes all detected values with the value of zero. An
+exception is float and double types, which are initialized to NaN.
+
+As an example a function that looks like this:
+
+.. code-block:: c++
+
+   void function() {
+ int x;
+ char *txt;
+ double d;
+
+ // Rest of the function.
+   }
+
+Would be rewritten to look like this:
+
+.. code-block:: c++
+
+   void function() {
+ int x = 0;
+ char *txt = nullptr;
+ double d = (0.0/0.0);

[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

2019-07-13 Thread Ziang Wan via Phabricator via cfe-commits
ziangwan updated this revision to Diff 209710.
ziangwan added a comment.

Update diff:

1. fix the spelling issue `may loses integer precision` -> `may lose precision`
2. issue more accurate warnings when `int->float` conversion involves constant 
integer.


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

https://reviews.llvm.org/D64666

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conversion.c
  clang/test/Sema/ext_vector_casts.c
  clang/test/Sema/implicit-float-conversion.c

Index: clang/test/Sema/implicit-float-conversion.c
===
--- /dev/null
+++ clang/test/Sema/implicit-float-conversion.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-float-conversion
+
+
+long testReturn(long a, float b) {
+  return a + b; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
+}
+
+
+void testAssignment() {
+  float f = 22;
+  double b = L;
+  
+  float ff = L; // expected-warning {{implicit conversion from 'long' to 'float' changes value from  to 1312}}
+  float  = UL; // expected-warning {{implicit conversion from 'unsigned long' to 'float' changes value from  to 1312}}
+
+  long l = L;
+  float fff = l; // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
+}
+
+
+void testExpression() {
+  float a = 0.0f;
+  float b = L + a; // expected-warning {{implicit conversion from 'long' to 'float' changes value from  to 1312}}
+
+  float g =  + ;
+  float c =  + 2223; // expected-warning {{implicit conversion from 'int' to 'float' changes value from 4445 to }}
+
+  int i = 0;
+  float d = i + a; // expected-warning {{implicit conversion from 'int' to 'float' may lose precision}}
+  
+  double e = 0.0;
+  double f = i + e;
+}
Index: clang/test/Sema/ext_vector_casts.c
===
--- clang/test/Sema/ext_vector_casts.c
+++ clang/test/Sema/ext_vector_casts.c
@@ -115,12 +115,12 @@
   vl = vl + t; // expected-warning {{implicit conversion loses integer precision}}
   
   vf = 1 + vf;
-  vf = l + vf;
+  vf = l + vf; // expected-warning {{implicit conversion from 'long' to 'float2' (vector of 2 'float' values) may lose precision}}
   vf = 2.0 + vf;
   vf = d + vf; // expected-warning {{implicit conversion loses floating-point precision}}
-  vf = vf + 0x;
+  vf = vf + 0x; // expected-warning {{implicit conversion from 'unsigned int' to 'float2' (vector of 2 'float' values) changes value from 4294967295 to 4294967296}}
   vf = vf + 2.1; // expected-warning {{implicit conversion loses floating-point precision}}
   
-  vd = l + vd;
-  vd = vd + t;
+  vd = l + vd; // expected-warning {{implicit conversion from 'long' to 'double2' (vector of 2 'double' values) may lose precision}}
+  vd = vd + t; // expected-warning {{implicit conversion from '__uint128_t' (aka 'unsigned __int128') to 'double2' (vector of 2 'double' values) may lose precision}}
 }
Index: clang/test/Sema/conversion.c
===
--- clang/test/Sema/conversion.c
+++ clang/test/Sema/conversion.c
@@ -233,7 +233,7 @@
   takes_int(v);
   takes_long(v);
   takes_longlong(v);
-  takes_float(v);
+  takes_float(v); // expected-warning {{implicit conversion from 'int' to 'float' may lose precision}}
   takes_double(v);
   takes_longdouble(v);
 }
@@ -244,8 +244,8 @@
   takes_int(v); // expected-warning {{implicit conversion loses integer precision}}
   takes_long(v);
   takes_longlong(v);
-  takes_float(v);
-  takes_double(v);
+  takes_float(v); // expected-warning {{implicit conversion from 'long' to 'float' may lose precision}}
+  takes_double(v); // expected-warning {{implicit conversion from 'long' to 'double' may lose precision}}
   takes_longdouble(v);
 }
 
@@ -255,8 +255,8 @@
   takes_int(v); // expected-warning {{implicit conversion loses integer precision}}
   takes_long(v);
   takes_longlong(v);
-  takes_float(v);
-  takes_double(v);
+  takes_float(v); // expected-warning {{implicit conversion from 'long long' to 'float' may lose precision}}
+  takes_double(v); // expected-warning {{implicit conversion from 'long long' to 'double' may lose precision}}
   takes_longdouble(v);
 }
 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11400,6 +11400,61 @@
 }
   }
 
+  // If we are casting an integer type to a floating point type, we might
+  // lose accuracy if the floating point type has a narrower significand
+  // than the integer type. Issue warnings for that accuracy l

[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

2019-07-13 Thread Ziang Wan via Phabricator via cfe-commits
ziangwan marked 9 inline comments as done.
ziangwan added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:11430
+SmallString<32> PrettyTargetValue;
+TargetFloatValue.toString(PrettyTargetValue,
+  TargetPrecision);

nickdesaulniers wrote:
> xbolva00 wrote:
> > Can you check my older patch + tests + discussion? 
> > 
> > I had to use other way to get this string..
> > 
> > 
> And I don't think there's a test for this case? Or at least one that checks 
> the printed value?
I have checked your older patch.

IIUC, you take the log of number of precision bits and print the floating point 
value out. E.g. 2555+E9. I am doing it differently. I print out all the 
precision bits. E.g. 2555677.000. The reason is that I think it is more clear 
to print out `changes value from  to 1312` than `changes 
value from  to 1+e3`.



Comment at: clang/lib/Sema/SemaChecking.cpp:11430
+SmallString<32> PrettyTargetValue;
+TargetFloatValue.toString(PrettyTargetValue,
+  TargetPrecision);

ziangwan wrote:
> nickdesaulniers wrote:
> > xbolva00 wrote:
> > > Can you check my older patch + tests + discussion? 
> > > 
> > > I had to use other way to get this string..
> > > 
> > > 
> > And I don't think there's a test for this case? Or at least one that checks 
> > the printed value?
> I have checked your older patch.
> 
> IIUC, you take the log of number of precision bits and print the floating 
> point value out. E.g. 2555+E9. I am doing it differently. I print out all the 
> precision bits. E.g. 2555677.000. The reason is that I think it is more clear 
> to print out `changes value from  to 1312` than `changes 
> value from  to 1+e3`.
Test cases are added


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

https://reviews.llvm.org/D64666



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


r366012 - [Driver] Simplify -lgcc & -lgcc_s

2019-07-13 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Jul 13 23:46:46 2019
New Revision: 366012

URL: http://llvm.org/viewvc/llvm-project?rev=366012&view=rev
Log:
[Driver] Simplify -lgcc & -lgcc_s

gcc defaults to -shared-libgcc in C++ mode.
Letting getLibGccType() return SharedLibGcc simplifies the logic.

Modified:
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=366012&r1=366011&r2=366012&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Sat Jul 13 23:46:46 2019
@@ -1135,16 +1135,12 @@ bool tools::isObjCAutoRefCount(const Arg
 
 enum class LibGccType { UnspecifiedLibGcc, StaticLibGcc, SharedLibGcc };
 
-static LibGccType getLibGccType(const ArgList &Args) {
-  bool Static = Args.hasArg(options::OPT_static_libgcc) ||
-Args.hasArg(options::OPT_static) ||
-Args.hasArg(options::OPT_static_pie);
-
-  bool Shared = Args.hasArg(options::OPT_shared_libgcc);
-  if (Shared)
-return LibGccType::SharedLibGcc;
-  if (Static)
+static LibGccType getLibGccType(const Driver &D, const ArgList &Args) {
+  if (Args.hasArg(options::OPT_static_libgcc) ||
+  Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie))
 return LibGccType::StaticLibGcc;
+  if (Args.hasArg(options::OPT_shared_libgcc) || D.CCCIsCXX())
+return LibGccType::SharedLibGcc;
   return LibGccType::UnspecifiedLibGcc;
 }
 
@@ -1170,8 +1166,8 @@ static void AddUnwindLibrary(const ToolC
   UNW == ToolChain::UNW_None)
 return;
 
-  LibGccType LGT = getLibGccType(Args);
-  bool AsNeeded = D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc &&
+  LibGccType LGT = getLibGccType(D, Args);
+  bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc &&
   !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing();
   if (AsNeeded)
 CmdArgs.push_back("--as-needed");
@@ -1180,11 +1176,11 @@ static void AddUnwindLibrary(const ToolC
   case ToolChain::UNW_None:
 return;
   case ToolChain::UNW_Libgcc: {
-LibGccType LGT = getLibGccType(Args);
-if (LGT == LibGccType::UnspecifiedLibGcc || LGT == 
LibGccType::SharedLibGcc)
-  CmdArgs.push_back("-lgcc_s");
-else if (LGT == LibGccType::StaticLibGcc)
+LibGccType LGT = getLibGccType(D, Args);
+if (LGT == LibGccType::StaticLibGcc)
   CmdArgs.push_back("-lgcc_eh");
+else
+  CmdArgs.push_back("-lgcc_s");
 break;
   }
   case ToolChain::UNW_CompilerRT:
@@ -1200,7 +1196,7 @@ static void AddLibgcc(const ToolChain &T
   ArgStringList &CmdArgs, const ArgList &Args) {
   bool isAndroid = TC.getTriple().isAndroid();
 
-  LibGccType LGT = getLibGccType(Args);
+  LibGccType LGT = getLibGccType(D, Args);
   bool LibGccFirst = (D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc) ||
  LGT == LibGccType::StaticLibGcc;
   if (LibGccFirst)
@@ -1216,7 +1212,7 @@ static void AddLibgcc(const ToolChain &T
   //
   // NOTE: This fixes a link error on Android MIPS as well.  The non-static
   // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl.
-  if (isAndroid && getLibGccType(Args) != LibGccType::StaticLibGcc)
+  if (isAndroid && getLibGccType(D, Args) != LibGccType::StaticLibGcc)
 CmdArgs.push_back("-ldl");
 }
 


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