[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 237251.
MaskRay added a comment.

-malign-branch-boundary= is the primary option. So swap the roles


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s

Index: clang/test/Driver/x86-malign-branch.s
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.s
@@ -0,0 +1,13 @@
+/// Test that -malign-branch* are handled for assembly files.
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE
+// TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
Index: clang/test/Driver/x86-malign-branch.c
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.c
@@ -0,0 +1,44 @@
+/// Test that -malign-branch* options are parsed and converted to -mllvm options.
+
+/// Test -malign-branch-boundary=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=8 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// RUN: %clang -target x86_64 -malign-branch-boundary=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// BOUNDARY-ERR: invalid argument {{.*}} to -malign-branch-boundary=
+
+/// Test -malign-branch=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE0
+// TYPE0: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp+ret+call+indirect %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE1
+// TYPE1: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+
+// RUN: %clang -target x86_64 -malign-branch=fused+foo+bar %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE-ERR
+// TYPE-ERR: invalid argument 'foo' to -malign-branch=; must be one of: fused, jcc, jmp, call, ret, indirect
+// TYPE-ERR: invalid argument 'bar' to -malign-branch=; must be one of: fused, jcc, jmp, call, ret, indirect
+
+/// Test -malign-branch-prefix-size=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0
+// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5
+// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6
+// PREFIX-6: invalid argument
+
+/// Test -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -mno-branches-within-32B-boundaries -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries -mno-branches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=NO32B
+// NO32B-NOT: "-x86-align-branch
+/// Test that -malign-branch* can override individual values of -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -malign-branch=jcc -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B-TYPE
+// 32B-TYPE:  "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=jcc" "-mllvm" "-x86-align-branch-prefix-size=5"
+
+/// Unsupported on other targets.
+// RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target

[clang-tools-extra] 164da67 - Restore order in clang-tidy section of release notes

2020-01-10 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-01-10T09:19:58+01:00
New Revision: 164da673009ba6c100ce45b6fa9a5dfd3b0b8e38

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

LOG: Restore order in clang-tidy section of release notes

Major changes are introduction of subsubsections to prevent people
putting new entries in wrong places. I also polished line length and
highlighting.

Patch by Eugene Zelenko!

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 86cdbf5e8b1a..65938a357ee9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -67,6 +67,9 @@ The improvements are...
 Improvements to clang-tidy
 --
 
+New checks
+^^
+
 - New :doc:`bugprone-bad-signal-to-kill-thread
   ` check.
 
@@ -89,16 +92,13 @@ Improvements to clang-tidy
   ` check
 
   Finds function calls where it is possible to cause a not null-terminated
-  result. Usually the proper length of a string is ``strlen(str) + 1`` or equal
-  length of this expression, because the null terminator needs an extra space.
-  Without the null terminator it can result in undefined behaviour when the
-  string is read.
+  result.
 
 - New :doc:`bugprone-signed-char-misuse
   ` check.
 
-  Finds ``signed char`` -> integer conversions which might indicate a 
programming
-  error.
+  Finds ``signed char`` to integer conversions which might indicate a
+  programming error.
 
 - New :doc:`cert-mem57-cpp
   ` check.
@@ -106,11 +106,6 @@ Improvements to clang-tidy
   Checks if an object of type with extended alignment is allocated by using
   the default ``operator new``.
 
-- New alias :doc:`cert-pos44-c
-  ` to
-  :doc:`bugprone-bad-signal-to-kill-thread
-  ` was added.
-
 - New :doc:`cert-oop58-cpp
   ` check.
 
@@ -120,6 +115,9 @@ Improvements to clang-tidy
 - New :doc:`cppcoreguidelines-init-variables
   ` check.
 
+  Checks whether there are local variables that are declared without an initial
+  value.
+
 - New :doc:`darwin-dispatch-once-nonstatic
   ` check.
 
@@ -132,11 +130,6 @@ Improvements to clang-tidy
   Finds uses of deprecated Googletest APIs with names containing ``case`` and
   replaces them with equivalent APIs with ``suite``.
 
-- Improved :doc:`hicpp-signed-bitwise
-  ` check.
-
-  The check now supports the ``IgnorePositiveIntegerLiterals`` option.
-
 - New :doc:`linuxkernel-must-use-errs
   ` check.
 
@@ -166,69 +159,88 @@ Improvements to clang-tidy
   Finds types that could be made trivially-destructible by removing out-of-line
   defaulted destructor declarations.
 
-- The :doc:`modernize-use-using
-  ` check now converts typedefs 
containing
-  struct definitions and multiple comma-separated types.
+- New :doc:`readability-make-member-function-const
+  ` check.
+
+  Finds non-static member functions that can be made ``const``
+  because the functions don't use ``this`` in a non-const way.
+
+- New :doc:`readability-redundant-access-specifiers
+  ` check.
+
+  Finds classes, structs, and unions that contain redundant member
+  access specifiers.
+
+New aliases
+^^^
+
+- New alias :doc:`cert-pos44-c
+  ` to
+  :doc:`bugprone-bad-signal-to-kill-thread
+  ` was added.
+
+Changes in existing checks
+^^
 
 - Improved :doc:`bugprone-posix-return
   ` check.
 
-  Now also checks if any calls to ``pthread_*`` functions expect negative 
return
-  values.
+  Now also checks if any calls to ``pthread_*`` functions expect negative
+  return values.
 
-- The 'objc-avoid-spinlock' check was renamed to :doc:`darwin-avoid-spinlock
-  `
+- Improved :doc:`hicpp-signed-bitwise
+  ` check.
+
+  The check now supports the `IgnorePositiveIntegerLiterals` option.
+
+- Improved :doc:`modernize-avoid-bind
+  ` check.
+
+  The check now supports supports diagnosing and fixing arbitrary callables
+  instead of only simple free functions. The `PermissiveParameterList` option
+  has also been added to address situations where the existing fix-it logic
+  would sometimes generate code that no longer compiles.
 
 - The :doc:`modernize-use-equals-default
   ` fix no longer adds
   semicolons where they would be redundant.
 
-- New :doc:`readability-redundant-access-specifiers
-  ` check.
+- Improved :doc:`modernize-use-override
+  ` check.
 
-  Finds classes, structs, and unions that contain redundant member
-  access specifiers.
+  The check now supports the `AllowOverrideAndFinal` option to eliminate
+  conflicts with `gcc -Wsuggest-override` or `gcc -Werror=suggest-override`.
+
+- The :doc:`modernize-use-using
+  ` check now converts typedefs
+  containing struct definitions and multiple comma-separated types.
 
 - 

[PATCH] D72450: [clangd] Improve type printing in hover

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72450



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61743 tests passed, 0 failed 
and 780 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

In D72227  you wrote

> I think options should follow these principles:
> 
> 1. Different options are position independent. -mA -mB should be the same as 
> -mB -mA.
> 2. -mA and -mno-A are position dependent and the last one wins. Sometimes, 
> the set may include more than 2 options, e.g. the last of -fno-pic -fpie and 
> -fpic wins.
> 3. More specific options can override semantics of less specific options. In 
> our case, -malign-branch* are more specific than 
> -malign-branch-within-32B-boundaries.

This implemetation is consistent with the principles.  However, as I mentioned 
in D72227 , I hold a slightly different 
opinion about the principles.

> 1. Different options are position independent. -mA -mB should be the same as 
> -mB -mA.

I think only when A and B are not related,  (-mA -mB) == (-mB -mA).

> 2. -mA and -mno-A are position dependent and the last one wins. Sometimes, 
> the set may include more than 2 options, e.g. the last of -fno-pic -fpie and 
> -fpic wins

Totally agree.

> 3. More specific options can override semantics of less specific options. In 
> our case, -malign-branch* are more specific than 
> -malign-branch-within-32B-boundaries.

I think general options can aslo override specific options. The last one wins. 
e.g.
The net effect of `-malign-branch=fused -malign-branch-within-32B-boundaries` 
should be `-malign-branch-boundary=32 -malign-branch=fused+jcc+jmp 
-malign-branch-prefix-size=5`




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2034
+<< T << "fused, jcc, jmp, call, ret, indirect";
+AlignBranch = StringRef();
+  }

`AlignBranch = StringRef()` seems unnecessary.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2040
+if (Value.getAsInteger(10, AlignBranchBoundary) ||
+AlignBranchBoundary < 16 || !llvm::isPowerOf2_64(AlignBranchBoundary)) 
{
+  D.Diag(diag::err_drv_invalid_argument_to_option)

Any reason for  precluding 16?



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2053
+  << Value << A->getOption().getName();
+  AlignBranch = StringRef();
+}

AlignBranch = StringRef() seems unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

Add revison D72225  as parent?




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2028
+if (Value.getAsInteger(10, AlignBranchBoundary) ||
+AlignBranchBoundary < 16 || !llvm::isPowerOf2_64(AlignBranchBoundary))
+  D.Diag(diag::err_drv_invalid_argument_to_option)

Any reason for precluding 16?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D71082: Allow system header to provide their own implementation of some builtin

2020-01-10 Thread serge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG921f871ac438: Allow system header to provide their own 
implementation of some builtin (authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71082

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memcpy-nobuiltin.c
  clang/test/CodeGen/memcpy-nobuiltin.inc

Index: clang/test/CodeGen/memcpy-nobuiltin.inc
===
--- /dev/null
+++ clang/test/CodeGen/memcpy-nobuiltin.inc
@@ -0,0 +1,19 @@
+#include 
+extern void *memcpy(void *dest, void const *from, size_t n);
+
+#ifdef WITH_DECL
+inline void *memcpy(void *dest, void const *from, size_t n) {
+  char const *ifrom = from;
+  char *idest = dest;
+  while (n--)
+*idest++ = *ifrom++;
+  return dest;
+}
+#endif
+#ifdef WITH_SELF_REFERENCE_DECL
+inline void *memcpy(void *dest, void const *from, size_t n) {
+  if (n != 0)
+memcpy(dest, from, n);
+  return dest;
+}
+#endif
Index: clang/test/CodeGen/memcpy-nobuiltin.c
===
--- /dev/null
+++ clang/test/CodeGen/memcpy-nobuiltin.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -DWITH_DECL | FileCheck --check-prefix=CHECK-WITH-DECL %s
+// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -UWITH_DECL | FileCheck --check-prefix=CHECK-NO-DECL %s
+// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -DWITH_SELF_REFERENCE_DECL | FileCheck --check-prefix=CHECK-SELF-REF-DECL %s
+//
+// CHECK-WITH-DECL-NOT: @llvm.memcpy
+// CHECK-NO-DECL: @llvm.memcpy
+// CHECK-SELF-REF-DECL: @llvm.memcpy
+//
+#include 
+void test(void *dest, void const *from, size_t n) {
+  memcpy(dest, from, n);
+
+  static char buffer[1];
+  memcpy(buffer, from, 2); // expected-warning {{'memcpy' will always overflow; destination buffer has size 1, but size argument is 2}}
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1840,6 +1840,11 @@
   else if (const auto *SA = FD->getAttr())
  F->setSection(SA->getName());
 
+  if (FD->isInlineBuiltinDeclaration()) {
+F->addAttribute(llvm::AttributeList::FunctionIndex,
+llvm::Attribute::NoBuiltin);
+  }
+
   if (FD->isReplaceableGlobalAllocationFunction()) {
 // A replaceable global allocation function does not act like a builtin by
 // default, only if it is invoked by a new-expression or delete-expression.
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -4622,8 +4622,15 @@
 }
 
 static CGCallee EmitDirectCallee(CodeGenFunction &CGF, const FunctionDecl *FD) {
+
   if (auto builtinID = FD->getBuiltinID()) {
-return CGCallee::forBuiltin(builtinID, FD);
+// Replaceable builtin provide their own implementation of a builtin. Unless
+// we are in the builtin implementation itself, don't call the actual
+// builtin. If we are in the builtin implementation, avoid trivial infinite
+// recursion.
+if (!FD->isInlineBuiltinDeclaration() ||
+CGF.CurFn->getName() == FD->getName())
+  return CGCallee::forBuiltin(builtinID, FD);
   }
 
   llvm::Constant *calleePtr = EmitFunctionDeclPointer(CGF.CGM, FD);
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3046,6 +3046,14 @@
   return Params == FPT->getNumParams();
 }
 
+bool FunctionDecl::isInlineBuiltinDeclaration() const {
+  if (!getBuiltinID())
+return false;
+
+  const FunctionDecl *Definition;
+  return hasBody(Definition) && Definition->isInlineSpecified();
+}
+
 bool FunctionDecl::isDestroyingOperatorDelete() const {
   // C++ P0722:
   //   Within a class C, a single object deallocation function with signature
Index: clang/include/clang/AST/Decl.h
===
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -2309,6 +2309,9 @@
   /// true through IsAligned.
   bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
 
+  /// Determine if this function provides an inline implementation of a builtin.
+  bool isInlineBuiltinDeclaration() const;
+
   /// Determine whether this is a destroying operator delete.
   bool isDestroyingOperatorDelete() const;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 237253.
MaskRay marked 5 inline comments as done.
MaskRay added a comment.

Delete a `AlignBranch = StringRef()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s

Index: clang/test/Driver/x86-malign-branch.s
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.s
@@ -0,0 +1,13 @@
+/// Test that -malign-branch* are handled for assembly files.
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE
+// TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
Index: clang/test/Driver/x86-malign-branch.c
===
--- /dev/null
+++ clang/test/Driver/x86-malign-branch.c
@@ -0,0 +1,44 @@
+/// Test that -malign-branch* options are parsed and converted to -mllvm options.
+
+/// Test -malign-branch-boundary=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY
+// BOUNDARY: "-mllvm" "-x86-align-branch-boundary=16"
+
+// RUN: %clang -target x86_64 -malign-branch-boundary=8 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// RUN: %clang -target x86_64 -malign-branch-boundary=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=BOUNDARY-ERR
+// BOUNDARY-ERR: invalid argument {{.*}} to -malign-branch-boundary=
+
+/// Test -malign-branch=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE0
+// TYPE0: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch=fused+jcc+jmp+ret+call+indirect %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE1
+// TYPE1: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+
+// RUN: %clang -target x86_64 -malign-branch=fused+foo+bar %s -c -### %s 2>&1 | FileCheck %s --check-prefix=TYPE-ERR
+// TYPE-ERR: invalid argument 'foo' to -malign-branch=; must be one of: fused, jcc, jmp, call, ret, indirect
+// TYPE-ERR: invalid argument 'bar' to -malign-branch=; must be one of: fused, jcc, jmp, call, ret, indirect
+
+/// Test -malign-branch-prefix-size=
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=0 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-0
+// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0"
+// RUN: %clang -target x86_64 -malign-branch-boundary=16 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5
+// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5"
+
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6
+// PREFIX-6: invalid argument
+
+/// Test -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -mno-branches-within-32B-boundaries -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
+// 32B: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=5"
+// RUN: %clang -target x86_64 -mbranches-within-32B-boundaries -mno-branches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=NO32B
+// NO32B-NOT: "-x86-align-branch
+/// Test that -malign-branch* can override individual values of -mbranches-within-32B-boundaries
+// RUN: %clang -target x86_64 -malign-branch=jcc -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B-TYPE
+// 32B-TYPE:  "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=jcc" "-mllvm" "-x86-align-branch-prefix-size=5"
+
+/// Unsupported on other targets.
+// RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck --check-prefix=UNUSED %s
+// RUN: %

[clang-tools-extra] ffd0f11 - [clangd] Improve type printing in hover

2020-01-10 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-01-10T09:51:20+01:00
New Revision: ffd0f116754c36146bb21a01b047782ce8a01e2e

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

LOG: [clangd] Improve type printing in hover

Summary:
Do not include tag keywords when printing types for symbol names, as it
will come from SymbolKind.
Also suppress them while printing definitions to prevent them occuring in
template arguments.
Make use of `getAsString`, instead of `print` in all places to have a consistent
style across the file.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 20883b347fdc..a9fa6443b196 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -16,13 +16,13 @@
 #include "Selection.h"
 #include "SourceCode.h"
 #include "index/SymbolCollector.h"
-
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -101,6 +101,7 @@ std::string printDefinition(const Decl *D) {
   printingPolicyForDecls(D->getASTContext().getPrintingPolicy());
   Policy.IncludeTagDefinition = false;
   Policy.SuppressTemplateArgsInCXXConstructors = true;
+  Policy.SuppressTagKeyword = true;
   D->print(OS, Policy);
   OS.flush();
   return Definition;
@@ -233,9 +234,7 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
 HI.Parameters->emplace_back();
 auto &P = HI.Parameters->back();
 if (!PVD->getType().isNull()) {
-  P.Type.emplace();
-  llvm::raw_string_ostream OS(*P.Type);
-  PVD->getType().print(OS, Policy);
+  P.Type = PVD->getType().getAsString(Policy);
 } else {
   std::string Param;
   llvm::raw_string_ostream OS(Param);
@@ -344,13 +343,10 @@ HoverInfo getHoverContents(const NamedDecl *D, const 
SymbolIndex *Index) {
   }
 
   // Fill in types and params.
-  if (const FunctionDecl *FD = getUnderlyingFunction(D)) {
+  if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  } else if (const auto *VD = dyn_cast(D)) {
-HI.Type.emplace();
-llvm::raw_string_ostream OS(*HI.Type);
-VD->getType().print(OS, Policy);
-  }
+  else if (const auto *VD = dyn_cast(D))
+HI.Type = VD->getType().getAsString(Policy);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {
@@ -380,9 +376,9 @@ HoverInfo getHoverContents(QualType T, ASTContext &ASTCtx,
 enhanceFromIndex(HI, *CommentD, Index);
   } else {
 // Builtin types
-llvm::raw_string_ostream OS(HI.Name);
-PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
-T.print(OS, Policy);
+auto Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
+Policy.SuppressTagKeyword = true;
+HI.Name = T.getAsString(Policy);
   }
   return HI;
 }

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 44337688ff87..91eb5a083ddf 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -446,7 +446,7 @@ class Foo {})cpp";
[](HoverInfo &HI) {
  HI.Name = "x";
  HI.NamespaceScope = "";
- HI.Definition = "enum Color x = GREEN";
+ HI.Definition = "Color x = GREEN";
  HI.Kind = index::SymbolKind::Variable;
  HI.Type = "enum Color";
  HI.Value = "GREEN (1)"; // Symbolic when hovering on an expression.
@@ -1427,7 +1427,7 @@ TEST(Hover, All) {
 HI.NamespaceScope = "";
 HI.LocalScope = "test::";
 HI.Type = "struct Test &&";
-HI.Definition = "struct Test &&test = {}";
+HI.Definition = "Test &&test = {}";
 HI.Value = "{}";
   }},
   {
@@ -1476,6 +1476,31 @@ TEST(Hover, All) {
 HI.ReturnType = "int";
 HI.Type = "int ()";
   }},
+  {
+  R"cpp(// type of nested templates.
+  template  struct cls {};
+  cls>> [[fo^o]];
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "cls>> foo";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "

[clang-tools-extra] abfa27e - [clangd] Fix markdown rendering in VSCode

2020-01-10 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-01-10T09:51:20+01:00
New Revision: abfa27e4f04dd84774bcfe15783942e21be391a5

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

LOG: [clangd] Fix markdown rendering in VSCode

Summary:
Eventough it is OK to have a new line without any preceding spaces in
some markdown specifications, VSCode requires two spaces before a new line to
break a line inside a paragraph.

Reviewers: sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FormattedString.cpp
clang-tools-extra/clangd/unittests/FormattedStringTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FormattedString.cpp 
b/clang-tools-extra/clangd/FormattedString.cpp
index cfa1210a2ee6..1e61b8b5fb1e 100644
--- a/clang-tools-extra/clangd/FormattedString.cpp
+++ b/clang-tools-extra/clangd/FormattedString.cpp
@@ -196,7 +196,8 @@ void Paragraph::renderMarkdown(llvm::raw_ostream &OS) const 
{
   }
   // Paragraphs are translated into markdown lines, not markdown paragraphs.
   // Therefore it only has a single linebreak afterwards.
-  OS << '\n';
+  // VSCode requires two spaces at the end of line to start a new one.
+  OS << "  \n";
 }
 
 void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {

diff  --git a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp 
b/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
index 3093ba2ce50d..825bf5bbd866 100644
--- a/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -121,7 +121,7 @@ TEST(Document, Separators) {
   D.addCodeBlock("test");
   D.addParagraph().appendText("bar");
 
-  const char ExpectedMarkdown[] = R"md(foo
+  const char ExpectedMarkdown[] = R"md(foo  
 ```cpp
 test
 ```
@@ -141,7 +141,7 @@ TEST(Document, Spacer) {
   D.addParagraph().appendText("foo");
   D.addSpacer();
   D.addParagraph().appendText("bar");
-  EXPECT_EQ(D.asMarkdown(), "foo\n\nbar");
+  EXPECT_EQ(D.asMarkdown(), "foo  \n\nbar");
   EXPECT_EQ(D.asPlainText(), "foo\n\nbar");
 }
 
@@ -217,10 +217,10 @@ TEST(BulletList, Render) {
   DeepDoc.addParagraph().appendText("baz");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz)md");
   EXPECT_EQ(L.asPlainText(), R"pt(- foo
 - bar
@@ -234,10 +234,10 @@ TEST(BulletList, Render) {
   Inner.addParagraph().appendText("after");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz
 
 after)md");



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


[PATCH] D72450: [clangd] Improve type printing in hover

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGffd0f116754c: [clangd] Improve type printing in hover 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72450

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -446,7 +446,7 @@
[](HoverInfo &HI) {
  HI.Name = "x";
  HI.NamespaceScope = "";
- HI.Definition = "enum Color x = GREEN";
+ HI.Definition = "Color x = GREEN";
  HI.Kind = index::SymbolKind::Variable;
  HI.Type = "enum Color";
  HI.Value = "GREEN (1)"; // Symbolic when hovering on an expression.
@@ -1427,7 +1427,7 @@
 HI.NamespaceScope = "";
 HI.LocalScope = "test::";
 HI.Type = "struct Test &&";
-HI.Definition = "struct Test &&test = {}";
+HI.Definition = "Test &&test = {}";
 HI.Value = "{}";
   }},
   {
@@ -1476,6 +1476,31 @@
 HI.ReturnType = "int";
 HI.Type = "int ()";
   }},
+  {
+  R"cpp(// type of nested templates.
+  template  struct cls {};
+  cls>> [[fo^o]];
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "cls>> foo";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "foo";
+HI.Type = "cls > >";
+HI.Value = "{}";
+  }},
+  {
+  R"cpp(// type of nested templates.
+  template  struct cls {};
+  [[cl^s]]>> foo;
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "template <> struct cls>> {}";
+HI.Kind = index::SymbolKind::Struct;
+HI.NamespaceScope = "";
+HI.Name = "cls > >";
+HI.Documentation = "type of nested templates.";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -16,13 +16,13 @@
 #include "Selection.h"
 #include "SourceCode.h"
 #include "index/SymbolCollector.h"
-
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -101,6 +101,7 @@
   printingPolicyForDecls(D->getASTContext().getPrintingPolicy());
   Policy.IncludeTagDefinition = false;
   Policy.SuppressTemplateArgsInCXXConstructors = true;
+  Policy.SuppressTagKeyword = true;
   D->print(OS, Policy);
   OS.flush();
   return Definition;
@@ -233,9 +234,7 @@
 HI.Parameters->emplace_back();
 auto &P = HI.Parameters->back();
 if (!PVD->getType().isNull()) {
-  P.Type.emplace();
-  llvm::raw_string_ostream OS(*P.Type);
-  PVD->getType().print(OS, Policy);
+  P.Type = PVD->getType().getAsString(Policy);
 } else {
   std::string Param;
   llvm::raw_string_ostream OS(Param);
@@ -344,13 +343,10 @@
   }
 
   // Fill in types and params.
-  if (const FunctionDecl *FD = getUnderlyingFunction(D)) {
+  if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  } else if (const auto *VD = dyn_cast(D)) {
-HI.Type.emplace();
-llvm::raw_string_ostream OS(*HI.Type);
-VD->getType().print(OS, Policy);
-  }
+  else if (const auto *VD = dyn_cast(D))
+HI.Type = VD->getType().getAsString(Policy);
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {
@@ -380,9 +376,9 @@
 enhanceFromIndex(HI, *CommentD, Index);
   } else {
 // Builtin types
-llvm::raw_string_ostream OS(HI.Name);
-PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
-T.print(OS, Policy);
+auto Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
+Policy.SuppressTagKeyword = true;
+HI.Name = T.getAsString(Policy);
   }
   return HI;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2040
+if (Value.getAsInteger(10, AlignBranchBoundary) ||
+AlignBranchBoundary < 16 || !llvm::isPowerOf2_64(AlignBranchBoundary)) 
{
+  D.Diag(diag::err_drv_invalid_argument_to_option)

skan wrote:
> Any reason for  precluding 16?
I did not preclude 16.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2053
+  << Value << A->getOption().getName();
+  AlignBranch = StringRef();
+}

skan wrote:
> AlignBranch = StringRef() seems unnecessary.
This comment was for the previous diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72462: [clangd] Fix markdown rendering in VSCode

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGabfa27e4f04d: [clangd] Fix markdown rendering in VSCode 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72462

Files:
  clang-tools-extra/clangd/FormattedString.cpp
  clang-tools-extra/clangd/unittests/FormattedStringTests.cpp


Index: clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -121,7 +121,7 @@
   D.addCodeBlock("test");
   D.addParagraph().appendText("bar");
 
-  const char ExpectedMarkdown[] = R"md(foo
+  const char ExpectedMarkdown[] = R"md(foo  
 ```cpp
 test
 ```
@@ -141,7 +141,7 @@
   D.addParagraph().appendText("foo");
   D.addSpacer();
   D.addParagraph().appendText("bar");
-  EXPECT_EQ(D.asMarkdown(), "foo\n\nbar");
+  EXPECT_EQ(D.asMarkdown(), "foo  \n\nbar");
   EXPECT_EQ(D.asPlainText(), "foo\n\nbar");
 }
 
@@ -217,10 +217,10 @@
   DeepDoc.addParagraph().appendText("baz");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz)md");
   EXPECT_EQ(L.asPlainText(), R"pt(- foo
 - bar
@@ -234,10 +234,10 @@
   Inner.addParagraph().appendText("after");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz
 
 after)md");
Index: clang-tools-extra/clangd/FormattedString.cpp
===
--- clang-tools-extra/clangd/FormattedString.cpp
+++ clang-tools-extra/clangd/FormattedString.cpp
@@ -196,7 +196,8 @@
   }
   // Paragraphs are translated into markdown lines, not markdown paragraphs.
   // Therefore it only has a single linebreak afterwards.
-  OS << '\n';
+  // VSCode requires two spaces at the end of line to start a new one.
+  OS << "  \n";
 }
 
 void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {


Index: clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
===
--- clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
+++ clang-tools-extra/clangd/unittests/FormattedStringTests.cpp
@@ -121,7 +121,7 @@
   D.addCodeBlock("test");
   D.addParagraph().appendText("bar");
 
-  const char ExpectedMarkdown[] = R"md(foo
+  const char ExpectedMarkdown[] = R"md(foo  
 ```cpp
 test
 ```
@@ -141,7 +141,7 @@
   D.addParagraph().appendText("foo");
   D.addSpacer();
   D.addParagraph().appendText("bar");
-  EXPECT_EQ(D.asMarkdown(), "foo\n\nbar");
+  EXPECT_EQ(D.asMarkdown(), "foo  \n\nbar");
   EXPECT_EQ(D.asPlainText(), "foo\n\nbar");
 }
 
@@ -217,10 +217,10 @@
   DeepDoc.addParagraph().appendText("baz");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz)md");
   EXPECT_EQ(L.asPlainText(), R"pt(- foo
 - bar
@@ -234,10 +234,10 @@
   Inner.addParagraph().appendText("after");
   EXPECT_EQ(L.asMarkdown(), R"md(- foo
 - bar
-- foo
-  baz
-  - foo
-- baz
+- foo  
+  baz  
+  - foo  
+- baz  
   baz
 
 after)md");
Index: clang-tools-extra/clangd/FormattedString.cpp
===
--- clang-tools-extra/clangd/FormattedString.cpp
+++ clang-tools-extra/clangd/FormattedString.cpp
@@ -196,7 +196,8 @@
   }
   // Paragraphs are translated into markdown lines, not markdown paragraphs.
   // Therefore it only has a single linebreak afterwards.
-  OS << '\n';
+  // VSCode requires two spaces at the end of line to start a new one.
+  OS << "  \n";
 }
 
 void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added a comment.

The commutative property (independence of options) makes option composition 
easier. clangDriver makes heavy use of `getLastArg` and `hasArg`. Without the 
commutative property, it would now be able to shuffle code around.

The `-malign-branch=jmp -mno-branches-within-32B-boundaries` issue does not 
matter that much. I do not expect `-mno-branches-within-32B-boundaries` to be 
used much. If we want to disable branch alignment, `-malign-branch-boundary=0` 
can be used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 61741 tests passed, 2 failed 
and 780 were skipped.

  failed: Clang.Driver/x86-malign-branch.c
  failed: Clang.Driver/x86-malign-branch.s

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D72463#1813658 , @skan wrote:

> Add revison D72225  as parent?


`-x86-align-branch-prefix-size=` does not work without D72225 
, but I think the two patches can be 
independent. GCC does not support these options and no projects rely on the 
option yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D70524: Support DebugInfo generation for auto return type for C++ functions.

2020-01-10 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 237264.
awpandey added a comment.

@dblaikie I have added an LLVM test case and I will commit it like a different 
patch. 
I have also updated the clang test case.


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

https://reviews.llvm.org/D70524

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-auto-return.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/debug-info-auto-return.ll

Index: llvm/test/DebugInfo/X86/debug-info-auto-return.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-auto-return.ll
@@ -0,0 +1,70 @@
+; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+
+; CHECK: .debug_info contents:
+
+; CHECK: DW_TAG_subprogram 
+; CHECK-NEXT: DW_AT_linkage_name [DW_FORM_strx1](indexed {{.*}} string = "_ZN7myClass7findMaxEv")
+; CHECK: DW_AT_type [DW_FORM_ref4] (cu + {{.*}} "auto")
+; CHECK-NEXT: DW_AT_declaration [DW_FORM_flag_present]  (true)
+
+; CHECK: DW_TAG_subprogram 
+; CHECK: DW_AT_type [DW_FORM_ref4]   (cu + {{.*}} "double")
+; CHECK: DW_AT_specification [DW_FORM_ref4]  (cu + {{.*}} "_ZN7myClass7findMaxEv")
+
+; C++ source to regenerate:
+; struct myClass {
+;auto findMax();
+; };
+;
+; auto myClass::findMax() {
+;return 0.0;
+; }
+
+; $ clang++ -O0 -g -gdwarf-5 debug-info-template-align.cpp -c
+
+; ModuleID = '/dir/test.cpp'
+source_filename = "/dir/test.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.myClass = type { i8 }
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local double @_ZN7myClass7findMaxEv(%struct.myClass* %this) #0 align 2 !dbg !7 {
+entry:
+  %this.addr = alloca %struct.myClass*, align 8
+  store %struct.myClass* %this, %struct.myClass** %this.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.myClass** %this.addr, metadata !17, metadata !DIExpression()), !dbg !19
+  %this1 = load %struct.myClass*, %struct.myClass** %this.addr, align 8
+  ret double 0.00e+00, !dbg !20
+}
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind optnone uwtable }
+attributes #1 = { nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/dir/test.cpp", directory: "/dir/", checksumkind: CSK_MD5, checksum: "4bed8955bd441e3129c12f557ed53962")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 5}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 10.0.0"}
+!7 = distinct !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 20, type: !9, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !13, retainedNodes: !2)
+!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "myClass", file: !1, line: 16, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS7myClass")
+!9 = !DISubroutineType(types: !10)
+!10 = !{!11, !12}
+!11 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
+!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!13 = !DISubprogram(name: "findMax", linkageName: "_ZN7myClass7findMaxEv", scope: !8, file: !1, line: 17, type: !14, scopeLine: 17, flags: DIFlagPrototyped, spFlags: 0)
+!14 = !DISubroutineType(types: !15)
+!15 = !{!16, !12}
+!16 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto")
+!17 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !18, flags: DIFlagArtificial | DIFlagObjectPointer)
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!19 = !DILocation(line: 0, scope: !7)
+!20 = !DILocation(line: 21, column: 3, scope: !7)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1165,6 +1165,14 @@
   DIE *DeclDie = nullptr;
   StringRef DeclLinkageName;
   if (auto *SPDecl = SP->getDeclaration()) {
+DITypeRefArray DeclArgs, DefinationArgs;
+DeclArgs = SPDecl->getType()->getTypeArray();
+DefinationArgs = SP->getType()->getTypeArray();
+
+if (DeclArgs.size() && DefinationArgs.size())
+  if (DeclArgs[0] != DefinationArgs[0])
+addType(SPDie, DefinationArgs[0]);
+
 DeclDie = getDIE(SPDecl);
 assert(DeclDie

[PATCH] D71533: [clangd] Show template arguments in type hierarchy when possible

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM!




Comment at: clang-tools-extra/clangd/XRefs.cpp:715
+  if (auto *CTSD = dyn_cast(CXXRD)) {
+if (CTSD->isInvalidDecl()) {
+  CXXRD = CTSD->getSpecializedTemplate()->getTemplatedDecl();

nit: redundant braces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71533



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


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

Could you also add a test (and possibly support this in the visitors) for 
`findExplicitReferences`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: dgoldman, kadircet.
Herald added subscribers: cfe-commits, usaxena95, jfb, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

Could you also add a test (and possibly support this in the visitors) for 
`findExplicitReferences`?


In particular there's a common chain:

  OpaqueValueExpr->PseudoObjectExpr->ObjCPropertyRefExpr->ObjCPropertyDecl

and we weren't handling the first two edges


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72494

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -503,15 +503,16 @@
   EXPECT_DECLS("ObjCPropertyRefExpr", "- (void)setX:(int)x");
 
   Code = R"cpp(
-@interface Foo {}
-@property int x;
+@interface I {}
+@property(retain) I* x;
+@property(retain) I* y;
 @end
-void test(Foo *f) {
-  [[f.x]] = 42;
+void test(I *f) {
+  [[f.x]].y = 0;
 }
   )cpp";
-  EXPECT_DECLS("ObjCPropertyRefExpr",
-   "@property(atomic, assign, unsafe_unretained, readwrite) int 
x");
+  EXPECT_DECLS("OpaqueValueExpr",
+   "@property(atomic, retain, readwrite) I *x");
 
   Code = R"cpp(
 @protocol Foo
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -334,6 +334,12 @@
   void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
 Outer.add(OPE->getProtocol(), Flags);
   }
+  void VisitOpaqueValueExpr(const OpaqueValueExpr *OVE) {
+Outer.add(OVE->getSourceExpr(), Flags);
+  }
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+Outer.add(POE->getSyntacticForm(), Flags);
+  }
 };
 Visitor(*this, Flags).Visit(S);
   }


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -503,15 +503,16 @@
   EXPECT_DECLS("ObjCPropertyRefExpr", "- (void)setX:(int)x");
 
   Code = R"cpp(
-@interface Foo {}
-@property int x;
+@interface I {}
+@property(retain) I* x;
+@property(retain) I* y;
 @end
-void test(Foo *f) {
-  [[f.x]] = 42;
+void test(I *f) {
+  [[f.x]].y = 0;
 }
   )cpp";
-  EXPECT_DECLS("ObjCPropertyRefExpr",
-   "@property(atomic, assign, unsafe_unretained, readwrite) int x");
+  EXPECT_DECLS("OpaqueValueExpr",
+   "@property(atomic, retain, readwrite) I *x");
 
   Code = R"cpp(
 @protocol Foo
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -334,6 +334,12 @@
   void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE) {
 Outer.add(OPE->getProtocol(), Flags);
   }
+  void VisitOpaqueValueExpr(const OpaqueValueExpr *OVE) {
+Outer.add(OVE->getSourceExpr(), Flags);
+  }
+  void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
+Outer.add(POE->getSyntacticForm(), Flags);
+  }
 };
 Visitor(*this, Flags).Visit(S);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e44dedd - [CMake] Support running libc++abi tests in CrossWinToARMLinux cache file

2020-01-10 Thread Sergej Jaskiewicz via cfe-commits

Author: Sergej Jaskiewicz
Date: 2020-01-10T12:59:05+03:00
New Revision: e44dedd3631c20bc4a1e62b68919a11168d39354

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

LOG: [CMake] Support running libc++abi tests in CrossWinToARMLinux cache file

Summary:
Now that D71894 has landed, we're able to run libc++abi tests remotely.

For that we can use the same CMake command as before. The tests can be run 
using `ninja check-cxxabi`.

Reviewers: andreil99, vvereschaka, aorlov

Reviewed By: vvereschaka, aorlov

Subscribers: mgorny, kristof.beyls, ldionne, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/cmake/caches/CrossWinToARMLinux.cmake

Removed: 




diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 9fbf090767e9..d08e09a291f7 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -76,10 +76,13 @@ set(LIBCXXABI_USE_COMPILER_RT   ON CACHE BOOL 
"")
 set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
 set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")
 set(LIBCXXABI_SYSROOT   "${DEFAULT_SYSROOT}" CACHE STRING 
"")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXOFF CACHE BOOL "")
 
 set(LIBCXX_USE_COMPILER_RT  ON CACHE BOOL "")
 set(LIBCXX_TARGET_TRIPLE"${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")
 set(LIBCXX_SYSROOT  "${DEFAULT_SYSROOT}" CACHE STRING 
"")
+set(LIBCXX_ENABLE_SHAREDOFF CACHE BOOL "")
 
 set(BUILTINS_CMAKE_ARGS 
"-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")
 set(RUNTIMES_CMAKE_ARGS 
"-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")



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


[PATCH] D72459: [CMake] Support running libc++abi tests in CrossWinToARMLinux cache file

2020-01-10 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe44dedd3631c: [CMake] Support running libc++abi tests in 
CrossWinToARMLinux cache file (authored by broadwaylamb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72459

Files:
  clang/cmake/caches/CrossWinToARMLinux.cmake


Index: clang/cmake/caches/CrossWinToARMLinux.cmake
===
--- clang/cmake/caches/CrossWinToARMLinux.cmake
+++ clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -76,10 +76,13 @@
 set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
 set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")
 set(LIBCXXABI_SYSROOT   "${DEFAULT_SYSROOT}" CACHE STRING 
"")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXOFF CACHE BOOL "")
 
 set(LIBCXX_USE_COMPILER_RT  ON CACHE BOOL "")
 set(LIBCXX_TARGET_TRIPLE"${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")
 set(LIBCXX_SYSROOT  "${DEFAULT_SYSROOT}" CACHE STRING 
"")
+set(LIBCXX_ENABLE_SHAREDOFF CACHE BOOL "")
 
 set(BUILTINS_CMAKE_ARGS 
"-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")
 set(RUNTIMES_CMAKE_ARGS 
"-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")


Index: clang/cmake/caches/CrossWinToARMLinux.cmake
===
--- clang/cmake/caches/CrossWinToARMLinux.cmake
+++ clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -76,10 +76,13 @@
 set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
 set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE STRING "")
 set(LIBCXXABI_SYSROOT   "${DEFAULT_SYSROOT}" CACHE STRING "")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
+set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXOFF CACHE BOOL "")
 
 set(LIBCXX_USE_COMPILER_RT  ON CACHE BOOL "")
 set(LIBCXX_TARGET_TRIPLE"${CMAKE_C_COMPILER_TARGET}" CACHE STRING "")
 set(LIBCXX_SYSROOT  "${DEFAULT_SYSROOT}" CACHE STRING "")
+set(LIBCXX_ENABLE_SHAREDOFF CACHE BOOL "")
 
 set(BUILTINS_CMAKE_ARGS "-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")
 set(RUNTIMES_CMAKE_ARGS "-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_AR=${CMAKE_AR}" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61742 tests passed, 0 failed 
and 780 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D71510: [clang][checkers] Added new checker 'error-return-checker'.

2020-01-10 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a reviewer: NoQ.
balazske added a comment.

Checker was tested with tmux, no problems found (there are false positives but 
not easy to fix).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71510



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2040
+if (Value.getAsInteger(10, AlignBranchBoundary) ||
+AlignBranchBoundary < 16 || !llvm::isPowerOf2_64(AlignBranchBoundary)) 
{
+  D.Diag(diag::err_drv_invalid_argument_to_option)

MaskRay wrote:
> skan wrote:
> > Any reason for  precluding 16?
> I did not preclude 16.
I am sorry that I misunderstood the word "preclude".  As far as I know, we 
would like `AlignBranchBoundary>=32`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72497: [CodeComplete] Suggest 'return nullptr' in functions returning pointers

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72497

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/patterns.cpp


Index: clang/test/CodeCompletion/patterns.cpp
===
--- clang/test/CodeCompletion/patterns.cpp
+++ clang/test/CodeCompletion/patterns.cpp
@@ -33,20 +33,44 @@
 bool bool_return() {
   // line 34
 }
+int *ptr_return() {
+  // line 37
+}
+struct Cls {};
+int Cls::*memptr_return() {
+  // line 41
+}
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:1 %s -o - | FileCheck -check-prefix=RETURN-VAL %s
 // RETURN-VAL-NOT: COMPLETION: Pattern : return;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return false;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return true;
+// RETURN-VAL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VAL: COMPLETION: Pattern : return <#expression#>;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:31:1 %s -o - | FileCheck -check-prefix=RETURN-VOID %s
 // RETURN-VOID-NOT: COMPLETION: Pattern : return false;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return true;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return <#expression#>;
+// RETURN-VOID-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VOID: COMPLETION: Pattern : return;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:34:1 %s -o - | FileCheck -check-prefix=RETURN-BOOL %s
 // RETURN-BOOL-NOT: COMPLETION: Pattern : return;
+// RETURN-BOOL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-BOOL: COMPLETION: Pattern : return <#expression#>;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return false;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return true;{{$}}
+
+// Check both pointer and member pointer return types.
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RETURN-PTR-NOT: COMPLETION: Pattern : return false;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return true;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return;
+// RETURN-PTR: COMPLETION: Pattern : return <#expression#>;{{$}}
+// RETURN-PTR: COMPLETION: Pattern : return nullptr;
+
+// 'return nullptr' is not available before C++11.
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RETURN-PTR-STD03-NOT: COMPLETION: Pattern : return nullptr;
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -2312,6 +2312,13 @@
 Builder.AddChunk(CodeCompletionString::CK_SemiColon);
 Results.AddResult(Result(Builder.TakeString()));
   }
+  // For pointers, suggest 'return nullptr' in C++.
+  if (SemaRef.getLangOpts().CPlusPlus11 &&
+  (ReturnType->isPointerType() || ReturnType->isMemberPointerType())) {
+Builder.AddTypedTextChunk("return nullptr");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 // goto identifier ;


Index: clang/test/CodeCompletion/patterns.cpp
===
--- clang/test/CodeCompletion/patterns.cpp
+++ clang/test/CodeCompletion/patterns.cpp
@@ -33,20 +33,44 @@
 bool bool_return() {
   // line 34
 }
+int *ptr_return() {
+  // line 37
+}
+struct Cls {};
+int Cls::*memptr_return() {
+  // line 41
+}
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:1 %s -o - | FileCheck -check-prefix=RETURN-VAL %s
 // RETURN-VAL-NOT: COMPLETION: Pattern : return;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return false;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return true;
+// RETURN-VAL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VAL: COMPLETION: Pattern : return <#expression#>;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:31:1 %s -o - | FileCheck -check-prefix=RETURN-VOID %s
 // RETURN-VOID-NOT: COMPLETION: Pattern : return false;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return true;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return <#expression#>;
+// RETURN-VOID-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VOID: COMPLETION: Pattern : return;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion

[PATCH] D72496: [ARM,MVE] Make `vqrshrun` generate the right instruction.

2020-01-10 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a project: clang.

A copy-paste error in `arm_mve.td` meant that the MVE `vqrshrun`
intrinsic family was generating the `vqshrun` machine instruction,
because in the IR intrinsic call, the rounding flag argument was set
to 0 rather than 1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72496

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c


Index: clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
===
--- clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
+++ clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
@@ -1086,7 +1086,7 @@
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshrunbq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1100,7 +1100,7 @@
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshrunbq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1114,7 +1114,7 @@
 
 // CHECK-LABEL: @test_vqrshruntq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshruntq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1128,7 +1128,7 @@
 
 // CHECK-LABEL: @test_vqrshruntq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshruntq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1144,7 +1144,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 0, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 1, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
 // CHECK-NEXT:ret <16 x i8> [[TMP2]]
 //
 uint8x16_t test_vqrshrunbq_m_n_s16(uint8x16_t a, int16x8_t b, mve_pred16_t p)
@@ -1160,7 +1160,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.predicated.v8i16.v4i32.v4i1(<8 x i16> [[A:%.*]], <4 x i32> 
[[B:%.*]], i32 10, i32 1, i32 0, i32 1, i32 0, i32 0, <4 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.predicated.v8i16.v4i32.v4i1(<8 x i16> [[A:%.*]], <4 x i32> 
[[B:%.*]], i32 10, i32 1, i32 1, i32 1, i32 0, i32 0, <4 x i1> [[TMP1]])
 // CHECK-NEXT:ret <8 x i16> [[TMP2]]
 //
 uint16x8_t test_vqrshrunbq_m_n_s32(uint16x8_t a, int32x4_t b, mve_pred16_t p)
@@ -1176,7 +1176,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 3, i32 1, i32 0, i32 1, i32 0, i32 1, <8 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 3,

[PATCH] D72497: [CodeComplete] Suggest 'return nullptr' in functions returning pointers

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61741 tests passed, 0 failed 
and 780 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72497



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

In D72463#1813669 , @MaskRay wrote:

> The commutative property (independence of options) makes option composition 
> easier. clangDriver makes heavy use of `getLastArg` and `hasArg`. Without the 
> commutative property, it would now be able to shuffle code around.
>
> The `-malign-branch=jmp -mno-branches-within-32B-boundaries` issue does not 
> matter that much. I do not expect `-mno-branches-within-32B-boundaries` to be 
> used much. If we want to disable branch alignment, 
> `-malign-branch-boundary=0` can be used.


The behaviour of your proposal is "specific option is always override the 
gerneral option, no matter which is the last". I still prefer not to support 
the override, which makes things more clear. But I am fine if other reviewers 
believe this behaviour is reasonable. @jyknight  @reames @craig.topper




Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:254
+def err_drv_invalid_malign_branch_EQ : Error<
+  "invalid argument '%0' to -malign-branch=; must be one of: %1">;
+

The error information "must be one of: " is kind of misleading.
It seems that one kind of branch can be aligned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72463: [Driver][X86] Add -malign-branch* and -malign-branch-within-32B-boundaries

2020-01-10 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:254
+def err_drv_invalid_malign_branch_EQ : Error<
+  "invalid argument '%0' to -malign-branch=; must be one of: %1">;
+

skan wrote:
> The error information "must be one of: " is kind of misleading.
> It seems that one kind of branch can be aligned.
The error information "must be one of: " is kind of misleading.
It seems that "only" one kind of branch can be aligned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72463



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


[PATCH] D72496: [ARM,MVE] Make `vqrshrun` generate the right instruction.

2020-01-10 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Yeah, I said these would be tough to read! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72496



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Fixes https://github.com/clangd/clangd/issues/249


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72498

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1501,6 +1501,17 @@
 HI.Name = "cls > >";
 HI.Documentation = "type of nested templates.";
   }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -345,8 +345,14 @@
   // Fill in types and params.
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  else if (const auto *VD = dyn_cast(D))
-HI.Type = VD->getType().getAsString(Policy);
+  else if (const auto *VD = dyn_cast(D)) {
+QualType QT = VD->getType();
+// TypePrinter doesn't resolve decltypes, so resolve them here. We are 
going
+// to include decltype(X) info in `HoverInfo::Definition` anyway.
+if (auto *DT = QT->getAs())
+  QT = DT->getUnderlyingType();
+HI.Type = QT.getAsString(Policy);
+  }
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1501,6 +1501,17 @@
 HI.Name = "cls > >";
 HI.Documentation = "type of nested templates.";
   }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -345,8 +345,14 @@
   // Fill in types and params.
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  else if (const auto *VD = dyn_cast(D))
-HI.Type = VD->getType().getAsString(Policy);
+  else if (const auto *VD = dyn_cast(D)) {
+QualType QT = VD->getType();
+// TypePrinter doesn't resolve decltypes, so resolve them here. We are going
+// to include decltype(X) info in `HoverInfo::Definition` anyway.
+if (auto *DT = QT->getAs())
+  QT = DT->getUnderlyingType();
+HI.Type = QT.getAsString(Policy);
+  }
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ccee0e - [ARM, MVE] Make `vqrshrun` generate the right instruction.

2020-01-10 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-01-10T11:25:05Z
New Revision: 1ccee0e86386762bd742fd067391b6c4be089806

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

LOG: [ARM,MVE] Make `vqrshrun` generate the right instruction.

Summary:
A copy-paste error in `arm_mve.td` meant that the MVE `vqrshrun`
intrinsic family was generating the `vqshrun` machine instruction,
because in the IR intrinsic call, the rounding flag argument was set
to 0 rather than 1.

Reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard

Reviewed By: dmgreen

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td
clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index 86a04e33ce76..6d0bb96cba6f 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -681,7 +681,7 @@ let params = [s16, s32, u16, u32], pnt = PNT_NType in {
 }
 let params = [s16, s32], pnt = PNT_NType in {
   defm vqshrun  : VSHRN;
-  defm vqrshrun : VSHRN;
+  defm vqrshrun : VSHRN;
 }
 let params = T.Int, pnt = PNT_NType in {
   defm vsli : DyadicImmShift;

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
index 3d4f77b99d74..c5591392e373 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
@@ -1086,7 +1086,7 @@ uint16x8_t test_vqrshrntq_m_n_u32(uint16x8_t a, 
uint32x4_t b, mve_pred16_t p)
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshrunbq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1100,7 +1100,7 @@ uint8x16_t test_vqrshrunbq_n_s16(uint8x16_t a, int16x8_t 
b)
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshrunbq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1114,7 +1114,7 @@ uint16x8_t test_vqrshrunbq_n_s32(uint16x8_t a, int32x4_t 
b)
 
 // CHECK-LABEL: @test_vqrshruntq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshruntq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1128,7 +1128,7 @@ uint8x16_t test_vqrshruntq_n_s16(uint8x16_t a, int16x8_t 
b)
 
 // CHECK-LABEL: @test_vqrshruntq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshruntq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1144,7 +1144,7 @@ uint16x8_t test_vqrshruntq_n_s32(uint16x8_t a, int32x4_t 
b)
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 0, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 1, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
 // CHECK-NEXT:ret <16 x i8> [[TMP2]]
 //
 uint8x16_t test_vqrshrunbq_m_n_s16(uint8x16_t a, int16x8_t b, mve_pred16_t p

[PATCH] D72496: [ARM,MVE] Make `vqrshrun` generate the right instruction.

2020-01-10 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1ccee0e86386: [ARM,MVE] Make `vqrshrun` generate the right 
instruction. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72496

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c


Index: clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
===
--- clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
+++ clang/test/CodeGen/arm-mve-intrinsics/vector-shift-imm-dyadic.c
@@ -1086,7 +1086,7 @@
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
7, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshrunbq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1100,7 +1100,7 @@
 
 // CHECK-LABEL: @test_vqrshrunbq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 0)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshrunbq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1114,7 +1114,7 @@
 
 // CHECK-LABEL: @test_vqrshruntq_n_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
1, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <16 x i8> [[TMP0]]
 //
 uint8x16_t test_vqrshruntq_n_s16(uint8x16_t a, int16x8_t b)
@@ -1128,7 +1128,7 @@
 
 // CHECK-LABEL: @test_vqrshruntq_n_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 0, i32 1, i32 0, i32 1)
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
3, i32 1, i32 1, i32 1, i32 0, i32 1)
 // CHECK-NEXT:ret <8 x i16> [[TMP0]]
 //
 uint16x8_t test_vqrshruntq_n_s32(uint16x8_t a, int32x4_t b)
@@ -1144,7 +1144,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 0, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 4, i32 1, i32 1, i32 1, i32 0, i32 0, <8 x i1> [[TMP1]])
 // CHECK-NEXT:ret <16 x i8> [[TMP2]]
 //
 uint8x16_t test_vqrshrunbq_m_n_s16(uint8x16_t a, int16x8_t b, mve_pred16_t p)
@@ -1160,7 +1160,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.predicated.v8i16.v4i32.v4i1(<8 x i16> [[A:%.*]], <4 x i32> 
[[B:%.*]], i32 10, i32 1, i32 0, i32 1, i32 0, i32 0, <4 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <8 x i16> 
@llvm.arm.mve.vshrn.predicated.v8i16.v4i32.v4i1(<8 x i16> [[A:%.*]], <4 x i32> 
[[B:%.*]], i32 10, i32 1, i32 1, i32 1, i32 0, i32 0, <4 x i1> [[TMP1]])
 // CHECK-NEXT:ret <8 x i16> [[TMP2]]
 //
 uint16x8_t test_vqrshrunbq_m_n_s32(uint16x8_t a, int32x4_t b, mve_pred16_t p)
@@ -1176,7 +1176,7 @@
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 3, i32 1, i32 0, i32 1, i32 0, i32 1, <8 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <16 x i8> 
@llvm.arm.mve.vshrn.predicated.v16i8.v8i16.v8i1(<16 x i8> [[A:%.*]], <8 x i16> 
[[B:%.*]], i32 3, i32 1, i32 1, i32 1, i32 0, i32 1, <8 x i1> [[TMP1]])
 // CHECK-NEXT:ret <16 x i8> [[TMP2]]
 //
 uint8x16_t test_vqrshruntq_m_n_s16(uint8x16_t a, int16x

[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Hover.cpp:351
+// TypePrinter doesn't resolve decltypes, so resolve them here. We are 
going
+// to include decltype(X) info in `HoverInfo::Definition` anyway.
+if (auto *DT = QT->getAs())

nit: going to include the spelling "decltype(X)" in ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61742 tests passed, 0 failed 
and 780 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72499: [clangd] (DO NOT COMMIT) hovering on "md" raw strings displays those.

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

This is useful for testing markdown rendering in hover of editors.

It shoudn't be checked in (it'd be a nice easter egg, but the implementation
is too messy).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72499

Files:
  clang-tools-extra/clangd/FormattedString.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h


Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -71,6 +71,8 @@
   /// Contains the evaluated value of the symbol if available.
   llvm::Optional Value;
 
+  llvm::Optional RawResponse;
+
   /// Produce a user-readable information.
   markup::Document present() const;
 };
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -439,6 +439,15 @@
 // Look for a close enclosing expression to show the value of.
 if (!HI->Value)
   HI->Value = printExprValue(N, AST.getASTContext());
+  } else if (auto *SL = N->ASTNode.get()) {
+if (SL->getBeginLoc().isFileID()) {
+  const char *Data = SM.getCharacterData(SL->getBeginLoc());
+  // safe because null-terminated
+  if (Data && !strncmp("R\"md(", Data, 5)) {
+HI.emplace();
+HI->RawResponse = SL->getString();
+  }
+}
   }
   // FIXME: support hovers for other nodes?
   //  - certain expressions (sizeof etc)
@@ -463,6 +472,10 @@
 
 markup::Document HoverInfo::present() const {
   markup::Document Output;
+  if (RawResponse) {
+Output.addRaw(*RawResponse);
+return Output;
+  }
   // Header contains a text of the form:
   // variable `var` : `int`
   //
Index: clang-tools-extra/clangd/FormattedString.h
===
--- clang-tools-extra/clangd/FormattedString.h
+++ clang-tools-extra/clangd/FormattedString.h
@@ -35,6 +35,15 @@
   virtual ~Block() = default;
 };
 
+class RawBlock : public Block {
+ public:
+  RawBlock(std::string Text) : Text(std::move(Text)) {}
+  virtual void renderMarkdown(llvm::raw_ostream &OS) const override { OS << 
Text; }
+  virtual void renderPlainText(llvm::raw_ostream &OS) const override { OS << 
Text; }
+ private:
+  std::string Text;
+};
+
 /// Represents parts of the markup that can contain strings, like inline code,
 /// code block or plain text.
 /// One must introduce different paragraphs to create separate blocks.
@@ -88,6 +97,9 @@
   void addCodeBlock(std::string Code, std::string Language = "cpp");
 
   BulletList &addBulletList();
+  void addRaw(std::string Text) {
+Children.push_back(std::make_unique(std::move(Text)));
+  }
 
   /// Doesn't contain any trailing newlines.
   std::string asMarkdown() const;


Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -71,6 +71,8 @@
   /// Contains the evaluated value of the symbol if available.
   llvm::Optional Value;
 
+  llvm::Optional RawResponse;
+
   /// Produce a user-readable information.
   markup::Document present() const;
 };
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -439,6 +439,15 @@
 // Look for a close enclosing expression to show the value of.
 if (!HI->Value)
   HI->Value = printExprValue(N, AST.getASTContext());
+  } else if (auto *SL = N->ASTNode.get()) {
+if (SL->getBeginLoc().isFileID()) {
+  const char *Data = SM.getCharacterData(SL->getBeginLoc());
+  // safe because null-terminated
+  if (Data && !strncmp("R\"md(", Data, 5)) {
+HI.emplace();
+HI->RawResponse = SL->getString();
+  }
+}
   }
   // FIXME: support hovers for other nodes?
   //  - certain expressions (sizeof etc)
@@ -463,6 +472,10 @@
 
 markup::Document HoverInfo::present() const {
   markup::Document Output;
+  if (RawResponse) {
+Output.addRaw(*RawResponse);
+return Output;
+  }
   // Header contains a text of the form:
   // variable `var` : `int`
   //
Index: clang-tools-extra/clangd/FormattedString.h
===
--- clang-tools-extra/clangd/FormattedString.h
+++ clang-tools-extra/clangd/FormattedString.h
@@ -35,6 +35,15 @@
   virtual ~Block() = default;
 };
 
+class RawBlock : public Block {
+ public:
+  RawBlock(std::string Text) : Text(std::move(Text)) {}
+  virtua

[PATCH] D72499: [clangd] (DO NOT COMMIT) hovering on "md" raw strings displays those.

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61742 tests passed, 0 failed 
and 780 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72499



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


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D72494#1813719 , @ilya-biryukov 
wrote:

> Could you also add a test (and possibly support this in the visitors) for 
> `findExplicitReferences`?


I've written tests, but it doesn't work and it's not obvious to me yet how to 
make it work, so I'll do this in a separate patch.
(We're close to the release cut... as far as major features, this patch fixes 
go to def and hover. Extending to findExplicitRefs will fix rename. Xrefs works 
already via libindex)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D72500: [clangd] Show hower info for expressions

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

This currently populates only the Name with the expression's type and
Value if expression is evaluatable.

Fixes https://github.com/clangd/clangd/issues/56


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72500

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1512,6 +1512,30 @@
 HI.Name = "b";
 HI.Type = "int";
   }},
+  {
+  R"cpp(// sizeof expr
+  void foo() {
+(void)[[size^of]](char);
+  })cpp",
+  [](HoverInfo &HI) {
+HI.Name = "unsigned long";
+HI.Value = "1";
+  }},
+  {
+  R"cpp(// alignof expr
+  void foo() {
+(void)[[align^of]](char);
+  })cpp",
+  [](HoverInfo &HI) {
+HI.Name = "unsigned long";
+HI.Value = "1";
+  }},
+  {
+  R"cpp(// non-evaluatable expr
+  template  void foo() {
+(void)[[size^of]](T);
+  })cpp",
+  [](HoverInfo &HI) { HI.Name = "unsigned long"; }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Type.h"
 #include "clang/Index/IndexSymbol.h"
@@ -445,9 +446,13 @@
 // Look for a close enclosing expression to show the value of.
 if (!HI->Value)
   HI->Value = printExprValue(N, AST.getASTContext());
+  } else if (const Expr *E = N->ASTNode.get()) {
+// For expressions we currently print the type and the value, if they
+// are evaluatable.
+HI = getHoverContents(E->getType(), AST.getASTContext(), Index);
+HI->Value = printExprValue(E, AST.getASTContext());
   }
   // FIXME: support hovers for other nodes?
-  //  - certain expressions (sizeof etc)
   //  - built-in types
   //  - literals (esp user-defined)
 }


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1512,6 +1512,30 @@
 HI.Name = "b";
 HI.Type = "int";
   }},
+  {
+  R"cpp(// sizeof expr
+  void foo() {
+(void)[[size^of]](char);
+  })cpp",
+  [](HoverInfo &HI) {
+HI.Name = "unsigned long";
+HI.Value = "1";
+  }},
+  {
+  R"cpp(// alignof expr
+  void foo() {
+(void)[[align^of]](char);
+  })cpp",
+  [](HoverInfo &HI) {
+HI.Name = "unsigned long";
+HI.Value = "1";
+  }},
+  {
+  R"cpp(// non-evaluatable expr
+  template  void foo() {
+(void)[[size^of]](T);
+  })cpp",
+  [](HoverInfo &HI) { HI.Name = "unsigned long"; }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Type.h"
 #include "clang/Index/IndexSymbol.h"
@@ -445,9 +446,13 @@
 // Look for a close enclosing expression to show the value of.
 if (!HI->Value)
   HI->Value = printExprValue(N, AST.getASTContext());
+  } else if (const Expr *E = N->ASTNode.get()) {
+// For expressions we currently print the type and the value, if they
+// are evaluatable.
+HI = getHoverContents(E->getType(), AST.getASTContext(), Index);
+HI->Value = printExprValue(E, AST.getASTContext());
   }
   // FIXME: support hovers for other nodes?
-  //  - certain expressions (sizeof etc)
   //  - built-in types
   //  - literals (esp user-defined)
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm

[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 237284.
kadircet marked an inline comment as done.
kadircet added a comment.

- Update comment
- Iteratively resolve underlying decltypes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1501,6 +1501,40 @@
 HI.Name = "cls > >";
 HI.Documentation = "type of nested templates.";
   }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) c;
+  decltype(c) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(c) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  const decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "const decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -345,8 +345,14 @@
   // Fill in types and params.
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  else if (const auto *VD = dyn_cast(D))
-HI.Type = VD->getType().getAsString(Policy);
+  else if (const auto *VD = dyn_cast(D)) {
+QualType QT = VD->getType();
+// TypePrinter doesn't resolve decltypes, so resolve them here. We are 
going
+// to include spelling "decltype(X)" in `HoverInfo::Definition` anyway.
+while (auto *DT = QT->getAs())
+  QT = DT->getUnderlyingType();
+HI.Type = QT.getAsString(Policy);
+  }
 
   // Fill in value with evaluated initializer if possible.
   if (const auto *Var = dyn_cast(D)) {


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1501,6 +1501,40 @@
 HI.Name = "cls > >";
 HI.Documentation = "type of nested templates.";
   }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  decltype(a) c;
+  decltype(c) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "decltype(c) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
+  {
+  R"cpp(// type with decltype
+  int a;
+  const decltype(a) [[b^]] = a;)cpp",
+  [](HoverInfo &HI) {
+HI.Definition = "const decltype(a) b = a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Name = "b";
+HI.Type = "int";
+  }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -345,8 +345,14 @@
   // Fill in types and params.
   if (const FunctionDecl *FD = getUnderlyingFunction(D))
 fillFunctionTypeAndParams(HI, D, FD, Policy);
-  else if (const auto *VD = dyn_cast(D))
-HI.Type = VD->getType().getAsString(Policy);
+  else if (const auto *VD = dyn_cast(D)) {
+QualType QT = VD->getType();
+// TypePrinter doesn't resolve decltypes, so resolve them here. We are goin

[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D72494#1813875 , @sammccall wrote:

> In D72494#1813719 , @ilya-biryukov 
> wrote:
>
> > Could you also add a test (and possibly support this in the visitors) for 
> > `findExplicitReferences`?
>
>
> I've written tests, but it doesn't work and it's not obvious to me yet how to 
> make it work, so I'll do this in a separate patch.


By which I mean, adding the same delegation to the RAV there doesn't work, and 
I'm not confident that jiggling it around until the test passes is correct 
here, so I want to understand the traversal behavior a bit better first (RAV 
has several special cases around OVE/POE)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D72500: [clangd] Show hower info for expressions

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72500



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Could it be the case that we want to show the canonical types (i.e. without all 
syntax sugar)?
Maybe we want both the normal type and the canonical type?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This does not work for more complicated types, though?
E.g. `decltype(a+b)* a` or `vector a`?

Why do we prefer to drop `decltype()`, yet show the typedefs? Both could lead 
to complicated types, arguably decltypes can be even worse than typedefs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61742 tests passed, 0 failed 
and 780 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[clang] 57a51b6 - [CodeComplete] Suggest 'return nullptr' in functions returning pointers

2020-01-10 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2020-01-10T13:28:13+01:00
New Revision: 57a51b689e7b99c694a028104b0b5a69b80fd002

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

LOG: [CodeComplete] Suggest 'return nullptr' in functions returning pointers

Reviewers: kadircet

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/patterns.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index b4299b615a61..0f2434fc0a23 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2312,6 +2312,13 @@ static void 
AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S,
 Builder.AddChunk(CodeCompletionString::CK_SemiColon);
 Results.AddResult(Result(Builder.TakeString()));
   }
+  // For pointers, suggest 'return nullptr' in C++.
+  if (SemaRef.getLangOpts().CPlusPlus11 &&
+  (ReturnType->isPointerType() || ReturnType->isMemberPointerType())) {
+Builder.AddTypedTextChunk("return nullptr");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 // goto identifier ;

diff  --git a/clang/test/CodeCompletion/patterns.cpp 
b/clang/test/CodeCompletion/patterns.cpp
index 596fe829af43..5189e3e636d5 100644
--- a/clang/test/CodeCompletion/patterns.cpp
+++ b/clang/test/CodeCompletion/patterns.cpp
@@ -33,20 +33,44 @@ void void_return() {
 bool bool_return() {
   // line 34
 }
+int *ptr_return() {
+  // line 37
+}
+struct Cls {};
+int Cls::*memptr_return() {
+  // line 41
+}
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:1 %s -o - | FileCheck -check-prefix=RETURN-VAL %s
 // RETURN-VAL-NOT: COMPLETION: Pattern : return;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return false;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return true;
+// RETURN-VAL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VAL: COMPLETION: Pattern : return <#expression#>;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:31:1 %s -o - | FileCheck -check-prefix=RETURN-VOID %s
 // RETURN-VOID-NOT: COMPLETION: Pattern : return false;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return true;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return <#expression#>;
+// RETURN-VOID-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VOID: COMPLETION: Pattern : return;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:34:1 %s -o - | FileCheck -check-prefix=RETURN-BOOL %s
 // RETURN-BOOL-NOT: COMPLETION: Pattern : return;
+// RETURN-BOOL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-BOOL: COMPLETION: Pattern : return <#expression#>;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return false;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return true;{{$}}
+
+// Check both pointer and member pointer return types.
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RETURN-PTR-NOT: COMPLETION: Pattern : return false;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return true;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return;
+// RETURN-PTR: COMPLETION: Pattern : return <#expression#>;{{$}}
+// RETURN-PTR: COMPLETION: Pattern : return nullptr;
+
+// 'return nullptr' is not available before C++11.
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RETURN-PTR-STD03-NOT: COMPLETION: Pattern : return nullptr;



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


[PATCH] D72497: [CodeComplete] Suggest 'return nullptr' in functions returning pointers

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57a51b689e7b: [CodeComplete] Suggest 'return 
nullptr' in functions returning pointers (authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72497

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/patterns.cpp


Index: clang/test/CodeCompletion/patterns.cpp
===
--- clang/test/CodeCompletion/patterns.cpp
+++ clang/test/CodeCompletion/patterns.cpp
@@ -33,20 +33,44 @@
 bool bool_return() {
   // line 34
 }
+int *ptr_return() {
+  // line 37
+}
+struct Cls {};
+int Cls::*memptr_return() {
+  // line 41
+}
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:1 %s -o - | FileCheck -check-prefix=RETURN-VAL %s
 // RETURN-VAL-NOT: COMPLETION: Pattern : return;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return false;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return true;
+// RETURN-VAL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VAL: COMPLETION: Pattern : return <#expression#>;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:31:1 %s -o - | FileCheck -check-prefix=RETURN-VOID %s
 // RETURN-VOID-NOT: COMPLETION: Pattern : return false;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return true;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return <#expression#>;
+// RETURN-VOID-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VOID: COMPLETION: Pattern : return;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:34:1 %s -o - | FileCheck -check-prefix=RETURN-BOOL %s
 // RETURN-BOOL-NOT: COMPLETION: Pattern : return;
+// RETURN-BOOL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-BOOL: COMPLETION: Pattern : return <#expression#>;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return false;{{$}}
 // RETURN-BOOL: COMPLETION: Pattern : return true;{{$}}
+
+// Check both pointer and member pointer return types.
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR %s
+// RETURN-PTR-NOT: COMPLETION: Pattern : return false;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return true;{{$}}
+// RETURN-PTR-NOT: COMPLETION: Pattern : return;
+// RETURN-PTR: COMPLETION: Pattern : return <#expression#>;{{$}}
+// RETURN-PTR: COMPLETION: Pattern : return nullptr;
+
+// 'return nullptr' is not available before C++11.
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:37:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -code-completion-patterns 
-code-completion-at=%s:41:1 %s -o - | FileCheck -check-prefix=RETURN-PTR-STD03 
%s
+// RETURN-PTR-STD03-NOT: COMPLETION: Pattern : return nullptr;
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -2312,6 +2312,13 @@
 Builder.AddChunk(CodeCompletionString::CK_SemiColon);
 Results.AddResult(Result(Builder.TakeString()));
   }
+  // For pointers, suggest 'return nullptr' in C++.
+  if (SemaRef.getLangOpts().CPlusPlus11 &&
+  (ReturnType->isPointerType() || ReturnType->isMemberPointerType())) {
+Builder.AddTypedTextChunk("return nullptr");
+Builder.AddChunk(CodeCompletionString::CK_SemiColon);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 // goto identifier ;


Index: clang/test/CodeCompletion/patterns.cpp
===
--- clang/test/CodeCompletion/patterns.cpp
+++ clang/test/CodeCompletion/patterns.cpp
@@ -33,20 +33,44 @@
 bool bool_return() {
   // line 34
 }
+int *ptr_return() {
+  // line 37
+}
+struct Cls {};
+int Cls::*memptr_return() {
+  // line 41
+}
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:1 %s -o - | FileCheck -check-prefix=RETURN-VAL %s
 // RETURN-VAL-NOT: COMPLETION: Pattern : return;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return false;
 // RETURN-VAL-NOT: COMPLETION: Pattern : return true;
+// RETURN-VAL-NOT: COMPLETION: Pattern : return nullptr;
 // RETURN-VAL: COMPLETION: Pattern : return <#expression#>;{{$}}
 
 // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:31:1 %s -o - | FileCheck -check-prefix=RETURN-VOID %s
 // RETURN-VOID-NOT: COMPLETION: Pattern : return false;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return true;
 // RETURN-VOID-NOT: COMPLETION: Pattern : return <#expression#>

[PATCH] D71612: [analyzer] Add PlacementNewChecker

2020-01-10 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 237290.
martong added a comment.

- Declare ElementCountNL in if stmt
- Use makeArrayIndex instead makeIntVal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71612

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/test/Analysis/placement-new-user-defined.cpp
  clang/test/Analysis/placement-new.cpp

Index: clang/test/Analysis/placement-new.cpp
===
--- /dev/null
+++ clang/test/Analysis/placement-new.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_analyze_cc1 -std=c++11 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.PlacementNew \
+// RUN:   -analyzer-output=text -verify \
+// RUN:   -triple x86_64-unknown-linux-gnu
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void f() {
+  short s;// expected-note {{'s' declared without an initial value}}
+  long *lp = ::new (&s) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
+  (void)lp;
+}
+
+namespace testArrayNew {
+void f() {
+  short s;// expected-note {{'s' declared without an initial value}}
+  char *buf = ::new (&s) char[8]; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
+  (void)buf;
+}
+} // namespace testArrayNew
+
+namespace testBufferInOtherFun {
+void f(void *place) {
+  long *lp = ::new (place) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+void g() {
+  short buf; // expected-note {{'buf' declared without an initial value}}
+  f(&buf);   // expected-note 2 {{}}
+}
+} // namespace testBufferInOtherFun
+
+namespace testArrayBuffer {
+void f(void *place) {
+  long *lp = ::new (place) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+void g() {
+  char buf[2]; // expected-note {{'buf' initialized here}}
+  f(&buf); // expected-note 2 {{}}
+}
+} // namespace testArrayBuffer
+
+namespace testGlobalPtrAsPlace {
+void *gptr = nullptr;
+short gs;
+void f() {
+  gptr = &gs; // expected-note {{Value assigned to 'gptr'}}
+}
+void g() {
+  f();  // expected-note 2 {{}}
+  long *lp = ::new (gptr) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testGlobalPtrAsPlace
+
+namespace testRvalue {
+short gs;
+void *f() {
+  return &gs;
+}
+void g() {
+  long *lp = ::new (f()) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testRvalue
+
+namespace testNoWarning {
+void *f();
+void g() {
+  long *lp = ::new (f()) long;
+  (void)lp;
+}
+} // namespace testNoWarning
+
+namespace testPtrToArrayAsPlace {
+void f() {
+  //char *st = new char [8];
+  char buf[3];// expected-note {{'buf' initialized here}}
+  void *st = buf; // expected-note {{'st' initialized here}}
+  long *lp = ::new (st) long; // expected-warning{{Storage provided to placement new is only 3 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testPtrToArrayAsPlace
+
+namespace testPtrToArrayWithOffsetAsPlace {
+void f() {
+  int buf[3];  // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf + 2) long; // expected-warning{{Storage provided to placement new is only 4 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testPtrToArrayWithOffsetAsPlace
+
+namespace testHeapAllocatedBuffer {
+void g2() {
+  char *buf = new char[2]; // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testHeapAllocatedBuffer
+
+namespace testMultiDimensionalArray {
+void f() {
+  char buf[2][3];  // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf) long; // expected-warning{{Storage provided to placement new is only 6 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testMultiDimensionalArray
+
+namespace testMultiDimensionalArray2 {
+

[PATCH] D71612: [analyzer] Add PlacementNewChecker

2020-01-10 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 2 inline comments as done.
martong added a comment.

> Can we enable the check by default then? What pieces are missing? Like, the 
> symbolic extent/offset case is not a must. I think we have everything except 
> maybe some deeper testing. I'd rather spend some time on the above exercise, 
> but then enable by default if it goes well.

I am going to execute the analysis on LLVM/Clang as you suggested, so then 
we'll see what the experiment will bring us. And then we could enable it by 
default I think. BTW how can we do that? I could not find any default 
enablement related config in Checkers.td ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71612



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


[PATCH] D44352: [Concepts] Type Constraints

2020-01-10 Thread Saar Raz via Phabricator via cfe-commits
saar.raz added a comment.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D44352



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


[clang] 76e9c2a - [FPEnv] Generate constrained FP comparisons from clang

2020-01-10 Thread Ulrich Weigand via cfe-commits

Author: Ulrich Weigand
Date: 2020-01-10T14:33:10+01:00
New Revision: 76e9c2a9870e36415eb343d28942a42296f85597

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

LOG: [FPEnv] Generate constrained FP comparisons from clang

Update the IRBuilder to generate constrained FP comparisons in
CreateFCmp when IsFPConstrained is true, similar to the other
places in the IRBuilder.

Also, add a new CreateFCmpS to emit signaling FP comparisons,
and use it in clang where comparisons are supposed to be signaling
(currently, only when emitting code for the <, <=, >, >= operators).

Note that there is currently no way to add fast-math flags to a
constrained FP comparison, since this is implemented as an intrinsic
call that returns a boolean type, and FMF are only allowed for calls
returning a floating-point type. However, given the discussion around
https://bugs.llvm.org/show_bug.cgi?id=42179, it seems that FCmp itself
really shouldn't have any FMF either, so this is probably OK.

Reviewed by: craig.topper

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

Added: 
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c

Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
llvm/include/llvm/IR/IRBuilder.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 4adaca8ae571..4338d1c3dcdf 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -798,17 +798,17 @@ class ScalarExprEmitter
   // Comparisons.
   Value *EmitCompare(const BinaryOperator *E, llvm::CmpInst::Predicate 
UICmpOpc,
  llvm::CmpInst::Predicate SICmpOpc,
- llvm::CmpInst::Predicate FCmpOpc);
-#define VISITCOMP(CODE, UI, SI, FP) \
+ llvm::CmpInst::Predicate FCmpOpc, bool IsSignaling);
+#define VISITCOMP(CODE, UI, SI, FP, SIG) \
 Value *VisitBin##CODE(const BinaryOperator *E) { \
   return EmitCompare(E, llvm::ICmpInst::UI, llvm::ICmpInst::SI, \
- llvm::FCmpInst::FP); }
-  VISITCOMP(LT, ICMP_ULT, ICMP_SLT, FCMP_OLT)
-  VISITCOMP(GT, ICMP_UGT, ICMP_SGT, FCMP_OGT)
-  VISITCOMP(LE, ICMP_ULE, ICMP_SLE, FCMP_OLE)
-  VISITCOMP(GE, ICMP_UGE, ICMP_SGE, FCMP_OGE)
-  VISITCOMP(EQ, ICMP_EQ , ICMP_EQ , FCMP_OEQ)
-  VISITCOMP(NE, ICMP_NE , ICMP_NE , FCMP_UNE)
+ llvm::FCmpInst::FP, SIG); }
+  VISITCOMP(LT, ICMP_ULT, ICMP_SLT, FCMP_OLT, true)
+  VISITCOMP(GT, ICMP_UGT, ICMP_SGT, FCMP_OGT, true)
+  VISITCOMP(LE, ICMP_ULE, ICMP_SLE, FCMP_OLE, true)
+  VISITCOMP(GE, ICMP_UGE, ICMP_SGE, FCMP_OGE, true)
+  VISITCOMP(EQ, ICMP_EQ , ICMP_EQ , FCMP_OEQ, false)
+  VISITCOMP(NE, ICMP_NE , ICMP_NE , FCMP_UNE, false)
 #undef VISITCOMP
 
   Value *VisitBinAssign (const BinaryOperator *E);
@@ -3804,7 +3804,8 @@ static llvm::Intrinsic::ID GetIntrinsic(IntrinsicType IT,
 Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,
   llvm::CmpInst::Predicate UICmpOpc,
   llvm::CmpInst::Predicate SICmpOpc,
-  llvm::CmpInst::Predicate FCmpOpc) {
+  llvm::CmpInst::Predicate FCmpOpc,
+  bool IsSignaling) {
   TestAndClearIgnoreResultAssign();
   Value *Result;
   QualType LHSTy = E->getLHS()->getType();
@@ -3900,7 +3901,10 @@ Value *ScalarExprEmitter::EmitCompare(const 
BinaryOperator *E,
 if (BOInfo.isFixedPointBinOp()) {
   Result = EmitFixedPointBinOp(BOInfo);
 } else if (LHS->getType()->isFPOrFPVectorTy()) {
-  Result = Builder.CreateFCmp(FCmpOpc, LHS, RHS, "cmp");
+  if (!IsSignaling)
+Result = Builder.CreateFCmp(FCmpOpc, LHS, RHS, "cmp");
+  else
+Result = Builder.CreateFCmpS(FCmpOpc, LHS, RHS, "cmp");
 } else if (LHSTy->hasSignedIntegerRepresentation()) {
   Result = Builder.CreateICmp(SICmpOpc, LHS, RHS, "cmp");
 } else {
@@ -3957,6 +3961,8 @@ Value *ScalarExprEmitter::EmitCompare(const 
BinaryOperator *E,
 
 Value *ResultR, *ResultI;
 if (CETy->isRealFloatingType()) {
+  // As complex comparisons can only be equality comparisons, they
+  // are never signaling comparisons.
   ResultR = Builder.CreateFCmp(FCmpOpc, LHS.first, RHS.first, "cmp.r");
   ResultI = Builder.CreateFCmp(FCmpOpc, LHS.second, RHS.second, "cmp.i");
 } else {

diff  --git a/clang/test/CodeGen/fpconstrained-cmp-double.c 
b/clang/test/CodeGen/fpconstrained-cmp-double.c
new file mode 100644
index ..2819970a3fcf
--- /dev/null
+++ b/clang/test/CodeGen/fpconstrained-cmp-double.c
@@ -0,0 +1,151 @@
+// RUN: %clang_cc1 -ffp-exception-behavior=ignore -emit-llvm -o - %s | 
FileCheck %s -ch

[PATCH] D71467: [FPEnv] Generate constrained FP comparisons from clang

2020-01-10 Thread Ulrich Weigand via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76e9c2a9870e: [FPEnv] Generate constrained FP comparisons 
from clang (authored by uweigand).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71467

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/fpconstrained-cmp-double.c
  clang/test/CodeGen/fpconstrained-cmp-float.c
  llvm/include/llvm/IR/IRBuilder.h

Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -1195,6 +1195,18 @@
 return MetadataAsValue::get(Context, ExceptMDS);
   }
 
+  Value *getConstrainedFPPredicate(CmpInst::Predicate Predicate) {
+assert(CmpInst::isFPPredicate(Predicate) &&
+   Predicate != CmpInst::FCMP_FALSE &&
+   Predicate != CmpInst::FCMP_TRUE &&
+   "Invalid constrained FP comparison predicate!");
+
+StringRef PredicateStr = CmpInst::getPredicateName(Predicate);
+auto *PredicateMDS = MDString::get(Context, PredicateStr);
+
+return MetadataAsValue::get(Context, PredicateMDS);
+  }
+
 public:
   Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
bool HasNUW = false, bool HasNSW = false) {
@@ -2351,12 +2363,41 @@
 
   Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+if (IsFPConstrained)
+  return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmp,
+P, LHS, RHS, Name);
+
+if (auto *LC = dyn_cast(LHS))
+  if (auto *RC = dyn_cast(RHS))
+return Insert(Folder.CreateFCmp(P, LC, RC), Name);
+return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
+  }
+
+  Value *CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS,
+ const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+if (IsFPConstrained)
+  return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmps,
+P, LHS, RHS, Name);
+
 if (auto *LC = dyn_cast(LHS))
   if (auto *RC = dyn_cast(RHS))
 return Insert(Folder.CreateFCmp(P, LC, RC), Name);
 return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
   }
 
+  CallInst *CreateConstrainedFPCmp(
+  Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R,
+  const Twine &Name = "",
+  Optional Except = None) {
+Value *PredicateV = getConstrainedFPPredicate(P);
+Value *ExceptV = getConstrainedFPExcept(Except);
+
+CallInst *C = CreateIntrinsic(ID, {L->getType()},
+  {L, R, PredicateV, ExceptV}, nullptr, Name);
+setConstrainedFPCallAttr(C);
+return C;
+  }
+
   //======//
   // Instruction creation methods: Other Instructions
   //======//
Index: clang/test/CodeGen/fpconstrained-cmp-float.c
===
--- /dev/null
+++ clang/test/CodeGen/fpconstrained-cmp-float.c
@@ -0,0 +1,151 @@
+// RUN: %clang_cc1 -ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=FCMP
+// RUN: %clang_cc1 -ffp-exception-behavior=strict -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=EXCEPT
+// RUN: %clang_cc1 -ffp-exception-behavior=maytrap -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=IGNORE
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=EXCEPT
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
+
+_Bool QuietEqual(float f1, float f2) {
+  // CHECK-LABEL: define {{.*}}i1 @QuietEqual(float %f1, float %f2)
+
+  // FCMP: fcmp oeq float %{{.*}}, %{{.*}}
+  // IGNORE: call i1 @llvm.experimental.constrained.fcmp.f32(float %{{.*}}, float %{{.*}}, metadata !"oeq", metadata !"fpexcept.ignore")
+  // EXCEPT: call i1 @llvm.experimental.constrained.fcmp.f32(float %{{.*}}, float %{{.*}}, metadata !"oeq", metadata !"fpexcept.strict")
+  // MAYTRAP: call i1 @llvm.experimental.constrained.fcmp.f32(float %{{.*}}, float %{{.*}}, metadata !"oeq", metadata !"fpexcept.maytrap")
+  return f1 == f2;
+
+  // CHECK: ret
+}
+
+_Bool QuietNotEqual(float f1, float f2) {
+  // CHECK-LABEL: define {{.*}}i1 @QuietNotEqual(float %f1, float %f2)
+
+  // FCMP: fcmp une float %{{.*}}, %{{.*}}
+  // IGNORE: call i1 @llvm.experimental.constrained.fcmp.f32

[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Yeah we discussed that case offline and I should have mentioned.
Resolving this in places other than the top-level would be nice and probably 
worthy of a comment at least. But this special case seems common enough to be 
worth having.
The only place fully resolving could reasonably be done I guess is TypePrinter, 
because we can't actually transform the types into the correct form IIUC.
It's particularly unclear to me why typeprinter descends into auto but prints 
decltype, but Kadir says that seems to be intentional.

> Could it be the case that we want to show the canonical types (i.e. without 
> all syntax sugar)?

Maybe we want both the normal type and the canonical type?

Canonical types are often *really* ugly, especially with STL types (we don't 
have the "as written" form). And presenting the types twice might be at least 
as confusing/noisy as helpful. But if you have examples where this would be 
better, it'd be interesting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72500: [clangd] Show hower info for expressions

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Basing this on the hover for the type doesn't seem right. e.g. `int` should be 
the `Type` rather than the `Name`.

Rather than printing the value if evaluable, I think we should only show the 
hover if evaluable. There's a cost to showing it and the value of just the type 
doesn't seem clearly high enough.

I think we should avoid triggering for literals. Maybe some exceptions, but a 
hover saying that 0 is an int with value 0 seems silly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72500



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


[PATCH] D72448: [clang-tidy] readability-redundant-string-init now flags redundant initialisation in Field Decls and Constructor Initialisers

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237297.
njames93 edited the summary of this revision.
njames93 added a comment.

Checks for string initialisations which are spelt with braces

Ensures the check will detect and fix brace initializations
Example:

std::string a{""};
std::string b = {""};

CxxConstructor : A{""} {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72448

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
@@ -34,6 +34,12 @@
   std::string d(R"()");
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
   // CHECK-FIXES: std::string d;
+  std::string e{""};
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES: std::string e;
+  std::string f = {""};
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES: std::string f;
 
   std::string u = "u";
   std::string w("w");
@@ -227,3 +233,53 @@
   other::wstring e = L"";
   other::wstring f(L"");
 }
+
+class Foo {
+  std::string A = "";
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  std::string A;
+  std::string B;
+  std::string C;
+  std::string D;
+  std::string E = "NotEmpty";
+
+public:
+  // Check redundant constructor where Field has a redundant initializer.
+  Foo() : A("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:11: warning: redundant string initialization
+  // CHECK-FIXES:  Foo()  {}
+
+  // Check redundant constructor where Field has no initializer.
+  Foo(char) : B("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(char)  {}
+
+  // Check redundant constructor where Field has a valid initializer.
+  Foo(long) : E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(long) : E() {}
+
+  // Check how it handles removing 1 initializer, and defaulting the other.
+  Foo(int) : B(""), E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:21: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(int) :  E() {}
+
+  Foo(short) : B{""} {}
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(short)  {}
+
+  Foo(float) : A{""}, B{""} {}
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(float)  {}
+
+
+  // Check how it handles removing some redundant initializers while leaving
+  // valid initializers intact.
+  Foo(std::string Arg) : A(Arg), B(""), C("NonEmpty"), D(R"()"), E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:34: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:56: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-3]]:66: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(std::string Arg) : A(Arg),  C("NonEmpty"),  E() {}
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -218,9 +218,11 @@
   `"base class 'Foo' should be explicitly initialized in the copy constructor"`
   warnings or errors with ``gcc -Wextra`` or ``gcc -Werror=extra``.
 
-- The :doc:`readability-redundant-string-init
+- Improved :doc:`readability-redundant-string-init
   ` check now supports a
-  `StringNames` option enabling its application to custom string classes.
+  `StringNames` option enabling its application to custom string classes. The 
+  check now detects in class initializers and constructor initializers which 
+  are deemed to be redundant.
 
 - Improved :doc:`modernize-avoid-bind
   ` check.
Index: clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -20,6 +20,30 @@
 
 const char DefaultStringNames[] = "::std::basic_string";
 
+static const CXXConstructExpr *
+getConstructExpr(const CXXCtorInitializer &CtorInit) {
+  const Expr *InitExpr = CtorInit.getInit();
+  if (const auto *CleanUpExpr = dyn_cast(InitExpr))
+InitExpr = C

[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as not done.
kadircet added a comment.

In D72498#1813899 , @ilya-biryukov 
wrote:

> This does not work for more complicated types, though?
>  E.g. `decltype(a+b)* a` or `vector a`?


yes, and I think we should have a more sophisticated way to print composite 
types including decltypes to cover more cases.

> Why do we prefer to drop `decltype()`, yet show the typedefs? Both could lead 
> to complicated types, arguably decltypes can be even worse than typedefs.
>  Could it be the case that we want to show the canonical types (i.e. without 
> all syntax sugar)?
>  Maybe we want both the normal type and the canonical type?

I think typedef and decltype have different nature, the latter is a lot more 
obscure than the former, that was the reason why I handled decltypes 
specifically. 
I agree with your suggestion for typedefs though, I think there would be value 
in displaying the underlying type in hover card for type aliases to reduce 
navigation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D68720: Support -fstack-clash-protection for x86

2020-01-10 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 237298.
serge-sans-paille added a comment.

Take review into account.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68720

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/stack-clash-protection.c
  clang/test/Driver/stack-clash-protection.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/Target/X86/X86CallFrameOptimization.cpp
  llvm/lib/Target/X86/X86FrameLowering.cpp
  llvm/lib/Target/X86/X86FrameLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/lib/Target/X86/X86InstrCompiler.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/test/CodeGen/X86/stack-clash-dynamic-alloca.ll
  llvm/test/CodeGen/X86/stack-clash-large.ll
  llvm/test/CodeGen/X86/stack-clash-medium-natural-probes-mutliple-objects.ll
  llvm/test/CodeGen/X86/stack-clash-medium-natural-probes.ll
  llvm/test/CodeGen/X86/stack-clash-medium.ll
  llvm/test/CodeGen/X86/stack-clash-no-free-probe.ll
  llvm/test/CodeGen/X86/stack-clash-small.ll
  llvm/test/CodeGen/X86/stack-clash-unknown-call.ll

Index: llvm/test/CodeGen/X86/stack-clash-unknown-call.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-clash-unknown-call.ll
@@ -0,0 +1,31 @@
+; RUN: llc < %s | FileCheck %s
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg);
+
+define void @foo() local_unnamed_addr #0 {
+
+;CHECK-LABEL: foo:
+;CHECK: # %bb.0:
+;CHECK-NEXT:	subq	$4096, %rsp # imm = 0x1000
+; it's important that we don't use the call as a probe here
+;CHECK-NEXT:	movq	$0, (%rsp)
+;CHECK-NEXT:	subq	$3912, %rsp # imm = 0xF48
+;CHECK-NEXT:	.cfi_def_cfa_offset 8016
+;CHECK-NEXT:	movq	%rsp, %rdi
+;CHECK-NEXT:	movl	$8000, %edx # imm = 0x1F40
+;CHECK-NEXT:	xorl	%esi, %esi
+;CHECK-NEXT:	callq	memset
+;CHECK-NEXT:	addq	$8008, %rsp # imm = 0x1F48
+;CHECK-NEXT:	.cfi_def_cfa_offset 8
+;CHECK-NEXT:	retq
+
+  %a = alloca i8, i64 8000, align 16
+  call void @llvm.memset.p0i8.i64(i8* align 16 %a, i8 0, i64 8000, i1 false)
+  ret void
+}
+
+attributes #0 =  {"probe-stack"="inline-asm"}
Index: llvm/test/CodeGen/X86/stack-clash-small.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-clash-small.ll
@@ -0,0 +1,25 @@
+; RUN: llc < %s | FileCheck %s
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo() local_unnamed_addr #0 {
+; CHECK-LABEL: foo:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:  subq	$280, %rsp # imm = 0x118
+; CHECK-NEXT:  .cfi_def_cfa_offset 288
+; CHECK-NEXT:  movl	$1, 264(%rsp)
+; CHECK-NEXT:  movl	-128(%rsp), %eax
+; CHECK-NEXT:  addq	$280, %rsp # imm = 0x118
+; CHECK-NEXT:  .cfi_def_cfa_offset 8
+; CHECK-NEXT:  retq
+
+  %a = alloca i32, i64 100, align 16
+  %b = getelementptr inbounds i32, i32* %a, i64 98
+  store volatile i32 1, i32* %b
+  %c = load volatile i32, i32* %a
+  ret i32 %c
+}
+
+attributes #0 =  {"probe-stack"="inline-asm"}
Index: llvm/test/CodeGen/X86/stack-clash-no-free-probe.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-clash-no-free-probe.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo(i64 %i) local_unnamed_addr #0 {
+; CHECK-LABEL: foo:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:  subq	$4096, %rsp # imm = 0x1000
+; CHECK-NEXT:  movq	$0, (%rsp)
+; CHECK-NEXT:  subq	$3784, %rsp # imm = 0xEC8
+; CHECK-NEXT:  .cfi_def_cfa_offset 7888
+; CHECK-NEXT:  movl	$1, -128(%rsp,%rdi,4)
+; CHECK-NEXT:  movl	-128(%rsp), %eax
+; CHECK-NEXT:  addq	$7880, %rsp # imm = 0x1EC8
+; CHECK-NEXT:  .cfi_def_cfa_offset 8
+; CHECK-NEXT:  retq
+
+  %a = alloca i32, i32 2000, align 16
+  %b = getelementptr inbounds i32, i32* %a, i64 %i
+  store volatile i32 1, i32* %b
+  %c = load volatile i32, i32* %a
+  ret i32 %c
+}
+
+attributes #0 =  {"probe-stack"="inline-asm"}
+
Index: llvm/test/CodeGen/X86/stack-clash-medium.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/stack-clash-medium.ll
@@ -0,0 +1,30 @@
+; RUN: llc < %s | FileCheck %s
+
+
+t

[PATCH] D71566: New checks for fortified sprintf

2020-01-10 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@erik.pilkington up?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71566



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D72498#1813962 , @sammccall wrote:

> It's particularly unclear to me why typeprinter descends into auto but prints 
> decltype, but Kadir says that seems to be intentional.


Also don't see why they choose to have this inconsistency and I haven't seen 
any indication it's not a coincidence.
@kadircet, why do you think it's intentional? Should we put some comments there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D68720: Support -fstack-clash-protection for x86

2020-01-10 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked 9 inline comments as done.
serge-sans-paille added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:2254
+CGM.getDiags().Report(S.getAsmLoc(),
+  diag::warn_fe_stack_clash_protection_inline_asm);
+  }

craig.topper wrote:
> Why is this in the frontend diagnostic list?
As far as I understand, that's the only place where line/col accurate 
diagnostics are emitted.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2575
+  default:
+return;
+  case llvm::Triple::ArchType::x86:

tstellar wrote:
> Do we need to warn (or error) here for arches that don't implement 
> -fstack-clash-protection?
That's done indirectly because the argument is not claimed on unsupported 
platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68720



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D72498#1813963 , @kadircet wrote:

> I think typedef and decltype have different nature, the latter is a lot more 
> obscure than the former, that was the reason why I handled decltypes 
> specifically.


I tend to disagree here. `decltype` is normally the last resort, so whatever it 
produces is probably super-obscure, would even expect it to be not 
representable in C++ in many cases.
E.g.

  auto Callback = []() { ... };
  decltype(Callback) ^a = Callback;

Typedefs are often used with simple types, so that's not necessarily the case.

  typedef unordered_map IntMap;
  IntMap ^a =;



> I agree with your suggestion for typedefs though, I think there would be 
> value in displaying the underlying type in hover card for type aliases to 
> reduce navigation.

Would definitely be helpful. If you feel we have some room in hover, I would 
love to have that. But there's a balance to be made, see Sam's comments about 
canonical types being obscure. I agree on 50% of the cases :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D72498#1813962 , @sammccall wrote:

> Maybe we want both the normal type and the canonical type?
>
> Canonical types are often *really* ugly, especially with STL types (we don't 
> have the "as written" form). And presenting the types twice might be at least 
> as confusing/noisy as helpful. But if you have examples where this would be 
> better, it'd be interesting.


I'm mostly trying to find a consistent rule we can apply to make these decision.
`auto`, `decltype` and typedefs are very similar in this regard, it's a bit 
confusing we use different rules for those. Although I can see how `auto` and 
`decltype` could easily be perceived differently and fall into a different 
group.

STL types are unfortunate, that is so true. And most other types aren't. It 
could be worth looking into the rules clang applies in diagnostics (have you 
seen those that say `type X(aka vector)`?
I have no easy answer, though, it feels this will inevitably lead to terrible 
presentations of some types. FWIW, showing underlying type of decltype could 
lead us there too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I think i'm also comfortable with marking the linked bug as wontfix.

It's a contrived example that makes clangd look silly (why decltype(a) instead 
of int?) but also the user look silly (why hover the variable rather than the 
decltype?).
Real examples are certainly more mixed.

The only thing that gives me pause is that it does seem to be decltype and auto 
belong in the same bucket (more so than typedef). If we can make those 
consistent in typeprinter, I'm happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D72378: [clang-tidy] Add `bugprone-reserved-identifier`

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please rebase from trunk. I sorted Clang-tidy entries in Release Notes and 
aliases have own subsubsection. Please keep alphabetical order there.




Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-dcl51-cpp.rst:6
+cert-dcl51-cpp
+
+

Header length.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72378



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please rebase from trunk. I sorted Clang-tidy entries in Release Notes and 
aliases have own subsubsection. Please keep alphabetical order there.


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

https://reviews.llvm.org/D72217



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


[PATCH] D72505: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth created this revision.
JonasToth added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
JonasToth added a child revision: D54943: [clang-tidy] implement 
const-transformation for cppcoreguidelines-const-correctness.

The analysis for const-ness of local variables required a view generally useful
matchers that are extracted into its own patch.

They are `decompositionDecl` and `forEachArgumentWithParamType`, that works
for calls through function pointers as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72505

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -715,6 +715,158 @@
 std::make_unique>("v", 4)));
 }
 
+TEST(ForEachArgumentWithParamType, ReportsNoFalsePositives) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  // IntParam does not match.
+  EXPECT_TRUE(notMatches("void f(int* i) { int* y; f(y); }", CallExpr));
+  // ArgumentY does not match.
+  EXPECT_TRUE(notMatches("void f(int i) { int x; f(x); }", CallExpr));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCXXMemberCallExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct S {"
+  "  const S& operator[](int i) { return *this; }"
+  "};"
+  "void f(S S1) {"
+  "  int y = 1;"
+  "  S1[y];"
+  "}",
+CallExpr, std::make_unique>("type", 1)));
+
+  StatementMatcher CallExpr2 =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct S {"
+  "  static void g(int i);"
+  "};"
+  "void f() {"
+  "  int y = 1;"
+  "  S::g(y);"
+  "}",
+CallExpr2, std::make_unique>("type", 1)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCallExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
+ std::make_unique>(
+   "type")));
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
+ std::make_unique>(
+   "arg")));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void f(int i, int j) { int y; f(y, y); }", CallExpr,
+std::make_unique>("type", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void f(int i, int j) { int y; f(y, y); }", CallExpr,
+std::make_unique>("arg", 2)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesConstructExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher ConstructExpr =
+cxxConstructExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+ConstructExpr,
+std::make_unique>("type")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+ConstructExpr,
+std::make_unique>("arg")));
+}
+
+TEST(ForEachArgumentWithParamType, HandlesBoundNodesForNonMatches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void g(int i, int j) {"
+  "  int a;"
+  "  int b;"
+  "  int c;"
+  "  g(a, 0);"
+  "  g(a, b);"
+  "  g(0, b);"
+  "}",
+functionDecl(
+  forEachDescendant(varDecl().bind("v")),
+  forEachDescendant(callExpr(forEachArgumentWithParamType(
+declRefExpr(to(decl(equalsBoundNode("v", qualType(),
+std::make_unique>("v", 4)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesFunctionPtrCalls) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(builtinType()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+

[PATCH] D72276: [clang-format] Add IndentCaseBlocks option

2020-01-10 Thread Nicolas Capens via Phabricator via cfe-commits
capn added a comment.

Ping. Please land on my behalf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72276



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:70
 
+- The 'bugprone-suspicous-constructor-and-assignment' check was renamed to 
:doc:`cert-not-trivial-types-libc-memory-calls
+  `

Eugene.Zelenko wrote:
> Is this relevant?
nope, I renamed the check left that in , will remove


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488



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


[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237315.
njames93 marked 4 inline comments as done.
njames93 added a comment.

Added a way to specify custom mem set copy and compare functions plus nit fixes

Can now use the options MemSetNames, MemCpyNames and MemCmpNames to specify 
custom functions to flag on


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.cpp
  clang-tools-extra/clang-tidy/cert/NotTrivialTypesLibcMemoryCallsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-oop57-cpp.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp
@@ -0,0 +1,90 @@
+// RUN: %check_clang_tidy %s cert-oop57-cpp %t -- \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: cert-oop57-cpp.MemSetNames, value: mymemset}, \
+// RUN:  {key: cert-oop57-cpp.MemCpyNames, value: mymemcpy}, \
+// RUN:  {key: cert-oop57-cpp.MemCmpNames, value: mymemcmp}]}' \
+// RUN: --
+
+void mymemset(void *, unsigned char, decltype(sizeof(int)));
+void mymemcpy(void *, const void *, decltype(sizeof(int)));
+int mymemcmp(const void *, const void *, decltype(sizeof(int)));
+
+namespace std {
+void memset(void *, unsigned char, decltype(sizeof(int)));
+void memcpy(void *, const void *, decltype(sizeof(int)));
+void memmove(void *, const void *, decltype(sizeof(int)));
+void strcpy(void *, const void *, decltype(sizeof(int)));
+int memcmp(const void *, const void *, decltype(sizeof(int)));
+int strcmp(const void *, const void *, decltype(sizeof(int)));
+} // namespace std
+
+struct Trivial {
+  int I;
+  int J;
+};
+
+struct NonTrivial {
+  int I;
+  int J;
+
+  NonTrivial() : I(0), J(0) {}
+  NonTrivial &operator=(const NonTrivial &Other) {
+I = Other.I;
+J = Other.J;
+return *this;
+  }
+
+  bool operator==(const Trivial &Other) const {
+return I == Other.I && J == Other.J;
+  }
+  bool operator!=(const Trivial &Other) const {
+return !(*this == Other);
+  }
+};
+
+void foo(const Trivial &Other) {
+  Trivial Data;
+  std::memset(&Data, 0, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memset(&Data, 0, sizeof(Trivial));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void bar(const NonTrivial &Other) {
+  NonTrivial Data;
+  std::memset(&Data, 0, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  // Check it detects sizeof(Type) as well as sizeof(Instantiation)
+  std::memset(&Data, 0, sizeof(NonTrivial));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memset' on a non trivially default constructible class is undefined
+  std::memcpy(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memcpy' on a non trivially copyable class is undefined
+  std::memmove(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::memmove' on a non trivially copyable class is undefined
+  std::strcpy(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Calling 'std::strcpy' on a non trivially copyable class is undefined
+  std::memcmp(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::memcmp'
+  std::strcmp(&Data, &Other, sizeof(Data));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'std::strcmp'
+}
+
+void baz(c

[clang] cdd05f2 - [NFC] format unittest for ExprMutAnalyzer

2020-01-10 Thread Jonas Toth via cfe-commits

Author: Jonas Toth
Date: 2020-01-10T16:10:55+01:00
New Revision: cdd05f2aea3b950a4e2c496175117e6b47b2a050

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

LOG: [NFC] format unittest for ExprMutAnalyzer

This formatting is a preparation for review in
https://reviews.llvm.org/D54943 to separate pure formatting changes from
actual testing changes.

Added: 


Modified: 
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index 2c22a5cf9ed9..1c3e00ca4ae8 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -882,38 +882,36 @@ TEST(ExprMutationAnalyzerTest, CastToConstRef) {
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithAnAssigment) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y) = 5; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y) = 5; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithDecOp) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y)++; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y)++; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithNonConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() { mem ++; 
} };"
-   "void fn() { A o1, o2; (o1, o2).f(); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "class A { public: int mem; void f() { mem ++; } };"
+  "void fn() { A o1, o2; (o1, o2).f(); }",
+  {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o2")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() const  { } 
};"
-   "void fn() { A o1, o2; (o1, o2).f(); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "class A { public: int mem; void f() const  { } };"
+  "void fn() { A o1, o2; (o1, o2).f(); }",
+  {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o2")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
@@ -957,11 +955,10 @@ TEST(ExprMutationAnalyzerTest, CommaExprParmRef) {
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithAmpersandOp) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem;};"
-   "void fn () { A o1, o2;"
-   "void *addr = &(o2, o1); } ",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs("class A { public: int mem;};"
+"void fn () { A o1, o2;"
+"void *addr = &(o2, o1); } ",
+{"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o1")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
@@ -976,9 +973,8 @@ TEST(ExprMutationAnalyzerTest, CommaExprAsReturnAsValue) {
 }
 
 TEST(ExprMutationAnalyzerTest, CommaEpxrAsReturnAsNonConstRef) {
-  const auto AST =
-  buildASTFromCodeWithArgs("int& f() { int x, y; return (y, x); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "int& f() { int x, y; return (y, x); }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
@@ -995,13 +991,12 @@ TEST(ExprMutationAnalyzerTest, 
CommaExprAsArrayToPointerDecay) {
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprAsUniquePtr) {
-  const std::string UniquePtrDef =
-  "template  struct UniquePtr {"
-  "  UniquePtr();"
-  "  UniquePtr(const UniquePtr&) = delete;"
-  "  T& operator*() const;"
-  "  T* operator-

[PATCH] D72488: [clang-tidy] Add check for CERT-OOP57-CPP

2020-01-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please describe options in documentation. See other checks documentation as 
example.




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:112
+  
+  This check flags use of the c standard library functions ``memset``, 
``memcpy``,
+  ``memmove``, ``strcpy``, ``memcmp`` and ``strcmp`` on non trivial types.

Please remove This check. Same in documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72488



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 237317.
JonasToth added a comment.

- fix unit tests for exprmutanalyzer, whitespace was the problem
- Merge branch 'master' into feature_transform_const.patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -62,13 +62,18 @@
   const auto *const S = selectFirst("stmt", Results);
   SmallVector Chain;
   ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
+
+  std::string buffer;
   for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
 const Stmt *By = Analyzer.findMutation(E);
-std::string buffer;
+if (!By)
+  break;
+
 llvm::raw_string_ostream stream(buffer);
 By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
-Chain.push_back(StringRef(stream.str()).trim().str());
+Chain.emplace_back(StringRef(stream.str()).trim().str());
 E = dyn_cast(By);
+buffer.clear();
   }
   return Chain;
 }
@@ -382,22 +387,26 @@
   "void g(const int&&); void f() { int x; g(static_cast(x)); }");
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("struct A {}; A operator+(const A&&, int);"
  "void f() { A x; static_cast(x) + 1; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("void f() { struct A { A(const int&&); }; "
  "int x; A y(static_cast(x)); }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("void f() { struct A { A(); A(const A&&); }; "
  "A x; A y(static_cast(x)); }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 }
 
 TEST(ExprMutationAnalyzerTest, Move) {
@@ -567,7 +576,7 @@
   const auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_THAT(mutatedBy(Results, AST.get()),
-  ElementsAre("return static_cast(x);"));
+  ElementsAre("static_cast(x)"));
 }
 
 TEST(ExprMutationAnalyzerTest, ReturnAsConstRRef) {
@@ -575,7 +584,8 @@
   "const int&& f() { int x; return static_cast(x); }");
   const auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 }
 
 TEST(ExprMutationAnalyzerTest, TakeAddress) {
@@ -851,13 +861,13 @@
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_THAT(mutatedBy(Results, AST.get()),
-  ElementsAre("static_cast(x) = 10"));
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("typedef int& IntRef;"
  "void f() { int x; static_cast(x) = 10;

[PATCH] D72508: [clangd] Support pseudo-obj expr, opaque values, and property references in findExplicitReferences()

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:570
 auto AST = TU.build();
+EXPECT_THAT(AST.getDiagnostics(), ::testing::IsEmpty()) << Code;
 

For consistency with the targetDecl() tests in this file, and because I had an 
error in the testcase that threw me for a loop. I'll try to find a better 
solution project-wide though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72508



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


[PATCH] D72508: [clangd] Support pseudo-obj expr, opaque values, and property references in findExplicitReferences()

2020-01-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ilya-biryukov, dgoldman.
Herald added subscribers: cfe-commits, usaxena95, kadircet, jfb, arphaman, 
jkorous, MaskRay.
Herald added a project: clang.
sammccall added a parent revision: D72494: [clangd] Fix targetDecl() on certain 
usage of ObjC properties..
sammccall removed a parent revision: D72494: [clangd] Fix targetDecl() on 
certain usage of ObjC properties..
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:570
 auto AST = TU.build();
+EXPECT_THAT(AST.getDiagnostics(), ::testing::IsEmpty()) << Code;
 

For consistency with the targetDecl() tests in this file, and because I had an 
error in the testcase that threw me for a loop. I'll try to find a better 
solution project-wide though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72508

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -511,8 +511,7 @@
   [[f.x]].y = 0;
 }
   )cpp";
-  EXPECT_DECLS("OpaqueValueExpr",
-   "@property(atomic, retain, readwrite) I *x");
+  EXPECT_DECLS("OpaqueValueExpr", "@property(atomic, retain, readwrite) I *x");
 
   Code = R"cpp(
 @protocol Foo
@@ -565,8 +564,10 @@
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 TU.ExtraArgs.push_back("-std=c++17");
+TU.ExtraArgs.push_back("-xobjective-c++");
 
 auto AST = TU.build();
+EXPECT_THAT(AST.getDiagnostics(), ::testing::IsEmpty()) << Code;
 
 auto *TestDecl = &findDecl(AST, "foo");
 if (auto *T = llvm::dyn_cast(TestDecl))
@@ -664,7 +665,7 @@
  void foo() {
$0^Struct $1^x;
$2^Typedef $3^y;
-   static_cast<$4^Struct*>(0);
+   (void) static_cast<$4^Struct*>(0);
  }
)cpp",
 "0: targets = {Struct}\n"
@@ -675,10 +676,10 @@
// Name qualifiers.
{R"cpp(
  namespace a { namespace b { struct S { typedef int type; }; } }
- void foo() {
+ int foo() {
$0^a::$1^b::$2^S $3^x;
using namespace $4^a::$5^b;
-   $6^S::$7^type $8^y;
+   return $6^S::$7^type(5);
  }
 )cpp",
 "0: targets = {a}\n"
@@ -688,8 +689,7 @@
 "4: targets = {a}\n"
 "5: targets = {a::b}, qualifier = 'a::'\n"
 "6: targets = {a::b::S}\n"
-"7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"
-"8: targets = {y}, decl\n"},
+"7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"},
// Simple templates.
{R"cpp(
   template  struct vector { using value_type = T; };
@@ -719,7 +719,7 @@
 "3: targets = {vb}, decl\n"},
// MemberExpr should know their using declaration.
{R"cpp(
-struct X { void func(int); }
+struct X { void func(int); };
 struct Y : X {
   using X::func;
 };
@@ -744,8 +744,8 @@
 #define FOO a
 #define BAR b
 
-void foo(int a, int b) {
-  $0^FOO+$1^BAR;
+int foo(int a, int b) {
+  return $0^FOO+$1^BAR;
 }
 )cpp",
 "0: targets = {a}\n"
@@ -825,7 +825,7 @@
 void foo() {
   $0^TT $1^x;
   $2^foo<$3^TT>();
-  $4^foo<$5^vector>()
+  $4^foo<$5^vector>();
   $6^foo<$7^TP...>();
 }
 )cpp",
@@ -892,7 +892,7 @@
};
// delegating initializer
class $10^Foo {
- $11^Foo(int);
+ $11^Foo(int) {}
  $12^Foo(): $13^Foo(111) {}
};
  }
@@ -925,7 +925,7 @@
// Namespace aliases should be handled properly.
{
R"cpp(
-namespace ns { struct Type {} }
+namespace ns { struct Type {}; }
 namespace alias = ns;
 namespace rec_alias = alias;
 
@@ -966,7 +966,21 @@
   }
 )cpp",
"0: targets = {Test}\n"
-   "1: targets = {a}, decl\n"}};
+   "1: targets = {a}, decl\n"},
+   {
+   R"cpp(
+@interface I {}
+@property(retain) I* x;
+@property(retain) I* y;
+@end
+I *f;
+void foo() {
+  $0^f.$1^x.$2^y = 0;
+}
+  )cpp",
+   "0: targets = {f}\n"
+   "1: targets = {I::x}\n"
+   "2: targets = {I::y}\n"}};
 
   for (const auto &C : Cases) {
 llvm:

[PATCH] D72508: [clangd] Support pseudo-obj expr, opaque values, and property references in findExplicitReferences()

2020-01-10 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon question-circle color=gray} clang-format: unknown.

Build artifacts 
: 
diff.json 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72508



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


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D72414: Add new AST matcher `hasAnyCapture`

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4056
+///   matches [this](){};
+AST_MATCHER(LambdaExpr, capturesThis) {
+  for (const LambdaCapture &Capture : Node.captures()) {

rhiro wrote:
> aaron.ballman wrote:
> > I'm a bit less certain about the utility of this matcher. I would have 
> > assumed you could do `hasAnyCapture(cxxThisExpr())` to get the same 
> > behavior, but I am guessing that won't work -- though you may be able to 
> > add an overload to `hasAnyCapture()` to make that work. I think that might 
> > be a better approach, if it works.
> Thanks for that idea, it does seem a bit cleaner.
> 
> It would be nice if we could write a Matcher, so that the 
> macro composition could be more generically nested. e.g. hasAnyCapture that 
> just loops over the LambdaCaptures and passes them to the child matcher.  
> However, when I tried this, it became apparent that it is not a Node type 
> that can be matched on, and would require nontrivial changes.
Yeah, I think this would require some work within the guts of the AST matchers 
and I'm not certain it would be worth the effort yet.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4032-4034
+if (Capture.capturesThis()) {
+  continue;
+}

I would prefer to see this written as: `if (Capture.capturesVariable()) { ... 
}` so it's a bit more resilient to other non-var captures like VLA captures. 



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4058-4063
+  for (const LambdaCapture &Capture : Node.captures()) {
+if (Capture.capturesThis()) {
+  return true;
+}
+  }
+  return false;

`return llvm::any_of(Node.captures(), [](const LambdaCapture &LC) { return 
LC.capturesThis(); });`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72414



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


[PATCH] D57054: [MachineOutliner][ARM][RFC] Add Machine Outliner support for ARM

2020-01-10 Thread Sam Parker via Phabricator via cfe-commits
samparker added a comment.

> Even if you only decrease the size you can have a distance increase due to 
> aligment constraints

Ah... thanks for raising this. I'll look into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57054



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


[PATCH] D72505: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4207-4208
+  if (const auto *Call = dyn_cast(&Node)) {
+if (const Decl *Callee = Call->getCalleeDecl()) {
+  if (const auto *Value = dyn_cast(Callee)) {
+QualType QT = Value->getType();

`if (const auto *Value = dyn_cast_or_null(Call->getCalleeDecl())) { 
... }`



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4209
+  if (const auto *Value = dyn_cast(Callee)) {
+QualType QT = Value->getType();
+

Should you be getting the canonical type here? That would skip over things like 
paren types and typedefs.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4214-4215
+  FProto = FPT->getAs();
+  assert(FProto &&
+ "The call must have happened through a function pointer");
+}

This seems like an invalid assertion -- K&R C functions would have a function 
pointer type but not a prototype, for instance.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4243
+  if (FProto) {
+QualType ParamType = FProto->getParamType(ParamIndex);
+if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {

Should we be canonicalizing this type as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72505



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-10 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 237329.
njames93 added a comment.

Rebase onto trunk


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72217

Files:
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm-qualified-auto.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto-cxx20.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
@@ -0,0 +1,240 @@
+// RUN: %check_clang_tidy %s readability-qualified-auto %t
+
+namespace typedefs {
+typedef int *MyPtr;
+typedef int &MyRef;
+typedef const int *CMyPtr;
+typedef const int &CMyRef;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto TdNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedPtr' can be declared as 'auto *TdNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *TdNakedPtr = getPtr();
+  auto &TdNakedRef = getRef();
+  auto TdNakedRefDeref = getRef();
+  auto TdNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto TdNakedCPtr' can be declared as 'const auto *TdNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *TdNakedCPtr = getCPtr();
+  auto &TdNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &TdNakedCRef' can be declared as 'const auto &TdNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &TdNakedCRef = getCRef();
+  auto TdNakedCRefDeref = getCRef();
+}
+
+}; // namespace typedefs
+
+namespace usings {
+using MyPtr = int *;
+using MyRef = int &;
+using CMyPtr = const int *;
+using CMyRef = const int &;
+
+MyPtr getPtr();
+MyRef getRef();
+CMyPtr getCPtr();
+CMyRef getCRef();
+
+void foo() {
+  auto UNakedPtr = getPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedPtr' can be declared as 'auto *UNakedPtr'
+  // CHECK-FIXES: {{^}}  auto *UNakedPtr = getPtr();
+  auto &UNakedRef = getRef();
+  auto UNakedRefDeref = getRef();
+  auto UNakedCPtr = getCPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto UNakedCPtr' can be declared as 'const auto *UNakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *UNakedCPtr = getCPtr();
+  auto &UNakedCRef = getCRef();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto &UNakedCRef' can be declared as 'const auto &UNakedCRef'
+  // CHECK-FIXES: {{^}}  const auto &UNakedCRef = getCRef();
+  auto UNakedCRefDeref = getCRef();
+}
+
+}; // namespace usings
+
+int getInt();
+int *getIntPtr();
+const int *getCIntPtr();
+
+void foo() {
+  // make sure check disregards named types
+  int TypedInt = getInt();
+  int *TypedPtr = getIntPtr();
+  const int *TypedConstPtr = getCIntPtr();
+  int &TypedRef = *getIntPtr();
+  const int &TypedConstRef = *getCIntPtr();
+
+  // make sure check disregards auto types that aren't pointers or references
+  auto AutoInt = getInt();
+
+  auto NakedPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedPtr' can be declared as 'auto *NakedPtr'
+  // CHECK-FIXES: {{^}}  auto *NakedPtr = getIntPtr();
+  auto NakedCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedCPtr' can be declared as 'const auto *NakedCPtr'
+  // CHECK-FIXES: {{^}}  const auto *NakedCPtr = getCIntPtr();
+
+  const auto ConstPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstPtr' can be declared as 'auto *const ConstPtr'
+  // CHECK-FIXES: {{^}}  auto *const ConstPtr = getIntPtr();
+  const auto ConstCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'const auto ConstCPtr' can be declared as 'const auto *const ConstCPtr'
+  // CHECK-FIXES: {{^}}  const auto *const ConstCPtr = getCIntPtr();
+
+  volatile auto VolatilePtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatilePtr' can be declared as 'auto *volatile VolatilePtr'
+  // CHECK-FIXES: {{^}}  auto *volatile VolatilePtr = getIntPtr();
+  volatile auto VolatileCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'volatile auto VolatileCPtr' can be declared as 'const auto *volatile VolatileCPtr'
+  // CHECK-FIXES: {{^}}  const auto *volatile VolatileCPtr = getCIntPtr();
+
+  auto *QualPtr = getIntPtr();
+  auto *QualCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]

[PATCH] D70568: [Support] Possibly use exception handler in the Crash Recovery Context in the same way as global exceptions

2020-01-10 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Looks good to me. Thanks for pushing this forward!

(Only one very minor comment.)




Comment at: llvm/unittests/Support/CrashRecoveryTest.cpp:72
+  sys::RemoveFileOnSignal(Filename);
+  llvm::sys::AddSignalHandler(incrementGlobalWithCookie, nullptr);
+  GlobalInt = 0;

Is there a purpose to passing the pointer her, or could it just use 
incrementGlobal? If we can't, maybe call it WithPointer or something instead 
(or use an overload) - I was confused by the Cookie part until I realize you 
just mean it takes some argument.


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

https://reviews.llvm.org/D70568



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


[clang] bdd88b7 - Add support for __declspec(guard(nocf))

2020-01-10 Thread David Chisnall via cfe-commits

Author: Andrew Paverd
Date: 2020-01-10T16:04:12Z
New Revision: bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7

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

LOG: Add support for __declspec(guard(nocf))

Summary:
Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a
new `"guard_nocf"` function attribute to indicate that checks should not be
added on indirect calls within that function. Add support for
`__declspec(guard(nocf))` following the same syntax as MSVC.

Reviewers: rnk, dmajor, pcc, hans, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
clang/test/CodeGen/guard_nocf.c
clang/test/CodeGenCXX/guard_nocf.cpp
clang/test/Sema/attr-guard_nocf.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDeclAttr.cpp
llvm/lib/Transforms/CFGuard/CFGuard.cpp
llvm/test/CodeGen/AArch64/cfguard-checks.ll
llvm/test/CodeGen/ARM/cfguard-checks.ll
llvm/test/CodeGen/X86/cfguard-checks.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c992d6459f0c..d1c42e8af4d1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2907,6 +2907,15 @@ def MSAllocator : InheritableAttr {
   let Documentation = [MSAllocatorDocs];
 }
 
+def CFGuard : InheritableAttr {
+  // Currently only the __declspec(guard(nocf)) modifier is supported. In 
future
+  // we might also want to support __declspec(guard(suppress)).
+  let Spellings = [Declspec<"guard">];
+  let Subjects = SubjectList<[Function]>;
+  let Args = [EnumArgument<"Guard", "GuardArg", ["nocf"], ["nocf"]>];
+  let Documentation = [CFGuardDocs];
+}
+
 def MSStruct : InheritableAttr {
   let Spellings = [GCC<"ms_struct">];
   let Subjects = SubjectList<[Record]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 70bf2517cdcb..6692c3825ec6 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4558,6 +4558,26 @@ This attribute does not affect optimizations in any way, 
unlike GCC's
 }];
 }
 
+def CFGuardDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Code can indicate CFG checks are not wanted with the 
``__declspec(guard(nocf))``
+attribute. This directs the compiler to not insert any CFG checks for the 
entire
+function. This approach is typically used only sparingly in specific 
situations 
+where the programmer has manually inserted "CFG-equivalent" protection. The 
+programmer knows that they are calling through some read-only function table 
+whose address is obtained through read-only memory references and for which 
the 
+index is masked to the function table limit. This approach may also be applied 
+to small wrapper functions that are not inlined and that do nothing more than 
+make a call through a function pointer. Since incorrect usage of this 
directive 
+can compromise the security of CFG, the programmer must be very careful using 
+the directive. Typically, this usage is limited to very small functions that 
+only call one function.
+
+`Control Flow Guard documentation 
`
+}];
+}
+
 def HIPPinnedShadowDocs : Documentation {
   let Category = DocCatType;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b49b194d6112..e4803fde230f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4415,6 +4415,17 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (callOrInvoke)
 *callOrInvoke = CI;
 
+  // If this is within a function that has the guard(nocf) attribute and is an
+  // indirect call, add the "guard_nocf" attribute to this call to indicate 
that
+  // Control Flow Guard checks should not be added, even if the call is 
inlined.
+  if (const auto *FD = dyn_cast_or_null(CurFuncDecl)) {
+if (const auto *A = FD->getAttr()) {
+  if (A->getGuard() == CFGuardAttr::GuardArg::nocf && 
!CI->getCalledFunction())
+Attrs = Attrs.addAttribute(
+getLLVMContext(), llvm::AttributeList::FunctionIndex, 
"guard_nocf");
+}
+  }
+
   // Apply the attributes and calling convention.
   CI->setAttributes(Attrs);
   CI->setCallingConv(static_cast(CallingConv));

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7f1da406757d..142c6f156506 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6626,6 +6626

[PATCH] D72167: Add support for __declspec(guard(nocf))

2020-01-10 Thread David Chisnall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdd88b7ed395: Add support for __declspec(guard(nocf)) 
(authored by ajpaverd, committed by theraven).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72167

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/guard_nocf.c
  clang/test/CodeGenCXX/guard_nocf.cpp
  clang/test/Sema/attr-guard_nocf.c
  llvm/lib/Transforms/CFGuard/CFGuard.cpp
  llvm/test/CodeGen/AArch64/cfguard-checks.ll
  llvm/test/CodeGen/ARM/cfguard-checks.ll
  llvm/test/CodeGen/X86/cfguard-checks.ll

Index: llvm/test/CodeGen/X86/cfguard-checks.ll
===
--- llvm/test/CodeGen/X86/cfguard-checks.ll
+++ llvm/test/CodeGen/X86/cfguard-checks.ll
@@ -8,26 +8,26 @@
 declare i32 @target_func()
 
 
-; Test that Control Flow Guard checks are not added to functions with nocf_checks attribute.
-define i32 @func_nocf_checks() #0 {
+; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
+define i32 @func_guard_nocf() {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
   %0 = load i32 ()*, i32 ()** %func_ptr, align 8
-  %1 = call i32 %0()
+  %1 = call i32 %0() #0
   ret i32 %1
 
-  ; X32-LABEL: func_nocf_checks
+  ; X32-LABEL: func_guard_nocf
   ; X32: 	 movl  $_target_func, %eax
   ; X32-NOT: __guard_check_icall_fptr
 	; X32: 	 calll *%eax
 
-  ; X64-LABEL: func_nocf_checks
+  ; X64-LABEL: func_guard_nocf
   ; X64:   leaq	target_func(%rip), %rax
   ; X64-NOT: __guard_dispatch_icall_fptr
   ; X64:   callq	*%rax
 }
-attributes #0 = { nocf_check }
+attributes #0 = { "guard_nocf" }
 
 
 ; Test that Control Flow Guard checks are added even at -O0.
Index: llvm/test/CodeGen/ARM/cfguard-checks.ll
===
--- llvm/test/CodeGen/ARM/cfguard-checks.ll
+++ llvm/test/CodeGen/ARM/cfguard-checks.ll
@@ -7,26 +7,27 @@
 declare i32 @target_func()
 
 
-; Test that Control Flow Guard checks are not added to functions with nocf_checks attribute.
-define i32 @func_nocf_checks() #0 {
+; Test that Control Flow Guard checks are not added on calls with the "guard_nocf" attribute.
+define i32 @func_guard_nocf() #0 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
   %0 = load i32 ()*, i32 ()** %func_ptr, align 8
-  %1 = call arm_aapcs_vfpcc i32 %0()
+  %1 = call arm_aapcs_vfpcc i32 %0() #1
   ret i32 %1
 
-  ; CHECK-LABEL: func_nocf_checks
+  ; CHECK-LABEL: func_guard_nocf
   ; CHECK:   movw r0, :lower16:target_func
 	; CHECK:   movt r0, :upper16:target_func
   ; CHECK-NOT:   __guard_check_icall_fptr
 	; CHECK:   blx r0
 }
-attributes #0 = { nocf_check "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #0 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #1 = { "guard_nocf" }
 
 
 ; Test that Control Flow Guard checks are added even at -O0.
-define i32 @func_optnone_cf() #1 {
+define i32 @func_optnone_cf() #2 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
@@ -47,11 +48,11 @@
 	; CHECK:   blx r1
 	; CHECK-NEXT:  blx r4
 }
-attributes #1 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
+attributes #2 = { noinline optnone "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
 
 
 ; Test that Control Flow Guard checks are correctly added in optimized code (common case).
-define i32 @func_cf() #2 {
+define i32 @func_cf() #0 {
 entry:
   %func_ptr = alloca i32 ()*, align 8
   store i32 ()* @target_func, i32 ()** %func_ptr, align 8
@@ -70,11 +71,10 @@
 	; CHECK:   blx r1
 	; CHECK-NEXT:  blx r4
 }
-attributes #2 = { "target-cpu"="cortex-a9" "target-features"="+armv7-a,+dsp,+fp16,+neon,+strict-align,+thumb-mode,+vfp3"}
 
 
 ; Test that Control Flow Guard checks are correctly added on invoke instructions.
-define i32 @func_cf_invoke() #2 personality i8* bitcast (void ()* @h to i8*) {
+define i32 @func_cf_invoke() #0 personality i8* bitcast (void ()* @h to i8*) {
 entry:
   %0 = alloca i32, align 4
   %func_ptr = alloca i32 ()*, align 8
@@ -112,7 +112,7 @@
 %struct._SETJMP_FLOAT128 = type { [2 x i64] }
 @buf1 = internal global [16 x %struct._SETJMP_FLOAT128] zeroinitializer, align 16
 
-define i32 @func_cf_setjmp() #2 {
+define i32 @func_cf_setjmp() #0 {
   %1 = alloca i32, align 4
   %2 = alloca i32, align 4
   store i32 0, i32* %1, align 4
Index: llvm/test/CodeGen/AArch64/cfguard-ch

[PATCH] D71612: [analyzer] Add PlacementNewChecker

2020-01-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D71612#1813937 , @martong wrote:

> I am going to execute the analysis on LLVM/Clang as you suggested, so then 
> we'll see what the experiment will bring us. And then we could enable it by 
> default I think. BTW how can we do that? I could not find any default 
> enablement related config in Checkers.td ...


Enabling checkers by default is controlled by the messy code in 
`RenderAnalyzerOptions()` in the Driver.

Wait, you already made it on-by-default. Checkers that are currently under 
development go into the `alpha` package.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71612



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


[PATCH] D72505: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 237338.
JonasToth added a comment.

- address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72505

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -715,6 +715,158 @@
 std::make_unique>("v", 4)));
 }
 
+TEST(ForEachArgumentWithParamType, ReportsNoFalsePositives) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  // IntParam does not match.
+  EXPECT_TRUE(notMatches("void f(int* i) { int* y; f(y); }", CallExpr));
+  // ArgumentY does not match.
+  EXPECT_TRUE(notMatches("void f(int i) { int x; f(x); }", CallExpr));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCXXMemberCallExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct S {"
+  "  const S& operator[](int i) { return *this; }"
+  "};"
+  "void f(S S1) {"
+  "  int y = 1;"
+  "  S1[y];"
+  "}",
+CallExpr, std::make_unique>("type", 1)));
+
+  StatementMatcher CallExpr2 =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct S {"
+  "  static void g(int i);"
+  "};"
+  "void f() {"
+  "  int y = 1;"
+  "  S::g(y);"
+  "}",
+CallExpr2, std::make_unique>("type", 1)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCallExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
+ std::make_unique>(
+   "type")));
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
+ std::make_unique>(
+   "arg")));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void f(int i, int j) { int y; f(y, y); }", CallExpr,
+std::make_unique>("type", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void f(int i, int j) { int y; f(y, y); }", CallExpr,
+std::make_unique>("arg", 2)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesConstructExpr) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher ConstructExpr =
+cxxConstructExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+ConstructExpr,
+std::make_unique>("type")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+ConstructExpr,
+std::make_unique>("arg")));
+}
+
+TEST(ForEachArgumentWithParamType, HandlesBoundNodesForNonMatches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+"void g(int i, int j) {"
+  "  int a;"
+  "  int b;"
+  "  int c;"
+  "  g(a, 0);"
+  "  g(a, b);"
+  "  g(0, b);"
+  "}",
+functionDecl(
+  forEachDescendant(varDecl().bind("v")),
+  forEachDescendant(callExpr(forEachArgumentWithParamType(
+declRefExpr(to(decl(equalsBoundNode("v", qualType(),
+std::make_unique>("v", 4)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesFunctionPtrCalls) {
+  StatementMatcher ArgumentY =
+declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(builtinType()).bind("type");
+  StatementMatcher CallExpr =
+callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) {"
+ "void (*f_ptr)(int) = f; int y; f_ptr(y); }",
+ CallExpr,
+ std::make_unique>("type")));
+  EXPECT_TRUE(
+matchAndVerifyResultTrue("void f(int i) {"
+ "void (*f_ptr)(int) = f; i

[PATCH] D72505: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked 3 inline comments as done.
JonasToth added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4243
+  if (FProto) {
+QualType ParamType = FProto->getParamType(ParamIndex);
+if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {

aaron.ballman wrote:
> Should we be canonicalizing this type as well?
I think here we shouldn't. In that case you could not match if e.g. the 
parameter has a typedef. I think that would reduce possibilities for the 
matcher usage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72505



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


[PATCH] D70568: [Support] Possibly use exception handler in the Crash Recovery Context in the same way as global exceptions

2020-01-10 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea marked an inline comment as done.
aganea added a comment.

Thanks for taking the time @hans!




Comment at: llvm/unittests/Support/CrashRecoveryTest.cpp:72
+  sys::RemoveFileOnSignal(Filename);
+  llvm::sys::AddSignalHandler(incrementGlobalWithCookie, nullptr);
+  GlobalInt = 0;

hans wrote:
> Is there a purpose to passing the pointer her, or could it just use 
> incrementGlobal? If we can't, maybe call it WithPointer or something instead 
> (or use an overload) - I was confused by the Cookie part until I realize you 
> just mean it takes some argument.
The cookie thing is because:
```
  using SignalHandlerCallback = void (*)(void *);

  /// Add a function to be called when an abort/kill signal is delivered to the
  /// process. The handler can have a cookie passed to it to identify what
  /// instance of the handler it is.
  void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie);
```
Sure, I'll change it to an overload.


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

https://reviews.llvm.org/D70568



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


[PATCH] D69825: [Clang][Driver] Re-use the calling process instead of creating a new process for the cc1 invocation

2020-01-10 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/tools/driver/driver.cpp:267
+
+  StringRef SpawnCC1Str = ::getenv("CLANG_SPAWN_CC1");
+  if (!SpawnCC1Str.empty()) {

aganea wrote:
> hans wrote:
> > Maybe just do the "!!" thing like for the environment variables above? It's 
> > not pretty, but at least that would be consistent, and it avoids the 
> > problem of deciding what values mean "on" and what mean "off".
> Not if we want to negate the `CLANG_SPAWN_CC1` compile-time flag initialized 
> just above. `!!::getenv` will only say the option is there, it won't say what 
> we should do. My rationale was, if the env variable is there, its value 
> overrides the compile-time flag. Unless we want something along the lines of 
> `CLANG_ENABLE_SPAWN_CC1` / `CLANG_DISABLE_SPAWN_CC1`?
Ah, I didn't think about that.

This feels a bit fragile though, for example if the user sets it to "yes" 
instead of "on", it won't be obvious that it has the opposite effect. What do 
you think about only supporting 1 and 0, and printing a helpful error for other 
values?

Also, the comparisons could be done with equals(_lower) instead of the compare 
methods.


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

https://reviews.llvm.org/D69825



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


[PATCH] D68720: Support -fstack-clash-protection for x86

2020-01-10 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

@craig.topper do you think there is a chance that this change could be part of 
clang-10 ?
Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68720



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


[PATCH] D72498: [clangd] Print underlying type for decltypes in hover

2020-01-10 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D72498#1814008 , @sammccall wrote:

> I think i'm also comfortable with marking the linked bug as wontfix.


The previous example is just minimal repo.

  template  
  auto sum(T1 &t1, T2 &t2) ->decltype(t1 + t2))
  {  
return t1 + t2;  
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72498



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


[PATCH] D71973: [clang-tidy] Add bugprone-suspicious-memory-comparison check

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:30
+ uint64_t ComparedBits, uint64_t &TotalSize) {
+  const auto IsNotEmptyBase = [](const CXXBaseSpecifier &Base) {
+return !Base.getType()->getAsCXXRecordDecl()->isEmpty();

Drop top-level `const` qualifiers on locals (it's not a style we typically 
use), elsewhere as well.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:82-83
+
+static bool hasPadding(const ASTContext &Ctx, const RecordDecl *RD,
+   uint64_t ComparedBits) {
+  assert(RD && RD->isCompleteDefinition() &&

I am surprised that we have to do this much manual work, I would have expected 
this to be something that `RecordLayout` would handle for us. I am a bit 
worried about this manual work being split in a few places because we're likely 
to get it wrong in at least one of them. For instance, this doesn't seem to be 
taking into account things like `[[no_unique_address]]` or alignment when 
considering the layout of fields.

I sort of wonder if we should try using the `RecordLayout` class to do this 
work instead, even if that requires larger changes.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:130
+const Type *PointeeType = ArgType->getPointeeOrArrayElementType();
+assert(PointeeType != nullptr && "PointeeType should always be 
available.");
+

Can you add a test case like this:
```
struct S {
  operator void *() const;
};

S s;
memcmp(s, s, sizeof(s));
```
to ensure that this assertion doesn't trigger?



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:133-134
+if (PointeeType->isRecordType()) {
+  const RecordDecl *RD = PointeeType->getAsRecordDecl()->getDefinition();
+  if (RD != nullptr) {
+if (const auto *CXXDecl = dyn_cast(RD)) {

Sink the declaration into the if conditional to limit its scope.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:140
+ "type %0; consider using a comparison operator instead")
+<< PointeeType->getAsTagDecl()->getQualifiedNameAsString();
+break;

You can pass in `PointeeType->getAsTagDecl()` -- the diagnostic printer will 
automatically get the correct name from any `NamedDecl`.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:148
+  "consider comparing the fields manually")
+  << PointeeType->getAsTagDecl()->getQualifiedNameAsString();
+  break;

Same here as above.


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

https://reviews.llvm.org/D71973



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


[PATCH] D72508: [clangd] Support pseudo-obj expr, opaque values, and property references in findExplicitReferences()

2020-01-10 Thread David Goldman via Phabricator via cfe-commits
dgoldman requested changes to this revision.
dgoldman added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:624
+  /*IsDecl=*/false,
+  // Select the getter, setter, or @property depending on the call.
+  explicitReferenceTargets(DynTypedNode::create(*E), {})});

Worth mentioning this is handled in `add()`'s `Visitor`'s 
`VisitObjCPropertyRefExpr`?



Comment at: clang-tools-extra/clangd/FindTarget.cpp:740
 
+  bool TraverseOpaqueValueExpr(OpaqueValueExpr *OVE) {
+visitNode(DynTypedNode::create(*OVE));

Worth noting that these two functions are used currently for ObjC?



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:978
+void foo() {
+  $0^f.$1^x.$2^y = 0;
+}

Would also be good to have a test for implicit property refs (e.g `- (int)z; 
obj.z;`) Or maybe this should go in the other diff?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72508



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


[PATCH] D72494: [clangd] Fix targetDecl() on certain usage of ObjC properties.

2020-01-10 Thread David Goldman via Phabricator via cfe-commits
dgoldman accepted this revision.
dgoldman added a comment.

LGMT, thanks for fixing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72494



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


[PATCH] D72505: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a testing request.




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4243
+  if (FProto) {
+QualType ParamType = FProto->getParamType(ParamIndex);
+if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {

JonasToth wrote:
> aaron.ballman wrote:
> > Should we be canonicalizing this type as well?
> I think here we shouldn't. In that case you could not match if e.g. the 
> parameter has a typedef. I think that would reduce possibilities for the 
> matcher usage.
Okay, that's a good point!



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:868
+std::make_unique>("arg")));
+}
+

I would like to see one K&R C test case just to be sure we're not doing 
anything horrible:
```
void f();
void call_it_1(void) { f(1.0f, 2.0f); } // Especially curious about type 
promotions

void f(a, b) float a, b; { }
void call_it_2(void) { f(1.0f, 2.0f); } // And if they differ here (IIRC, we 
may have a bug here in the compiler)
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72505



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


[PATCH] D68720: Support -fstack-clash-protection for x86

2020-01-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:2254
+CGM.getDiags().Report(S.getAsmLoc(),
+  diag::warn_fe_stack_clash_protection_inline_asm);
+  }

serge-sans-paille wrote:
> craig.topper wrote:
> > Why is this in the frontend diagnostic list?
> As far as I understand, that's the only place where line/col accurate 
> diagnostics are emitted.
I was really asking about why we have to use FrontendDiagnostic.h and 
DriverDiagnostic.h? Is that what we normally use for diagnostics in Codegen 
files? Seems like a possible layering issue for modules build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68720



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 237345.
JonasToth added a comment.

- test if references to pointers are ignored if pointers are ignored as values
- add different possible auto constellations
- document the problematic cases for 'auto' deductions

I think a first pass of review might make sense now. I isolated the problematic
'auto' cases and added tests for them in clang-tidy. It turns out, that they
are only bad if they deduce to a reference to a template-type/typedef to a
template type.
In good faith, that this is somehow detectable in code, i think all known
false positives can be addressed.
Even though I hope this to land until the branch point, I don't want to pressure
reviewers or so (i chatted with aaron about it)! If the patch is not good enough
or has any outstanding issues, I will of course address them and land it later. 
:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -62,13 +62,18 @@
   const auto *const S = selectFirst("stmt", Results);
   SmallVector Chain;
   ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
+
+  std::string buffer;
   for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
 const Stmt *By = Analyzer.findMutation(E);
-std::string buffer;
+if (!By)
+  break;
+
 llvm::raw_string_ostream stream(buffer);
 By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
-Chain.push_back(StringRef(stream.str()).trim().str());
+Chain.emplace_back(StringRef(stream.str()).trim().str());
 E = dyn_cast(By);
+buffer.clear();
   }
   return Chain;
 }
@@ -382,22 +387,26 @@
   "void g(const int&&); void f() { int x; g(static_cast(x)); }");
   auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("struct A {}; A operator+(const A&&, int);"
  "void f() { A x; static_cast(x) + 1; }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("void f() { struct A { A(const int&&); }; "
  "int x; A y(static_cast(x)); }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 
   AST = buildASTFromCode("void f() { struct A { A(); A(const A&&); }; "
  "A x; A y(static_cast(x)); }");
   Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
-  EXPECT_FALSE(isMutated(Results, AST.get()));
+  EXPECT_THAT(mutatedBy(Results, AST.get()),
+  ElementsAre("static_cast(x)"));
 }
 
 TEST(ExprMutationAnalyzerTest, Move) {
@@ -567,7 +576,7 @@
   const auto Results =
   match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
   EXPECT_THAT(mutatedBy(Results, AST.get()),
-  ElementsAre("return static_cast(x);"));
+  ElementsAre("static_cast(x)"));
 }
 
 TEST(ExprMutationAnalyzerTest, ReturnAsConstRRef) {
@@ -575,7 +584,8 @@
   "const int&& f() { int x; return static_cast(x); }");
   const au

[clang] 5e7beb0 - [analyzer] Add PlacementNewChecker

2020-01-10 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-01-10T17:59:06+01:00
New Revision: 5e7beb0a4146267f1d65c57543e67ca158aca4aa

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

LOG: [analyzer] Add PlacementNewChecker

Summary:
This checker verifies if default placement new is provided with pointers
to sufficient storage capacity.

Noncompliant Code Example:
  #include 
  void f() {
short s;
long *lp = ::new (&s) long;
  }

Based on SEI CERT rule MEM54-CPP
https://wiki.sei.cmu.edu/confluence/display/cplusplus/MEM54-CPP.+Provide+placement+new+with+properly+aligned+pointe
This patch does not implement checking of the alignment.

Reviewers: NoQ, xazax.hun

Subscribers: mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet,
rnkovacs, a.sidorin, mikhail.ramalho, donat

Tags: #clang

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

Added: 
clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
clang/test/Analysis/placement-new-user-defined.cpp
clang/test/Analysis/placement-new.cpp

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 34d29ba344c9..dd2365e873fd 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -292,6 +292,20 @@ Check for memory leaks. Traces memory managed by 
new/delete.
int *p = new int;
  } // warn
 
+.. _cplusplus-PlacementNewChecker:
+
+cplusplus.PlacementNewChecker (C++)
+"""
+Check if default placement new is provided with pointers to sufficient storage 
capacity.
+
+.. code-block:: cpp
+
+ #include 
+
+ void f() {
+   short s;
+   long *lp = ::new (&s) long; // warn
+ }
 
 .. _cplusplus-SelfAssignment:
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 6d68d8215597..fc1529f2ea1c 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -470,6 +470,12 @@ def NewDeleteLeaksChecker : Checker<"NewDeleteLeaks">,
   Dependencies<[NewDeleteChecker]>,
   Documentation;
 
+def PlacementNewChecker : Checker<"PlacementNew">,
+  HelpText<"Check if default placement new is provided with pointers to "
+   "sufficient storage capacity">,
+  Dependencies<[NewDeleteChecker]>,
+  Documentation;
+
 def CXXSelfAssignmentChecker : Checker<"SelfAssignment">,
   HelpText<"Checks C++ copy and move assignment operators for self 
assignment">,
   Documentation,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index f9c4757c3ca8..936a3eacc1eb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -19,6 +19,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
+  CheckPlacementNew.cpp
   CheckSecuritySyntaxOnly.cpp
   CheckSizeofPointer.cpp
   CheckerDocumentation.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
new file mode 100644
index ..6fe3cb63cde9
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
@@ -0,0 +1,119 @@
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/FormatVariadic.h"
+
+using namespace clang;
+using namespace ento;
+
+class PlacementNewChecker : public Checker> {
+public:
+  void checkPreStmt(const CXXNewExpr *NE, CheckerContext &C) const;
+
+private:
+  // Returns the size of the target in a placement new expression.
+  // E.g. in "new (&s) long" it returns the size of `long`.
+  SVal getExtentSizeOfNewTarget(const CXXNewExpr *NE, ProgramStateRef State,
+CheckerContext &C) const;
+  // Returns the size of the place in a placement new expression.
+  // E.g. in "new (&s) long" it returns the size of `s`.
+  SVal getExtentSizeOfPlace(const Expr *NE, ProgramStateRef State,
+CheckerContext &C) const;
+  BugType BT{this, "Insufficient storage for placement new",
+ categories::MemoryError};
+};
+
+SVal PlacementNewChecker::getExtentSizeOfPlace(const Expr *Place,
+   ProgramStateRef State,
+   CheckerContext &C) const {
+  const MemRegion *MRegion = C.getSVal(Place).g

[PATCH] D72378: [clang-tidy] Add `bugprone-reserved-identifier`

2020-01-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D72378#1812620 , @logan-5 wrote:

> In D72378#1810763 , @aaron.ballman 
> wrote:
>
> > This check is missing a whole lot of reserved identifiers. For instance, in 
> > C++ it is missing everything from http://eel.is/c++draft/zombie.names and 
> > for C it is missing everything from future library directions. Are you 
> > intending to cover those cases as well?
>
>
> I admit that those are outside the scope of what I had originally planned for 
> this check -- I was primarily concerned about 'uglified' names, and writing a 
> check that was 'invertible' in that regard. Now that you mention these, 
> though, I do feel like this check doesn't live up to its name without 
> including them.
>
> I'd be interested in incorporating them. It doesn't sound difficult, but it 
> does sound like it'd be a sizable addition to this diff. Still familiarizing 
> with the workflow around here... would it be alright to leave a TODO comment 
> in this patch and add them in an upcoming patch, to keep this one more 
> self-contained?


I would be fine putting a TODO in the code and addressing it in a follow-up 
patch. It's not critical for the initial offering.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp:121
+return Info;
+  } else {
+if (!(hasReservedDoubleUnderscore(Name, LangOpts) ||

Sorry, I missed this before -- you can drop the `else` as well -- we don't use 
`else` after an unconditional `return` as part of our usual style guidelines.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp:152-161
+  Failure.Info.KindName == "non-reserved"
+  ? "declaration uses identifier '%0', which is not a reserved "
+"identifier"
+  : Failure.Info.KindName == "global-under"
+? "declaration uses identifier '%0', which is reserved in "
+  "the global "
+  "namespace; this causes undefined behavior"

Rather than use a complex conditional, I would prefer to see some string 
constants and a variable. It's a bit hard to reason about the diagnostic text 
as-is.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-reserved-identifier.rst:31
+namespace.
+
+Options

You should probably add some links here back to the CERT checks with some words 
like "this check also covers the following CERT secure coding guidelines" or 
somesuch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72378



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


[PATCH] D71612: [analyzer] Add PlacementNewChecker

2020-01-10 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e7beb0a4146: [analyzer] Add PlacementNewChecker (authored 
by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71612

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/test/Analysis/placement-new-user-defined.cpp
  clang/test/Analysis/placement-new.cpp

Index: clang/test/Analysis/placement-new.cpp
===
--- /dev/null
+++ clang/test/Analysis/placement-new.cpp
@@ -0,0 +1,141 @@
+// RUN: %clang_analyze_cc1 -std=c++11 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=cplusplus.NewDelete \
+// RUN:   -analyzer-checker=cplusplus.PlacementNew \
+// RUN:   -analyzer-output=text -verify \
+// RUN:   -triple x86_64-unknown-linux-gnu
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void f() {
+  short s;// expected-note {{'s' declared without an initial value}}
+  long *lp = ::new (&s) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
+  (void)lp;
+}
+
+namespace testArrayNew {
+void f() {
+  short s;// expected-note {{'s' declared without an initial value}}
+  char *buf = ::new (&s) char[8]; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 3 {{}}
+  (void)buf;
+}
+} // namespace testArrayNew
+
+namespace testBufferInOtherFun {
+void f(void *place) {
+  long *lp = ::new (place) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+void g() {
+  short buf; // expected-note {{'buf' declared without an initial value}}
+  f(&buf);   // expected-note 2 {{}}
+}
+} // namespace testBufferInOtherFun
+
+namespace testArrayBuffer {
+void f(void *place) {
+  long *lp = ::new (place) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+void g() {
+  char buf[2]; // expected-note {{'buf' initialized here}}
+  f(&buf); // expected-note 2 {{}}
+}
+} // namespace testArrayBuffer
+
+namespace testGlobalPtrAsPlace {
+void *gptr = nullptr;
+short gs;
+void f() {
+  gptr = &gs; // expected-note {{Value assigned to 'gptr'}}
+}
+void g() {
+  f();  // expected-note 2 {{}}
+  long *lp = ::new (gptr) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testGlobalPtrAsPlace
+
+namespace testRvalue {
+short gs;
+void *f() {
+  return &gs;
+}
+void g() {
+  long *lp = ::new (f()) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testRvalue
+
+namespace testNoWarning {
+void *f();
+void g() {
+  long *lp = ::new (f()) long;
+  (void)lp;
+}
+} // namespace testNoWarning
+
+namespace testPtrToArrayAsPlace {
+void f() {
+  //char *st = new char [8];
+  char buf[3];// expected-note {{'buf' initialized here}}
+  void *st = buf; // expected-note {{'st' initialized here}}
+  long *lp = ::new (st) long; // expected-warning{{Storage provided to placement new is only 3 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testPtrToArrayAsPlace
+
+namespace testPtrToArrayWithOffsetAsPlace {
+void f() {
+  int buf[3];  // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf + 2) long; // expected-warning{{Storage provided to placement new is only 4 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testPtrToArrayWithOffsetAsPlace
+
+namespace testHeapAllocatedBuffer {
+void g2() {
+  char *buf = new char[2]; // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf) long; // expected-warning{{Storage provided to placement new is only 2 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testHeapAllocatedBuffer
+
+namespace testMultiDimensionalArray {
+void f() {
+  char buf[2][3];  // expected-note {{'buf' initialized here}}
+  long *lp = ::new (buf) long; // expected-warning{{Storage provided to placement new is only 6 bytes, whereas the allocated type requires 8 bytes}} expected-note 1 {{}}
+  (void)lp;
+}
+} // namespace testMultiDimensionalArray
+
+namespace testMultiDime

  1   2   3   >