[PATCH] D75022: clang-format: Extend AllowShortLoopsOnASingleLine to do ... while loops.

2020-02-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I think its look good, please add the extra tests, then lets give people a 
couple of days




Comment at: unittests/Format/FormatTest.cpp:570
+   AllowsMergedLoops);
 }
 

horrible code though they are, could you add a test for the label and comment 
case

```
do
label:
a++
white(true);
```

and

```
do
// comment
a++
white(true);
```


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

https://reviews.llvm.org/D75022



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


[PATCH] D75034: [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation

2020-02-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I tend to agree with your assessment, I think its worth waiting for some others 
to comment.




Comment at: clang/unittests/Format/FormatTest.cpp:10293
Tab));
-  EXPECT_EQ("/*\n"
-"\t  a\t\tcomment\n"

fickert wrote:
> MyDeveloperDay wrote:
> > Sorry this isn't clear to be which test this is a duplicate of, as this is 
> > an example where there are tabs in the comment and trailing tabs
> This test case is identical to the one in line 10182-10190. There are several 
> test cases that appear multiple times, but usually with changes to the 
> formatting settings in between. This is not the case for these two test cases 
> (no changes in between), so this one seems to be obsolete.
thank you for highlighting that.


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

https://reviews.llvm.org/D75034



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


[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D69560#1890026 , @aaron.ballman 
wrote:

> In D69560#1889925 , @vingeldal wrote:
>
> > Doesn't clang-tidy exclude warnings from system headers by default though?
>
>
> Third-party SDKs are not always brought in as system headers, unfortunately. 
> Even ignoring system and third-party headers, having two parameters of the 
> same type is a natural occurrence for some data types (like `bool`) where it 
> is going to be extremely hard to tell whether they're related or unrelated 
> parameters.


I have specifically applied the matcher in this patch in a way that it only 
matches for the **definition** of the function symbol. If you never create a 
build database out of the third party "package" and run the check on the 
third-party library's source code, you will not get a warning for these.

While it's //somewhat// wonky that an "interface" rule is matching the 
"implementation" nodes, it is a natural restriction to only warn the user about 
things they have a reliable way of fixing. Hopefully, they will not forget to 
align their headers after potentially fixing the implementation code.


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

https://reviews.llvm.org/D69560



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


[PATCH] D75106: [clangd] Fix early selection for non-vardecl declarators

2020-02-25 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.

Selection tree was performing an early claim only for VarDecls, but
there are other cases where we can have declarators, e.g. FieldDecls. This patch
extends the early claim logic to all types of declarators.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75106

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -369,6 +369,17 @@
 int test(I *f) { return 42 + [[f.^foo]]; }
   )cpp",
   "ObjCPropertyRefExpr"},
+  {
+  R"cpp(
+// We've got this nice trick, as annotation library eagerly selects
+// the range and if we've got [32] below, there's no way to select
+// the full range.
+#define X [32]
+struct foo {
+  [[int has^h X]];
+};
+  )cpp",
+  "FieldDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -10,6 +10,7 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -602,12 +603,15 @@
   // Usually empty, but sometimes children cover tokens but shouldn't own them.
   SourceRange earlySourceRange(const DynTypedNode &N) {
 if (const Decl *D = N.get()) {
+  // FunctionDecl is also a DeclaratorDecl, but getLocation doesn't work 
for
+  // operator overloads, e.g. operator [[int]](); Therefore we handle them
+  // explicitly.
   // void [[foo]]();
   if (auto *FD = llvm::dyn_cast(D))
 return FD->getNameInfo().getSourceRange();
   // int (*[[s]])();
-  else if (auto *VD = llvm::dyn_cast(D))
-return VD->getLocation();
+  if (auto *DD = llvm::dyn_cast(D))
+return DD->getLocation();
 } else if (const auto* CCI = N.get()) {
   // : [[b_]](42)
   return CCI->getMemberLocation();


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -369,6 +369,17 @@
 int test(I *f) { return 42 + [[f.^foo]]; }
   )cpp",
   "ObjCPropertyRefExpr"},
+  {
+  R"cpp(
+// We've got this nice trick, as annotation library eagerly selects
+// the range and if we've got [32] below, there's no way to select
+// the full range.
+#define X [32]
+struct foo {
+  [[int has^h X]];
+};
+  )cpp",
+  "FieldDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -10,6 +10,7 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -602,12 +603,15 @@
   // Usually empty, but sometimes children cover tokens but shouldn't own them.
   SourceRange earlySourceRange(const DynTypedNode &N) {
 if (const Decl *D = N.get()) {
+  // FunctionDecl is also a DeclaratorDecl, but getLocation doesn't work for
+  // operator overloads, e.g. operator [[int]](); Therefore we handle them
+  // explicitly.
   // void [[foo]]();
   if (auto *FD = llvm::dyn_cast(D))
 return FD->getNameInfo().getSourceRange();
   // int (*[[s]])();
-  else if (auto *VD = llvm::dyn_cast(D))
-return VD->getLocation();
+  if (auto *DD = llvm::dyn_cast(D))
+return DD->getLocation();
 } else if (const auto* CCI = N.get()) {
   // : [[b_]](42)
   return CCI->getMemberLocation();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D69560#1889925 , @vingeldal wrote:

> I think this value very well may strike a good balance in that compromise but 
> I still think it is a clear deviation from the guideline as specified.
>  IMO all deviations from the guideline should be explicitly requested by the 
> user, not set by default, no matter how useful that deviation is.


While I am still planning to compile a measurement with potentially tagging 
false and true positives -- albeit classifying this on random projects I have 
no domain knowledge about is hard at first glance...

@aaron.ballman Could it be a useful compromise to //not// say we are trying to 
solve the `cppcoreguidelines-` rule, but rather introduce this checker in 
another "namespace" and maybe mention in the docs that it could, although with 
caveats, apply "parts" of the Core Guidelines rule?


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

https://reviews.llvm.org/D69560



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


[PATCH] D75107: [clang-tidy] hicpp-signed-bitwise IgnorePositiveIntegerLiterals now partially recursive

2020-02-25 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, alexfh, hokein, JonasToth.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Addresses hicpp-signed-bitwise.IgnorePositiveIntegerLiterals should be 
recursive. 
Only recursive for `|`, `^` and `&` operations and their assignment 
counterparts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75107

Files:
  clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
@@ -21,6 +21,11 @@
   IResult = Int << 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
   IResult = ~0; //Ok
+
+  IResult = 2 | 4 | 8;
+  IResult = 2 | 4 | 8 | 16;
+  IResult = 2 | 4 | 8 | 16 | -1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand 
with a binary bitwise operator
 }
 
 enum EnumConstruction {
Index: clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
===
--- clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
+++ clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
@@ -46,15 +46,24 @@
  "::std::ios_base::openmode"));
   const auto IsStdBitmask = 
ignoringImpCasts(declRefExpr(hasType(BitmaskType)));
 
+  const auto SignNoInterferenceOp =
+  hasAnyOperatorName("^", "^=", "|", "|=", "&", "&=");
+
+  const auto SignedIntegerOperandExtended =
+  (IgnorePositiveIntegerLiterals
+   ? expr(ignoringImpCasts(hasType(isSignedInteger())),
+  unless(anyOf(integerLiteral(),
+   binaryOperator(SignNoInterferenceOp
+   : expr(ignoringImpCasts(hasType(isSignedInteger()
+  .bind("signed-operand");
+
   // Match binary bitwise operations on signed integer arguments.
   Finder->addMatcher(
-  binaryOperator(anyOf(hasOperatorName("^"), hasOperatorName("|"),
-   hasOperatorName("&"), hasOperatorName("^="),
-   hasOperatorName("|="), hasOperatorName("&=")),
+  binaryOperator(SignNoInterferenceOp,
 
  unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
 
- hasEitherOperand(SignedIntegerOperand),
+ hasEitherOperand(SignedIntegerOperandExtended),
  hasLHS(hasType(isInteger())), 
hasRHS(hasType(isInteger(
   .bind("binary-no-sign-interference"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/hicpp-signed-bitwise-integer-literals.cpp
@@ -21,6 +21,11 @@
   IResult = Int << 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
   IResult = ~0; //Ok
+
+  IResult = 2 | 4 | 8;
+  IResult = 2 | 4 | 8 | 16;
+  IResult = 2 | 4 | 8 | 16 | -1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator
 }
 
 enum EnumConstruction {
Index: clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
===
--- clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
+++ clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp
@@ -46,15 +46,24 @@
  "::std::ios_base::openmode"));
   const auto IsStdBitmask = ignoringImpCasts(declRefExpr(hasType(BitmaskType)));
 
+  const auto SignNoInterferenceOp =
+  hasAnyOperatorName("^", "^=", "|", "|=", "&", "&=");
+
+  const auto SignedIntegerOperandExtended =
+  (IgnorePositiveIntegerLiterals
+   ? expr(ignoringImpCasts(hasType(isSignedInteger())),
+  unless(anyOf(integerLiteral(),
+   binaryOperator(SignNoInterferenceOp
+   : expr(ignoringImpCasts(hasType(isSignedInteger()
+  .bind("signed-operand");
+
   // Match binary bitwise operations on signed integer arguments.
   Finder->addMatcher(
-  binaryOperator(anyOf(hasOperatorName("^"), hasOperatorName("|"),
-   hasOperatorName("&"), hasOperatorName("^="),
-   hasOperatorName("|="), hasOperatorName("&=")),
+  binaryOperator(SignNoInterferenceOp,
 
  unless(

Re: [PATCH] D69876: Support output constraints on "asm goto"

2020-02-25 Thread Yvan Roux via cfe-commits
Hi Bill,

This commit broke AArch64 bots, logs are available here:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/22291/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Auninit-asm-goto.cpp

Thanks
Yvan

On Tue, 25 Feb 2020 at 04:01, Bill Wendling via Phabricator via
llvm-commits  wrote:
>
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rG50cac248773c: Support output constraints on "asm 
> goto" (authored by void).
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D69876/new/
>
> https://reviews.llvm.org/D69876
>
> Files:
>   clang/docs/LanguageExtensions.rst
>   clang/include/clang/AST/Stmt.h
>   clang/include/clang/Basic/Features.def
>   clang/lib/AST/Stmt.cpp
>   clang/lib/Analysis/UninitializedValues.cpp
>   clang/lib/CodeGen/CGStmt.cpp
>   clang/lib/Parse/ParseStmtAsm.cpp
>   clang/lib/Sema/SemaStmtAsm.cpp
>   clang/test/Analysis/uninit-asm-goto.cpp
>   clang/test/CodeGen/asm-goto.c
>   clang/test/Parser/asm-goto.c
>   clang/test/Parser/asm-goto.cpp
>   clang/test/Sema/asm-goto.cpp
>
> ___
> llvm-commits mailing list
> llvm-comm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75106: [clangd] Fix early selection for non-vardecl declarators

2020-02-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Selection.cpp:613
   // int (*[[s]])();
-  else if (auto *VD = llvm::dyn_cast(D))
-return VD->getLocation();
+  if (auto *DD = llvm::dyn_cast(D))
+return DD->getLocation();

I think we can combine these two cases.
The weird cases handled by FunctionDecl are actually a bit wrong at the moment 
(early claiming types).
 - conversion operator: we should probably be claiming `operator` only, which 
hapepns to be getLocation()
 - destructor: we should be claiming ~ only, which is also getLocation()
 - constructor: we shouldn't be claiming anything, need to blacklist
 - all the others seem fine to be handled by the DeclaratorDecl case

This changes more behaviour (and the changes are likely to be seen as 
regressions in some cases, though more consistent) so we could also consider 
just landing this as-is.



Comment at: clang-tools-extra/clangd/unittests/SelectionTests.cpp:374
+  R"cpp(
+// We've got this nice trick, as annotation library eagerly selects
+// the range and if we've got [32] below, there's no way to select

I'd suggest using digraphs instead, if it works:

`int hash<:32:>`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75106



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


[libclc] 814fb65 - libclc: cmake configure should depend on file list

2020-02-25 Thread Jan Vesely via cfe-commits

Author: Jan Vesely
Date: 2020-02-25T04:43:14-05:00
New Revision: 814fb658ca262f5c2df47f11d47f91fac188e0d6

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

LOG: libclc: cmake configure should depend on file list

This makes sure targets are rebuilt if a file is added or removed.
Reviewer: tstellar
Differential Revision: https://reviews.llvm.org/D74662

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 440eab076509..4afed0d8f994 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -2,6 +2,16 @@ cmake_minimum_required( VERSION 3.9.2 )
 
 project( libclc VERSION 0.2.0 LANGUAGES CXX )
 include( GNUInstallDirs )
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
+  amdgcn-amdhsa/lib/SOURCES;
+  amdgcn/lib/SOURCES;
+  amdgcn-mesa3d/lib/SOURCES;
+  amdgpu/lib/SOURCES;
+  generic/lib/SOURCES;
+  ptx/lib/SOURCES;
+  ptx-nvidiacl/lib/SOURCES;
+  r600/lib/SOURCES
+)
 
 # List of all targets
 set( LIBCLC_TARGETS_ALL



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


[PATCH] D75053: [clangd] Disable ExtractVariable for C

2020-02-25 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/refactor/tweaks/ExtractVariable.cpp:453
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable C (and maybe objective-c) once we start spelling types
+  // explicitly instead of making use of auto.

I think "non-C++" would be clearer, and don't mention obj-c at all.
Formally C++ is independent of whether obj-c is enabled, and that's relevant 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75053



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


[PATCH] D71018: [ASTImporter] Improved import of TypeSourceInfo (TypeLoc)

2020-02-25 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

My only problem is the reimplementation of the default visit methods with (from 
what I can tell) the same behavior as the default. If you delete all of these 
then that would also fix Shafik's point that all the custom dispatch code is 
technically untested in the unit test (I think not testing the dispatch code 
from the TypeLocVisitor is fine).




Comment at: clang/lib/AST/ASTImporter.cpp:8133
+  Error VisitTypedefTypeLoc(TypedefTypeLoc From) {
+return VisitTypeSpecTypeLoc(From);
+  }

I know the ASTImporter is doing these reimplementation of the default visitor 
behavior quite often, but I feel in this case it would be much more readable to 
omit all these default implementations and just let the TypeLocVisitor do the 
dispatch to parent class logic. Especially since from what I understand it's 
unlikely that we need custom logic for all these TypeLoc subclasses in the 
future? It would also make this code less fragile in case the inheritance 
hierarchy every gets another intermediate class that might require special 
handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71018



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


[clang] 9fd7ce7 - [analyzer][MallocChecker][NFC] Communicate the allocation family to auxiliary functions with parameters

2020-02-25 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2020-02-25T11:17:32+01:00
New Revision: 9fd7ce7f4449619bc85ab4d2643e656836a2d5e2

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

LOG: [analyzer][MallocChecker][NFC] Communicate the allocation family to 
auxiliary functions with parameters

The following series of refactoring patches aim to fix the horrible mess that 
MallocChecker.cpp is.

I genuinely hate this file. It goes completely against how most of the checkers
are implemented, its by far the biggest headache regarding checker dependencies,
checker options, or anything you can imagine. On top of all that, its just bad
code. Its seriously everything that you shouldn't do in C++, or any other
language really. Bad variable/class names, in/out parameters... Apologies, rant
over.

So: there are a variety of memory manipulating function this checker models. One
aspect of these functions is their AllocationFamily, which we use to distinguish
between allocation kinds, like using free() on an object allocated by operator
new. However, since we always know which function we're actually modeling, in
fact we know it compile time, there is no need to use tricks to retrieve this
information out of thin air n+1 function calls down the line. This patch changes
many methods of MallocChecker to take a non-optional AllocationFamily template
parameter (which also makes stack dumps a bit nicer!), and removes some no
longer needed auxiliary functions.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h 
b/clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
index 9642588d6a41..99731d6044a0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
+++ b/clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
@@ -11,13 +11,19 @@
 
 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_INTERCHECKERAPI_H
 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_INTERCHECKERAPI_H
-namespace clang {
-class CheckerManager;
 
+// FIXME: This file goes against how a checker should be implemented either in
+// a single file, or be exposed in a header file. Let's try to get rid of it!
+
+namespace clang {
 namespace ento {
 
+class CheckerManager;
+
 /// Register the part of MallocChecker connected to InnerPointerChecker.
 void registerInnerPointerCheckerAux(CheckerManager &Mgr);
 
-}}
+} // namespace ento
+} // namespace clang
+
 #endif /* INTERCHECKERAPI_H_ */

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 1d365bb727fd..fd3ce6cf3b9b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -44,13 +44,14 @@
 //
 
//===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "AllocationState.h"
 #include "InterCheckerAPI.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -64,7 +65,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
-#include "AllocationState.h"
+#include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
 
@@ -72,7 +73,10 @@ using namespace clang;
 using namespace ento;
 
 
//===--===//
-// The types of allocation we're modeling.
+// The types of allocation we're modeling. This is used to check whether a
+// dynamically allocated object is deallocated with the correct function, like
+// not using operator delete on an object created by malloc(), or alloca 
regions
+// aren't ever deallocated manually.
 
//===--===//
 
 namespace {
@@ -92,22 +96,14 @@ struct MemFunctionInfoTy;
 
 } // end of anonymous namespace
 
-/// Determine family of a deallocation expression.
-static AllocationFamily
-getAllocationFamily(const MemFunctionInfoTy &MemFunctionInfo, CheckerContext 
&C,
-const Stmt *S);
-
 /// Print names of allocators and deallocators.
 ///
 /// \returns true on success.
-static bool printAllocDeallocName(raw_ostream &os, CheckerContext &C,
-  const Expr

[PATCH] D71018: [ASTImporter] Improved import of TypeSourceInfo (TypeLoc)

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:3281
 
+  // Import the function parameters.
+  SmallVector Parameters;

shafik wrote:
> I am curious, why move this chunk of code up?
See comments at line 8238?



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5850
+
+TEST_P(ImportTypeLoc, Function) {
+  Decl *FromTU = getTuDecl(

shafik wrote:
> Maybe I am missing it but these tests don't seem like they cover all the 
> visit methods of `TypeLocImporter`.
It could be useful to add some kind of generic imported AST similarity tests. 
These can test for things that should match in the imported and original AST, 
for example source locations.
(The AST does not always match after import but often.) Such a test can catch 
many import errors with objects that have no specific test.
The test in https://reviews.llvm.org/D60463 is somewhat similar but it uses 
text dump of the AST, this can be improved. Actually that test was used to 
discover the import problems of `SourceLocation` and `TypeSourceInfo`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71018



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


[PATCH] D68162: [analyzer][MallocChecker][NFC] Communicate the allocation family to auxiliary functions with parameters

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9fd7ce7f4449: [analyzer][MallocChecker][NFC] Communicate the 
allocation family to auxiliary… (authored by Szelethus).
Herald added subscribers: martong, steakhal.

Changed prior to commit:
  https://reviews.llvm.org/D68162?vs=222781&id=246390#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68162

Files:
  clang/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -44,13 +44,14 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "AllocationState.h"
 #include "InterCheckerAPI.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -64,7 +65,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
-#include "AllocationState.h"
+#include "llvm/Support/ErrorHandling.h"
 #include 
 #include 
 
@@ -72,7 +73,10 @@
 using namespace ento;
 
 //===--===//
-// The types of allocation we're modeling.
+// The types of allocation we're modeling. This is used to check whether a
+// dynamically allocated object is deallocated with the correct function, like
+// not using operator delete on an object created by malloc(), or alloca regions
+// aren't ever deallocated manually.
 //===--===//
 
 namespace {
@@ -92,22 +96,14 @@
 
 } // end of anonymous namespace
 
-/// Determine family of a deallocation expression.
-static AllocationFamily
-getAllocationFamily(const MemFunctionInfoTy &MemFunctionInfo, CheckerContext &C,
-const Stmt *S);
-
 /// Print names of allocators and deallocators.
 ///
 /// \returns true on success.
-static bool printAllocDeallocName(raw_ostream &os, CheckerContext &C,
-  const Expr *E);
+static bool printMemFnName(raw_ostream &os, CheckerContext &C, const Expr *E);
 
-/// Print expected name of an allocator based on the deallocator's
-/// family derived from the DeallocExpr.
-static void printExpectedAllocName(raw_ostream &os,
-   const MemFunctionInfoTy &MemFunctionInfo,
-   CheckerContext &C, const Expr *E);
+/// Print expected name of an allocator based on the deallocator's family
+/// derived from the DeallocExpr.
+static void printExpectedAllocName(raw_ostream &os, AllocationFamily Family);
 
 /// Print expected name of a deallocator based on the allocator's
 /// family.
@@ -208,7 +204,7 @@
 /// value; if unspecified, the value of expression \p E is used.
 static ProgramStateRef MallocUpdateRefState(CheckerContext &C, const Expr *E,
 ProgramStateRef State,
-AllocationFamily Family = AF_Malloc,
+AllocationFamily Family,
 Optional RetVal = None);
 
 //===--===//
@@ -402,7 +398,7 @@
   /// Process C++ operator new()'s allocation, which is the part of C++
   /// new-expression that goes before the constructor.
   void processNewAllocation(const CXXNewExpr *NE, CheckerContext &C,
-SVal Target) const;
+SVal Target, AllocationFamily Family) const;
 
   /// Perform a zero-allocation check.
   ///
@@ -450,7 +446,7 @@
   static ProgramStateRef MallocMemAux(CheckerContext &C, const CallExpr *CE,
   const Expr *SizeEx, SVal Init,
   ProgramStateRef State,
-  AllocationFamily Family = AF_Malloc);
+  AllocationFamily Family);
 
   /// Models memory allocation.
   ///
@@ -464,7 +460,7 @@
   static ProgramStateRef MallocMemAux(CheckerContext &C, const CallExpr *CE,
   SVal Size, SVal Init,
   ProgramStateRef State,
-  AllocationFam

[PATCH] D75048: [ASTImporter] Improved import of AlignedAttr.

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 246392.
balazske added a comment.

- Do not call AlignedAttr::Create with same parameters at 2 places. I think the 
code duplication was near to each other and only 2 instances that is not a big 
problem, anyway now it is a bit better.
- Improved the comment in the test and added some new checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75048

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5887,6 +5887,41 @@
   EXPECT_FALSE(ToSM.isBeforeInTranslationUnit(Location2, Location1));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
+  // Test if import of these packed and aligned attributes does not trigger an
+  // error situation where source location from 'From' context is referenced in
+  // 'To' context through evaluation of the alignof attribute.
+  // This happens if the 'alignof(A)' expression is not imported correctly.
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct __attribute__((packed)) A { int __attribute__((aligned(8))) X; };
+  struct alignas(alignof(A)) S {};
+  )",
+  Lang_CXX11, "input.cc");
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("S"), unless(isImplicit(;
+  ASSERT_TRUE(FromD);
+
+  auto *ToD = Import(FromD, Lang_CXX11);
+  ASSERT_TRUE(ToD);
+
+  auto *FromAttr = FromD->getAttr();
+  auto *ToAttr = ToD->getAttr();
+  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
+  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
+  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
+  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
+  EXPECT_EQ(FromAttr->getSemanticSpelling(), ToAttr->getSemanticSpelling());
+  EXPECT_TRUE(ToAttr->getAlignmentExpr());
+
+  auto *ToA = FirstDeclMatcher().match(
+  ToD->getTranslationUnitDecl(),
+  cxxRecordDecl(hasName("A"), unless(isImplicit(;
+  // Ensure that 'struct A' was imported (through reference from attribute of
+  // 'S').
+  EXPECT_TRUE(ToA);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -7929,12 +7929,47 @@
 }
 
 Expected ASTImporter::Import(const Attr *FromAttr) {
-  Attr *ToAttr = FromAttr->clone(ToContext);
-  if (auto ToRangeOrErr = Import(FromAttr->getRange()))
-ToAttr->setRange(*ToRangeOrErr);
-  else
-return ToRangeOrErr.takeError();
-
+  Attr *ToAttr = nullptr;
+  SourceRange ToRange;
+  if (Error Err = importInto(ToRange, FromAttr->getRange()))
+return std::move(Err);
+
+  // FIXME: Is there some kind of AttrVisitor to use here?
+  switch (FromAttr->getKind()) {
+  case attr::Aligned: {
+auto *From = cast(FromAttr);
+AlignedAttr *To;
+auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) {
+  return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange,
+ From->getSyntax(),
+ From->getSemanticSpelling());
+};
+if (From->isAlignmentExpr()) {
+  if (auto ToEOrErr = Import(From->getAlignmentExpr()))
+To = CreateAlign(true, *ToEOrErr);
+  else
+return ToEOrErr.takeError();
+} else {
+  if (auto ToTOrErr = Import(From->getAlignmentType()))
+To = CreateAlign(false, *ToTOrErr);
+  else
+return ToTOrErr.takeError();
+}
+To->setInherited(From->isInherited());
+To->setPackExpansion(From->isPackExpansion());
+To->setImplicit(From->isImplicit());
+ToAttr = To;
+break;
+  }
+  default:
+// FIXME: 'clone' copies every member but some of them should be imported.
+// Handle other Attrs that have parameters that should be imported.
+ToAttr = FromAttr->clone(ToContext);
+ToAttr->setRange(ToRange);
+break;
+  }
+  assert(ToAttr && "Attribute should be created.");
+  
   return ToAttr;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75047: Add Control Flow Guard in Clang release notes.

2020-02-25 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.

Excellent. Thanks!

Do you have commits access, or would you like me to commit for you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75047



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


[PATCH] D75047: Add Control Flow Guard in Clang release notes.

2020-02-25 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd added a comment.

In D75047#1890976 , @hans wrote:

> Do you have commits access, or would you like me to commit for you?


I don't yet have commit access. Please could you commit this for me. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75047



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


[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:92
+
+  bool IncludePath = false, ShouldEmitAsError = false, FixitsAsRemarks = false,
+   ApplyFixIts = false;

Charusso wrote:
> NoQ wrote:
> > I'll be perfectly happy with removing `FixitsAsRemarks` entirely. Your new 
> > mechanism is superior.
> Okai, challenge accepted. Thanks!
So, can we remove `FixitsAsRemarks` now or is anything still blocking it?


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

https://reviews.llvm.org/D69746



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


[PATCH] D75093: clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Instead of replacing the old cc1 "--show-includes" with "--show-includes 
-sys-header-deps" -- which looks a little ugly maybe -- would it be simpler to 
just introduce a new cc1 flag instead, e.g. "--show-user-includes", and just 
expand /showIncludes:user to that?


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

https://reviews.llvm.org/D75093



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


[PATCH] D74878: [remark][diagnostics] [codegen] Fix PR44896

2020-02-25 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere accepted this revision.
jeroen.dobbelaere added a comment.
This revision is now accepted and ready to land.

Looks good to me.


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

https://reviews.llvm.org/D74878



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


[PATCH] D75053: [clangd] Disable ExtractVariable for C

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

- Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75053

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+void foo() {
+  int x = [[1]];
+})cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
 // error-ok: broken code, but shouldn't crash
 template
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
 return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly 
instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
   computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+void foo() {
+  int x = [[1]];
+})cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
 // error-ok: broken code, but shouldn't crash
 template
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
 return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
   computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-02-25 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 2 inline comments as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:92
+
+  bool IncludePath = false, ShouldEmitAsError = false, FixitsAsRemarks = false,
+   ApplyFixIts = false;

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > I'll be perfectly happy with removing `FixitsAsRemarks` entirely. Your 
> > > new mechanism is superior.
> > Okai, challenge accepted. Thanks!
> So, can we remove `FixitsAsRemarks` now or is anything still blocking it?
https://reviews.llvm.org/D73729


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

https://reviews.llvm.org/D69746



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


[PATCH] D75106: [clangd] Fix early selection for non-vardecl declarators

2020-02-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 246405.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75106

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


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -375,6 +375,9 @@
 int test(I *f) { return 42 + [[f.^foo]]; }
   )cpp",
   "ObjCPropertyRefExpr"},
+  {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"},
+  // FIXME: This should be class itself instead.
+  {"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -339,14 +339,12 @@
  HI.Definition = "~X()";
  HI.Parameters.emplace();
}},
-  {"class X { operator [[in^t]](); };",
+  {"class X { operator [[^X]](); };",
[](HoverInfo &HI) {
  HI.NamespaceScope = "";
- HI.Name = "operator int";
- HI.LocalScope = "X::";
- HI.Kind = index::SymbolKind::ConversionFunction;
- HI.Definition = "operator int()";
- HI.Parameters.emplace();
+ HI.Name = "X";
+ HI.Kind = index::SymbolKind::Class;
+ HI.Definition = "class X {}";
}},
 
   // auto on lambda
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -10,6 +10,7 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -605,13 +606,22 @@
   // Usually empty, but sometimes children cover tokens but shouldn't own them.
   SourceRange earlySourceRange(const DynTypedNode &N) {
 if (const Decl *D = N.get()) {
+  // We want constructor name to be claimed by TypeLoc not the constructor
+  // itself.
+  // FIXME: Unfortunately this doesn't work, even though 
RecursiveASTVisitor
+  // traverses the underlying TypeLoc inside DeclarationName, it is null 
for
+  // constructors.
+  if (isa(D))
+return SourceRange();
+  // This will capture Field, Function, MSProperty, NonTypeTemplateParm and
+  // VarDecls. We want the name in the declarator to be claimed by the decl
+  // and not by any children. For example:
   // void [[foo]]();
-  if (auto *FD = llvm::dyn_cast(D))
-return FD->getNameInfo().getSourceRange();
   // int (*[[s]])();
-  else if (auto *VD = llvm::dyn_cast(D))
-return VD->getLocation();
-} else if (const auto* CCI = N.get()) {
+  // struct X { int [[hash]] [32]; [[operator]] int();}
+  if (auto *DD = llvm::dyn_cast(D))
+return DD->getLocation();
+} else if (const auto *CCI = N.get()) {
   // : [[b_]](42)
   return CCI->getMemberLocation();
 }


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -375,6 +375,9 @@
 int test(I *f) { return 42 + [[f.^foo]]; }
   )cpp",
   "ObjCPropertyRefExpr"},
+  {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"},
+  // FIXME: This should be class itself instead.
+  {"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -339,14 +339,12 @@
  HI.Definition = "~X()";
  HI.Parameters.emplace();
}},
-  {"class X { operator [[in^t]](); };",
+  {"class X { operator [[^X]](); };",
[](HoverInfo &HI) {
  HI.NamespaceScope = "";
- HI.Name = "operator int";
- HI.LocalScope = "X::";
- HI.Kind = index::SymbolKind::ConversionFunction;
- HI.Definition = "operator int()";
- HI.Parameters.emplace();
+ HI.Name = "X";
+ HI.Kind = index::SymbolKind::Class;
+ HI.Defini

[PATCH] D75047: Add Control Flow Guard in Clang release notes.

2020-02-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Pushed to 10.x as 3a11c86849c27e1e21d5e8cdf55cfa724164db57 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75047



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


[clang-tools-extra] 555d5ad - [clangd] Disable ExtractVariable for C

2020-02-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-02-25T12:15:15+01:00
New Revision: 555d5ad85a4986d003040eb94109c72579021423

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

LOG: [clangd] Disable ExtractVariable for C

Summary:
Currently extract variable doesn't spell the type explicitly and just
uses an `auto` instead, which is not available in C.

Reviewers: usaxena95

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
index 83bc901a3f2f..cf38227c29d7 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@ bool ExtractVariable::prepare(const Selection &Inputs) {
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
 return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly 
instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
   computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))

diff  --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp 
b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index 40ab6b12643e..24210aaa101d 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@ TEST_F(ExtractVariableTest, Test) {
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+void foo() {
+  int x = [[1]];
+})cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
 // error-ok: broken code, but shouldn't crash
 template



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


[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-02-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a reviewer: Szelethus.
xazax.hun added a comment.
Herald added subscribers: martong, steakhal.

Maybe Kristof has some opinion whether we still need this :) He might be up to 
date whether CodeChecker is using this feature.


Repository:
  rC Clang

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

https://reviews.llvm.org/D73729



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


[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Great, thanks!!


Repository:
  rC Clang

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

https://reviews.llvm.org/D73729



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


[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:92
+
+  bool IncludePath = false, ShouldEmitAsError = false, FixitsAsRemarks = false,
+   ApplyFixIts = false;

Charusso wrote:
> NoQ wrote:
> > Charusso wrote:
> > > NoQ wrote:
> > > > I'll be perfectly happy with removing `FixitsAsRemarks` entirely. Your 
> > > > new mechanism is superior.
> > > Okai, challenge accepted. Thanks!
> > So, can we remove `FixitsAsRemarks` now or is anything still blocking it?
> https://reviews.llvm.org/D73729
Oh crap, how did i miss this? Thanks!!


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

https://reviews.llvm.org/D69746



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


[PATCH] D75053: [clangd] Disable ExtractVariable for C

2020-02-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG555d5ad85a49: [clangd] Disable ExtractVariable for C 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75053

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+void foo() {
+  int x = [[1]];
+})cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
 // error-ok: broken code, but shouldn't crash
 template
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
 return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly 
instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
   computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+void foo() {
+  int x = [[1]];
+})cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
 // error-ok: broken code, but shouldn't crash
 template
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
 return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
   computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 4 inline comments as done.
balazske added a comment.

An improvement can be made if the check runs only when size of `char` and `int` 
are equal. And it is possible to avoid the warning if `fgetc` is called after 
`fgetc` (with no functions in between). (More complicated thing is to test for 
loop construct and maybe not more efficient.)

The code can be improved somewhat but there are now too many special cases and 
there is already a default eval function. Probably it is better to have every 
"check" function take and return `ExplodedNode` instead of state.




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:255-261
+  if (EOFv == 0) {
+if (const llvm::Optional OptInt =
+tryExpandAsInteger("EOF", C.getPreprocessor()))
+  EOFv = *OptInt;
+else
+  EOFv = -1;
+  }

Szelethus wrote:
> I'm 99% sure that the `Preprocessor` is retrievable in the checker registry 
> function (`register*Checker`), and this code should be moved there, and `EOFv 
> ` be made non-mutable. 
I am not sure if this would be good. The `Preprocessor` is not available easily 
and the "register" function is probably there to register a checker and do 
nothing else. Probably the source code is not even known when it is called. And 
how to pass the EOF value to the created checker in the register function (if 
not a static variable is used)?



Comment at: clang/test/Analysis/stream.c:182
+
+void check_fgetc_error() {
+  FILE *fp = fopen("foo.c", "r");

martong wrote:
> Do you have tests for `getc` as well? Maybe we could have at least one for 
> getc too.
`getc` is not done yet. It can need more change in `StreamChecker` to handle 
functions on std streams (at least stdin).



Comment at: clang/test/Analysis/stream.c:188
+C = fgetc(fp);
+fread(0, 0, 0, fp); // expected-warning {{Should call}}
+fread(0, 0, 0, fp);

Szelethus wrote:
> Are we sure that this is the error message we want to emit here? Sure, not 
> checking whether the stream is in an error state is a recipe for disaster, 
> but this seems to clash with
> > Should call 'feof' and 'ferror' after failed character read.
> as error here is not even checking the return value. Shouldn't we say
> > Should check the return value of `fgetc` before ...
> instead?
No, it is not enough to check the return value of `fgetc`, exactly this is the 
reason for the checker. "Should call 'feof' and 'ferror' after failed character 
read." is more exact: The read was suspected to fail because EOF was returned 
but should call feof (...) to verify it. A better message can be:

If 'fgetc' returns EOF call 'feof' and 'ferror' to check for error.



Comment at: clang/test/Analysis/stream.c:246-247
+if (C == EOF) {
+  feof(fp);
+  ferror(fp);
+}

Szelethus wrote:
> I bet this isn't how we envision how these function to be used. Maybe 
> `ReturnValueChecker` could be deployed here? In any case, that would be a 
> topic of a different revision.
If `fgetc` returns non-EOF we can be sure that there is no error, so no need to 
call `ferror` and `feof`. If it returns EOF we must "double-check" that it was 
a real error or an EOF-looking character that was read.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75045



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


[PATCH] D75061: [RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC

2020-02-25 Thread Edward Jones via Phabricator via cfe-commits
edward-jones accepted this revision.
edward-jones added a comment.
This revision is now accepted and ready to land.

Looks good to me. Clang tests all pass on my local build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75061



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


[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def:310
-ANALYZER_OPTION(bool, ShouldEmitFixItHintsAsRemarks, "fixits-as-remarks",
-"Emit fix-it hints as remarks for testing purposes",
-false)

>>! In D73729#1891015, @xazax.hun wrote:
> Maybe Kristof has some opinion whether we still need this :) He might be up 
> to date whether CodeChecker is using this feature.

Well, it clearly said "for testing purposes" :P

It should be much easier for CodeChecker to read fixits from plists.


Repository:
  rC Clang

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

https://reviews.llvm.org/D73729



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


[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-02-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def:310
-ANALYZER_OPTION(bool, ShouldEmitFixItHintsAsRemarks, "fixits-as-remarks",
-"Emit fix-it hints as remarks for testing purposes",
-false)

NoQ wrote:
> >>! In D73729#1891015, @xazax.hun wrote:
> > Maybe Kristof has some opinion whether we still need this :) He might be up 
> > to date whether CodeChecker is using this feature.
> 
> Well, it clearly said "for testing purposes" :P
> 
> It should be much easier for CodeChecker to read fixits from plists.
Fair point :) LGTM!


Repository:
  rC Clang

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

https://reviews.llvm.org/D73729



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


[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D75045#1891055 , @NoQ wrote:

> How many such platforms can you name?


I mean, does Clang even support such targets?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75045



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


[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D75045#1891032 , @balazske wrote:

> An improvement can be made if the check runs only when size of `char` and 
> `int` are equal.


How many such platforms can you name? Please correct me if i'm wrong but it 
sounds like we're adding a lot of logic to maintain for a very very low-value 
check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75045



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


[PATCH] D75106: [clangd] Fix early selection for non-vardecl declarators

2020-02-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Selection.cpp:615
+  if (isa(D))
+return SourceRange();
+  // This will capture Field, Function, MSProperty, NonTypeTemplateParm and

we may have to blacklist deduction guides too?



Comment at: clang-tools-extra/clangd/unittests/SelectionTests.cpp:378
   "ObjCPropertyRefExpr"},
+  {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"},
+  // FIXME: This should be class itself instead.

can you add the other special cases we discussed offline? conversion operations 
should be triggered by `operator`, destructors by `~`.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75106



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


[PATCH] D74878: [remark][diagnostics] [codegen] Fix PR44896

2020-02-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

SGTM


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

https://reviews.llvm.org/D74878



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


[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D75045#1891056 , @NoQ wrote:

> In D75045#1891055 , @NoQ wrote:
>
> > How many such platforms can you name?
>
>
> I mean, does Clang even support such targets?


The problem can occur with the "wide" variants of the getc functions when 
`wchar_t` is same width as `wint_t`, this can be more often (but I am not 
sure). Even then the character set should contain a character similar to 
`WEOF`, that is not true for UTF-16 and 32. So there may be low probability for 
the problem to occur. Is this reason to not have this check at all?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75045



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


[PATCH] D75093: clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This is what -MD passes (which is why the -sys flag already exists), and more 
orthogonal flags instead of fewer, tangled ones is what we usually go for at 
the cc1 layer. So I like it more as is.


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

https://reviews.llvm.org/D75093



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


[PATCH] D75012: [ReleaseNotes] Mention -fmacro-prefix-map and -ffile-prefix-map.

2020-02-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> Should such change be committed directly to the release/10.x branch by @hans ?

Peter can commit to release/10.x himself, or let me know if he prefers me to do 
it. Thanks for writing release notes!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75012



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


[PATCH] D75012: [ReleaseNotes] Mention -fmacro-prefix-map and -ffile-prefix-map.

2020-02-25 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn updated this revision to Diff 246413.
Lekensteyn marked 2 inline comments as done.
Lekensteyn added a comment.

Updated the comment based on @MaskRay's feedback, thanks!
This (and the previous) patch were based on release/10.x, I plan to commit it 
later today since the final tag is tomorrow.


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

https://reviews.llvm.org/D75012

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -138,6 +138,12 @@
   please let us know if you encounter a situation where you need to specify 
this
   flag for correct program behavior.
 
+- ``-fmacro-prefix-map=OLD=NEW`` substitutes directory prefix ``OLD`` for
+  ``NEW`` in predefined preprocessor macros such as ``__FILE__``. This helps
+  with reproducible builds that are location independent. The new
+  ``-ffile-prefix-map`` option is equivalent to specifying both
+  ``-fdebug-prefix-map`` and ``-fmacro-prefix-map``.
+
 Deprecated Compiler Flags
 -
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -138,6 +138,12 @@
   please let us know if you encounter a situation where you need to specify this
   flag for correct program behavior.
 
+- ``-fmacro-prefix-map=OLD=NEW`` substitutes directory prefix ``OLD`` for
+  ``NEW`` in predefined preprocessor macros such as ``__FILE__``. This helps
+  with reproducible builds that are location independent. The new
+  ``-ffile-prefix-map`` option is equivalent to specifying both
+  ``-fdebug-prefix-map`` and ``-fmacro-prefix-map``.
+
 Deprecated Compiler Flags
 -
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D75045#1891064 , @balazske wrote:

> In D75045#1891056 , @NoQ wrote:
>
> > In D75045#1891055 , @NoQ wrote:
> >
> > > How many such platforms can you name?
> >
> >
> > I mean, does Clang even support such targets?
>
>
> The problem can occur with the "wide" variants of the getc functions when 
> `wchar_t` is same width as `wint_t`, this can be more often (but I am not 
> sure). Even then the character set should contain a character similar to 
> `WEOF`, that is not true for UTF-16 and 32. So there may be low probability 
> for the problem to occur. Is this reason to not have this check at all?


If we can detect that the code is non-portable, it doesn't really matter in my 
opinion if we don't support the target on which the problem would occur. Also, 
I can't come up with a specific platform that would have an issue like this 
(maybe in a dishwasher? (: ), but CERT is known to create rules based on real 
vulnerabilities. A quick glance lead me to this page, though these 
vulnerabilities may not be directly related to this rule:

https://wiki.sei.cmu.edu/confluence/display/c/AA.+Bibliography#AA.Bibliography-ISO/IECTS17961-2013

In D75045#1891032 , @balazske wrote:

> An improvement can be made if the check runs only when size of `char` and 
> `int` are equal.


Since the rule specifically states that the problem here is portability 
related, I think we shouldn't do that.

> The code can be improved somewhat but there are now too many special cases 
> and there is already a default eval function. Probably it is better to have 
> every "check" function take and return `ExplodedNode` instead of state.

This really ties into my main concern, that this **isn't** a stream management 
function specific problem, but rather an unchecked stream problem **after** we 
know that it returns `EOF`. I think we should first emit warnings on operations 
on `EOF`-returning streams, and implement this rule after that. WDYT?




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:255-261
+  if (EOFv == 0) {
+if (const llvm::Optional OptInt =
+tryExpandAsInteger("EOF", C.getPreprocessor()))
+  EOFv = *OptInt;
+else
+  EOFv = -1;
+  }

balazske wrote:
> Szelethus wrote:
> > I'm 99% sure that the `Preprocessor` is retrievable in the checker registry 
> > function (`register*Checker`), and this code should be moved there, and 
> > `EOFv ` be made non-mutable. 
> I am not sure if this would be good. The `Preprocessor` is not available 
> easily and the "register" function is probably there to register a checker 
> and do nothing else. Probably the source code is not even known when it is 
> called. And how to pass the EOF value to the created checker in the register 
> function (if not a static variable is used)?
`CheckerManager::registerChecker` in fact returns the non-const checker object. 
The registry function is responsible for the registration //and// 
initialization of the checker object.

Though you have a point in the sense that this isn't terribly well defined (I 
should really finish D58065...).

I had a look, and my usual motto of //"Any manager can be retrieved in clang at 
arbitrary locations if you try hard enough"// seems to have been wrong. I don't 
see how I could get my hands on a `Preprocessor` in the checker registry 
function. So, feel free to disregard this comment.



Comment at: clang/test/Analysis/stream.c:188
+C = fgetc(fp);
+fread(0, 0, 0, fp); // expected-warning {{Should call}}
+fread(0, 0, 0, fp);

balazske wrote:
> Szelethus wrote:
> > Are we sure that this is the error message we want to emit here? Sure, not 
> > checking whether the stream is in an error state is a recipe for disaster, 
> > but this seems to clash with
> > > Should call 'feof' and 'ferror' after failed character read.
> > as error here is not even checking the return value. Shouldn't we say
> > > Should check the return value of `fgetc` before ...
> > instead?
> No, it is not enough to check the return value of `fgetc`, exactly this is 
> the reason for the checker. "Should call 'feof' and 'ferror' after failed 
> character read." is more exact: The read was suspected to fail because EOF 
> was returned but should call feof (...) to verify it. A better message can be:
> 
> If 'fgetc' returns EOF call 'feof' and 'ferror' to check for error.
The compliant solution in the rule description has the following example:

```lang=c++

#include 
 
void func(void) {
  int c;
 
  do {
c = getchar();
  } while (c != EOF);
  if (feof(stdin)) {
/* Handle end of file */
  } else if (ferror(stdin)) {
/* Handle file error */
  } else {
/* Received a character that resembles EOF; handle error */
  }
}
```
because if the character 

[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.

Looks great! Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D73729



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


[PATCH] D69662: [Checkers] Avoid using evalCall in StreamChecker.

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D69662#1890007 , @NoQ wrote:

> In D69662#1889545 , @Szelethus wrote:
>
> > Sorry for the slack :)
> >
> > One should never count on the invocation order of callback funcions in 
> > between checkers. In fact, I'm not too sure that my patches affect this, 
> > but I suspect that it does, as the container of choice for checker objects 
> > is `std::vector`.
>
>
> With checker dependencies introduced, i think it's not an unreasonable 
> guarantee to make. Like, if you rely on your dependency to model things for 
> you, you probably want to have your callbacks called after everything is set 
> up by the dependency.
>
> That said, it's not always obvious what does "after" mean. I wouldn't be 
> shocked if it turns out that the correct order is different in pre-stmt and 
> post-stmt (i.e., dependent - dependency - actual event - dependency - 
> dependent).


Well, you raise a valid point. While I do think that implementing complex 
checkers that have strong interaction should be left to the 
bit-more-experienced, maybe it'd be better to make the interface a bit more 
intuitive. I like to point at `IteratorChecker`, which is spread out across 
multiple files, despite it packing a lot of knowledge.

I'm afraid that I too have more questions then possible solution to this 
answer. My patches related to `MallocChecker` was (is) a research of some sort 
to come up with one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69662



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


[PATCH] D75093: clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 246417.
thakis added a comment.

add one more test


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

https://reviews.llvm.org/D75093

Files:
  clang/include/clang/Driver/CLCompatOptions.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/HeaderIncludeGen.cpp
  clang/test/Driver/cl-options.c
  clang/test/Frontend/print-header-includes.c
  clang/test/Preprocessor/headermap-rel2.c

Index: clang/test/Preprocessor/headermap-rel2.c
===
--- clang/test/Preprocessor/headermap-rel2.c
+++ clang/test/Preprocessor/headermap-rel2.c
@@ -1,7 +1,10 @@
 // RUN: rm -f %t.hmap
 // RUN: %hmaptool write %S/Inputs/headermap-rel2/project-headers.hmap.json %t.hmap
-// RUN: %clang_cc1 -v -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H
-// RUN: %clang_cc1 -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
+
+// RUN: %clang -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
+// RUN: FileCheck %s -input-file %t.out
+
+// RUN: env CC_PRINT_HEADERS=1 %clang -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 2> %t.out
 // RUN: FileCheck %s -input-file %t.out
 
 // CHECK: Product/someheader.h
Index: clang/test/Frontend/print-header-includes.c
===
--- clang/test/Frontend/print-header-includes.c
+++ clang/test/Frontend/print-header-includes.c
@@ -1,32 +1,51 @@
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h -E -H -o /dev/null %s 2> %t.stderr
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E -H -o /dev/null %s 2> %t.stderr
 // RUN: FileCheck < %t.stderr %s
 
 // CHECK-NOT: test3.h
+// CHECK-NOT: . {{.*noline.h}}
 // CHECK: . {{.*test.h}}
 // CHECK: .. {{.*test2.h}}
 
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h --show-includes -o /dev/null %s | \
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E -H -sys-header-deps -o /dev/null %s 2> %t.stderr
+// RUN: FileCheck --check-prefix SYSHEADERS < %t.stderr %s
+
+// SYSHEADERS-NOT: test3.h
+// SYSHEADERS: . {{.*noline.h}}
+// SYSHEADERS: . {{.*test.h}}
+// SYSHEADERS: .. {{.*test2.h}}
+
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: --show-includes -o /dev/null %s | \
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-STDOUT %s
 // MS-STDOUT-NOT: 
+// MS-STDOUT-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-STDOUT: Note: including file: {{[^ ]*test3.h}}
 // MS-STDOUT: Note: including file: {{[^ ]*test.h}}
 // MS-STDOUT: Note: including file:  {{[^ ]*test2.h}}
 // MS-STDOUT-NOT: Note
 
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h -E --show-includes -o /dev/null %s 2> %t.stderr
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E --show-includes -o /dev/null %s 2> %t.stderr
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-STDERR < %t.stderr %s
 // MS-STDERR-NOT: 
+// MS-STDERR-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-STDERR: Note: including file: {{[^ ]*test3.h}}
 // MS-STDERR: Note: including file: {{[^ ]*test.h}}
 // MS-STDERR: Note: including file:  {{[^ ]*test2.h}}
 // MS-STDERR-NOT: Note
 
 // RUN: echo "fun:foo" > %t.blacklist
-// RUN: %clang_cc1 -I%S -fsanitize=address -fdepfile-entry=%t.blacklist --show-includes -o /dev/null %s | \
+// RUN: %clang_cc1 -I%S -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -fsanitize=address -fdepfile-entry=%t.blacklist \
+// RUN: --show-includes -o /dev/null %s | \
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-BLACKLIST %s
 // MS-BLACKLIST: Note: including file: {{[^ ]*\.blacklist}}
+// MS-BLACKLIST-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-BLACKLIST: Note: including file: {{[^ ]*test.h}}
 // MS-BLACKLIST: Note: including file:  {{[^ ]*test2.h}}
 // MS-BLACKLIST-NOT: Note
 
+#include 
 #include "Inputs/test.h"
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -199,10 +199,16 @@
 // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s
 // Qvec_-NOT: -vectorize-loops
 
-// RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s
-// showIncludes: --show-includes
+// RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_ %s
+// showIncludes_: --show-includes
+// showIncludes_: -sys-header-deps
+
+// RUN: %clang_cl /showIncludes:user -### -- %s 2>&1 | FileCh

[PATCH] D75044: [AArch64] __builtin_extract_return_addr for PAuth.

2020-02-25 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss marked 2 inline comments as done.
danielkiss added inline comments.



Comment at: clang/test/CodeGen/arm64-extractreturnaddress.c:15
+// CHECK:  define dso_local i8* @bar() #0 {
+// CHECK-NEXT:ret i8* inttoptr (i64 42 to i8*)
+// CHECK-PAC: %1 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))

// CHECK-NEXT:  entry:
// CHECK-NEXT:ret i8* inttoptr (i64 42 to i8*)



Comment at: clang/test/CodeGen/arm64-extractreturnaddress.c:16
+// CHECK-NEXT:ret i8* inttoptr (i64 42 to i8*)
+// CHECK-PAC: %1 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))
+// CHECK-PAC83:   %1 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))

// CHECK-PAC: %0 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))
// CHECK-PAC83:   %0 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))
// CHECK-BPROT8:  %0 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))
// CHECK-BPROT83: %0 = call i8* @llvm.extractreturnaddress.p0i8.p0i8(i8* 
inttoptr (i64 42 to i8*))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75044



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


[PATCH] D75006: [clang-format] Wrap lines for C# property accessors

2020-02-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.

This is pretty cool!


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

https://reviews.llvm.org/D75006



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


[PATCH] D74131: [analyzer][taint] Add isTainted debug expression inspection check

2020-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 246420.
steakhal added a comment.

Declaring the purpose of this checker:

>   [...]
>   This would help to reduce the *noise* that the `TaintTest` debug checker 
> would
>   introduce and let you focus on the `expected-warning`s that you really care
>   about.

Added test to `exactly one argument` requirement.


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

https://reviews.llvm.org/D74131

Files:
  clang/docs/analyzer/developer-docs/DebugChecks.rst
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/test/Analysis/debug-exprinspection-istainted.c

Index: clang/test/Analysis/debug-exprinspection-istainted.c
===
--- /dev/null
+++ clang/test/Analysis/debug-exprinspection-istainted.c
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=alpha.security.taint
+
+int scanf(const char *restrict format, ...);
+void clang_analyzer_isTainted(char);
+void clang_analyzer_isTainted_any_suffix(char);
+void clang_analyzer_isTainted_many_arguments(char, int, int);
+
+void foo() {
+  char buf[32] = "";
+  clang_analyzer_isTainted(buf[0]);// expected-warning {{NO}}
+  clang_analyzer_isTainted_any_suffix(buf[0]); // expected-warning {{NO}}
+  scanf("%s", buf);
+  clang_analyzer_isTainted(buf[0]);// expected-warning {{YES}}
+  clang_analyzer_isTainted_any_suffix(buf[0]); // expected-warning {{YES}}
+
+  int tainted_value = buf[0]; // no-warning
+}
+
+void exactly_one_argument_required() {
+  char buf[32] = "";
+  scanf("%s", buf);
+  clang_analyzer_isTainted_many_arguments(buf[0], 42, 42);
+  // expected-warning@-1 {{clang_analyzer_isTainted() requires exactly one argument}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "Taint.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
@@ -46,6 +47,7 @@
   void analyzerHashDump(const CallExpr *CE, CheckerContext &C) const;
   void analyzerDenote(const CallExpr *CE, CheckerContext &C) const;
   void analyzerExpress(const CallExpr *CE, CheckerContext &C) const;
+  void analyzerIsTainted(const CallExpr *CE, CheckerContext &C) const;
 
   typedef void (ExprInspectionChecker::*FnCheck)(const CallExpr *,
  CheckerContext &C) const;
@@ -73,26 +75,34 @@
 
   // These checks should have no effect on the surrounding environment
   // (globals should not be invalidated, etc), hence the use of evalCall.
-  FnCheck Handler = llvm::StringSwitch(C.getCalleeName(CE))
-.Case("clang_analyzer_eval", &ExprInspectionChecker::analyzerEval)
-.Case("clang_analyzer_checkInlined",
-  &ExprInspectionChecker::analyzerCheckInlined)
-.Case("clang_analyzer_crash", &ExprInspectionChecker::analyzerCrash)
-.Case("clang_analyzer_warnIfReached",
-  &ExprInspectionChecker::analyzerWarnIfReached)
-.Case("clang_analyzer_warnOnDeadSymbol",
-  &ExprInspectionChecker::analyzerWarnOnDeadSymbol)
-.StartsWith("clang_analyzer_explain", &ExprInspectionChecker::analyzerExplain)
-.StartsWith("clang_analyzer_dump", &ExprInspectionChecker::analyzerDump)
-.Case("clang_analyzer_getExtent", &ExprInspectionChecker::analyzerGetExtent)
-.Case("clang_analyzer_printState",
-  &ExprInspectionChecker::analyzerPrintState)
-.Case("clang_analyzer_numTimesReached",
-  &ExprInspectionChecker::analyzerNumTimesReached)
-.Case("clang_analyzer_hashDump", &ExprInspectionChecker::analyzerHashDump)
-.Case("clang_analyzer_denote", &ExprInspectionChecker::analyzerDenote)
-.Case("clang_analyzer_express", &ExprInspectionChecker::analyzerExpress)
-.Default(nullptr);
+  FnCheck Handler =
+  llvm::StringSwitch(C.getCalleeName(CE))
+  .Case("clang_analyzer_eval", &ExprInspectionChecker::analyzerEval)
+  .Case("clang_analyzer_checkInlined",
+&ExprInspectionChecker::analyzerCheckInlined)
+  .Case("clang_analyzer_crash", &ExprInspectionChecker::analyzerCrash)
+  .Case("clang_analyzer_warnIfReached",
+&ExprInspectionChecker::analyzerWarnIfReached)
+  .Case("clang_analyzer_warnOnDeadSymbol",
+&ExprInspectionChecker::analyzerWarnOnDeadSymbol)
+  .StartsWith("clang_analyzer_explain",
+  &ExprInspectionChecker::analyzerExplain)
+  .StartsWith("clang_analyzer_d

[PATCH] D74131: [analyzer][taint] Add isTainted debug expression inspection check

2020-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked 2 inline comments as done.
steakhal added a comment.

Marking comments done.


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

https://reviews.llvm.org/D74131



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


[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D69560#1890767 , @vingeldal wrote:

> In D69560#1890026 , @aaron.ballman 
> wrote:
>
> > That is an option, but it would be better for the check to be usable 
> > without requiring a lot of custom configuration.
>
>
> One can't really expect a ones own .clang-tidy file to be applicable to all 
> third party code used in ones project. It is a fact, with or without this 
> check, that if you use third party libraries you can't expect the third party 
> libraries to comply with your own .clang-tidy file. You should expect to set 
> up a separate .clang-tidy file for all third party libraries used by your 
> project with or without this check -and that's ok because it is arguably not 
> a big effort to do so.


We typically aim for checks to require as little configuration as possible by 
tailoring the default check behavior to be as reasonable as we can make it.

>> Incremental improvement is always a good thing, but it has to start from a 
>> stable base. I'm not yet convinced this check meets the bar for inclusion in 
>> clang-tidy. There is no proposed way to tell how two parameters relate to 
>> one another, and the simple enforcement seems dangerously simple.
>> 
>>> Would it not be a reasonable approach to accept this implementation and 
>>> improve `NOLINT` to work on entire files or lists of files rather than 
>>> squeezing more heuristics (prone to false negatives) to the check?
>> 
>> AFAICT, that would be a novel new use of `NOLINT`, so I'm wary of it. I 
>> think the first thing is to gather some data as to how this check performs 
>> as-is. If the behavior is unreasonable, we can see what ways in which it is 
>> unreasonable with the dataset and see if we can tease out either heuristics 
>> or configuration options that would make it more palatable. We may also want 
>> to rope some of the C++ Core Guidelines authors in on the discussion at that 
>> point because that would be data suggesting their suggested simple 
>> enforcement is untenable.
> 
> There is also the --header-filter command line option to configure the tool 
> to skip some headers.

That is true.

> To sum up my position:
>  I'm all for investigating the performance of this check and basing any 
> decisions on data. Until we have that data I just want to challenge the claim 
> that there are no suitable ways to turn the check of for select portions of 
> the code base,
>  there are definitely ways to do that which both work satisfyingly and are in 
> no way novel or unconventional.

Using the header filters would be a reasonable approach, if a bit heavy-handed. 
Ideally, the check would warn about what the rule wants it to warn about. I 
think the unsatisfying bit is the lack of clarity in the rule itself. Trying to 
write a checker for a rule with that much subjectivity typically leads to a lot 
of configuration needs.

In D69560#1890855 , @whisperity wrote:

> In D69560#1889925 , @vingeldal wrote:
>
> > I think this value very well may strike a good balance in that compromise 
> > but I still think it is a clear deviation from the guideline as specified.
> >  IMO all deviations from the guideline should be explicitly requested by 
> > the user, not set by default, no matter how useful that deviation is.
>
>
> While I am still planning to compile a measurement with potentially tagging 
> false and true positives -- albeit classifying this on random projects I have 
> no domain knowledge about is hard at first glance...


LLVM itself might be a good starting point since we've all got some passing 
familiarity with the project.

> @aaron.ballman Could it be a useful compromise to //not// say we are trying 
> to solve the `cppcoreguidelines-` rule, but rather introduce this checker in 
> another "namespace" and maybe mention in the docs that it could, although 
> with caveats, apply "parts" of the Core Guidelines rule?

I think that could be a useful compromise, or name it 
`cppcoreguidelines-experimental-avoid-adjacent-parameters-of-same-type` to make 
it clear that we're trying things out to see what works in practice and the 
behavior may not match the guideline. I think the most important thing we do 
will be to eventually coordinate with the C++ Core Guidelines folks though. The 
eventual goal is for the clang-tidy check to cover what the guideline wants it 
to cover as its default behavior, but in a way that's going to give acceptable 
behavior for our users. This may mean we have a slightly chattier diagnostic 
than I'd like, and it may also mean that some updates to the core guideline are 
needed to help clarify what constitutes a "related" parameter in a way that's 
acceptable for analysis tools. What I want to avoid is having users say "this 
check doesn't match the guideline" or "we want to enable all the guidelines but 
we a

[PATCH] D75006: [clang-format] Wrap lines for C# property accessors

2020-02-25 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe marked an inline comment as done.
jbcoe added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:246
-   "get;\n"
-   "}");
 

MyDeveloperDay wrote:
> Nit: I feel like this layout should really be an option, (maybe for the 
> future).
> 
> When we originally did the C# work, we did say we might want in the future to 
> add options that might be specific like laying out the accessors 
> 
> I think VS has support for formatting them as either
> 
> ```
> public int Goo { set; get; }
> ```
> 
> and 
> 
> ```
> public int Goo
> {
>  set; get;
> }
> ```
> 
> and the following is equally valid in my eyes
> 
> ```
> public int Goo
> {
>  set; 
>  get;
> }
> ```
> 
> as well as what is being proposed here of
> 
> ```
> public int Goo
> {   set; get; }
> ```
> 
> I'm not completely sure how much the other options are controlling this at 
> present and how much is not in the control of your merging
> 
> and how does that change when there is actually code in the setter and getter?
> 
> 
> 
Agreed that this should be configured by an option in a future revision.


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

https://reviews.llvm.org/D75006



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


[PATCH] D75006: [clang-format] Wrap lines for C# property accessors

2020-02-25 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM




Comment at: clang/unittests/Format/FormatTestCSharp.cpp:246
-   "get;\n"
-   "}");
 

Nit: I feel like this layout should really be an option, (maybe for the future).

When we originally did the C# work, we did say we might want in the future to 
add options that might be specific like laying out the accessors 

I think VS has support for formatting them as either

```
public int Goo { set; get; }
```

and 

```
public int Goo
{
 set; get;
}
```

and the following is equally valid in my eyes

```
public int Goo
{
 set; 
 get;
}
```

as well as what is being proposed here of

```
public int Goo
{   set; get; }
```

I'm not completely sure how much the other options are controlling this at 
present and how much is not in the control of your merging

and how does that change when there is actually code in the setter and getter?





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

https://reviews.llvm.org/D75006



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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-02-25 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 246425.
baloghadamsoftware added a comment.
Herald added subscribers: martong, steakhal.

Minor update.


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

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,407 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t
+
+class Simple1 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple1() {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+  // CHECK-FIXES: double x{0.0};
+
+public:
+  Simple2() : n (0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  // CHECK-FIXES: int n{0};
+  double x;
+
+public:
+  Simple3() : x (0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+public:
+  Complex2() : n(0) {
+if (!dice())
+  return;
+m = 1;
+// NO-MESSAGES: initialization of 'm' follows a conditional expression
+  }
+
+  ~Complex2() = default;
+};
+
+class Complex3 {
+  int n;
+  int m;
+
+public:
+  Complex3() : n(0) {
+while (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional loop
+  }
+
+  ~Complex3() = default;
+};
+
+class Complex4 {
+  int n;
+  int m;
+
+public:
+  Complex4() : n(0) {
+while (!dice())
+  return;
+m =

[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

@aaron.ballman @vingeldal I'll go over the findings (as I've run this on LLVM 
and various other projects, a few examples are uploaded in my first comment as 
HTML renders of the bug report!) soon, but I want to wait until a research 
paper I have based on this topic gets a final decision. (It should happen 
soon.) I also plan to refurbish D20689  and 
have it upstreamed as a "co-checker" of this (one for the interface rule, one 
for the call sites, they kinda want to solve different aspects of the same 
issue, let it be up for the project how much they wish to enforce).


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

https://reviews.llvm.org/D69560



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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-02-25 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 2 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:43
+static bool isLiteral(const Expr *E) {
+  return isa(E) ||
+ isa(E) ||

aaron.ballman wrote:
> What about other kinds of literals like user-defined literals, or literal 
> class types? Should this be using `E->getType()->isLiteralType()`?
`E->getType()->isLiteralType()` does not work since it tells about the type, 
not the expression itself. Here we should return `true` for literals only, not 
for any expressions whose type is a literal type. Thus `int` is a literal type, 
`5` is an `int` literal, but `n` or `return_any_int()` not.


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

https://reviews.llvm.org/D71199



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


[clang] 7b6168e - [ASTImporter] Improved variable template redecl chain handling.

2020-02-25 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-02-25T14:48:37+01:00
New Revision: 7b6168e7bef1cdc355fd28572bd69ea4057c57f8

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

LOG: [ASTImporter] Improved variable template redecl chain handling.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, teemperor, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterGenericRedeclTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 9d141997d026..066dd1b38c06 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3881,6 +3881,13 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 ToVar->setPreviousDecl(Recent);
   }
 
+  // Import the described template, if any.
+  if (D->getDescribedVarTemplate()) {
+auto ToVTOrErr = import(D->getDescribedVarTemplate());
+if (!ToVTOrErr)
+  return ToVTOrErr.takeError();
+  }
+
   if (Error Err = ImportInitializer(D, ToVar))
 return std::move(Err);
 
@@ -5460,20 +5467,6 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateSpecializationDecl(
 }
 
 ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
-  // If this variable has a definition in the translation unit we're coming
-  // from,
-  // but this particular declaration is not that definition, import the
-  // definition and map to that.
-  auto *Definition =
-  cast_or_null(D->getTemplatedDecl()->getDefinition());
-  if (Definition && Definition != D->getTemplatedDecl()) {
-if (ExpectedDecl ImportedDefOrErr = import(
-Definition->getDescribedVarTemplate()))
-  return Importer.MapImported(D, *ImportedDefOrErr);
-else
-  return ImportedDefOrErr.takeError();
-  }
-
   // Import the major distinguishing characteristics of this variable template.
   DeclContext *DC, *LexicalDC;
   DeclarationName Name;
@@ -5487,19 +5480,26 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
   // We may already have a template of the same name; try to find and match it.
   assert(!DC->isFunctionOrMethod() &&
  "Variable templates cannot be declared at function scope");
+
   SmallVector ConflictingDecls;
   auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
+  VarTemplateDecl *FoundByLookup = nullptr;
   for (auto *FoundDecl : FoundDecls) {
 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
   continue;
 
-Decl *Found = FoundDecl;
-if (VarTemplateDecl *FoundTemplate = dyn_cast(Found)) {
+if (VarTemplateDecl *FoundTemplate = dyn_cast(FoundDecl)) 
{
   if (IsStructuralMatch(D, FoundTemplate)) {
-// The variable templates structurally match; call it the same 
template.
-Importer.MapImported(D->getTemplatedDecl(),
- FoundTemplate->getTemplatedDecl());
-return Importer.MapImported(D, FoundTemplate);
+// The Decl in the "From" context has a definition, but in the
+// "To" context we already have a definition.
+VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
+if (D->isThisDeclarationADefinition() && FoundDef)
+  // FIXME Check for ODR error if the two definitions have
+  // 
diff erent initializers?
+  return Importer.MapImported(D, FoundDef);
+
+FoundByLookup = FoundTemplate;
+break;
   }
   ConflictingDecls.push_back(FoundDecl);
 }
@@ -5544,6 +5544,18 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
   ToVarTD->setLexicalDeclContext(LexicalDC);
   LexicalDC->addDeclInternal(ToVarTD);
 
+  if (FoundByLookup) {
+auto *Recent =
+const_cast(FoundByLookup->getMostRecentDecl());
+if (!ToTemplated->getPreviousDecl()) {
+  auto *PrevTemplated =
+  FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
+  if (ToTemplated != PrevTemplated)
+ToTemplated->setPreviousDecl(PrevTemplated);
+}
+ToVarTD->setPreviousDecl(Recent);
+  }
+
   if (DTemplated->isThisDeclarationADefinition() &&
   !ToTemplated->isThisDeclarationADefinition()) {
 // FIXME: Import definition!

diff  --git a/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp 
b/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
index e0c5e9407788..944256e857c7 100644
--- a/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
+++ b/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
@@ -74,6 +74,21 @@ struct ClassTemplate {
   }
 };
 
+struct VariableTemplate {
+  using DeclTy = VarTemplateDecl;
+  static constexpr auto *Prototype = "template  extern T X;";
+  stati

[PATCH] D74720: [ASTImporter] Improved variable template redecl chain handling.

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7b6168e7bef1: [ASTImporter] Improved variable template 
redecl chain handling. (authored by balazske).

Changed prior to commit:
  https://reviews.llvm.org/D74720?vs=244980&id=246428#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74720

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterGenericRedeclTest.cpp

Index: clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
===
--- clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
+++ clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
@@ -74,6 +74,21 @@
   }
 };
 
+struct VariableTemplate {
+  using DeclTy = VarTemplateDecl;
+  static constexpr auto *Prototype = "template  extern T X;";
+  static constexpr auto *Definition =
+  R"(
+  template  T X;
+  template <> int X;
+  )";
+  // There is no matcher for varTemplateDecl so use a work-around.
+  BindableMatcher getPattern() {
+return namedDecl(hasName("X"), unless(isImplicit()),
+ has(templateTypeParmDecl()));
+  }
+};
+
 struct FunctionTemplateSpec {
   using DeclTy = FunctionDecl;
   static constexpr auto *Prototype =
@@ -428,6 +443,9 @@
 RedeclChain, ClassTemplate, ,
 PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
+RedeclChain, VariableTemplate, ,
+PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
 RedeclChain, FunctionTemplateSpec, ,
 PrototypeShouldBeImportedAsAPrototypeWhenThereIsNoDefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(
@@ -446,6 +464,8 @@
 DefinitionShouldBeImportedAsADefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
 DefinitionShouldBeImportedAsADefinition)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
+DefinitionShouldBeImportedAsADefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
 DefinitionShouldBeImportedAsADefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
@@ -463,6 +483,8 @@
 ImportPrototypeAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
 ImportPrototypeAfterImportedPrototype)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
+ImportPrototypeAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
 ImportPrototypeAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
@@ -480,6 +502,8 @@
 ImportDefinitionAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
 ImportDefinitionAfterImportedPrototype)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
+ImportDefinitionAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
 ImportDefinitionAfterImportedPrototype)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
@@ -497,6 +521,8 @@
 ImportPrototypeAfterImportedDefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
 ImportPrototypeAfterImportedDefinition)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
+ImportPrototypeAfterImportedDefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
 ImportPrototypeAfterImportedDefinition)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
@@ -513,6 +539,8 @@
 ImportPrototypes)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplate, ,
 ImportPrototypes)
+ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, VariableTemplate, ,
+ImportPrototypes)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, ClassTemplateSpec, ,
 ImportPrototypes)
 ASTIMPORTER_INSTANTIATE_TYPED_TEST_CASE(RedeclChain, FunctionTemplateSpec, ,
@@ -529,6 +557,8 @@
 ImportDefi

[PATCH] D74966: [PATCH] [ARM] Add Cortex-M55 Support for clang and llvm

2020-02-25 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson updated this revision to Diff 246427.
LukeGeeson marked an inline comment as done.
LukeGeeson added a comment.

- Addressed dmgreen's comments (removed whitespace, added m55 test)
- Added CPU Part number to Host.cpp


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

https://reviews.llvm.org/D74966

Files:
  clang/test/CodeGen/arm-target-features.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/test/CodeGen/ARM/build-attributes.ll
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -290,6 +290,11 @@
  ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
   EXPECT_TRUE(testARMCPU("cortex-m35p", "armv8-m.main", "fpv5-sp-d16",
  ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
+  EXPECT_TRUE(testARMCPU("cortex-m55", "armv8.1-m.main", "fp-armv8-fullfp16-d16",
+ ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_SIMD |
+ ARM::AEK_FP | ARM::AEK_RAS | ARM::AEK_LOB |
+ ARM::AEK_FP16,
+"8.1-M.Mainline"));
   EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
  ARM::AEK_NONE, "iwmmxt"));
   EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
@@ -299,7 +304,7 @@
  "7-S"));
 }
 
-static constexpr unsigned NumARMCPUArchs = 85;
+static constexpr unsigned NumARMCPUArchs = 86;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
Index: llvm/test/CodeGen/ARM/build-attributes.ll
===
--- llvm/test/CodeGen/ARM/build-attributes.ll
+++ llvm/test/CodeGen/ARM/build-attributes.ll
@@ -233,6 +233,7 @@
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi | FileCheck %s --check-prefix=ARMv81M-MAIN
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve | FileCheck %s --check-prefix=ARMv81M-MAIN-MVEINT
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp | FileCheck %s --check-prefix=ARMv81M-MAIN-MVEFP
+; RUN: llc < %s -mtriple=arm-none-none-eabi -mcpu=cortex-m55 | FileCheck %s --check-prefix=CORTEX-M55
 
 ; CPU-SUPPORTED-NOT: is not a recognized processor for this target
 
@@ -1722,6 +1723,28 @@
 ; ARMv81M-MAIN-MVEINT: .eabi_attribute 48, 1 @ Tag_MVE_arch
 ; ARMv81M-MAIN-MVEFP: .eabi_attribute 6, 21 @ Tag_CPU_arch
 ; ARMv81M-MAIN-MVEFP: .eabi_attribute 48, 2 @ Tag_MVE_arch
+
+; CORTEX-M55: .cpu cortex-m55
+; CORTEX-M55: .eabi_attribute 6, 21
+; CORTEX-M55: .eabi_attribute 7, 77
+; CORTEX-M55: .eabi_attribute 8, 0
+; CORTEX-M55: .eabi_attribute 9, 3
+; CORTEX-M55: .fpu fpv5-d16
+; CORTEX-M55: .eabi_attribute 36, 1
+; CORTEX-M55-NOT: .eabi_attribute 44
+; CORTEX-M55: .eabi_attribute 46, 1
+; CORTEX-M55: .eabi_attribute 34, 1
+; CORTEX-M55: .eabi_attribute 17, 1
+; CORTEX-M55-NOT: .eabi_attribute 19
+; CORTEX-M55: .eabi_attribute 20, 1
+; CORTEX-M55: .eabi_attribute 21, 1
+; CORTEX-M55: .eabi_attribute 23, 3
+; CORTEX-M55: .eabi_attribute 24, 1
+; CORTEX-M55: .eabi_attribute 25, 1
+; CORTEX-M55-NOT: .eabi_attribute 28
+; CORTEX-M55: .eabi_attribute 38, 1
+; CORTEX-M55: .eabi_attribute 14, 0
+
 define i32 @f(i64 %z) {
 ret i32 0
 }
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -1124,6 +1124,14 @@
  FeatureUseMISched,
  FeatureHasNoBranchPredictor]>;
 
+def : ProcessorModel<"cortex-m55", CortexM4Model,  [ARMv81mMainline,
+ FeatureDSP,
+ FeatureFPARMv8_D16,
+ FeatureUseMISched,
+ FeatureHasNoBranchPredictor,
+ FeaturePrefLoopAlign32,
+ FeatureHasSlowFPVMLx,
+ HasMVEFloatOps]>;
 
 def : ProcNoItin<"cortex-a32",   [ARMv8a,
  FeatureHWDivThumb,
Index: llvm/lib/Support/Host.cpp
===
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -192,6 +192,7 @@
 .Case("0xc20", "cortex-m0")
 .Case("0xc23", "cortex-m3")
 .Case("0xc24", "cortex-m4")
+   

[clang] 770ad9f - [Analyzer] Fix for iterator modeling and checkers: handle negative numbers correctly

2020-02-25 Thread Adam Balogh via cfe-commits

Author: Adam Balogh
Date: 2020-02-25T14:57:34+01:00
New Revision: 770ad9f55e660e0ec89f61d5579dfafad17ab5f5

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

LOG: [Analyzer] Fix for iterator modeling and checkers: handle negative numbers 
correctly

Currently, using negative numbers in iterator operations (additions and
subractions) results in advancements with huge positive numbers due to
an error. This patch fixes it.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
clang/test/Analysis/iterator-modelling.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp 
b/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
index 64daf358fbe5..e80d8bc32dec 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
@@ -200,22 +200,29 @@ ProgramStateRef advancePosition(ProgramStateRef State, 
const SVal &Iter,
 
   auto &SymMgr = State->getStateManager().getSymbolManager();
   auto &SVB = State->getStateManager().getSValBuilder();
+  auto &BVF = State->getStateManager().getBasicVals();
 
   assert ((Op == OO_Plus || Op == OO_PlusEqual ||
Op == OO_Minus || Op == OO_MinusEqual) &&
   "Advance operator must be one of +, -, += and -=.");
   auto BinOp = (Op == OO_Plus || Op == OO_PlusEqual) ? BO_Add : BO_Sub;
-  if (const auto IntDist = Distance.getAs()) {
-// For concrete integers we can calculate the new position
-const auto NewPos =
-  Pos->setTo(SVB.evalBinOp(State, BinOp,
-   nonloc::SymbolVal(Pos->getOffset()),
-   *IntDist, SymMgr.getType(Pos->getOffset()))
- .getAsSymbol());
-return setIteratorPosition(State, Iter, NewPos);
-  }
+  const auto IntDistOp = Distance.getAs();
+  if (!IntDistOp)
+return nullptr;
 
-  return nullptr;
+  // For concrete integers we can calculate the new position
+  nonloc::ConcreteInt IntDist = *IntDistOp;
+
+  if (IntDist.getValue().isNegative()) {
+IntDist = nonloc::ConcreteInt(BVF.getValue(-IntDist.getValue()));
+BinOp = (BinOp == BO_Add) ? BO_Sub : BO_Add;
+  }
+  const auto NewPos =
+Pos->setTo(SVB.evalBinOp(State, BinOp,
+ nonloc::SymbolVal(Pos->getOffset()),
+ IntDist, SymMgr.getType(Pos->getOffset()))
+   .getAsSymbol());
+  return setIteratorPosition(State, Iter, NewPos);
 }
 
 // This function tells the analyzer's engine that symbols produced by our

diff  --git a/clang/test/Analysis/iterator-modelling.cpp 
b/clang/test/Analysis/iterator-modelling.cpp
index b2551939986a..4e40319cedc1 100644
--- a/clang/test/Analysis/iterator-modelling.cpp
+++ b/clang/test/Analysis/iterator-modelling.cpp
@@ -100,6 +100,16 @@ void plus_equal(const std::vector &v) {
   clang_analyzer_express(clang_analyzer_iterator_position(i)); 
//expected-warning{{$v.begin() + 2}}
 }
 
+void plus_equal_negative(const std::vector &v) {
+  auto i = v.end();
+
+  clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
+
+  i += -2;
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i)); 
//expected-warning{{$v.end() - 2}}
+}
+
 void minus_equal(const std::vector &v) {
   auto i = v.end();
 
@@ -110,6 +120,16 @@ void minus_equal(const std::vector &v) {
   clang_analyzer_express(clang_analyzer_iterator_position(i)); 
//expected-warning{{$v.end() - 2}}
 }
 
+void minus_equal_negative(const std::vector &v) {
+  auto i = v.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
+
+  i -= -2;
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i)); 
//expected-warning{{$v.begin() + 2}}
+}
+
 void copy(const std::vector &v) {
   auto i1 = v.end();
 
@@ -132,6 +152,17 @@ void plus(const std::vector &v) {
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); 
//expected-warning{{$v.begin() + 2}}
 }
 
+void plus_negative(const std::vector &v) {
+  auto i1 = v.end();
+
+  clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
+
+  auto i2 = i1 + (-2);
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // 
expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); 
//expected-warning{{$v.end() - 2}}
+}
+
 void minus(const std::vector &v) {
   auto i1 = v.end();
 
@@ -143,6 +174,17 @@ void minus(const std::vector &v) {
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); 
//expected-warning{{$v.end() - 2}}
 }
 
+void minus_negative(const std::vector &v) {
+  auto i1 = v.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
+
+  auto i2 = i1 - (-2);
+
+  clang_analyzer_eval(clang_analy

[PATCH] D72035: [analyzer][NFC] Use CallEvent checker callback in GenericTaintChecker

2020-02-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked 5 inline comments as done.
steakhal added a comment.

In D72035#1889320 , @Szelethus wrote:

> Wow. Its a joy to see you do C++. LGTM. Are you planning to introduce 
> `CallDescriptionMap` at one point? :)


Yes, definitely.




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:492-509
+const auto OneOf = [FDecl](const auto &... Name) {
+  // FIXME: use fold expression in C++17
+  using unused = int[];
+  bool ret = false;
+  static_cast(unused{
+  0, (ret |= CheckerContext::isCLibraryFunction(FDecl, Name), 0)...});
+  return ret;

Szelethus wrote:
> Whoa, this is amazing, but looks like a google interview question or 
> something -- is this a technique I should know about it? I feel like we kinda 
> sacrificed readability for coolness.
Actually, I agree but still convinced that it is the future-compatible way of 
doing this.
```lang=c++
const auto OneOf = [FDecl](const auto &... Name) {
  // FIXME: use fold expression in C++17
  using unused = int[];
  bool ret = false;
  static_cast(unused{
  0, (ret |= CheckerContext::isCLibraryFunction(FDecl, Name), 0)...});
  return ret;
};
```
In C++17 using fold expressions the whole lambda could be implemented such a 
way:
```lang=c++
const auto OneOf = [FDecl](const auto &... Name) {
  return (CheckerContext::isCLibraryFunction(FDecl, Name) || ...);
};
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72035



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


[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D69560#1891185 , @whisperity wrote:

> @aaron.ballman @vingeldal I'll go over the findings (as I've run this on LLVM 
> and various other projects, a few examples are uploaded in my first comment 
> as HTML renders of the bug report!) soon, but I want to wait until a research 
> paper I have based on this topic gets a final decision. (It should happen 
> soon.) I also plan to refurbish D20689  and 
> have it upstreamed as a "co-checker" of this (one for the interface rule, one 
> for the call sites, they kinda want to solve different aspects of the same 
> issue, let it be up for the project how much they wish to enforce).


Sounds great, thank you!


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

https://reviews.llvm.org/D69560



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


[PATCH] D74878: [remark][diagnostics] [codegen] Fix PR44896

2020-02-25 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Nice work, LGTM too.


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

https://reviews.llvm.org/D74878



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


[PATCH] D74760: [Analyzer] Fix for iterator modeling and checkers: handle negative numbers correctly

2020-02-25 Thread Balogh, Ádám via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG770ad9f55e66: [Analyzer] Fix for iterator modeling and 
checkers: handle negative numbers… (authored by baloghadamsoftware).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74760

Files:
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/test/Analysis/iterator-modelling.cpp

Index: clang/test/Analysis/iterator-modelling.cpp
===
--- clang/test/Analysis/iterator-modelling.cpp
+++ clang/test/Analysis/iterator-modelling.cpp
@@ -100,6 +100,16 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i)); //expected-warning{{$v.begin() + 2}}
 }
 
+void plus_equal_negative(const std::vector &v) {
+  auto i = v.end();
+
+  clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
+
+  i += -2;
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i)); //expected-warning{{$v.end() - 2}}
+}
+
 void minus_equal(const std::vector &v) {
   auto i = v.end();
 
@@ -110,6 +120,16 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i)); //expected-warning{{$v.end() - 2}}
 }
 
+void minus_equal_negative(const std::vector &v) {
+  auto i = v.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
+
+  i -= -2;
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i)); //expected-warning{{$v.begin() + 2}}
+}
+
 void copy(const std::vector &v) {
   auto i1 = v.end();
 
@@ -132,6 +152,17 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); //expected-warning{{$v.begin() + 2}}
 }
 
+void plus_negative(const std::vector &v) {
+  auto i1 = v.end();
+
+  clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
+
+  auto i2 = i1 + (-2);
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); //expected-warning{{$v.end() - 2}}
+}
+
 void minus(const std::vector &v) {
   auto i1 = v.end();
 
@@ -143,6 +174,17 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); //expected-warning{{$v.end() - 2}}
 }
 
+void minus_negative(const std::vector &v) {
+  auto i1 = v.begin();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
+
+  auto i2 = i1 - (-2);
+
+  clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); //expected-warning{{$v.begin() + 2}}
+}
+
 void copy_and_increment1(const std::vector &v) {
   auto i1 = v.begin();
 
Index: clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
+++ clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
@@ -200,22 +200,29 @@
 
   auto &SymMgr = State->getStateManager().getSymbolManager();
   auto &SVB = State->getStateManager().getSValBuilder();
+  auto &BVF = State->getStateManager().getBasicVals();
 
   assert ((Op == OO_Plus || Op == OO_PlusEqual ||
Op == OO_Minus || Op == OO_MinusEqual) &&
   "Advance operator must be one of +, -, += and -=.");
   auto BinOp = (Op == OO_Plus || Op == OO_PlusEqual) ? BO_Add : BO_Sub;
-  if (const auto IntDist = Distance.getAs()) {
-// For concrete integers we can calculate the new position
-const auto NewPos =
-  Pos->setTo(SVB.evalBinOp(State, BinOp,
-   nonloc::SymbolVal(Pos->getOffset()),
-   *IntDist, SymMgr.getType(Pos->getOffset()))
- .getAsSymbol());
-return setIteratorPosition(State, Iter, NewPos);
-  }
+  const auto IntDistOp = Distance.getAs();
+  if (!IntDistOp)
+return nullptr;
 
-  return nullptr;
+  // For concrete integers we can calculate the new position
+  nonloc::ConcreteInt IntDist = *IntDistOp;
+
+  if (IntDist.getValue().isNegative()) {
+IntDist = nonloc::ConcreteInt(BVF.getValue(-IntDist.getValue()));
+BinOp = (BinOp == BO_Add) ? BO_Sub : BO_Add;
+  }
+  const auto NewPos =
+Pos->setTo(SVB.evalBinOp(State, BinOp,
+ nonloc::SymbolVal(Pos->getOffset()),
+ IntDist, SymMgr.getType(Pos->getOffset()))
+   .getAsSymbol());
+  return setIteratorPosition(State, Iter, NewPos);
 }
 
 // This function tells the analyzer's engine that symbols produced by our
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D69560#1891167 , @aaron.ballman 
wrote:

> Btw, we should update the terminology in the patch to use `parameter` instead 
> of `argument` (parameters are what the function declares, arguments are what 
> are passed in at the call site and they bind to parameters -- the issue this 
> check is trying to solve is on the declaration side, not the caller side).


Indeed, I think I got confused because the rule heading says "parameter" but 
immediately the line following says "argument". I'll rename the check, also 
potentially rebase and all that, it should be a trivial thing to do.
My bigger concerns are about the subsequent patch which makes this rule 
matching order of magnitude more powerful is implicit conversions. See D75041 
 for that.

(Originally, the entire idea we came up with was more of a local brainstorming, 
and it was only during development that I realised that there is a (somewhat?) 
matching guideline rule about this.)


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

https://reviews.llvm.org/D69560



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


[PATCH] D75041: [WIP][clang-tidy] Approximate implicit conversion issues for the 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Whisperity via Phabricator via cfe-commits
whisperity added a reviewer: aaron.ballman.
whisperity added subscribers: vingeldal, zporky.
whisperity added a comment.

**WIP** because there's a lot of debug stuff that should be cleared out from 
here. This is a crude patch. It works fancy, but the code is crude.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75041



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


[PATCH] D74846: fix -fcodegen-modules code when used with PCH (PR44953)

2020-02-25 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

@llunak Do you have time to address this patch this week? If not, I can finish 
it and land it. Please let me know. We'd like to see it merged into 10.0.


Repository:
  rC Clang

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

https://reviews.llvm.org/D74846



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


[PATCH] D71524: [analyzer] Support tainted objects in GenericTaintChecker

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/test/Analysis/taint-generic.cpp:189
+  istream& getline(istream& is, string& str);
+}
+

These `std` declarations are at a better place in 
`system-header-simulator-cxx.h` or a similar file.


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

https://reviews.llvm.org/D71524



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


[clang] 83f4372 - [CodeGen] fix clang test that runs the optimizer pipeline; NFC

2020-02-25 Thread Sanjay Patel via cfe-commits

Author: Sanjay Patel
Date: 2020-02-25T09:13:49-05:00
New Revision: 83f4372f3a708ceaa800feff8b1bd92ae2c3be5f

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

LOG: [CodeGen] fix clang test that runs the optimizer pipeline; NFC

There's already a FIXME note on this file; it can break when the
underlying LLVM behavior changes independently of anything in clang.

Added: 


Modified: 
clang/test/CodeGen/complex-math.c

Removed: 




diff  --git a/clang/test/CodeGen/complex-math.c 
b/clang/test/CodeGen/complex-math.c
index e42418ad72c2..54dee473a364 100644
--- a/clang/test/CodeGen/complex-math.c
+++ b/clang/test/CodeGen/complex-math.c
@@ -93,14 +93,15 @@ float _Complex mul_float_rc(float a, float _Complex b) {
   // X86: ret
   return a * b;
 }
+
 float _Complex mul_float_cc(float _Complex a, float _Complex b) {
   // X86-LABEL: @mul_float_cc(
   // X86: %[[AC:[^ ]+]] = fmul
   // X86: %[[BD:[^ ]+]] = fmul
   // X86: %[[AD:[^ ]+]] = fmul
   // X86: %[[BC:[^ ]+]] = fmul
-  // X86: %[[RR:[^ ]+]] = fsub float %[[AC]], %[[BD]]
-  // X86: %[[RI:[^ ]+]] = fadd float
+  // X86: %[[RR:[^ ]+]] = fsub
+  // X86: %[[RI:[^ ]+]] = fadd
   // X86-DAG: %[[AD]]
   // X86-DAG: ,
   // X86-DAG: %[[BC]]



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


[clang] 91f7f0d - [RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC

2020-02-25 Thread Luís Marques via cfe-commits

Author: Luís Marques
Date: 2020-02-25T14:17:45Z
New Revision: 91f7f0d8e3ef2b6be07bc9621de075ff11c730c9

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

LOG: [RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC

D68391 added tests that check scenarios where no RISC-V GCC toolchain is
supposed to be detected. When running the tests on RISC-V hosts the system's
GCC toolchain will be detected, and the tests will fail. This patch adds a
`--gcc-toolchain` option pointing to a path where no GCC toolchain is
present, ensuring that the tests are run under the expected conditions, and
therefore are able to pass in all test environments.

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

Added: 


Modified: 
clang/test/Driver/riscv32-toolchain-extra.c
clang/test/Driver/riscv64-toolchain-extra.c

Removed: 




diff  --git a/clang/test/Driver/riscv32-toolchain-extra.c 
b/clang/test/Driver/riscv32-toolchain-extra.c
index ad3974bd9c78..ff9842b37c02 100644
--- a/clang/test/Driver/riscv32-toolchain-extra.c
+++ b/clang/test/Driver/riscv32-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld 
%T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf 
%T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
 // RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv32-baremetal-nogcc/invalid \
 // RUN:-target riscv32-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 

diff  --git a/clang/test/Driver/riscv64-toolchain-extra.c 
b/clang/test/Driver/riscv64-toolchain-extra.c
index 2213d96456ec..6b474e88f473 100644
--- a/clang/test/Driver/riscv64-toolchain-extra.c
+++ b/clang/test/Driver/riscv64-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld 
%T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/riscv64-unknown-elf 
%T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf
 // RUN: %T/testroot-riscv64-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv64-baremetal-nogcc/invalid \
 // RUN:-target riscv64-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV64-BAREMETAL-LP64-NOGCC %s
 



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


[PATCH] D75113: [docs] dump-ast-matchers removes const from Matcher args and handles template functions slightly better

2020-02-25 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, joerg.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75113

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/tools/dump_ast_matchers.py

Index: clang/docs/tools/dump_ast_matchers.py
===
--- clang/docs/tools/dump_ast_matchers.py
+++ clang/docs/tools/dump_ast_matchers.py
@@ -101,6 +101,8 @@
   args = re.sub(r'extern const\s+(.*)&', r'\1 ', args)
   args = re.sub(r'&', r' ', args)
   args = re.sub(r'(^|\s)M\d?(\s)', r'\1Matcher<*>\2', args)
+  args = re.sub(r'BindableMatcher', r'Matcher', args)
+  args = re.sub(r'const Matcher', r'Matcher', args)
   return args
 
 def unify_type(result_type):
@@ -125,7 +127,8 @@
 'id': matcher_id,
   }
   if is_dyncast:
-node_matchers[result_type + name] = matcher_html
+dict = node_matchers
+lookup = result_type + name
   # Use a heuristic to figure out whether a matcher is a narrowing or
   # traversal matcher. By default, matchers that take other matchers as
   # arguments (and are not node matchers) do traversal. We specifically
@@ -133,9 +136,14 @@
   # arguments.
   elif ('Matcher<' not in args or
 name in ['allOf', 'anyOf', 'anything', 'unless']):
-narrowing_matchers[result_type + name + esc(args)] = matcher_html
+dict = narrowing_matchers
+lookup = result_type + name + esc(args)
   else:
-traversal_matchers[result_type + name + esc(args)] = matcher_html
+dict = traversal_matchers
+lookup = result_type + name + esc(args)
+  
+  if dict.get(lookup) is None or len(dict.get(lookup)) < len(matcher_html):
+dict[lookup] = matcher_html
 
 def act_on_decl(declaration, comment, allowed_types):
   """Parse the matcher out of the given declaration and comment.
@@ -145,6 +153,9 @@
  definition.
   """
   if declaration.strip():
+
+if re.match(r'^\s?(#|namespace|using)', declaration): return
+
 # Node matchers are defined by writing:
 #   VariadicDynCastAllOfMatcher name;
 m = re.match(r""".*Variadic(?:DynCast)?AllOfMatcher\s*<
@@ -317,16 +328,27 @@
 
 # Parse free standing matcher functions, like:
 #   Matcher Name(Matcher InnerMatcher) {
-m = re.match(r"""^\s*(.*)\s+
+m = re.match(r"""^\s*(?:template\s+<\s*(?:class|typename)\s+(.+)\s*>\s+)?   
+ (.*)\s+
  ([^\s\(]+)\s*\(
  (.*)
  \)\s*{""", declaration, re.X)
 if m:
-  result, name, args = m.groups()
+  template_name, result, name, args = m.groups()
+  if template_name:
+matcherTemplateArgs = re.findall(r'Matcher<\s*(%s)\s*>' % template_name, args)
+templateArgs = re.findall(r'(?:^|[\s,<])(%s)(?:$|[\s,>])' % template_name, args)
+if len(matcherTemplateArgs) < len(templateArgs):
+  # The template name is used naked, so don't replace with `*`` later on
+  template_name = None
+else :
+  args = re.sub(r'(^|[\s,<])%s($|[\s,>])' % template_name, r'\1*\2', args)
   args = ', '.join(p.strip() for p in args.split(','))
-  m = re.match(r'.*\s+internal::(Bindable)?Matcher<([^>]+)>$', result)
+  m = re.match(r'(?:^|.*\s+)internal::(?:Bindable)?Matcher<([^>]+)>$', result)
   if m:
-result_types = [m.group(2)]
+result_types = [m.group(1)]
+if template_name and len(result_types) is 1 and result_types[0] == template_name:
+  result_types = ['*']
   else:
 result_types = extract_result_types(comment)
   if not result_types:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -4669,6 +4669,22 @@
 
 
 
+Matcher<*>findAllMatcher<*>  Matcher
+Matches if the node or any descendant matches.
+
+Generates results for each match.
+
+For example, in:
+  class A { class B {}; class C {}; };
+The matcher:
+  cxxRecordDecl(hasName("::A"),
+findAll(cxxRecordDecl(isDefinition()).bind("m")))
+will generate results for A, B and C.
+
+Usable as: Any Matcher
+
+
+
 Matcher<*>forEachDescendantMatcher<*>
 Matches AST nodes that have descendant AST nodes that match the
 provided matcher.
@@ -4803,6 +4819,22 @@
 
 
 
+Matcher<*>traverseTraversalKind TK, Matcher<*>  InnerMatcher
+Causes all nested matchers to be matched with the specified traversal kind.
+
+Given
+  void foo()
+  {
+  int i = 3.0;
+  }
+The matcher
+  traverse(TK_IgnoreImplicitCastsAndParentheses,
+varDecl(hasInitializer(floatLiteral().bind("init")))
+  )
+matches the variable declaration with "init" bound to the "3.0".
+
+
+
 MatcherAbstractConditionalOperator>hasConditionMatcher

[PATCH] D69560: [clang-tidy] Add 'cppcoreguidelines-avoid-adjacent-arguments-of-same-type' check

2020-02-25 Thread Zoltan Porkolab via Phabricator via cfe-commits
zporky added a comment.

Agree that we could make an attempt to detect "related" parameters.
A possible heuristic to detect "related arguments" would be to look for 
interactions between  these arguments, e.g. check whether we use them in 
specific operations, e.g.

// tipical for related iterators
par1 == par2
par1 != par2 
etc

// tipical for pointers
par1 - par2 
*par1 = *par2

and similar.


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

https://reviews.llvm.org/D69560



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


[PATCH] D75061: [RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC

2020-02-25 Thread Luís Marques via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91f7f0d8e3ef: [RISCV] Fix sysroot tests without GCC on 
RISC-V hosts with GCC (authored by luismarques).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75061

Files:
  clang/test/Driver/riscv32-toolchain-extra.c
  clang/test/Driver/riscv64-toolchain-extra.c


Index: clang/test/Driver/riscv64-toolchain-extra.c
===
--- clang/test/Driver/riscv64-toolchain-extra.c
+++ clang/test/Driver/riscv64-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld 
%T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/riscv64-unknown-elf 
%T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf
 // RUN: %T/testroot-riscv64-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv64-baremetal-nogcc/invalid \
 // RUN:-target riscv64-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV64-BAREMETAL-LP64-NOGCC %s
 
Index: clang/test/Driver/riscv32-toolchain-extra.c
===
--- clang/test/Driver/riscv32-toolchain-extra.c
+++ clang/test/Driver/riscv32-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld 
%T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf 
%T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
 // RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv32-baremetal-nogcc/invalid \
 // RUN:-target riscv32-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 


Index: clang/test/Driver/riscv64-toolchain-extra.c
===
--- clang/test/Driver/riscv64-toolchain-extra.c
+++ clang/test/Driver/riscv64-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/bin/riscv64-unknown-elf-ld %T/testroot-riscv64-baremetal-nogcc/bin/riscv64-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv64_nogcc_tree/riscv64-unknown-elf %T/testroot-riscv64-baremetal-nogcc/riscv64-unknown-elf
 // RUN: %T/testroot-riscv64-baremetal-nogcc/bin/clang %s -### -no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv64-baremetal-nogcc/invalid \
 // RUN:-target riscv64-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV64-BAREMETAL-LP64-NOGCC %s
 
Index: clang/test/Driver/riscv32-toolchain-extra.c
===
--- clang/test/Driver/riscv32-toolchain-extra.c
+++ clang/test/Driver/riscv32-toolchain-extra.c
@@ -19,6 +19,7 @@
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld %T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
 // RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf %T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
 // RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### -no-canonical-prefixes \
+// RUN:--gcc-toolchain=%T/testroot-riscv32-baremetal-nogcc/invalid \
 // RUN:-target riscv32-unknown-elf --rtlib=platform 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2bd6974 - [clang-format] Wrap lines for C# property accessors

2020-02-25 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-02-25T14:23:47Z
New Revision: 2bd6974aaa664f01e8822514295425fee380b131

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

LOG: [clang-format]  Wrap lines for C# property accessors

Summary: Ensure that auto-implemented properties `{ get; private set }` are 
wrapped on to one line for C# code.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 0e1b5e95e9dd..da9ee41da71b 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -292,6 +292,13 @@ class LineJoiner {
   }
 }
 
+// Try to merge a CSharp property declaration like `{ get; private set }`.
+if (Style.isCSharp()) {
+  unsigned CSPA = tryMergeCSharpPropertyAccessor(I, E, Limit);
+  if (CSPA > 0)
+return CSPA;
+}
+
 // Try to merge a function block with left brace unwrapped
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First != TheLine->Last) {
@@ -421,6 +428,64 @@ class LineJoiner {
 return 0;
   }
 
+  // true for lines of the form [access-modifier] {get,set} [;]
+  bool isMergeablePropertyAccessor(const AnnotatedLine *Line) {
+auto *Tok = Line->First;
+if (!Tok)
+  return false;
+
+if (Tok->isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private,
+ Keywords.kw_internal))
+  Tok = Tok->Next;
+
+if (!Tok || (Tok->TokenText != "get" && Tok->TokenText != "set"))
+  return false;
+
+if (!Tok->Next || Tok->Next->is(tok::semi))
+  return true;
+
+return false;
+  }
+
+  unsigned tryMergeCSharpPropertyAccessor(
+  SmallVectorImpl::const_iterator I,
+  SmallVectorImpl::const_iterator E, unsigned /*Limit*/) {
+
+auto CurrentLine = I;
+// Does line start with `{`
+if (!(*CurrentLine)->Last || 
(*CurrentLine)->Last->isNot(TT_FunctionLBrace))
+  return 0;
+++CurrentLine;
+
+unsigned MergedLines = 0;
+bool HasGetOrSet = false;
+while (CurrentLine != E) {
+  bool LineIsGetOrSet = isMergeablePropertyAccessor(*CurrentLine);
+  HasGetOrSet = HasGetOrSet || LineIsGetOrSet;
+  if (LineIsGetOrSet) {
+++CurrentLine;
+++MergedLines;
+continue;
+  }
+  auto *Tok = (*CurrentLine)->First;
+  if (Tok && Tok->is(tok::r_brace)) {
+++CurrentLine;
+++MergedLines;
+// See if the next line is a default value so that we can merge `{ get;
+// set } = 0`
+if (CurrentLine != E && (*CurrentLine)->First &&
+(*CurrentLine)->First->is(tok::equal)) {
+  ++MergedLines;
+}
+break;
+  }
+  // Not a '}' or a get/set line so do not merege lines.
+  return 0;
+}
+
+return HasGetOrSet ? MergedLines : 0;
+  }
+
   unsigned
   tryMergeSimplePPDirective(SmallVectorImpl::const_iterator I,
 SmallVectorImpl::const_iterator E,

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 1800768d6771..68a8e9fefe2d 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -240,18 +240,12 @@ TEST_F(FormatTestCSharp, Attributes) {
 
   verifyFormat("[TestMethod]\n"
"public string Host\n"
-   "{\n"
-   "set;\n"
-   "get;\n"
-   "}");
+   "{ set; get; }");
 
   verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server "
"listening on provided host\")]\n"
"public string Host\n"
-   "{\n"
-   "set;\n"
-   "get;\n"
-   "}");
+   "{ set; get; }");
 
   verifyFormat(
   "[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n"
@@ -554,5 +548,32 @@ PrintOrderDetails(orderNum: 31, productName: "Red Mug",  
// comment
Style);
 }
 
+TEST_F(FormatTestCSharp, CSharpPropertyAccessors) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("int Value { get }", Style);
+  verifyFormat("int Value { get; }", Style);
+  verifyFormat("int Value { internal get; }", Style);
+  verifyFormat("int Value { get; } = 0", Style);
+  verifyFormat("int Value { set }", Style);
+  verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { internal set; }", Style);
+  verifyForma

[PATCH] D75006: [clang-format] Wrap lines for C# property accessors

2020-02-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2bd6974aaa66: [clang-format]  Wrap lines for C# property 
accessors (authored by Jonathan Coe ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75006

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -240,18 +240,12 @@
 
   verifyFormat("[TestMethod]\n"
"public string Host\n"
-   "{\n"
-   "set;\n"
-   "get;\n"
-   "}");
+   "{ set; get; }");
 
   verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server "
"listening on provided host\")]\n"
"public string Host\n"
-   "{\n"
-   "set;\n"
-   "get;\n"
-   "}");
+   "{ set; get; }");
 
   verifyFormat(
   "[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n"
@@ -554,5 +548,32 @@
Style);
 }
 
+TEST_F(FormatTestCSharp, CSharpPropertyAccessors) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("int Value { get }", Style);
+  verifyFormat("int Value { get; }", Style);
+  verifyFormat("int Value { internal get; }", Style);
+  verifyFormat("int Value { get; } = 0", Style);
+  verifyFormat("int Value { set }", Style);
+  verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { internal set; }", Style);
+  verifyFormat("int Value { set; } = 0", Style);
+  verifyFormat("int Value { get; set }", Style);
+  verifyFormat("int Value { set; get }", Style);
+  verifyFormat("int Value { get; private set; }", Style);
+  verifyFormat("int Value { get; set; }", Style);
+  verifyFormat("int Value { get; set; } = 0", Style);
+  verifyFormat("int Value { internal get; internal set; }", Style);
+
+  // Do not wrap expression body definitions.
+  verifyFormat(R"(//
+public string Name {
+  get => _name;
+  set => _name = value;
+})",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -292,6 +292,13 @@
   }
 }
 
+// Try to merge a CSharp property declaration like `{ get; private set }`.
+if (Style.isCSharp()) {
+  unsigned CSPA = tryMergeCSharpPropertyAccessor(I, E, Limit);
+  if (CSPA > 0)
+return CSPA;
+}
+
 // Try to merge a function block with left brace unwrapped
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First != TheLine->Last) {
@@ -421,6 +428,64 @@
 return 0;
   }
 
+  // true for lines of the form [access-modifier] {get,set} [;]
+  bool isMergeablePropertyAccessor(const AnnotatedLine *Line) {
+auto *Tok = Line->First;
+if (!Tok)
+  return false;
+
+if (Tok->isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private,
+ Keywords.kw_internal))
+  Tok = Tok->Next;
+
+if (!Tok || (Tok->TokenText != "get" && Tok->TokenText != "set"))
+  return false;
+
+if (!Tok->Next || Tok->Next->is(tok::semi))
+  return true;
+
+return false;
+  }
+
+  unsigned tryMergeCSharpPropertyAccessor(
+  SmallVectorImpl::const_iterator I,
+  SmallVectorImpl::const_iterator E, unsigned /*Limit*/) {
+
+auto CurrentLine = I;
+// Does line start with `{`
+if (!(*CurrentLine)->Last || (*CurrentLine)->Last->isNot(TT_FunctionLBrace))
+  return 0;
+++CurrentLine;
+
+unsigned MergedLines = 0;
+bool HasGetOrSet = false;
+while (CurrentLine != E) {
+  bool LineIsGetOrSet = isMergeablePropertyAccessor(*CurrentLine);
+  HasGetOrSet = HasGetOrSet || LineIsGetOrSet;
+  if (LineIsGetOrSet) {
+++CurrentLine;
+++MergedLines;
+continue;
+  }
+  auto *Tok = (*CurrentLine)->First;
+  if (Tok && Tok->is(tok::r_brace)) {
+++CurrentLine;
+++MergedLines;
+// See if the next line is a default value so that we can merge `{ get;
+// set } = 0`
+if (CurrentLine != E && (*CurrentLine)->First &&
+(*CurrentLine)->First->is(tok::equal)) {
+  ++MergedLines;
+}
+break;
+  }
+  // Not a '}' or a get/set line so do not merege lines.
+  return 0;
+}
+
+return HasGetOrSet ? MergedLines : 0;
+  }
+
   unsigned
   tryMergeSimplePPDirective(SmallVectorImpl::const_iterator I,
 SmallVectorImpl::const_iterator E,
__

[PATCH] D68163: [analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 5 inline comments as done.
Szelethus added inline comments.
Herald added subscribers: martong, steakhal.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:259
   /// calls.
   bool isCalled(const CallDescription &CD) const;
 

Szelethus wrote:
> NoQ wrote:
> > I don't fully understand how does overload resolution work in this case, 
> > maybe rename the original function?
> Well, `isCalled` may now have an arbitrary number of arguments. The single 
> argument version is this function, and the //n//-argument ones call this 
> //n// times: `isCalled(A, B, C)` -> `isCalled(A) || isCalled(B) || 
> isCalled(B)`. I guess I could rename the other one to `isAnyCalled`, but I 
> think its fine.
But that would be super ugly imo :/ I think the current implementation is 
intuitive enough, but I'm happy to change it if you disagree.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1006
   const FunctionDecl *FD = C.getCalleeDecl(CE);
-  if (!FD)
+  if (!FD || FD->getKind() != Decl::Function)
 return;

Szelethus wrote:
> kimgr wrote:
> > NoQ wrote:
> > > The `FD->getKind() != Decl::Function` part is super mega redundant here.
> > Sorry for jumping in from nowhere. AFAIK, this is the only way to detect 
> > free vs member functions. It looks like this wants to discard member 
> > functions. Are you sure it's redundant? 
> Please do! Though I have a suspicion that if this isn't redundant, such a 
> check should be done in `CallDescription`.
I agree that it should be removed, since we explicitly support functions 
annotated to return a dynamically allocated memory region, //even// if it is a 
member function.


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

https://reviews.llvm.org/D68163



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


[PATCH] D75001: [OpenMP][cmake] ignore warning on unknown CUDA version

2020-02-25 Thread Kelvin Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe16e267bb6ee: [OpenMP][cmake] ignore warning on unknown CUDA 
version (authored by kkwli0).
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75001

Files:
  openmp/runtime/cmake/LibompCheckLinkerFlag.cmake


Index: openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
===
--- openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
+++ openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
@@ -38,7 +38,8 @@
 
   if(try_compile_result)
 foreach(regex IN LISTS failed_regexes)
-  if("${OUTPUT}" MATCHES ${regex})
+  # Ignore the warning about the newer or unknown CUDA version.
+  if(("${OUTPUT}" MATCHES ${regex}) AND NOT ("${OUTPUT}" MATCHES "Unknown 
CUDA version"))
 set(retval FALSE)
   endif()
 endforeach()


Index: openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
===
--- openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
+++ openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
@@ -38,7 +38,8 @@
 
   if(try_compile_result)
 foreach(regex IN LISTS failed_regexes)
-  if("${OUTPUT}" MATCHES ${regex})
+  # Ignore the warning about the newer or unknown CUDA version.
+  if(("${OUTPUT}" MATCHES ${regex}) AND NOT ("${OUTPUT}" MATCHES "Unknown CUDA version"))
 set(retval FALSE)
   endif()
 endforeach()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] e09754c - [clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers

2020-02-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-02-25T15:36:45+01:00
New Revision: e09754ccefc8cff7ae5fa18ce73db76339b559f5

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

LOG: [clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers

Summary:
Also fixes a bug, resulting from directly using ND.getEndLoc() for end
location of the range. As ND.getEndLoc() points to the begining of the last
token, whereas it should point one past the end, since LSP ranges are half open
(exclusive on the end).

Reviewers: sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/test/type-hierarchy.test

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index c723f97dc501..3e0c9f79fc57 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -36,6 +36,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/STLExtras.h"
@@ -593,22 +594,23 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 
const LocatedSymbol &S) {
 
 // FIXME(nridge): Reduce duplication between this function and declToSym().
 static llvm::Optional
-declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
+declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
+const syntax::TokenBuffer &TB) {
   auto &SM = Ctx.getSourceManager();
-
   SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top 
of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
-  SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
-  SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
+  auto FilePath =
+  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(NameLoc)), SM);
+  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
+  if (!FilePath || !TUPath)
+return llvm::None; // Not useful without a uri.
+
+  auto DeclToks = 
TB.spelledForExpanded(TB.expandedTokens(ND.getSourceRange()));
+  if (!DeclToks || DeclToks->empty())
 return llvm::None;
 
-  Position NameBegin = sourceLocToPosition(SM, NameLoc);
-  Position NameEnd = sourceLocToPosition(
-  SM, Lexer::getLocForEndOfToken(NameLoc, 0, SM, Ctx.getLangOpts()));
+  auto NameToks = TB.spelledForExpanded(TB.expandedTokens(NameLoc));
+  if (!NameToks || NameToks->empty())
+return llvm::None;
 
   index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
   // FIXME: this is not classifying constructors, destructors and operators
@@ -619,20 +621,18 @@ declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl 
&ND) {
   THI.name = printName(Ctx, ND);
   THI.kind = SK;
   THI.deprecated = ND.isDeprecated();
-  THI.range =
-  Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, 
EndLoc)};
-  THI.selectionRange = Range{NameBegin, NameEnd};
+  THI.range = halfOpenToRange(
+  SM, syntax::Token::range(SM, DeclToks->front(), DeclToks->back())
+  .toCharRange(SM));
+  THI.selectionRange = halfOpenToRange(
+  SM, syntax::Token::range(SM, NameToks->front(), NameToks->back())
+  .toCharRange(SM));
   if (!THI.range.contains(THI.selectionRange)) {
 // 'selectionRange' must be contained in 'range', so in cases where clang
 // reports unrelated ranges we need to reconcile somehow.
 THI.range = THI.selectionRange;
   }
 
-  auto FilePath =
-  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(BeginLoc)), SM);
-  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
-  if (!FilePath || !TUPath)
-return llvm::None; // Not useful without a uri.
   THI.uri = URIForFile::canonicalize(*FilePath, *TUPath);
 
   return THI;
@@ -685,7 +685,8 @@ using RecursionProtectionSet = llvm::SmallSet;
 
 static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
std::vector &SuperTypes,
-   RecursionProtectionSet &RPSet) {
+   RecursionProtectionSet &RPSet,
+   const syntax::TokenBuffer &TB) {
   // typeParents() will replace dependent template specializations
   // with their

[PATCH] D75093: clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D75093#1891067 , @thakis wrote:

> This is what -MD passes (which is why the -sys flag already exists), and more 
> orthogonal flags instead of fewer, tangled ones is what we usually go for at 
> the cc1 layer. So I like it more as is.


Ah cool, I didn't realize that. Yes, this makes sense then.


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

https://reviews.llvm.org/D75093



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


[PATCH] D74850: [clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers

2020-02-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe09754ccefc8: [clangd] Migrate Lexer usages in TypeHierarchy 
to TokenBuffers (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74850

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/test/type-hierarchy.test

Index: clang-tools-extra/clangd/test/type-hierarchy.test
===
--- clang-tools-extra/clangd/test/type-hierarchy.test
+++ clang-tools-extra/clangd/test/type-hierarchy.test
@@ -48,7 +48,7 @@
 # CHECK-NEXT:"parents": [],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 15,
+# CHECK-NEXT:"character": 16,
 # CHECK-NEXT:"line": 0
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
@@ -71,7 +71,7 @@
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"character": 25,
 # CHECK-NEXT:"line": 1
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
@@ -94,7 +94,7 @@
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"character": 25,
 # CHECK-NEXT:"line": 2
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -36,6 +36,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/STLExtras.h"
@@ -593,22 +594,23 @@
 
 // FIXME(nridge): Reduce duplication between this function and declToSym().
 static llvm::Optional
-declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
+declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
+const syntax::TokenBuffer &TB) {
   auto &SM = Ctx.getSourceManager();
-
   SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
-  SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
-  SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
+  auto FilePath =
+  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(NameLoc)), SM);
+  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
+  if (!FilePath || !TUPath)
+return llvm::None; // Not useful without a uri.
+
+  auto DeclToks = TB.spelledForExpanded(TB.expandedTokens(ND.getSourceRange()));
+  if (!DeclToks || DeclToks->empty())
 return llvm::None;
 
-  Position NameBegin = sourceLocToPosition(SM, NameLoc);
-  Position NameEnd = sourceLocToPosition(
-  SM, Lexer::getLocForEndOfToken(NameLoc, 0, SM, Ctx.getLangOpts()));
+  auto NameToks = TB.spelledForExpanded(TB.expandedTokens(NameLoc));
+  if (!NameToks || NameToks->empty())
+return llvm::None;
 
   index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
   // FIXME: this is not classifying constructors, destructors and operators
@@ -619,20 +621,18 @@
   THI.name = printName(Ctx, ND);
   THI.kind = SK;
   THI.deprecated = ND.isDeprecated();
-  THI.range =
-  Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, EndLoc)};
-  THI.selectionRange = Range{NameBegin, NameEnd};
+  THI.range = halfOpenToRange(
+  SM, syntax::Token::range(SM, DeclToks->front(), DeclToks->back())
+  .toCharRange(SM));
+  THI.selectionRange = halfOpenToRange(
+  SM, syntax::Token::range(SM, NameToks->front(), NameToks->back())
+  .toCharRange(SM));
   if (!THI.range.contains(THI.selectionRange)) {
 // 'selectionRange' must be contained in 'range', so in cases where clang
 // reports unrelated ranges we need to reconcile somehow.
 THI.range = THI.selectionRange;
   }
 
-  auto FilePath =
-  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(BeginLoc)), SM);
-  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
-  if (!FilePath || !TUPath)
-return llvm::None; // Not useful without a uri.
   THI.uri = URIForFile::canonicalize(*FilePath, *TUPath);
 
   return THI;
@@ -685,7 +685,8 @@
 
 static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,

[PATCH] D74850: [clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers

2020-02-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 246439.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74850

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/test/type-hierarchy.test

Index: clang-tools-extra/clangd/test/type-hierarchy.test
===
--- clang-tools-extra/clangd/test/type-hierarchy.test
+++ clang-tools-extra/clangd/test/type-hierarchy.test
@@ -48,7 +48,7 @@
 # CHECK-NEXT:"parents": [],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 15,
+# CHECK-NEXT:"character": 16,
 # CHECK-NEXT:"line": 0
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
@@ -71,7 +71,7 @@
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"character": 25,
 # CHECK-NEXT:"line": 1
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
@@ -94,7 +94,7 @@
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"character": 25,
 # CHECK-NEXT:"line": 2
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "start": {
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -36,6 +36,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/STLExtras.h"
@@ -593,22 +594,23 @@
 
 // FIXME(nridge): Reduce duplication between this function and declToSym().
 static llvm::Optional
-declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
+declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
+const syntax::TokenBuffer &TB) {
   auto &SM = Ctx.getSourceManager();
-
   SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
-  // getFileLoc is a good choice for us, but we also need to make sure
-  // sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
-  // that to make sure it does not switch files.
-  // FIXME: sourceLocToPosition should not switch files!
-  SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
-  SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
-  if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
+  auto FilePath =
+  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(NameLoc)), SM);
+  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
+  if (!FilePath || !TUPath)
+return llvm::None; // Not useful without a uri.
+
+  auto DeclToks = TB.spelledForExpanded(TB.expandedTokens(ND.getSourceRange()));
+  if (!DeclToks || DeclToks->empty())
 return llvm::None;
 
-  Position NameBegin = sourceLocToPosition(SM, NameLoc);
-  Position NameEnd = sourceLocToPosition(
-  SM, Lexer::getLocForEndOfToken(NameLoc, 0, SM, Ctx.getLangOpts()));
+  auto NameToks = TB.spelledForExpanded(TB.expandedTokens(NameLoc));
+  if (!NameToks || NameToks->empty())
+return llvm::None;
 
   index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
   // FIXME: this is not classifying constructors, destructors and operators
@@ -619,20 +621,18 @@
   THI.name = printName(Ctx, ND);
   THI.kind = SK;
   THI.deprecated = ND.isDeprecated();
-  THI.range =
-  Range{sourceLocToPosition(SM, BeginLoc), sourceLocToPosition(SM, EndLoc)};
-  THI.selectionRange = Range{NameBegin, NameEnd};
+  THI.range = halfOpenToRange(
+  SM, syntax::Token::range(SM, DeclToks->front(), DeclToks->back())
+  .toCharRange(SM));
+  THI.selectionRange = halfOpenToRange(
+  SM, syntax::Token::range(SM, NameToks->front(), NameToks->back())
+  .toCharRange(SM));
   if (!THI.range.contains(THI.selectionRange)) {
 // 'selectionRange' must be contained in 'range', so in cases where clang
 // reports unrelated ranges we need to reconcile somehow.
 THI.range = THI.selectionRange;
   }
 
-  auto FilePath =
-  getCanonicalPath(SM.getFileEntryForID(SM.getFileID(BeginLoc)), SM);
-  auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
-  if (!FilePath || !TUPath)
-return llvm::None; // Not useful without a uri.
   THI.uri = URIForFile::canonicalize(*FilePath, *TUPath);
 
   return THI;
@@ -685,7 +685,8 @@
 
 static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
std::vector &SuperTypes,
-   RecursionProtectionS

[clang] e551333 - [analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription

2020-02-25 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2020-02-25T15:43:33+01:00
New Revision: e5513336aee4a9b10cb98f234145aeb4763fdd69

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

LOG: [analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to 
CallDescription

Exactly what it says on the tin! I decided not to merge this with the patch that
changes all these to a CallDescriptionMap object, so the patch is that much more
trivial.

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

Added: 
clang/test/Analysis/malloc-annotations.cpp

Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/kmalloc-linux.c

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index fc1cc9138826..5b9bbb197e82 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -258,6 +258,13 @@ class CallEvent {
   /// calls.
   bool isCalled(const CallDescription &CD) const;
 
+  /// Returns true whether the CallEvent is any of the CallDescriptions 
supplied
+  /// as a parameter.
+  template 
+  bool isCalled(const FirstCallDesc &First, const CallDescs &... Rest) const {
+return isCalled(First) || isCalled(Rest...);
+  }
+
   /// Returns a source range for the entire call, suitable for
   /// outputting in diagnostics.
   virtual SourceRange getSourceRange() const {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fd3ce6cf3b9b..23b4abc67079 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -268,8 +268,6 @@ REGISTER_MAP_WITH_PROGRAMSTATE(ReallocPairs, SymbolRef, 
ReallocPair)
 
 namespace {
 
-enum class MemoryOperationKind { MOK_Allocate, MOK_Free, MOK_Any };
-
 struct MemFunctionInfoTy {
   /// The value of the MallocChecker:Optimistic is stored in this variable.
   ///
@@ -279,44 +277,41 @@ struct MemFunctionInfoTy {
   /// which might free a pointer are annotated.
   DefaultBool ShouldIncludeOwnershipAnnotatedFunctions;
 
-  // TODO: Change these to CallDescription, and get rid of lazy initialization.
-  mutable IdentifierInfo *II_alloca = nullptr, *II_win_alloca = nullptr,
- *II_malloc = nullptr, *II_free = nullptr,
- *II_realloc = nullptr, *II_calloc = nullptr,
- *II_valloc = nullptr, *II_reallocf = nullptr,
- *II_strndup = nullptr, *II_strdup = nullptr,
- *II_win_strdup = nullptr, *II_kmalloc = nullptr,
- *II_if_nameindex = nullptr,
- *II_if_freenameindex = nullptr, *II_wcsdup = nullptr,
- *II_win_wcsdup = nullptr, *II_g_malloc = nullptr,
- *II_g_malloc0 = nullptr, *II_g_realloc = nullptr,
- *II_g_try_malloc = nullptr,
- *II_g_try_malloc0 = nullptr,
- *II_g_try_realloc = nullptr, *II_g_free = nullptr,
- *II_g_memdup = nullptr, *II_g_malloc_n = nullptr,
- *II_g_malloc0_n = nullptr, *II_g_realloc_n = nullptr,
- *II_g_try_malloc_n = nullptr,
- *II_g_try_malloc0_n = nullptr, *II_kfree = nullptr,
- *II_g_try_realloc_n = nullptr;
-
-  void initIdentifierInfo(ASTContext &C) const;
-
-  ///@{
-  /// Check if this is one of the functions which can allocate/reallocate
-  /// memory pointed to by one of its arguments.
-  bool isMemFunction(const FunctionDecl *FD, ASTContext &C) const;
-  bool isCMemFunction(const FunctionDecl *FD, ASTContext &C,
-  AllocationFamily Family,
-  MemoryOperationKind MemKind) const;
-
-  /// Tells if the callee is one of the builtin new/delete operators, including
-  /// placement operators and other standard overloads.
-  bool isStandardNewDelete(const FunctionDecl *FD, ASTContext &C) const;
-  ///@}
+  CallDescription CD_alloca{{"alloca"}, 1}, CD_win_alloca{{"_alloca"}, 1},
+  CD_malloc{{"malloc"}, 1}, CD_BSD_malloc{{"malloc"}, 3},
+  CD_free{{"free"}, 1}, CD_realloc{{"realloc"}, 2},
+  CD_calloc{{"calloc"}, 2}, CD_valloc{{"valloc"}, 1},
+  CD_reallocf{{"reallocf"}, 2}, CD_strndup{{"strndup"}, 2},
+  CD_strdup{{"strdup"}, 1}, CD_win_strdup{{"_strdup"}, 1},
+  CD_kmalloc{{"kmalloc"}, 2}, CD_if_nameindex{{"if_nameindex"}, 1},
+  CD_if_freenameindex{{"if_freenameindex"}

[clang] bcda126 - clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2020-02-25T09:43:52-05:00
New Revision: bcda1269c4c4d5d19d2be425c0a52d19fe09f146

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

LOG: clang-cl: Add a `/showIncludes:user` flag.

This flag is like /showIncludes, but it only includes user headers and
omits system headers (similar to MD and MMD). The motivation is that
projects that already track system includes though other means can use
this flag to get consistent behavior on Windows and non-Windows, and it
saves tools that output /showIncludes output (e.g. ninja) some work.

implementation-wise, this makes `HeaderIncludesCallback` honor the
existing `IncludeSystemHeaders` bit, and changes the three clients of
`HeaderIncludesCallback` (`/showIncludes`, `-H`, `CC_PRINT_HEADERS=1`)
to pass `-sys-header-deps` to set that bit -- except for
`/showIncludes:user`, which doesn't pass it.

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

Added: 


Modified: 
clang/include/clang/Driver/CLCompatOptions.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/DependencyFile.cpp
clang/lib/Frontend/HeaderIncludeGen.cpp
clang/test/Driver/cl-options.c
clang/test/Frontend/print-header-includes.c
clang/test/Preprocessor/headermap-rel2.c

Removed: 




diff  --git a/clang/include/clang/Driver/CLCompatOptions.td 
b/clang/include/clang/Driver/CLCompatOptions.td
index 561746d931ed..17d248a3c5ad 100644
--- a/clang/include/clang/Driver/CLCompatOptions.td
+++ b/clang/include/clang/Driver/CLCompatOptions.td
@@ -156,8 +156,9 @@ def _SLASH_Qvec : CLFlag<"Qvec">,
 def _SLASH_Qvec_ : CLFlag<"Qvec-">,
   HelpText<"Disable the loop vectorization passes">, Alias;
 def _SLASH_showIncludes : CLFlag<"showIncludes">,
-  HelpText<"Print info about included files to stderr">,
-  Alias;
+  HelpText<"Print info about included files to stderr">;
+def _SLASH_showIncludes_user : CLFlag<"showIncludes:user">,
+  HelpText<"Like /showIncludes but omit system headers">;
 def _SLASH_showFilenames : CLFlag<"showFilenames">,
   HelpText<"Print the name of each compiled file">;
 def _SLASH_showFilenames_ : CLFlag<"showFilenames-">,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 4bd0b5e1fb27..19a23c9de5b3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4758,11 +4758,17 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   Args.AddAllArgs(CmdArgs, options::OPT_v);
-  Args.AddLastArg(CmdArgs, options::OPT_H);
+
+  if (Args.getLastArg(options::OPT_H)) {
+CmdArgs.push_back("-H");
+CmdArgs.push_back("-sys-header-deps");
+  }
+
   if (D.CCPrintHeaders && !D.CCGenDiagnostics) {
 CmdArgs.push_back("-header-include-file");
 CmdArgs.push_back(D.CCPrintHeadersFilename ? D.CCPrintHeadersFilename
: "-");
+CmdArgs.push_back("-sys-header-deps");
   }
   Args.AddLastArg(CmdArgs, options::OPT_P);
   Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
@@ -6433,7 +6439,13 @@ void Clang::AddClangCLArgs(const ArgList &Args, 
types::ID InputType,
 CmdArgs.push_back("--dependent-lib=oldnames");
   }
 
-  Args.AddLastArg(CmdArgs, options::OPT_show_includes);
+  if (Arg *ShowIncludes =
+  Args.getLastArg(options::OPT__SLASH_showIncludes,
+  options::OPT__SLASH_showIncludes_user)) {
+CmdArgs.push_back("--show-includes");
+if (ShowIncludes->getOption().matches(options::OPT__SLASH_showIncludes))
+  CmdArgs.push_back("-sys-header-deps");
+  }
 
   // This controls whether or not we emit RTTI data for polymorphic types.
   if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,

diff  --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index f39ffd805d0e..c9240f4122a7 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -137,9 +137,10 @@ struct DepCollectorASTListener : public ASTReaderListener {
 };
 } // end anonymous namespace
 
-void DependencyCollector::maybeAddDependency(StringRef Filename, bool 
FromModule,
-bool IsSystem, bool IsModuleFile,
-bool IsMissing) {
+void DependencyCollector::maybeAddDependency(StringRef Filename,
+ bool FromModule, bool IsSystem,
+ bool IsModuleFile,
+ bool IsMissing) {
   if (sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing))
 addDependency(Filename);
 }
@@ -160,8 +161,8 @@ static bool isSpecialFilename(StringRef Filename) {
 }
 
 bool Depende

[PATCH] D68163: [analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription

2020-02-25 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5513336aee4: [analyzer][MallocChecker][NFC] Change the use 
of IdentifierInfo* to… (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D68163?vs=222791&id=246441#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68163

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/kmalloc-linux.c
  clang/test/Analysis/malloc-annotations.cpp

Index: clang/test/Analysis/malloc-annotations.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-annotations.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_analyze_cc1 -analyzer-store=region -verify \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.deadcode.UnreachableCode \
+// RUN:   -analyzer-checker=alpha.core.CastSize \
+// RUN:   -analyzer-checker=unix.Malloc \
+// RUN:   -analyzer-config unix.DynamicMemoryModeling:Optimistic=true %s
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+
+struct MemoryAllocator {
+  void __attribute((ownership_returns(malloc))) * my_malloc(size_t);
+  void __attribute((ownership_takes(malloc, 2))) my_free(void *);
+  void __attribute((ownership_holds(malloc, 2))) my_hold(void *);
+};
+
+void *myglobalpointer;
+
+struct stuff {
+  void *somefield;
+};
+
+struct stuff myglobalstuff;
+
+void af1(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  return; // expected-warning{{Potential leak of memory pointed to by}}
+}
+
+void af1_b(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+} // expected-warning{{Potential leak of memory pointed to by}}
+
+void af1_c(MemoryAllocator &Alloc) {
+  myglobalpointer = Alloc.my_malloc(12); // no-warning
+}
+
+// Test that we can pass out allocated memory via pointer-to-pointer.
+void af1_e(MemoryAllocator &Alloc, void **pp) {
+  *pp = Alloc.my_malloc(42); // no-warning
+}
+
+void af1_f(MemoryAllocator &Alloc, struct stuff *somestuff) {
+  somestuff->somefield = Alloc.my_malloc(12); // no-warning
+}
+
+// Allocating memory for a field via multiple indirections to our arguments is OK.
+void af1_g(MemoryAllocator &Alloc, struct stuff **pps) {
+  *pps = (struct stuff *)Alloc.my_malloc(sizeof(struct stuff)); // no-warning
+  (*pps)->somefield = Alloc.my_malloc(42); // no-warning
+}
+
+void af2(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  Alloc.my_free(p);
+  free(p); // expected-warning{{Attempt to free released memory}}
+}
+
+void af2b(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  free(p);
+  Alloc.my_free(p); // expected-warning{{Attempt to free released memory}}
+}
+
+void af2c(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  free(p);
+  Alloc.my_hold(p); // expected-warning{{Attempt to free released memory}}
+}
+
+// No leak if malloc returns null.
+void af2e(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  if (!p)
+return; // no-warning
+  free(p); // no-warning
+}
+
+// This case inflicts a possible double-free.
+void af3(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  Alloc.my_hold(p);
+  free(p); // expected-warning{{Attempt to free non-owned memory}}
+}
+
+void * af4(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  Alloc.my_free(p);
+  return p; // expected-warning{{Use of memory after it is freed}}
+}
+
+// This case is (possibly) ok, be conservative
+void * af5(MemoryAllocator &Alloc) {
+  void *p = Alloc.my_malloc(12);
+  Alloc.my_hold(p);
+  return p; // no-warning
+}
+
Index: clang/test/Analysis/kmalloc-linux.c
===
--- clang/test/Analysis/kmalloc-linux.c
+++ clang/test/Analysis/kmalloc-linux.c
@@ -1,10 +1,10 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux %s
 
-#include "Inputs/system-header-simulator.h"
-
 #define __GFP_ZERO 0x8000
 #define NULL ((void *)0)
 
+typedef __typeof(sizeof(int)) size_t;
+
 void *kmalloc(size_t, int);
 
 struct test {
@@ -56,3 +56,54 @@
   }
   kfree(list);
 }
+
+typedef unsigned long long uint64_t;
+
+struct malloc_type;
+
+void *malloc(unsigned long size, struct malloc_type *mtp, int flags);
+
+void test_3arg_malloc(struct malloc_type *mtp) {
+  struct test **list, *t;
+  int i;
+
+  list = malloc(sizeof(*list) * 10, mtp, __GFP_ZERO);
+  if (list == NULL)
+return;
+
+  for (i = 0; i < 10; i++) {
+t = list[i];
+foo(t);
+  }
+  kfree(list); // no-warning
+}
+
+void test_3arg_malloc_nonzero(struct malloc_type *mtp) {
+  struct test **list, *t;
+  int i;
+
+  list = malloc(sizeof(*list) * 10, mtp, 0);
+  if (list == NULL)
+return;
+
+  for (i = 0; i < 10; i++) {
+t = list[i]; // expected-warning{{undefined}}
+foo(t);
+  }
+  kfree(list);
+}
+
+void test_

[PATCH] D75093: clang-cl: Add a `/showIncludes:user` flag.

2020-02-25 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcda1269c4c4: clang-cl: Add a `/showIncludes:user` flag. 
(authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75093

Files:
  clang/include/clang/Driver/CLCompatOptions.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/HeaderIncludeGen.cpp
  clang/test/Driver/cl-options.c
  clang/test/Frontend/print-header-includes.c
  clang/test/Preprocessor/headermap-rel2.c

Index: clang/test/Preprocessor/headermap-rel2.c
===
--- clang/test/Preprocessor/headermap-rel2.c
+++ clang/test/Preprocessor/headermap-rel2.c
@@ -1,7 +1,10 @@
 // RUN: rm -f %t.hmap
 // RUN: %hmaptool write %S/Inputs/headermap-rel2/project-headers.hmap.json %t.hmap
-// RUN: %clang_cc1 -v -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H
-// RUN: %clang_cc1 -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
+
+// RUN: %clang -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 -H 2> %t.out
+// RUN: FileCheck %s -input-file %t.out
+
+// RUN: env CC_PRINT_HEADERS=1 %clang -fsyntax-only %s -iquote %t.hmap -isystem %S/Inputs/headermap-rel2/system/usr/include -I %S/Inputs/headermap-rel2 2> %t.out
 // RUN: FileCheck %s -input-file %t.out
 
 // CHECK: Product/someheader.h
Index: clang/test/Frontend/print-header-includes.c
===
--- clang/test/Frontend/print-header-includes.c
+++ clang/test/Frontend/print-header-includes.c
@@ -1,32 +1,51 @@
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h -E -H -o /dev/null %s 2> %t.stderr
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E -H -o /dev/null %s 2> %t.stderr
 // RUN: FileCheck < %t.stderr %s
 
 // CHECK-NOT: test3.h
+// CHECK-NOT: . {{.*noline.h}}
 // CHECK: . {{.*test.h}}
 // CHECK: .. {{.*test2.h}}
 
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h --show-includes -o /dev/null %s | \
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E -H -sys-header-deps -o /dev/null %s 2> %t.stderr
+// RUN: FileCheck --check-prefix SYSHEADERS < %t.stderr %s
+
+// SYSHEADERS-NOT: test3.h
+// SYSHEADERS: . {{.*noline.h}}
+// SYSHEADERS: . {{.*test.h}}
+// SYSHEADERS: .. {{.*test2.h}}
+
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: --show-includes -o /dev/null %s | \
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-STDOUT %s
 // MS-STDOUT-NOT: 
+// MS-STDOUT-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-STDOUT: Note: including file: {{[^ ]*test3.h}}
 // MS-STDOUT: Note: including file: {{[^ ]*test.h}}
 // MS-STDOUT: Note: including file:  {{[^ ]*test2.h}}
 // MS-STDOUT-NOT: Note
 
-// RUN: %clang_cc1 -I%S -include Inputs/test3.h -E --show-includes -o /dev/null %s 2> %t.stderr
+// RUN: %clang_cc1 -I%S -include Inputs/test3.h -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -E --show-includes -o /dev/null %s 2> %t.stderr
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-STDERR < %t.stderr %s
 // MS-STDERR-NOT: 
+// MS-STDERR-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-STDERR: Note: including file: {{[^ ]*test3.h}}
 // MS-STDERR: Note: including file: {{[^ ]*test.h}}
 // MS-STDERR: Note: including file:  {{[^ ]*test2.h}}
 // MS-STDERR-NOT: Note
 
 // RUN: echo "fun:foo" > %t.blacklist
-// RUN: %clang_cc1 -I%S -fsanitize=address -fdepfile-entry=%t.blacklist --show-includes -o /dev/null %s | \
+// RUN: %clang_cc1 -I%S -isystem %S/Inputs/SystemHeaderPrefix \
+// RUN: -fsanitize=address -fdepfile-entry=%t.blacklist \
+// RUN: --show-includes -o /dev/null %s | \
 // RUN: FileCheck --strict-whitespace --check-prefix=MS-BLACKLIST %s
 // MS-BLACKLIST: Note: including file: {{[^ ]*\.blacklist}}
+// MS-BLACKLIST-NOT: Note: including file: {{[^ ]*noline.h}}
 // MS-BLACKLIST: Note: including file: {{[^ ]*test.h}}
 // MS-BLACKLIST: Note: including file:  {{[^ ]*test2.h}}
 // MS-BLACKLIST-NOT: Note
 
+#include 
 #include "Inputs/test.h"
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -199,10 +199,16 @@
 // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s
 // Qvec_-NOT: -vectorize-loops
 
-// RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s
-// showIncludes: --show-includes
+// RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefi

[PATCH] D75068: libclang: Add static build support for Windows

2020-02-25 Thread Cristian Adam via Phabricator via cfe-commits
cristian.adam added a comment.

I've tested this patch with:

  -D LIBCLANG_BUILD_STATIC=OFF
  -D LLVM_ENABLE_PIC=ON

All green https://github.com/cristianadam/llvm-project/actions/runs/44839699

Then:

  -D LIBCLANG_BUILD_STATIC=ON
  -D LLVM_ENABLE_PIC=OFF

All green https://github.com/cristianadam/llvm-project/actions/runs/44755935

And lastly:

  -D LIBCLANG_BUILD_STATIC=OFF
  -D LLVM_ENABLE_PIC=OFF

Which builds on Windows and macOS, and fails on Linux as expected 
https://github.com/cristianadam/llvm-project/actions/runs/44423211

The expected Linux error is:

  /usr/bin/ld: lib/libclangBasic.a(Stack.cpp.o): relocation R_X86_64_TPOFF32 
against `_ZL13BottomOfStack' can not be used when making a shared object; 
recompile with -fPIC
  /usr/bin/ld: lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): relocation 
R_X86_64_TPOFF32 against `_ZL20PrettyStackTraceHead' can not be used when 
making a shared object; recompile with -fPIC
  /usr/bin/ld: lib/libLLVMSupport.a(TimeProfiler.cpp.o): relocation 
R_X86_64_TPOFF32 against `_ZN12_GLOBAL__N_125TimeTraceProfilerInstanceE' can 
not be used when making a shared object; recompile with -fPIC
  /usr/bin/ld: 
tools/clang/tools/libclang/CMakeFiles/obj.libclang.dir/CIndex.cpp.o: relocation 
R_X86_64_PC32 against symbol `clang_getCursorLocation' can not be used when 
making a shared object; recompile with -fPIC
  /usr/bin/ld: final link failed: Bad value

From my point of view it passes all configurations. What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75068



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


[PATCH] D75001: [OpenMP][cmake] ignore warning on unknown CUDA version

2020-02-25 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D75001#1887876 , @jdoerfert wrote:

> I like this way better. I was hoping we could do it in our cmake only :)
>
> Give others a day or so to comment before your commit but I'm fine with this.


Well, that doesn't really work if `openmp-commits` is only subscribed on 
commit. That said, the solution is a bit ugly but I don't have an alternative 
right now.

Somewhat related, that means Clang issues a warning for every compilation 
should there be a "unsupported" CUDA version around, even if it's not used? 
@tra maybe we can only issue the warning if CUDA is going to be used?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75001



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


[clang] fc466f8 - Make test not write to the source directory

2020-02-25 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-02-25T16:03:06+01:00
New Revision: fc466f87804f97b322394ef3b9db43ea3febcc15

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

LOG: Make test not write to the source directory

Added: 


Modified: 
clang/test/CodeGen/static-init.cpp

Removed: 




diff  --git a/clang/test/CodeGen/static-init.cpp 
b/clang/test/CodeGen/static-init.cpp
index b9437ecdeded..e336b55a0483 100644
--- a/clang/test/CodeGen/static-init.cpp
+++ b/clang/test/CodeGen/static-init.cpp
@@ -1,8 +1,8 @@
 // RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ %s \
-// RUN: 2>&1 | FileCheck %s
+// RUN: -o /dev/null 2>&1 | FileCheck %s
 
 // RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ %s 
\
-// RUN: 2>&1 | FileCheck %s
+// RUN: -o /dev/null 2>&1 | FileCheck %s
 
 struct test {
   test();



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


[PATCH] D75077: [OpenMP5.0] Allow pointer arithmetic in motion/map clause

2020-02-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:15683
   }
+  bool VisitUnaryOperator(UnaryOperator *UO) {
+if (SemaRef.getLangOpts().OpenMP < 50) {

I think you need to extend this to support paren expressions, at least.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:15708-15710
+const clang::Type *RootT = BO->getType().getTypePtr();
+const clang::Type *LT = LE->getType().getTypePtr();
+const clang::Type *RT = RE->getType().getTypePtr();

I don't think you need these variables here anymore.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:15714-15718
+  if (RootT == LT)
+Visit(LE);
+  else
+Visit(RE);
+  return true;

This does not look correct. At least, it should return the result of one of 
`Visit()` calls. Plus, it seems to me, it won't handle something like `*(a+5)`. 
That's why I suggest excluding binary op from this patch, it is not complete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75077



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


[PATCH] D74966: [PATCH] [ARM] Add Cortex-M55 Support for clang and llvm

2020-02-25 Thread Momchil Velikov via Phabricator via cfe-commits
chill accepted this revision.
chill added a comment.
This revision is now accepted and ready to land.

LGTM. Please, wait a couple of days before committing.


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

https://reviews.llvm.org/D74966



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


[PATCH] D68163: [analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:259
   /// calls.
   bool isCalled(const CallDescription &CD) const;
 

Szelethus wrote:
> Szelethus wrote:
> > NoQ wrote:
> > > I don't fully understand how does overload resolution work in this case, 
> > > maybe rename the original function?
> > Well, `isCalled` may now have an arbitrary number of arguments. The single 
> > argument version is this function, and the //n//-argument ones call this 
> > //n// times: `isCalled(A, B, C)` -> `isCalled(A) || isCalled(B) || 
> > isCalled(B)`. I guess I could rename the other one to `isAnyCalled`, but I 
> > think its fine.
> But that would be super ugly imo :/ I think the current implementation is 
> intuitive enough, but I'm happy to change it if you disagree.
Ok, so, maybe in such cases we should add a flag to our `CallDescriptionMap` 
and then write code like
```lang=c++
if (CDM.lookup(Call)->hasFlag) {
  ...
}
```
?

(or, maybe, make a separate map if these calls are never present in the rest of 
the code... do we want `CallDescriptionSet` for this purpose?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68163



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


[clang] a82ffe9 - [analyzer] Add support for CXXInheritedCtorInitExpr.

2020-02-25 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2020-02-25T18:37:23+03:00
New Revision: a82ffe9d93a24abf30bcf63081096ea18baf78dc

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

LOG: [analyzer] Add support for CXXInheritedCtorInitExpr.

So far we've been dropping coverage every time we've encountered
a CXXInheritedCtorInitExpr. This patch attempts to add some
initial support for it.

Constructors for arguments of a CXXInheritedCtorInitExpr are still
not fully supported.

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

Added: 
clang/test/Analysis/cxx-inherited-ctor-init-expr.cpp

Modified: 
clang/include/clang/Analysis/AnyCall.h
clang/include/clang/Analysis/ConstructionContext.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/Analysis/RetainSummaryManager.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
clang/test/Analysis/osobject-retain-release.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/AnyCall.h 
b/clang/include/clang/Analysis/AnyCall.h
index 97a94d299e64..16371eb1da18 100644
--- a/clang/include/clang/Analysis/AnyCall.h
+++ b/clang/include/clang/Analysis/AnyCall.h
@@ -41,6 +41,9 @@ class AnyCall {
 /// An implicit or explicit C++ constructor call
 Constructor,
 
+/// A C++ inherited constructor produced by a "using T::T" directive
+InheritedConstructor,
+
 /// A C++ allocation function call (operator `new`), via C++ new-expression
 Allocator,
 
@@ -84,6 +87,9 @@ class AnyCall {
   AnyCall(const CXXConstructExpr *NE)
   : E(NE), D(NE->getConstructor()), K(Constructor) {}
 
+  AnyCall(const CXXInheritedCtorInitExpr *CIE)
+  : E(CIE), D(CIE->getConstructor()), K(InheritedConstructor) {}
+
   AnyCall(const CXXDestructorDecl *D) : E(nullptr), D(D), K(Destructor) {}
 
   AnyCall(const CXXConstructorDecl *D) : E(nullptr), D(D), K(Constructor) {}
@@ -114,6 +120,8 @@ class AnyCall {
   return AnyCall(CXDE);
 } else if (const auto *CXCE = dyn_cast(E)) {
   return AnyCall(CXCE);
+} else if (const auto *CXCIE = dyn_cast(E)) {
+  return AnyCall(CXCIE);
 } else {
   return None;
 }
@@ -169,6 +177,7 @@ class AnyCall {
   return cast(E)->getCallReturnType(Ctx);
 case Destructor:
 case Constructor:
+case InheritedConstructor:
 case Allocator:
 case Deallocator:
   return cast(D)->getReturnType();

diff  --git a/clang/include/clang/Analysis/ConstructionContext.h 
b/clang/include/clang/Analysis/ConstructionContext.h
index f1564f9fe740..4fa5c8b454a0 100644
--- a/clang/include/clang/Analysis/ConstructionContext.h
+++ b/clang/include/clang/Analysis/ConstructionContext.h
@@ -110,6 +110,9 @@ class ConstructionContextItem {
   ConstructionContextItem(const CXXConstructExpr *CE, unsigned Index)
   : Data(CE), Kind(ArgumentKind), Index(Index) {}
 
+  ConstructionContextItem(const CXXInheritedCtorInitExpr *CE, unsigned Index)
+  : Data(CE), Kind(ArgumentKind), Index(Index) {}
+
   ConstructionContextItem(const ObjCMessageExpr *ME, unsigned Index)
   : Data(ME), Kind(ArgumentKind), Index(Index) {}
 
@@ -117,7 +120,7 @@ class ConstructionContextItem {
   ConstructionContextItem(const Expr *E, unsigned Index)
   : Data(E), Kind(ArgumentKind), Index(Index) {
 assert(isa(E) || isa(E) ||
-   isa(E));
+   isa(E) || isa(E));
   }
 
   ConstructionContextItem(const CXXCtorInitializer *Init)

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index 5b9bbb197e82..60705dd27d6b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -63,6 +63,9 @@ enum CallEventKind {
   CE_BEG_CXX_INSTANCE_CALLS = CE_CXXMember,
   CE_END_CXX_INSTANCE_CALLS = CE_CXXDestructor,
   CE_CXXConstructor,
+  CE_CXXInheritedConstructor,
+  CE_BEG_CXX_CONSTRUCTOR_CALLS = CE_CXXConstructor,
+  CE_END_CXX_CONSTRUCTOR_CALLS = CE_CXXInheritedConstructor,
   CE_CXXAllocator,
   CE_BEG_FUNCTION_CALLS = CE_Function,
   CE_END_FUNCTION_CALLS = CE_CXXAllocator,
@@ -818,10 +821,38 @@ class CXXDestructorCall : public CXXInstanceCall {
   }
 };
 
+/// Represents any constructor invocation. This includes regular constructors
+/// and inherited constructors.
+class AnyCXXConstructorCall : public AnyFunctionCall {
+protected:
+  AnyCXXConstructorCall(const Expr *E, const MemRegion *Target,
+   

[PATCH] D71018: [ASTImporter] Improved import of TypeSourceInfo (TypeLoc)

2020-02-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8133
+  Error VisitTypedefTypeLoc(TypedefTypeLoc From) {
+return VisitTypeSpecTypeLoc(From);
+  }

teemperor wrote:
> I know the ASTImporter is doing these reimplementation of the default visitor 
> behavior quite often, but I feel in this case it would be much more readable 
> to omit all these default implementations and just let the TypeLocVisitor do 
> the dispatch to parent class logic. Especially since from what I understand 
> it's unlikely that we need custom logic for all these TypeLoc subclasses in 
> the future? It would also make this code less fragile in case the inheritance 
> hierarchy every gets another intermediate class that might require special 
> handling.
It is really better to remove these redundant visit branches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71018



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


[PATCH] D74735: [analyzer] Add support for CXXInheritedCtorInitExpr.

2020-02-25 Thread Artem Dergachev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa82ffe9d93a2: [analyzer] Add support for 
CXXInheritedCtorInitExpr. (authored by dergachev.a).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74735

Files:
  clang/include/clang/Analysis/AnyCall.h
  clang/include/clang/Analysis/ConstructionContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/cxx-inherited-ctor-init-expr.cpp
  clang/test/Analysis/osobject-retain-release.cpp

Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -739,3 +739,18 @@
   return outParamWithWeirdResult(&obj); // no-warning
 }
 } // namespace weird_result
+
+namespace inherited_constructor_crash {
+struct a {
+  a(int);
+};
+struct b : a {
+  // This is an "inherited constructor".
+  using a::a;
+};
+void test() {
+  // RetainCountChecker used to crash when looking for a summary
+  // for the inherited constructor invocation.
+  b(0);
+}
+} // namespace inherited_constructor_crash
Index: clang/test/Analysis/cxx-inherited-ctor-init-expr.cpp
===
--- /dev/null
+++ clang/test/Analysis/cxx-inherited-ctor-init-expr.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(bool);
+
+namespace basic_tests {
+struct A {
+  int x;
+  A(int x): x(x) {}
+};
+
+struct B : A {
+  using A::A;
+};
+
+struct C : B {
+  using B::B;
+};
+
+void test_B() {
+  B b(1);
+  clang_analyzer_eval(b.x == 1); // expected-warning{{TRUE}}
+}
+
+void test_C() {
+  C c(2);
+  clang_analyzer_eval(c.x == 2); // expected-warning{{TRUE}}
+}
+} // namespace basic_tests
+
+namespace arguments_with_constructors {
+struct S {
+  int x, y;
+  S(int x, int y): x(x), y(y) {}
+  ~S() {}
+};
+
+struct A {
+  S s;
+  int z;
+  A(S s, int z) : s(s), z(z) {}
+};
+
+struct B : A {
+  using A::A;
+};
+
+void test_B() {
+  B b(S(1, 2), 3);
+  // FIXME: There should be no execution path on which this is false.
+  clang_analyzer_eval(b.s.x == 1); // expected-warning{{TRUE}}
+   // expected-warning@-1{{FALSE}}
+
+  // FIXME: There should be no execution path on which this is false.
+  clang_analyzer_eval(b.s.y == 2); // expected-warning{{TRUE}}
+   // expected-warning@-1{{FALSE}}
+
+  clang_analyzer_eval(b.z == 3); // expected-warning{{TRUE}}
+}
+} // namespace arguments_with_constructors
Index: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -542,6 +542,11 @@
 if (!Loc)
   return true;
 
+// Anonymous parameters of an inheriting constructor are live for the entire
+// duration of the constructor.
+if (isa(Loc))
+  return true;
+
 if (LCtx->getAnalysis()->isLive(Loc, VR->getDecl()))
   return true;
 
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -668,8 +668,8 @@
 assert(RTC->getStmt() == Call.getOriginExpr());
 EvalCallOptions CallOpts; // FIXME: We won't really need those.
 std::tie(State, Target) =
-prepareForObjectConstruction(Call.getOriginExpr(), State, LCtx,
- RTC->getConstructionContext(), CallOpts);
+handleConstructionContext(Call.getOriginExpr(), State, LCtx,
+  RTC->getConstructionContext(), CallOpts);
 const MemRegion *TargetR = Target.getAsRegion();
 assert(TargetR);
 // Invalidate the region so that it didn't look uninitialized. If this is
@@ -789,6 +789,11 @@
 
 break;
   }
+  case CE_CXXInheritedConstructor: {
+// This doesn't really increase the cost of inlining ever, because
+// the stack frame of the inherited constructor is trivial.
+return CIP_Allowed;
+  }
   case CE_CXXDestructor: {
 if (!Opts.mayInlineCXXMemberFunction(CIMK_Destructors))
   return CIP_DisallowedAlways;
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
==

[PATCH] D73020: [Sema] Perform call checking when building CXXNewExpr

2020-02-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D73020#1857704 , @rsmith wrote:

> Looks good if you change the error to a warning.


I'm going to treat that as an implicit accept since the error got changed into 
a warning.
Will commit this soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73020



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


[PATCH] D75056: [Driver] Default to -fno-common

2020-02-25 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 246457.
SjoerdMeijer retitled this revision from "[ARM][AArch64] Default to 
-fno-common" to "[Driver] Default to -fno-common".
SjoerdMeijer edited the summary of this revision.
SjoerdMeijer added reviewers: tstellar, jyknight.
SjoerdMeijer added a comment.
Herald added subscribers: s.egerton, simoncook, fedor.sergeev, aheejin.

Following the discussion on the llvm dev list, this is a first draft to enable 
`-fno-common` for all targets.

TODO: doc changes.


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

https://reviews.llvm.org/D75056

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/2009-10-20-GlobalDebug.c
  clang/test/Driver/no-common.c
  clang/test/Driver/rewrite-legacy-objc.m
  clang/test/Driver/rewrite-objc.m
  clang/test/Frontend/ast-codegen.c

Index: clang/test/Frontend/ast-codegen.c
===
--- clang/test/Frontend/ast-codegen.c
+++ clang/test/Frontend/ast-codegen.c
@@ -5,7 +5,7 @@
 // CHECK: module asm "foo"
 __asm__("foo");
 
-// CHECK: @g0 = common dso_local global i32 0, align 4
+// CHECK: @g0 = dso_local global i32 0, align 4
 int g0;
 
 // CHECK: define dso_local i32 @f0()
Index: clang/test/Driver/rewrite-objc.m
===
--- clang/test/Driver/rewrite-objc.m
+++ clang/test/Driver/rewrite-objc.m
@@ -3,4 +3,4 @@
 // TEST0: clang{{.*}}" "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead.
-// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
+// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fno-common" "-fdiagnostics-show-option"
Index: clang/test/Driver/rewrite-legacy-objc.m
===
--- clang/test/Driver/rewrite-legacy-objc.m
+++ clang/test/Driver/rewrite-legacy-objc.m
@@ -3,11 +3,11 @@
 // TEST0: clang{{.*}}" "-cc1"
 // TEST0: "-rewrite-objc"
 // FIXME: CHECK-NOT is broken somehow, it doesn't work here. Check adjacency instead.
-// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
+// TEST0: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fexceptions" "-fmax-type-align=16" "-fno-common" "-fdiagnostics-show-option"
 // TEST0: rewrite-legacy-objc.m"
 // RUN: %clang -no-canonical-prefixes -target i386-apple-macosx10.9.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST1 %s
 // RUN: %clang -no-canonical-prefixes -target i386-apple-macosx10.6.0 -rewrite-legacy-objc %s -o - -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=TEST2 %s
-// TEST1: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
-// TEST2: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fdiagnostics-show-option"
+// TEST1: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fno-common" "-fdiagnostics-show-option"
+// TEST2: "-fmessage-length" "0" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fobjc-runtime=macosx-fragile" "-fobjc-subscripting-legacy-runtime" "-fno-objc-infer-related-result-type" "-fobjc-exceptions" "-fmax-type-align=16" "-fno-common" "-fdiagnostics-show-option"
Index

[clang] e6d0bad - [clang-rename] Add the USR of incomplete decl to the USRSet.

2020-02-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-25T16:56:35+01:00
New Revision: e6d0bad843c4c84bb762cf93a56c5bdd5cc535c0

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

LOG: [clang-rename] Add the USR of incomplete decl to the USRSet.

Summary:
This fixes a clangd rename issue, which is missing the reference of
an incomplete specialization.

Unfortunately, I didn't reproduce this issue in clang-rename, I guess
the input `FoundDecl` of AdditionalUSRFinder is different in clangd vs
clang-rename, clang-rename uses the underlying CXXRecordDecl of the
ClassTemplateDecl, which is fixed in 
https://github.com/llvm/llvm-project/commit/5d862c042b52ae2aad37471d0b83b6c678a520e3;
while clangd-rename uses the ClassTemplateDecl.

Reviewers: kbobyrev

Reviewed By: kbobyrev

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/RenameTests.cpp
clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index aa08be484ea3..82930eb3e0ce 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -202,6 +202,13 @@ TEST(RenameTest, WithinFileRename) {
 }
   )cpp",
 
+  // Incomplete class specializations
+  R"cpp(
+template 
+class [[Fo^o]] {};
+void func([[Foo]]);
+  )cpp",
+
   // Template class instantiations.
   R"cpp(
 template 

diff  --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp 
b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
index a17b880a71a0..43dc32e158d3 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -126,12 +126,14 @@ class AdditionalUSRFinder : public 
RecursiveASTVisitor {
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
-  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
-RecordDecl = RecordDecl->getDefinition();
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
+const auto* RecordDecl = RD->getDefinition();
 
 // Skip if the CXXRecordDecl doesn't have definition.
-if (!RecordDecl)
+if (!RecordDecl) {
+  USRSet.insert(getUSRForDecl(RD));
   return;
+}
 
 for (const auto *CtorDecl : RecordDecl->ctors())
   USRSet.insert(getUSRForDecl(CtorDecl));



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


[PATCH] D74829: [clang-rename] Add the USR of incomplete decl to the USRSet.

2020-02-25 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6d0bad843c4: [clang-rename] Add the USR of incomplete decl 
to the USRSet. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74829

Files:
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -126,12 +126,14 @@
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
-  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
-RecordDecl = RecordDecl->getDefinition();
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
+const auto* RecordDecl = RD->getDefinition();
 
 // Skip if the CXXRecordDecl doesn't have definition.
-if (!RecordDecl)
+if (!RecordDecl) {
+  USRSet.insert(getUSRForDecl(RD));
   return;
+}
 
 for (const auto *CtorDecl : RecordDecl->ctors())
   USRSet.insert(getUSRForDecl(CtorDecl));
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -202,6 +202,13 @@
 }
   )cpp",
 
+  // Incomplete class specializations
+  R"cpp(
+template 
+class [[Fo^o]] {};
+void func([[Foo]]);
+  )cpp",
+
   // Template class instantiations.
   R"cpp(
 template 


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -126,12 +126,14 @@
 addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
   }
 
-  void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
-RecordDecl = RecordDecl->getDefinition();
+  void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
+const auto* RecordDecl = RD->getDefinition();
 
 // Skip if the CXXRecordDecl doesn't have definition.
-if (!RecordDecl)
+if (!RecordDecl) {
+  USRSet.insert(getUSRForDecl(RD));
   return;
+}
 
 for (const auto *CtorDecl : RecordDecl->ctors())
   USRSet.insert(getUSRForDecl(CtorDecl));
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -202,6 +202,13 @@
 }
   )cpp",
 
+  // Incomplete class specializations
+  R"cpp(
+template 
+class [[Fo^o]] {};
+void func([[Foo]]);
+  )cpp",
+
   // Template class instantiations.
   R"cpp(
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75121: Put microsoft template parameter shadow warning behind separate flag (PR44794)

2020-02-25 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added reviewers: rnk, thakis.

This puts the warning behind a separate -Wmicrosoft-template-shadow flag as 
suggested on the bug.


https://reviews.llvm.org/D75121

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4273,7 +4273,7 @@
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
 def ext_template_param_shadow : ExtWarn<
-  err_template_param_shadow.Text>, InGroup;
+  err_template_param_shadow.Text>, InGroup;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1018,7 +1018,8 @@
 def MicrosoftEnumValue : DiagGroup<"microsoft-enum-value">;
 def MicrosoftDefaultArgRedefinition :
 DiagGroup<"microsoft-default-arg-redefinition">;
-def MicrosoftTemplate : DiagGroup<"microsoft-template">;
+def MicrosoftTemplateShadow : DiagGroup<"microsoft-template-shadow">;
+def MicrosoftTemplate : DiagGroup<"microsoft-template", 
[MicrosoftTemplateShadow]>;
 def MicrosoftInconsistentDllImport : DiagGroup<"inconsistent-dllimport">;
 def MicrosoftRedeclareStatic : DiagGroup<"microsoft-redeclare-static">;
 def MicrosoftEnumForwardReference :


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4273,7 +4273,7 @@
 def err_template_param_shadow : Error<
   "declaration of %0 shadows template parameter">;
 def ext_template_param_shadow : ExtWarn<
-  err_template_param_shadow.Text>, InGroup;
+  err_template_param_shadow.Text>, InGroup;
 def note_template_param_here : Note<"template parameter is declared here">;
 def warn_template_export_unsupported : Warning<
   "exported templates are unsupported">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1018,7 +1018,8 @@
 def MicrosoftEnumValue : DiagGroup<"microsoft-enum-value">;
 def MicrosoftDefaultArgRedefinition :
 DiagGroup<"microsoft-default-arg-redefinition">;
-def MicrosoftTemplate : DiagGroup<"microsoft-template">;
+def MicrosoftTemplateShadow : DiagGroup<"microsoft-template-shadow">;
+def MicrosoftTemplate : DiagGroup<"microsoft-template", [MicrosoftTemplateShadow]>;
 def MicrosoftInconsistentDllImport : DiagGroup<"inconsistent-dllimport">;
 def MicrosoftRedeclareStatic : DiagGroup<"microsoft-redeclare-static">;
 def MicrosoftEnumForwardReference :
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7b65886 - Make builtbot happy.

2020-02-25 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-02-25T17:04:38+01:00
New Revision: 7b65886ec2d0de431959f6b1d1801ef43a958f55

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

LOG: Make builtbot happy.

Disable the failing rename test, it should not be failed, needs further
investigation.

Added: 


Modified: 
clang/unittests/Rename/RenameClassTest.cpp

Removed: 




diff  --git a/clang/unittests/Rename/RenameClassTest.cpp 
b/clang/unittests/Rename/RenameClassTest.cpp
index 04a9138f741f..1c00ad7912e7 100644
--- a/clang/unittests/Rename/RenameClassTest.cpp
+++ b/clang/unittests/Rename/RenameClassTest.cpp
@@ -780,7 +780,8 @@ TEST_F(RenameClassTest, UsingAlias) {
   CompareSnippets(Expected, After);
 }
 
-TEST_F(ClangRenameTest, NestedTemplates) {
+// FIXME: investigate why the test fails when adding a new USR to the USRSet.
+TEST_F(ClangRenameTest, DISABLED_NestedTemplates) {
   std::string Before = R"(
   namespace a { template  struct A {}; }
   a::A> foo;)";



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


[clang] fa755d3 - [Sema][C++] Propagate conversion kind to specialize the diagnostics

2020-02-25 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-02-25T16:05:37Z
New Revision: fa755d3e71ed590ac5c62f0e1eff09435c9593fe

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

LOG: [Sema][C++] Propagate conversion kind to specialize the diagnostics

Compute and propagate conversion kind to diagnostics helper in C++
to provide more specific diagnostics about incorrect implicit
conversions in assignments, initializations, params, etc...

Duplicated some diagnostics as errors because C++ is more strict.

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/conv/conv.fctptr/p1.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/except/except.handle/p16.cpp
clang/test/CXX/expr/p13.cpp
clang/test/CXX/temp/temp.spec/temp.expl.spec/p19.cpp
clang/test/CXX/temp/temp.spec/temp.explicit/p10.cpp
clang/test/CXX/temp/temp.spec/temp.explicit/p9.cpp
clang/test/OpenMP/allocate_allocator_messages.cpp
clang/test/Sema/block-call.c
clang/test/Sema/block-return.c
clang/test/Sema/callingconv-ms_abi.c
clang/test/Sema/callingconv-sysv_abi.c
clang/test/Sema/callingconv.c
clang/test/Sema/overloadable.c
clang/test/Sema/pass-object-size.c
clang/test/Sema/preserve-call-conv.c
clang/test/SemaCXX/addr-of-overloaded-function.cpp
clang/test/SemaCXX/decl-microsoft-call-conv.cpp
clang/test/SemaCXX/goto.cpp
clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
clang/test/SemaCXX/ms-property-error.cpp
clang/test/SemaObjC/arc.m
clang/test/SemaObjC/comptypes-legal.m
clang/test/SemaObjCXX/arc-type-conversion.mm
clang/test/SemaObjCXX/comptypes-1.mm
clang/test/SemaObjCXX/comptypes-7.mm
clang/test/SemaObjCXX/instantiate-expr.mm
clang/test/SemaObjCXX/instantiate-stmt.mm
clang/test/SemaObjCXX/noescape.mm
clang/test/SemaObjCXX/nullability-pragmas.mm
clang/test/SemaObjCXX/objc-container-subscripting.mm
clang/test/SemaObjCXX/parameterized_classes_subst.mm
clang/test/SemaObjCXX/property-invalid-type.mm
clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
clang/test/SemaOpenCL/address-spaces.cl
clang/test/SemaTemplate/extern-templates.cpp
clang/test/SemaTemplate/instantiate-member-class.cpp
clang/test/SemaTemplate/member-access-expr.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 60f2c777676d..91688cf99f9c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7367,6 +7367,21 @@ def warn_incompatible_qualified_id : Warning<
   "sending type to parameter of incompatible type}0,1"
   "|%
diff {casting $ to incompatible type $|"
   "casting type to incompatible type}0,1}2">;
+def err_incompatible_qualified_id : Error<
+  "%select{%
diff {assigning to $ from incompatible type $|"
+  "assigning to type from incompatible type}0,1"
+  "|%
diff {passing $ to parameter of incompatible type $|"
+  "passing type to parameter of incompatible type}0,1"
+  "|%
diff {returning $ from a function with incompatible result type $|"
+  "returning type from a function with incompatible result type}0,1"
+  "|%
diff {converting $ to incompatible type $|"
+  "converting type to incompatible type}0,1"
+  "|%
diff {initializing $ with an expression of incompatible type $|"
+  "initializing type with an expression of incompatible type}0,1"
+  "|%
diff {sending $ to parameter of incompatible type $|"
+  "sending type to parameter of incompatible type}0,1"
+  "|%
diff {casting $ to incompatible type $|"
+  "casting type to incompatible type}0,1}2">;
 def ext_typecheck_convert_pointer_int : ExtWarn<
   "incompatible pointer to integer conversion "
   "%select{%
diff {assigning to $ from $|assigning to 
diff erent types}0,1"
@@ -7385,6 +7400,23 @@ def ext_typecheck_convert_pointer_int : ExtWarn<
   "; remove *|"
   "; remove &}3">,
   InGroup;
+def err_typecheck_convert_pointer_int : Error<
+  "incompatible pointer to integer conversion "
+  "%select{%
diff {assigning to $ from $|assigning to 
diff erent types}0,1"
+  "|%
diff {passing $ to parameter of type $|"
+  "passing to parameter of 
diff erent type}0,1"
+  "|%
diff {returning $ from a function with result type $|"
+  "returning from function with 
diff erent return type}0,1"
+  "|%
diff {converting $ to type $|converting between types}0,1"
+  "|%
diff {initializing $ with an expression of type $|"
+  "initializing with expression of 
diff erent type}0,1"
+  "|%
diff {sending 

  1   2   3   >