[PATCH] D66564: [clang-tidy] new FPGA struct pack align check

2019-08-21 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention new module and check in Release Notes.




Comment at: clang-tidy/fpga/FPGATidyModule.cpp:5
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.

License was changed this year. Same in other files.



Comment at: clang-tidy/fpga/StructPackAlignCheck.cpp:31
+  const auto *Struct = Result.Nodes.getNodeAs("struct");
+  const auto *StructDef = Struct->getDefinition();
+  

Please don't use auto when type is not spelled in same statement or not 
iterator.



Comment at: clang-tidy/fpga/StructPackAlignCheck.cpp:34
+  // If not a definition, do nothing
+  if (Struct != StructDef) return;
+  

Please run Clang-format.



Comment at: docs/clang-tidy/checks/fpga-struct-pack-align.rst:12
+
+Based on the "Altera SDK for OpenCL: Best Practices Guide".
+

Please add link to Altera documentation.



Comment at: docs/clang-tidy/index.rst:67
 ``clang-analyzer-``Clang Static Analyzer checks.
+``fpga-``  Checks related to OpenCL programming for FPGAs..
 ``fuchsia-``   Checks related to Fuchsia coding conventions.

Please fix double dot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66564



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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> I don't understand how you draw that conclusion, but the reason behind why we 
> went with that as a way to silence the diagnostic is because using the prefix 
> acts as a signal that the developer wants to do bit manipulation more than 
> just a decimal literal does. It's not ideal because it's largely a hidden way 
> to silence diagnostics, but it's also not the only place where we do that 
> sort of thing (like surrounding something in parens to silence a diagnostic, 
> or casting something to void, etc).

I think adding parens and casts are fairly well-understood to suppress 
warnings. Other things, like changing the spelling of literals, aren't. C++ is 
already a fairly baroque language, and every new thing that makes your code 
behave subtly different with a different compiler makes it more so. So I think 
we should be careful to not attach semantic meaning in surprising ways. 
Warnings have to carry their weight.

>> Maybe a better fixit is to suggest `xor` instead of `^` which also 
>> suppresses the warning and which is imho a bit less weird. (`xor` is so rare 
>> that it's still a bit weird though.)
> 
> I don't think suggesting a fixit for `xor` is a good solution. For starters, 
> you need a header included in order to use that for C. As a textual 
> suggestion "; use the 'xor' alternative token to perform an exclusive OR" 
> wouldn't bother me too much though.

I don't like xor all that much either :)

I do like Richard's suggestion.

Quuxplusone: Saying "the chromium devs don't want to change their code" is 
missing the mark. I'm happy to change that file, but that doesn't really help. 
There are hundreds of people committing hundreds of changes to the code base 
every day. They have varying levels of C++ proficiency (like everywhere). It's 
not just about getting our code to compile today, but also about the long-term 
effects of the warnings we have enabled. We have to be careful about which 
warnings we enable, and this one is maybe not quite there yet on a 
usefulness/overhead tradeoff evaluation. I'd argue that Chromium is fairly 
typical here and that clang's default warning set should follow similar 
considerations.

I looked through D63423  and didn't find an 
evaluation of false / true positive rates when lhs and rhs are just literals vs 
when they're identifiers / macros. Glancing through 
https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=10+%5E=Search , I 
couldn't find a single true positive where lhs or rhs weren't a bare literal 
(but I didn't look super carefully). Did I just miss that in D63423 
? What was the motivation for firing on more 
than bare literals?


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

https://reviews.llvm.org/D66397



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


[PATCH] D66572: [analyzer] BugReporter Separation Ep.I.

2019-08-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D66572#1640518 , @Szelethus wrote:

> Super high level question: `CheckerManager` knows whether a checker, and I 
> suspect a checker callback is path sensitive or not, do you think we can 
> automate this decision (whether the bug report is path sensitive of 
> syntactic)? For the purposes of clang-tidy, can we say such a thing that if 
> we can't prove a bug report to be path sensitive, it will not be that?


I want to reserve the ability for path-sensitive checkers to occasionally emit 
path-insensitive reports. This is due to my pipe dream of making a poor man's 
data flow engine by simply trusting ExprEngine when it says that it has 
explored all execution paths through a function. Cf. `UnreachableCodeChecker`, 
`TestAfterDivZeroChecker`. There are no other reasons because if we're not 
presenting a path we must admit that the problem happens on all paths, which 
implies some sort of must-problem, which implies no proper symbolic execution.

Maybe also we can consider reporting path-insensitive reports when we are about 
to emit a path-sensitive report but look at the AST at the last minute and it 
turns out that the problem is entirely local.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66572



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jdenny marked 2 inline comments as done.
Closed by commit rL369619: [OpenMP] Permit map with DSA on combined directive 
(authored by jdenny, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65835?vs=216502=216547#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65835

Files:
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaOpenMP.cpp
  cfe/trunk/lib/Sema/SemaStmt.cpp
  
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_messages.cpp
  
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_simd_firstprivate_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_simd_private_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_map_codegen.cpp
  cfe/trunk/test/OpenMP/target_teams_map_messages.cpp

Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -756,13 +756,16 @@
   unsigned short CapRegionKind;
 
   unsigned short OpenMPLevel;
+  unsigned short OpenMPCaptureLevel;
 
   CapturedRegionScopeInfo(DiagnosticsEngine , Scope *S, CapturedDecl *CD,
   RecordDecl *RD, ImplicitParamDecl *Context,
-  CapturedRegionKind K, unsigned OpenMPLevel)
+  CapturedRegionKind K, unsigned OpenMPLevel,
+  unsigned OpenMPCaptureLevel)
   : CapturingScopeInfo(Diag, ImpCap_CapturedRegion),
 TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S),
-ContextParam(Context), CapRegionKind(K), OpenMPLevel(OpenMPLevel) {
+ContextParam(Context), CapRegionKind(K), OpenMPLevel(OpenMPLevel),
+OpenMPCaptureLevel(OpenMPCaptureLevel) {
 Kind = SK_CapturedRegion;
   }
 
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1421,8 +1421,8 @@
   void RecordParsingTemplateParameterDepth(unsigned Depth);
 
   void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
-   RecordDecl *RD,
-   CapturedRegionKind K);
+   RecordDecl *RD, CapturedRegionKind K,
+   unsigned OpenMPCaptureLevel = 0);
 
   /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short
   /// time after they've been popped.
@@ -3979,7 +3979,8 @@
   typedef std::pair CapturedParamNameType;
   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
 CapturedRegionKind Kind,
-ArrayRef Params);
+ArrayRef Params,
+unsigned OpenMPCaptureLevel = 0);
   StmtResult ActOnCapturedRegionEnd(Stmt *S);
   void ActOnCapturedRegionError();
   RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *,
@@ -9028,7 +9029,9 @@
   /// reference.
   /// \param Level Relative level of nested OpenMP construct for that the check
   /// is performed.
-  bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level) const;
+  /// \param OpenMPCaptureLevel Capture level within an OpenMP construct.
+  bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
+ unsigned OpenMPCaptureLevel) const;
 
   /// Check if the specified variable is used in one of the private
   /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP
Index: cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
+++ cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=40 -fopenmp %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=45 -fopenmp %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected -fopenmp-version=50 -fopenmp %s -Wuninitialized
 
-// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-simd %s -Wuninitialized
 
 typedef void **omp_allocator_handle_t;
 extern const 

r369619 - [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Wed Aug 21 20:34:30 2019
New Revision: 369619

URL: http://llvm.org/viewvc/llvm-project?rev=369619=rev
Log:
[OpenMP] Permit map with DSA on combined directive

For `map`, the following restriction changed in OpenMP 5.0:

* OpenMP 4.5 [2.15.5.1, Restrictions]: "A list item cannot appear in
  both a map clause and a data-sharing attribute clause on the same
  construct.

* OpenMP 5.0 [2.19.7.1, Restrictions]: "A list item cannot appear in
  both a map clause and a data-sharing attribute clause on the same
  construct unless the construct is a combined construct."

This patch removes this restriction in the case of combined constructs
and OpenMP 5.0, and it updates Sema not to capture a scalar by copy in
the target region when `firstprivate` and `map` appear for that scalar
on a combined target construct.

This patch also adds a fixme to a test that now reveals that a
diagnostic about loop iteration variables is dropped in the case of
OpenMP 5.0.  That bug exists regardless of this patch's changes.

Reviewed By: ABataev, jdoerfert, hfinkel, kkwli0

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

Added:
cfe/trunk/test/OpenMP/target_teams_map_codegen.cpp
Modified:
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_firstprivate_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_private_messages.cpp
cfe/trunk/test/OpenMP/target_teams_map_messages.cpp

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=369619=369618=369619=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Wed Aug 21 20:34:30 2019
@@ -756,13 +756,16 @@ public:
   unsigned short CapRegionKind;
 
   unsigned short OpenMPLevel;
+  unsigned short OpenMPCaptureLevel;
 
   CapturedRegionScopeInfo(DiagnosticsEngine , Scope *S, CapturedDecl *CD,
   RecordDecl *RD, ImplicitParamDecl *Context,
-  CapturedRegionKind K, unsigned OpenMPLevel)
+  CapturedRegionKind K, unsigned OpenMPLevel,
+  unsigned OpenMPCaptureLevel)
   : CapturingScopeInfo(Diag, ImpCap_CapturedRegion),
 TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S),
-ContextParam(Context), CapRegionKind(K), OpenMPLevel(OpenMPLevel) {
+ContextParam(Context), CapRegionKind(K), OpenMPLevel(OpenMPLevel),
+OpenMPCaptureLevel(OpenMPCaptureLevel) {
 Kind = SK_CapturedRegion;
   }
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=369619=369618=369619=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Aug 21 20:34:30 2019
@@ -1421,8 +1421,8 @@ public:
   void RecordParsingTemplateParameterDepth(unsigned Depth);
 
   void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
-   RecordDecl *RD,
-   CapturedRegionKind K);
+   RecordDecl *RD, CapturedRegionKind K,
+   unsigned OpenMPCaptureLevel = 0);
 
   /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short
   /// time after they've been popped.
@@ -3979,7 +3979,8 @@ public:
   typedef std::pair CapturedParamNameType;
   void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
 CapturedRegionKind Kind,
-ArrayRef Params);
+ArrayRef Params,
+unsigned OpenMPCaptureLevel = 0);
   StmtResult ActOnCapturedRegionEnd(Stmt *S);
   void ActOnCapturedRegionError();
   RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *,
@@ -9028,7 +9029,9 @@ public:
   /// reference.
   /// \param Level Relative level of nested OpenMP construct for that the check
   /// is performed.
-  bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level) const;
+  /// \param OpenMPCaptureLevel Capture level within an OpenMP construct.
+  bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
+ unsigned OpenMPCaptureLevel) const;
 
   /// Check if the specified variable is used in one of 

[PATCH] D66404: [CFG] Make destructor calls more accurate

2019-08-21 Thread Nicholas Allegra via Phabricator via cfe-commits
comex updated this revision to Diff 216545.
comex marked 9 inline comments as done.
comex added a comment.

Changes since last version:

- Rebased.
- Added `ExternallyDestructed` parameter to `VisitExprWithCleanups` and 
`CFGBuilder::Visit`; removed `VisitExternallyDestructed`.
- Changed CFG printing to show when the type being destructed is an array.
- Fixed temporary filename mismatch in test.
- Improved comments to address feedback.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66404

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/missing-bind-temporary.cpp
  clang/test/Analysis/more-dtors-cfg-output.cpp
  clang/test/Analysis/scopes-cfg-output.cpp
  clang/test/Analysis/temporaries.cpp

Index: clang/test/Analysis/temporaries.cpp
===
--- clang/test/Analysis/temporaries.cpp
+++ clang/test/Analysis/temporaries.cpp
@@ -830,12 +830,7 @@
   // On each branch the variable is constructed directly.
   if (coin) {
 clang_analyzer_eval(x == 1); // expected-warning{{TRUE}}
-#if __cplusplus < 201703L
 clang_analyzer_eval(y == 1); // expected-warning{{TRUE}}
-#else
-// FIXME: Destructor called twice in C++17?
-clang_analyzer_eval(y == 2); // expected-warning{{TRUE}}
-#endif
 clang_analyzer_eval(z == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(w == 0); // expected-warning{{TRUE}}
 
@@ -843,12 +838,7 @@
 clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(y == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(z == 1); // expected-warning{{TRUE}}
-#if __cplusplus < 201703L
 clang_analyzer_eval(w == 1); // expected-warning{{TRUE}}
-#else
-// FIXME: Destructor called twice in C++17?
-clang_analyzer_eval(w == 2); // expected-warning{{TRUE}}
-#endif
   }
 }
 } // namespace test_match_constructors_and_destructors
@@ -1055,16 +1045,11 @@
 #endif
 
   bar2(S(2));
-  // FIXME: Why are we losing information in C++17?
   clang_analyzer_eval(glob == 2);
 #ifdef TEMPORARY_DTORS
-#if __cplusplus < 201703L
-  // expected-warning@-3{{TRUE}}
-#else
-  // expected-warning@-5{{UNKNOWN}}
-#endif
+  // expected-warning@-2{{TRUE}}
 #else
-  // expected-warning@-8{{UNKNOWN}}
+  // expected-warning@-4{{UNKNOWN}}
 #endif
 
   C *c = new D();
Index: clang/test/Analysis/scopes-cfg-output.cpp
===
--- clang/test/Analysis/scopes-cfg-output.cpp
+++ clang/test/Analysis/scopes-cfg-output.cpp
@@ -38,7 +38,7 @@
 // CHECK-NEXT:   3: A a[2];
 // CHECK-NEXT:   4:  (CXXConstructExpr, [B1.5], class A [0])
 // CHECK-NEXT:   5: A b[0];
-// CHECK-NEXT:   6: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: [B1.3].~A [2]() (Implicit destructor)
 // CHECK-NEXT:   7: CFGScopeEnd(a)
 // CHECK-NEXT:   Preds (1): B2
 // CHECK-NEXT:   Succs (1): B0
@@ -810,7 +810,7 @@
 // CHECK-NEXT:   1: CFGScopeEnd(__end1)
 // CHECK-NEXT:   2: CFGScopeEnd(__begin1)
 // CHECK-NEXT:   3: CFGScopeEnd(__range1)
-// CHECK-NEXT:   4: [B5.3].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B5.3].~A [10]() (Implicit destructor)
 // CHECK-NEXT:   5: CFGScopeEnd(a)
 // CHECK-NEXT:   Preds (1): B2
 // CHECK-NEXT:   Succs (1): B0
Index: clang/test/Analysis/more-dtors-cfg-output.cpp
===
--- /dev/null
+++ clang/test/Analysis/more-dtors-cfg-output.cpp
@@ -0,0 +1,317 @@
+// RUN: rm -f %t.14 %t.2a
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -std=c++14 -DCXX2A=0 -fblocks -Wall -Wno-unused -Werror %s > %t.14 2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -std=c++2a -DCXX2A=1 -fblocks -Wall -Wno-unused -Werror %s > %t.2a 2>&1
+// RUN: FileCheck --input-file=%t.14 -check-prefixes=CHECK,CXX14 -implicit-check-not=destructor %s
+// RUN: FileCheck --input-file=%t.2a -check-prefixes=CHECK,CXX2A -implicit-check-not=destructor %s
+
+int puts(const char *);
+
+struct Foo {
+  Foo() = delete;
+#if CXX2A
+  // Guarantee that the elided examples are actually elided by deleting the
+  // copy constructor.
+  Foo(const Foo &) = delete;
+#else
+  // No elision support, so we need a copy constructor.
+  Foo(const Foo &);
+#endif
+  ~Foo();
+};
+
+struct TwoFoos {
+  Foo foo1, foo2;
+  ~TwoFoos();
+};
+
+Foo get_foo();
+
+struct Bar {
+  Bar();
+  Bar(const Bar &);
+  ~Bar();
+  Bar =(const Bar &);
+};
+
+Bar get_bar();
+
+struct TwoBars {
+  Bar foo1, foo2;
+  ~TwoBars();
+};
+
+// Start of tests:
+
+void elided_assign() {
+  Foo x = get_foo();
+}
+// CHECK: void elided_assign()
+// CXX14: (CXXConstructExpr{{.*}}, struct Foo)
+// CXX14: ~Foo() (Temporary object destructor)
+// CHECK: ~Foo() (Implicit destructor)
+
+void nonelided_assign() {
+  Bar x = 

[PATCH] D66404: [CFG] Make destructor calls more accurate

2019-08-21 Thread Nicholas Allegra via Phabricator via cfe-commits
comex abandoned this revision.
comex marked 18 inline comments as done.
comex added inline comments.



Comment at: lib/Analysis/CFG.cpp:2102
 case Stmt::CompoundStmtClass:
-  return VisitCompoundStmt(cast(S));
+  return VisitCompoundStmt(cast(S), 
/*ExternallyDestructed=*/false);
 

NoQ wrote:
> This goes over the 80 characters limit :)
Thanks, fixed.



Comment at: lib/Analysis/CFG.cpp:2290-2295
+if (BuildOpts.AddTemporaryDtors) {
+  TempDtorContext Context;
+  VisitForTemporaryDtors(EC->getSubExpr(),
+ /*ExternallyDestructed=*/true, Context);
+}
+return Visit(EC->getSubExpr(), asc);

NoQ wrote:
> This looks like a copy-paste from `VisitExprWithCleanups` with the 
> `ExternallyDestructed` flag flipped. Could you double-check if the update to 
> `asc` that's present in `VisitExprWithCleanups` is relevant here as well? 
> I've actually no idea what do these do and we don't seem to have any tests 
> for them, so feel free to ignore, but it might make sense to at least 
> deduplicate the code.
Oops.  I omitted it because the function is always called with `AlwaysAdd`, but 
should have removed the second parameter to reflect that.  However, on 
reflection, I think it would be better to simply add an `ExternallyDestructed` 
parameter to `Visit` and `VisitExprWithCleanups`.  I'll do that in the updated 
patch.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:3
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -std=c++14 
-DCXX2A=0 -fblocks -Wall -Wno-unused -Werror %s > %t.14 2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -std=c++2a 
-DCXX2A=1 -fblocks -Wall -Wno-unused -Werror %s > %t.17 2>&1
+// RUN: FileCheck --input-file=%t.14 -check-prefixes=CHECK,CXX14 
-implicit-check-not=destructor %s

NoQ wrote:
> Did you mean `t.20`? :)
Yep, will fix.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:50
+// CXX14: (CXXConstructExpr{{.*}}, struct Foo)
+// CXX14: ~Foo() (Temporary object destructor)
+// CHECK: ~Foo() (Implicit destructor)

NoQ wrote:
> Maybe also add `CXX20-NOT` so that to make sure that the destructor *isn't* 
> there? (i think this applies to a lot of other tests)
The `-implicit-check-not=destructor` handles that: it complains if any line 
containing "destructor" isn't covered by a CHECK.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:93
+
+void elided_lambda_capture_init() {
+  // The copy from get_foo() into the lambda should be elided.  Should call

NoQ wrote:
> Pls mention somehow that this language feature is called "generalized lambda 
> captures" because it's fairly hard to google for :)
Okay :)



Comment at: test/Analysis/more-dtors-cfg-output.cpp:233
+
+// FIXME: Here are some cases that are currently handled wrongly:
+

NoQ wrote:
> I'm afraid that nobody will notice this comment when more items will be added 
> to this test file. Having a `FIXME` in tests themselves is sufficient.
Okay, I'll remove it.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:251-252
+void default_ctor_with_default_arg() {
+  // FIXME: The CFG records a construction of the array type but a destruction
+  // of the base type, which is inconsistent.  It really should should be
+  // emitting a loop, which should also contain the construction/destruction of

NoQ wrote:
> Is it just mismatching dump styles or is it an actual error?
Oops – it's actually just the printing code for implicit destructors that does:

```
if (const ArrayType *AT = ACtx.getAsArrayType(T))
  T = ACtx.getBaseElementType(AT);
```

I'm not sure why that's there: perhaps because `~Foo[]()` is not valid C++ 
syntax, but there's plenty of other places in the printing code that can print 
invalid syntax, and printing just `~Foo()` is misleading.
For now, until this code is overhauled to emit loops for constructors and 
destructors, I think it makes the most sense to remove those two lines.  I'll 
do that in the updated patch.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:252-254
+  // of the base type, which is inconsistent.  It really should should be
+  // emitting a loop, which should also contain the construction/destruction of
+  // default arguments.

NoQ wrote:
> These should most likely be two separate loops: default arguments are 
> destroyed immediately after the constructor of `qux[2]`, but elements of 
> `qux` should not be destroyed before the end of the scope.
Yeah, that's what I meant.  I'll clarify the text.



Comment at: test/Analysis/more-dtors-cfg-output.cpp:273
+#if CXX2A
+// Boilerplate needed to test co_return:
+

NoQ wrote:
> Feel free to move this into 
> `test/Analysis/inputs/system-header-simulator-cxx.h`, we could always 

[PATCH] D66381: [analyzer] Enable control dependency condition tracking by default

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f9e530c0f4d: [analyzer] Enable control dependency condition 
tracking by default (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66381

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/diagnostics/no-store-func-path-notes.m
  clang/test/Analysis/return-value-guaranteed.cpp
  clang/test/Analysis/track-control-dependency-conditions.cpp


Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -6,6 +6,7 @@
 
 // RUN: not %clang_analyze_cc1 -verify %s \
 // RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config track-conditions=false \
 // RUN:   -analyzer-config track-conditions-debug=true \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-DEBUG
 
@@ -22,6 +23,7 @@
 
 // RUN: %clang_analyze_cc1 %s -verify \
 // RUN:   -analyzer-output=text \
+// RUN:   -analyzer-config track-conditions=false \
 // RUN:   -analyzer-checker=core
 
 namespace example_1 {
Index: clang/test/Analysis/return-value-guaranteed.cpp
===
--- clang/test/Analysis/return-value-guaranteed.cpp
+++ clang/test/Analysis/return-value-guaranteed.cpp
@@ -24,6 +24,7 @@
   // class-note@-1 {{The value 0 is assigned to 'F.Field'}}
   return !MCAsmParser::Error();
   // class-note@-1 {{'MCAsmParser::Error' returns true}}
+  // class-note@-2 {{Returning zero, which participates in a condition later}}
 }
 
 bool parseFile() {
@@ -57,6 +58,7 @@
 struct MCAsmParser {
   static bool Error() {
 return false; // class-note {{'MCAsmParser::Error' returns false}}
+// class-note@-1 {{Returning zero, which participates in a condition 
later}}
   }
 };
 
@@ -72,6 +74,7 @@
   return MCAsmParser::Error();
   // class-note@-1 {{Calling 'MCAsmParser::Error'}}
   // class-note@-2 {{Returning from 'MCAsmParser::Error'}}
+  // class-note@-3 {{Returning zero, which participates in a condition later}}
 }
 
 bool parseFile() {
Index: clang/test/Analysis/diagnostics/no-store-func-path-notes.m
===
--- clang/test/Analysis/diagnostics/no-store-func-path-notes.m
+++ clang/test/Analysis/diagnostics/no-store-func-path-notes.m
@@ -16,6 +16,7 @@
 return 0;
   }
   return 1; // expected-note{{Returning without writing to '*var'}}
+  // expected-note@-1{{Returning the value 1, which participates in a 
condition later}}
 }
 @end
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -87,7 +87,7 @@
 // CHECK-NEXT: suppress-c++-stdlib = true
 // CHECK-NEXT: suppress-inlined-defensive-checks = true
 // CHECK-NEXT: suppress-null-return-paths = true
-// CHECK-NEXT: track-conditions = false
+// CHECK-NEXT: track-conditions = true
 // CHECK-NEXT: track-conditions-debug = false
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unroll-loops = false
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -294,7 +294,7 @@
 ANALYZER_OPTION(bool, ShouldTrackConditions, "track-conditions",
 "Whether to track conditions that are a control dependency of "
 "an already tracked variable.",
-false)
+true)
 
 ANALYZER_OPTION(bool, ShouldTrackConditionsDebug, "track-conditions-debug",
 "Whether to place an event at each tracked condition.",


Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -6,6 +6,7 @@
 
 // RUN: not %clang_analyze_cc1 -verify %s \
 // RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config track-conditions=false \
 // RUN:   -analyzer-config track-conditions-debug=true \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-DEBUG
 
@@ -22,6 +23,7 @@
 
 // RUN: %clang_analyze_cc1 %s -verify \
 // RUN:   -analyzer-output=text \
+// RUN:   -analyzer-config track-conditions=false \
 // RUN:   -analyzer-checker=core
 
 namespace example_1 {
Index: clang/test/Analysis/return-value-guaranteed.cpp
===
--- 

Re: [PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Nico Weber via cfe-commits
No worries. If it takes a while to analyze, please revert while you you
investigate, to keep trunk green.

On Wed, Aug 21, 2019 at 10:29 PM Csaba Dabis via Phabricator via
cfe-commits  wrote:

> Charusso added a comment.
>
>  return C.getNoteTag(
>   -  [=] {
>   +  [=]() -> std::string {
>SmallString<128> Msg;
>
> That was the fix by rL369609 . Somehow
> it converted to a temporary object therefore that was an issue:
>
>   [175/176] Running the Clang regression tests
>   llvm-lit:
> /b/sanitizer-x86_64-linux-fast/build/llvm/utils/lit/lit/llvm/config.py:340:
> note: using clang:
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang
>   -- Testing: 15399 tests, 64 threads --
>   Testing: 0
>   FAIL: Clang :: Analysis/cast-value-notes.cpp (355 of 15399)
>    TEST 'Clang :: Analysis/cast-value-notes.cpp'
> FAILED 
>   Script:
>   --
>   : 'RUN: at line 1';
>  /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -cc1
> -internal-isystem
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/lib/clang/10.0.0/include
> -nostdsysteminc -analyze -analyzer-constraints=range
>  -analyzer-checker=core,apiModeling.llvm.CastValue   -analyzer-output=text
> -verify
> /b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/cast-value-notes.cpp
>   --
>   Exit Code: 1
>
>   Command Output (stderr):
>   --
>   =
>   ==43337==ERROR: AddressSanitizer: stack-use-after-scope on address
> 0x7fa639ecfa30 at pc 0x00c7ac85 bp 0x7fff83887490 sp 0x7fff83886c40
>   READ of size 19 at 0x7fa639ecfa30 thread T0
>   #0 0xc7ac84 in __asan_memcpy
> /b/sanitizer-x86_64-linux-fast/build/llvm/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:22
>   #1 0xa328415 in copy
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__string:225:50
>   #2 0xa328415 in __init
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/string:1792
>   #3 0xa328415 in basic_string
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/string:1813
>   #4 0xa328415 in str
> /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/StringRef.h:220
>   #5 0xa328415 in operator basic_string
> /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/StringRef.h:247
>   #6 0xa328415 in __call<(lambda at
> /b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:113:7)
> &>
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__functional_base:317
>   #7 0xa328415 in operator()
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1540
>   #8 0xa328415 in
> std::__1::__function::__func clang::ento::DynamicCastInfo const*, clang::QualType, clang::Expr const*,
> bool, bool)::$_0,
> std::__1::allocator clang::ento::DynamicCastInfo const*, clang::QualType, clang::Expr const*,
> bool, bool)::$_0>, std::__1::basic_string std::__1::char_traits, std::__1::allocator > ()>::operator()()
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1714
>   #9 0xa32751d in operator()
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1867:16
>   #10 0xa32751d in operator()
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:2473
>   #11 0xa32751d in operator()
> /b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259
>   #12 0xa32751d in __invoke<(lambda at
> /b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259:23)
> &, clang::ento::BugReporterContext &, clang::ento::BugReport &>
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/type_traits:3501
>   #13 0xa32751d in __call<(lambda at
> /b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259:23)
> &, clang::ento::BugReporterContext &, clang::ento::BugReport &>
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__functional_base:317
>   #14 0xa32751d in operator()
> /b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1540
>   #15 0xa32751d in
> std::__1::__function::__func std::__1::char_traits, std::__1::allocator > ()>&&,
> bool)::'lambda'(clang::ento::BugReporterContext&, clang::ento::BugReport&),
> std::__1::allocator std::__1::char_traits, std::__1::allocator > ()>&&,
> bool)::'lambda'(clang::ento::BugReporterContext&,
> clang::ento::BugReport&)>, std::__1::basic_string std::__1::char_traits, std::__1::allocator >
> (clang::ento::BugReporterContext&,
> clang::ento::BugReport&)>::operator()(clang::ento::BugReporterContext&,
> clang::ento::BugReport&)
> 

r369616 - [analyzer] Enable control dependency condition tracking by default

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 20:08:48 2019
New Revision: 369616

URL: http://llvm.org/viewvc/llvm-project?rev=369616=rev
Log:
[analyzer] Enable control dependency condition tracking by default

This patch concludes my GSoC'19 project by enabling track-conditions by default.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
cfe/trunk/test/Analysis/return-value-guaranteed.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=369616=369615=369616=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Wed Aug 21 
20:08:48 2019
@@ -294,7 +294,7 @@ ANALYZER_OPTION(bool, DisplayCTUProgress
 ANALYZER_OPTION(bool, ShouldTrackConditions, "track-conditions",
 "Whether to track conditions that are a control dependency of "
 "an already tracked variable.",
-false)
+true)
 
 ANALYZER_OPTION(bool, ShouldTrackConditionsDebug, "track-conditions-debug",
 "Whether to place an event at each tracked condition.",

Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=369616=369615=369616=diff
==
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Wed Aug 21 20:08:48 2019
@@ -87,7 +87,7 @@
 // CHECK-NEXT: suppress-c++-stdlib = true
 // CHECK-NEXT: suppress-inlined-defensive-checks = true
 // CHECK-NEXT: suppress-null-return-paths = true
-// CHECK-NEXT: track-conditions = false
+// CHECK-NEXT: track-conditions = true
 // CHECK-NEXT: track-conditions-debug = false
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unroll-loops = false

Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m?rev=369616=369615=369616=diff
==
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m (original)
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m Wed Aug 21 
20:08:48 2019
@@ -16,6 +16,7 @@ extern int coin();
 return 0;
   }
   return 1; // expected-note{{Returning without writing to '*var'}}
+  // expected-note@-1{{Returning the value 1, which participates in a 
condition later}}
 }
 @end
 

Modified: cfe/trunk/test/Analysis/return-value-guaranteed.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/return-value-guaranteed.cpp?rev=369616=369615=369616=diff
==
--- cfe/trunk/test/Analysis/return-value-guaranteed.cpp (original)
+++ cfe/trunk/test/Analysis/return-value-guaranteed.cpp Wed Aug 21 20:08:48 2019
@@ -24,6 +24,7 @@ bool parseFoo(Foo ) {
   // class-note@-1 {{The value 0 is assigned to 'F.Field'}}
   return !MCAsmParser::Error();
   // class-note@-1 {{'MCAsmParser::Error' returns true}}
+  // class-note@-2 {{Returning zero, which participates in a condition later}}
 }
 
 bool parseFile() {
@@ -57,6 +58,7 @@ namespace test_break {
 struct MCAsmParser {
   static bool Error() {
 return false; // class-note {{'MCAsmParser::Error' returns false}}
+// class-note@-1 {{Returning zero, which participates in a condition 
later}}
   }
 };
 
@@ -72,6 +74,7 @@ bool parseFoo(Foo ) {
   return MCAsmParser::Error();
   // class-note@-1 {{Calling 'MCAsmParser::Error'}}
   // class-note@-2 {{Returning from 'MCAsmParser::Error'}}
+  // class-note@-3 {{Returning zero, which participates in a condition later}}
 }
 
 bool parseFile() {

Modified: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp?rev=369616=369615=369616=diff
==
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp (original)
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp Wed Aug 21 
20:08:48 2019
@@ -6,6 +6,7 @@
 
 // RUN: not %clang_analyze_cc1 -verify %s \
 // RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config track-conditions=false \
 // RUN:   -analyzer-config track-conditions-debug=true \
 // RUN:   2>&1 | FileCheck %s 

[PATCH] D66423: [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369615: [analyzer] CastValueChecker: Model isa(), 
isa_and_nonnull() (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66423?vs=216541=216542#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66423

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  cfe/trunk/test/Analysis/Inputs/llvm.h
  cfe/trunk/test/Analysis/cast-value-logic.cpp
  cfe/trunk/test/Analysis/cast-value-notes.cpp

Index: cfe/trunk/test/Analysis/Inputs/llvm.h
===
--- cfe/trunk/test/Analysis/Inputs/llvm.h
+++ cfe/trunk/test/Analysis/Inputs/llvm.h
@@ -16,4 +16,10 @@
 const X *dyn_cast_or_null(Y *Value);
 template 
 const X *dyn_cast_or_null(Y );
+
+template 
+bool isa(Y Value);
+
+template 
+bool isa_and_nonnull(Y Value);
 } // namespace llvm
Index: cfe/trunk/test/Analysis/cast-value-notes.cpp
===
--- cfe/trunk/test/Analysis/cast-value-notes.cpp
+++ cfe/trunk/test/Analysis/cast-value-notes.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
 // RUN:  -analyzer-output=text -verify %s
 
 #include "Inputs/llvm.h"
@@ -43,16 +43,21 @@
 return;
   }
 
-  if (dyn_cast_or_null(C)) {
+  if (isa(C)) {
 // expected-note@-1 {{'C' is not a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
-  (void)(1 / !C);
-  // expected-note@-1 {{'C' is non-null}}
-  // expected-note@-2 {{Division by zero}}
-  // expected-warning@-3 {{Division by zero}}
+  if (isa(C)) {
+// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-2 {{Taking true branch}}
+
+(void)(1 / !C);
+// expected-note@-1 {{'C' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+  }
 }
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
@@ -60,7 +65,13 @@
   // expected-note@-1 {{'S' is a 'Circle'}}
   // expected-note@-2 {{'C' initialized here}}
 
-  if (!cast(C)) {
+  if (!isa(C)) {
+// expected-note@-1 {{Assuming 'C' is a 'Triangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (!isa(C)) {
 // expected-note@-1 {{'C' is a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
Index: cfe/trunk/test/Analysis/cast-value-logic.cpp
===
--- cfe/trunk/test/Analysis/cast-value-logic.cpp
+++ cfe/trunk/test/Analysis/cast-value-logic.cpp
@@ -23,11 +23,16 @@
 using namespace llvm;
 using namespace clang;
 
-void test_regions(const Shape *A, const Shape *B) {
+void test_regions_dyn_cast(const Shape *A, const Shape *B) {
   if (dyn_cast(A) && !dyn_cast(B))
 clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
 }
 
+void test_regions_isa(const Shape *A, const Shape *B) {
+  if (isa(A) && !isa(B))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
 namespace test_cast {
 void evalLogic(const Shape *S) {
   const Circle *C = cast(S);
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -16,6 +16,7 @@
 //
 //===--===//
 
+#include "clang/AST/DeclTemplate.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -30,7 +31,7 @@
 
 namespace {
 class CastValueChecker : public Checker {
-  enum class CallKind { Function, Method };
+  enum class CallKind { Function, Method, InstanceOf };
 
   using CastCheck =
   std::functiongetAsFunction();
+  QualType CastToTy = FD->getTemplateSpecializationArgs()->get(0).getAsType();
+  QualType CastFromTy = getRecordType(Call.parameters()[0]->getType());
+
+  const MemRegion *MR = DV.getAsRegion();
+  const DynamicCastInfo *CastInfo =
+  getDynamicCastInfo(State, MR, CastFromTy, CastToTy);
+
+  bool CastSucceeds;
+  if (CastInfo)
+CastSucceeds = IsInstanceOf && CastInfo->succeeds();
+  else
+CastSucceeds = IsInstanceOf || CastFromTy == CastToTy;
+
+  if (isInfeasibleCast(CastInfo, CastSucceeds)) {
+C.generateSink(State, C.getPredecessor());
+return;
+  }
+
+  // Store the type and the cast information.
+  bool IsKnownCast = CastInfo || CastFromTy == CastToTy;
+  if (!IsKnownCast)
+State = setDynamicTypeAndCastInfo(State, MR, 

[PATCH] D66423: [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Thanks for the review!


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

https://reviews.llvm.org/D66423



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


r369615 - [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 19:57:59 2019
New Revision: 369615

URL: http://llvm.org/viewvc/llvm-project?rev=369615=rev
Log:
[analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

Summary: -

Reviewed By: NoQ

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/Inputs/llvm.h
cfe/trunk/test/Analysis/cast-value-logic.cpp
cfe/trunk/test/Analysis/cast-value-notes.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=369615=369614=369615=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Wed Aug 21 
19:57:59 2019
@@ -16,6 +16,7 @@
 //
 
//===--===//
 
+#include "clang/AST/DeclTemplate.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -30,7 +31,7 @@ using namespace ento;
 
 namespace {
 class CastValueChecker : public Checker {
-  enum class CallKind { Function, Method };
+  enum class CallKind { Function, Method, InstanceOf };
 
   using CastCheck =
   std::functiongetAsFunction();
+  QualType CastToTy = FD->getTemplateSpecializationArgs()->get(0).getAsType();
+  QualType CastFromTy = getRecordType(Call.parameters()[0]->getType());
+
+  const MemRegion *MR = DV.getAsRegion();
+  const DynamicCastInfo *CastInfo =
+  getDynamicCastInfo(State, MR, CastFromTy, CastToTy);
+
+  bool CastSucceeds;
+  if (CastInfo)
+CastSucceeds = IsInstanceOf && CastInfo->succeeds();
+  else
+CastSucceeds = IsInstanceOf || CastFromTy == CastToTy;
+
+  if (isInfeasibleCast(CastInfo, CastSucceeds)) {
+C.generateSink(State, C.getPredecessor());
+return;
+  }
+
+  // Store the type and the cast information.
+  bool IsKnownCast = CastInfo || CastFromTy == CastToTy;
+  if (!IsKnownCast)
+State = setDynamicTypeAndCastInfo(State, MR, CastFromTy, CastToTy,
+  Call.getResultType(), IsInstanceOf);
+
+  C.addTransition(
+  State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
+  C.getSValBuilder().makeTruthVal(CastSucceeds)),
+  getNoteTag(C, CastInfo, CastToTy, Call.getArgExpr(0), CastSucceeds,
+ IsKnownCast));
+}
+
 
//===--===//
 // Evaluating cast, dyn_cast, cast_or_null, dyn_cast_or_null.
 
//===--===//
@@ -278,6 +327,41 @@ void CastValueChecker::evalGetAs(const C
 }
 
 
//===--===//
+// Evaluating isa, isa_and_nonnull.
+//===--===//
+
+void CastValueChecker::evalIsa(const CallEvent , DefinedOrUnknownSVal DV,
+   CheckerContext ) const {
+  ProgramStateRef NonNullState, NullState;
+  std::tie(NonNullState, NullState) = C.getState()->assume(DV);
+
+  if (NonNullState) {
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/true);
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/false);
+  }
+
+  if (NullState) {
+C.generateSink(NullState, C.getPredecessor());
+  }
+}
+
+void CastValueChecker::evalIsaAndNonNull(const CallEvent ,
+ DefinedOrUnknownSVal DV,
+ CheckerContext ) const {
+  ProgramStateRef NonNullState, NullState;
+  std::tie(NonNullState, NullState) = C.getState()->assume(DV);
+
+  if (NonNullState) {
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/true);
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/false);
+  }
+
+  if (NullState) {
+addInstanceOfTransition(Call, DV, NullState, C, /*IsInstanceOf=*/false);
+  }
+}
+
+//===--===//
 // Main logic to evaluate a call.
 
//===--===//
 
@@ -287,12 +371,14 @@ bool CastValueChecker::evalCall(const Ca
   if (!Lookup)
 return false;
 
+  const CastCheck  = Lookup->first;
+  CallKind Kind = Lookup->second;
+
   // We need to obtain the record type of the call's result to model it.
-  if (!getRecordType(Call.getResultType())->isRecordType())
+  if (Kind != CallKind::InstanceOf &&
+  !getRecordType(Call.getResultType())->isRecordType())
 return false;
 
-  const CastCheck  = Lookup->first;
-  CallKind Kind = Lookup->second;
   Optional DV;
 
   switch 

[PATCH] D66423: [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 216541.
Charusso added a comment.

- Fix.


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

https://reviews.llvm.org/D66423

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/Inputs/llvm.h
  clang/test/Analysis/cast-value-logic.cpp
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
 // RUN:  -analyzer-output=text -verify %s
 
 #include "Inputs/llvm.h"
@@ -43,16 +43,21 @@
 return;
   }
 
-  if (dyn_cast_or_null(C)) {
+  if (isa(C)) {
 // expected-note@-1 {{'C' is not a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
-  (void)(1 / !C);
-  // expected-note@-1 {{'C' is non-null}}
-  // expected-note@-2 {{Division by zero}}
-  // expected-warning@-3 {{Division by zero}}
+  if (isa(C)) {
+// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-2 {{Taking true branch}}
+
+(void)(1 / !C);
+// expected-note@-1 {{'C' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+  }
 }
 
 void evalNonNullParamNonNullReturn(const Shape *S) {
@@ -60,7 +65,13 @@
   // expected-note@-1 {{'S' is a 'Circle'}}
   // expected-note@-2 {{'C' initialized here}}
 
-  if (!cast(C)) {
+  if (!isa(C)) {
+// expected-note@-1 {{Assuming 'C' is a 'Triangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (!isa(C)) {
 // expected-note@-1 {{'C' is a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
Index: clang/test/Analysis/cast-value-logic.cpp
===
--- clang/test/Analysis/cast-value-logic.cpp
+++ clang/test/Analysis/cast-value-logic.cpp
@@ -23,11 +23,16 @@
 using namespace llvm;
 using namespace clang;
 
-void test_regions(const Shape *A, const Shape *B) {
+void test_regions_dyn_cast(const Shape *A, const Shape *B) {
   if (dyn_cast(A) && !dyn_cast(B))
 clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
 }
 
+void test_regions_isa(const Shape *A, const Shape *B) {
+  if (isa(A) && !isa(B))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
 namespace test_cast {
 void evalLogic(const Shape *S) {
   const Circle *C = cast(S);
Index: clang/test/Analysis/Inputs/llvm.h
===
--- clang/test/Analysis/Inputs/llvm.h
+++ clang/test/Analysis/Inputs/llvm.h
@@ -16,4 +16,10 @@
 const X *dyn_cast_or_null(Y *Value);
 template 
 const X *dyn_cast_or_null(Y );
+
+template 
+bool isa(Y Value);
+
+template 
+bool isa_and_nonnull(Y Value);
 } // namespace llvm
Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -16,6 +16,7 @@
 //
 //===--===//
 
+#include "clang/AST/DeclTemplate.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -30,7 +31,7 @@
 
 namespace {
 class CastValueChecker : public Checker {
-  enum class CallKind { Function, Method };
+  enum class CallKind { Function, Method, InstanceOf };
 
   using CastCheck =
   std::functiongetAsFunction();
+  QualType CastToTy = FD->getTemplateSpecializationArgs()->get(0).getAsType();
+  QualType CastFromTy = getRecordType(Call.parameters()[0]->getType());
+
+  const MemRegion *MR = DV.getAsRegion();
+  const DynamicCastInfo *CastInfo =
+  getDynamicCastInfo(State, MR, CastFromTy, CastToTy);
+
+  bool CastSucceeds;
+  if (CastInfo)
+CastSucceeds = IsInstanceOf && CastInfo->succeeds();
+  else
+CastSucceeds = IsInstanceOf || CastFromTy == CastToTy;
+
+  if (isInfeasibleCast(CastInfo, CastSucceeds)) {
+C.generateSink(State, C.getPredecessor());
+return;
+  }
+
+  // Store the type and the cast information.
+  bool IsKnownCast = CastInfo || CastFromTy == CastToTy;
+  if (!IsKnownCast)
+State = setDynamicTypeAndCastInfo(State, MR, CastFromTy, CastToTy,
+  Call.getResultType(), IsInstanceOf);
+
+  C.addTransition(
+  State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
+  C.getSValBuilder().makeTruthVal(CastSucceeds)),
+  getNoteTag(C, CastInfo, CastToTy, Call.getArgExpr(0), CastSucceeds,
+ 

[PATCH] D66572: [analyzer] BugReporter Separation Ep.I.

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Super high level question: `CheckerManager` knows whether a checker, and I 
suspect a checker callback is path sensitive or not, do you think we can 
automate this decision (whether the bug report is path sensitive of syntactic)? 
For the purposes of clang-tidy, can we say such a thing that if we can't prove 
a bug report to be path sensitive, it will not be that?




Comment at: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h:56
 
-class RefCountReport : public BugReport {
+class RefCountReport : public PathSensitiveBugReport {
 protected:

NoQ wrote:
> I'm not pointing any fingers...
Mhm, I can see that :^)


Repository:
  rC Clang

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

https://reviews.llvm.org/D66572



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


[PATCH] D66131: [analyzer] Don't track the condition of foreach loops

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369613: [analyzer] Dont track the condition of foreach 
loops (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66131?vs=214791=216540#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66131

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp


Index: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
===
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
@@ -407,6 +407,39 @@
 }
 } // end of namespace condition_written_in_nested_stackframe_before_assignment
 
+namespace dont_explain_foreach_loops {
+
+struct Iterator {
+  int *pos;
+  bool operator!=(Iterator other) const {
+return pos && other.pos && pos != other.pos;
+  }
+  int operator*();
+  Iterator operator++();
+};
+
+struct Container {
+  Iterator begin();
+  Iterator end();
+};
+
+void f(Container Cont) {
+  int flag = 0;
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer 
value{{$
+  for (int i : Cont)
+if (i) // expected-note-re   ^}}Assuming 'i' is not equal to 0{{$
+   // expected-note-re@-1^}}Taking true branch{{$
+   // debug-note-re@-2^}}Tracking condition 'i'{{$
+  flag = i;
+
+  if (flag) // expected-note-re^}}'flag' is not equal to 0{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace dont_explain_foreach_loops
+
 namespace condition_lambda_capture_by_reference_last_write {
 int getInt();
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1800,6 +1800,11 @@
 return nullptr;
 
   if (ControlDeps.isControlDependent(OriginB, NB)) {
+// We don't really want to explain for range loops. Evidence suggests that
+// the only thing that leads to is the addition of calls to operator!=.
+if (isa(NB->getTerminator()))
+  return nullptr;
+
 if (const Expr *Condition = NB->getLastCondition()) {
   // Keeping track of the already tracked conditions on a visitor level
   // isn't sufficient, because a new visitor is created for each tracked


Index: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
===
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
@@ -407,6 +407,39 @@
 }
 } // end of namespace condition_written_in_nested_stackframe_before_assignment
 
+namespace dont_explain_foreach_loops {
+
+struct Iterator {
+  int *pos;
+  bool operator!=(Iterator other) const {
+return pos && other.pos && pos != other.pos;
+  }
+  int operator*();
+  Iterator operator++();
+};
+
+struct Container {
+  Iterator begin();
+  Iterator end();
+};
+
+void f(Container Cont) {
+  int flag = 0;
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
+  for (int i : Cont)
+if (i) // expected-note-re   ^}}Assuming 'i' is not equal to 0{{$
+   // expected-note-re@-1^}}Taking true branch{{$
+   // debug-note-re@-2^}}Tracking condition 'i'{{$
+  flag = i;
+
+  if (flag) // expected-note-re^}}'flag' is not equal to 0{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace dont_explain_foreach_loops
+
 namespace condition_lambda_capture_by_reference_last_write {
 int getInt();
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1800,6 +1800,11 @@
 return nullptr;
 
   if (ControlDeps.isControlDependent(OriginB, NB)) {
+// We don't really want to explain for range loops. Evidence suggests that
+// the only thing that leads to is the addition of calls to operator!=.
+if 

r369613 - [analyzer] Don't track the condition of foreach loops

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 19:44:19 2019
New Revision: 369613

URL: http://llvm.org/viewvc/llvm-project?rev=369613=rev
Log:
[analyzer] Don't track the condition of foreach loops

As discussed on the mailing list, notes originating from the tracking of foreach
loop conditions are always meaningless.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369613=369612=369613=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
19:44:19 2019
@@ -1800,6 +1800,11 @@ PathDiagnosticPieceRef TrackControlDepen
 return nullptr;
 
   if (ControlDeps.isControlDependent(OriginB, NB)) {
+// We don't really want to explain for range loops. Evidence suggests that
+// the only thing that leads to is the addition of calls to operator!=.
+if (isa(NB->getTerminator()))
+  return nullptr;
+
 if (const Expr *Condition = NB->getLastCondition()) {
   // Keeping track of the already tracked conditions on a visitor level
   // isn't sufficient, because a new visitor is created for each tracked

Modified: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp?rev=369613=369612=369613=diff
==
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp (original)
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp Wed Aug 21 
19:44:19 2019
@@ -407,6 +407,39 @@ void f() {
 }
 } // end of namespace condition_written_in_nested_stackframe_before_assignment
 
+namespace dont_explain_foreach_loops {
+
+struct Iterator {
+  int *pos;
+  bool operator!=(Iterator other) const {
+return pos && other.pos && pos != other.pos;
+  }
+  int operator*();
+  Iterator operator++();
+};
+
+struct Container {
+  Iterator begin();
+  Iterator end();
+};
+
+void f(Container Cont) {
+  int flag = 0;
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer 
value{{$
+  for (int i : Cont)
+if (i) // expected-note-re   ^}}Assuming 'i' is not equal to 0{{$
+   // expected-note-re@-1^}}Taking true branch{{$
+   // debug-note-re@-2^}}Tracking condition 'i'{{$
+  flag = i;
+
+  if (flag) // expected-note-re^}}'flag' is not equal to 0{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace dont_explain_foreach_loops
+
 namespace condition_lambda_capture_by_reference_last_write {
 int getInt();
 


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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

 return C.getNoteTag(
  -  [=] {
  +  [=]() -> std::string {
   SmallString<128> Msg;

That was the fix by rL369609 . Somehow it 
converted to a temporary object therefore that was an issue:

  [175/176] Running the Clang regression tests
  llvm-lit: 
/b/sanitizer-x86_64-linux-fast/build/llvm/utils/lit/lit/llvm/config.py:340: 
note: using clang: 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang
  -- Testing: 15399 tests, 64 threads --
  Testing: 0 
  FAIL: Clang :: Analysis/cast-value-notes.cpp (355 of 15399)
   TEST 'Clang :: Analysis/cast-value-notes.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/lib/clang/10.0.0/include 
-nostdsysteminc -analyze -analyzer-constraints=range   
-analyzer-checker=core,apiModeling.llvm.CastValue   -analyzer-output=text 
-verify 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/cast-value-notes.cpp
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  =
  ==43337==ERROR: AddressSanitizer: stack-use-after-scope on address 
0x7fa639ecfa30 at pc 0x00c7ac85 bp 0x7fff83887490 sp 0x7fff83886c40
  READ of size 19 at 0x7fa639ecfa30 thread T0
  #0 0xc7ac84 in __asan_memcpy 
/b/sanitizer-x86_64-linux-fast/build/llvm/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:22
  #1 0xa328415 in copy 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__string:225:50
  #2 0xa328415 in __init 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/string:1792
  #3 0xa328415 in basic_string 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/string:1813
  #4 0xa328415 in str 
/b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/StringRef.h:220
  #5 0xa328415 in operator basic_string 
/b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/ADT/StringRef.h:247
  #6 0xa328415 in __call<(lambda at 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:113:7)
 &> 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__functional_base:317
  #7 0xa328415 in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1540
  #8 0xa328415 in 
std::__1::__function::__func, std::__1::basic_string, 
std::__1::allocator > ()>::operator()() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1714
  #9 0xa32751d in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1867:16
  #10 0xa32751d in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:2473
  #11 0xa32751d in operator() 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259
  #12 0xa32751d in __invoke<(lambda at 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259:23)
 &, clang::ento::BugReporterContext &, clang::ento::BugReport &> 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/type_traits:3501
  #13 0xa32751d in __call<(lambda at 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h:259:23)
 &, clang::ento::BugReporterContext &, clang::ento::BugReport &> 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/__functional_base:317
  #14 0xa32751d in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1540
  #15 0xa32751d in 
std::__1::__function::__func, std::__1::allocator > ()>&&, 
bool)::'lambda'(clang::ento::BugReporterContext&, clang::ento::BugReport&), 
std::__1::allocator, std::__1::allocator > ()>&&, 
bool)::'lambda'(clang::ento::BugReporterContext&, clang::ento::BugReport&)>, 
std::__1::basic_string, 
std::__1::allocator > (clang::ento::BugReporterContext&, 
clang::ento::BugReport&)>::operator()(clang::ento::BugReporterContext&, 
clang::ento::BugReport&) 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1714
  #16 0xa990926 in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:1867:16
  #17 0xa990926 in operator() 
/b/sanitizer-x86_64-linux-fast/build/libcxx_build_asan/include/c++/v1/functional:2473
  #18 0xa990926 in generateMessage 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:572
  #19 0xa990926 in 
clang::ento::TagVisitor::VisitNode(clang::ento::ExplodedNode const*, 

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D66325#1640483 , @thakis wrote:

> Thanks! Looks like it builds fine now, but the tests are failing: 
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/19297/steps/test-check-all/logs/stdio
>  Failing Tests (2):
>
>   Clang :: Analysis/cast-value-notes.cpp
>   Clang :: Analysis/cast-value-state-dump.cpp


I have noticed something is broken other than the first fix, just I am not that 
professional C++ developer to immediately catch the error. I am totally on it, 
thanks!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66325



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


[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

And, unrelatedly, for libc++, shouldn't we just add the attribute to the libc++ 
source instead of trying to infer it in the compiler?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66179



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


[PATCH] D66573: [clang][ifs] Dropping older experimental interface stub formats.

2019-08-21 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added a reviewer: compnerd.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Working on a new tool, llvm-ifs, for merging interface stub files generated by 
clang and I've iterated on my derivative format of TBE to a newer format. This 
format is pretty straight forward and mainly has two fields which are the LLVM 
triple and the object format (since the triple doesn't encode that). For 
instance, you may want PE/COFF on Linux or something like that so a triple like 
x86_64-linux-gnu can't really tell you what the object is. Anyways, I think 
this format is more straight forward than something derived from objyaml and 
more intended for merging than TBE (also more platform agnostic).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66573

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- clang/test/InterfaceStubs/weak.cpp
+++ clang/test/InterfaceStubs/weak.cpp
@@ -1,12 +1,8 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
 // RUN: FileCheck %s
 
-// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
-// RUN: FileCheck --check-prefix=CHECK-YAML %s
-
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
 // RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
 
@@ -14,14 +10,6 @@
 // CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
 // CHECK-DAG:  _Z10strongFuncv: { Type: Func }
 
-// CHECK-YAML: Symbols:
-// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
-// CHECK-YAML-DAG: Type:STT_FUNC
-// CHECK-YAML-DAG: Binding: STB_WEAK
-// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
-// CHECK-YAML-DAG: Type:STT_FUNC
-// CHECK-YAML-DAG: Binding: STB_GLOBAL
-
 // CHECK-SYMBOLS-DAG: _Z10strongFuncv
 // CHECK-SYMBOLS-DAG: _Z8weakFuncv
 __attribute__((weak)) void weakFunc() {}
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- clang/test/InterfaceStubs/visibility.cpp
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -1,26 +1,26 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: -interface-stub-version=experimental-ifs-v1 -fvisibility=hidden \
 // RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: -interface-stub-version=experimental-ifs-v1 -fvisibility=hidden \
 // RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD2 %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD2 %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
Index: 

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks! Looks like it builds fine now, but the tests are failing: 
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/19297/steps/test-check-all/logs/stdio

  FAIL: Clang :: Analysis/cast-value-state-dump.cpp (4352 of 48515)
   TEST 'Clang :: Analysis/cast-value-state-dump.cpp' 
FAILED 
  Script:
  --
  : 'RUN: at line 1';   
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.exe 
-cc1 -internal-isystem 
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\lib\clang\10.0.0\include
 -nostdsysteminc -analyze -analyzer-constraints=range   
-analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection  
-analyzer-output=text -verify 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-state-dump.cpp
 2>&1 | 
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\filecheck.exe
 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-state-dump.cpp
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.exe" 
"-cc1" "-internal-isystem" 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\lib\clang\10.0.0\include"
 "-nostdsysteminc" "-analyze" "-analyzer-constraints=range" 
"-analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection" 
"-analyzer-output=text" "-verify" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-state-dump.cpp"
  note: command had no output on stdout or stderr
  error: command failed with exit status: 1
  $ 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\filecheck.exe"
 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-state-dump.cpp"
  
  --
  
  
  PASS: Clang :: Analysis/castexpr-callback.c (4353 of 48515)
  PASS: Clang :: Analysis/bool-assignment.c (4354 of 48515)
  PASS: Clang :: Analysis/builtin-functions.cpp (4355 of 48515)
  PASS: Clang :: Analysis/cfg-indirect-goto-determinism.cpp (4356 of 48515)
  PASS: Clang :: Analysis/casts.m (4357 of 48515)
  FAIL: Clang :: Analysis/cast-value-notes.cpp (4358 of 48515)
   TEST 'Clang :: Analysis/cast-value-notes.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.exe 
-cc1 -internal-isystem 
c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\lib\clang\10.0.0\include
 -nostdsysteminc -analyze -analyzer-constraints=range   
-analyzer-checker=core,apiModeling.llvm.CastValue   -analyzer-output=text 
-verify 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
  --
  Exit Code: 1
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\bin\clang.exe" 
"-cc1" "-internal-isystem" 
"c:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\build\lib\clang\10.0.0\include"
 "-nostdsysteminc" "-analyze" "-analyzer-constraints=range" 
"-analyzer-checker=core,apiModeling.llvm.CastValue" "-analyzer-output=text" 
"-verify" 
"C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp"
  # command stderr:
  error: 'note' diagnostics expected but not seen: 
  
File 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
 Line 23 (directive at 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp:24):
 Assuming 'S' is not a 'Circle'
  
File 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
 Line 30 (directive at 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp:31):
 Assuming 'S' is a 'Circle'
  
File 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
 Line 34 (directive at 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp:35):
 'C' is a 'Circle'
  
File 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
 Line 40 (directive at 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp:41):
 Assuming 'C' is not a 'Triangle'
  
File 
C:\ps4-buildslave2\llvm-clang-x86_64-expensive-checks-win\llvm\tools\clang\test\Analysis\cast-value-notes.cpp
 Line 46 (directive at 

r369609 - [analyzer] CastValueChecker: Try to fix the buildbots

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 18:41:06 2019
New Revision: 369609

URL: http://llvm.org/viewvc/llvm-project?rev=369609=rev
Log:
[analyzer] CastValueChecker: Try to fix the buildbots

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=369609=369608=369609=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Wed Aug 21 
18:41:06 2019
@@ -110,7 +110,7 @@ static const NoteTag *getNoteTag(Checker
   Object = Object->IgnoreParenImpCasts();
 
   return C.getNoteTag(
-  [=] {
+  [=]() -> std::string {
 SmallString<128> Msg;
 llvm::raw_svector_ostream Out(Msg);
 


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


[PATCH] D66572: [analyzer] BugReporter Separation Ep.I.

2019-08-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked 6 inline comments as done.
NoQ added a comment.

Most of the patch is boring but here are a few places that i wanted attract 
attention to.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:225
+
+protected:
+  /// The ExplodedGraph node against which the report was thrown. It 
corresponds

Yes, we allow inheriting from these specific `BugReport` sub-classes, because 
there turned out to be one checker that was using it.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h:56
 
-class RefCountReport : public BugReport {
+class RefCountReport : public PathSensitiveBugReport {
 protected:

I'm not pointing any fingers...



Comment at: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h:77
 
 class RefLeakReport : public RefCountReport {
   const MemRegion* AllocBinding;

...and still not pointing any fingers.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:2713
+
+  BugReporter::emitReport(std::move(R));
+}

I vaguely remember that this pattern is frowned upon. Does anybody want me to 
extract this into a common non-virtual function?



Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:2983-2984
+  if (isa(exampleReport))
+return BugReporter::generateDiagnosticForConsumerMap(exampleReport,
+ consumers, 
bugReports);
 

Same question about extracting into a non-virtual function.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:2993-2996
+  // Avoid copying the whole array because there may be a lot of reports.
+  ArrayRef convertedArrayOfReports(
+  reinterpret_cast(&*bugReports.begin()),
+  reinterpret_cast(&*bugReports.end()));

//*crosses fingers*//


Repository:
  rC Clang

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

https://reviews.llvm.org/D66572



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D66325#1640426 , @thakis wrote:

> It looks like this renamed DynamicTypeMap.h but didn't update all users, see 
> all the files in Checkers at 
> http://llvm-cs.pcc.me.uk/?q=include.*dynamictypemap.h for example.
>
> Which targets did you try to build locally?


Well, the errors are in the Static Analyzer, and I have not got any warnings, 
but now I realized that this header has plenty of injections. Thanks for the 
fast response, I have fixed it!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66325



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


r369607 - [analyzer] CastValueChecker: Rewrite dead header hotfix

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:36:42 2019
New Revision: 369607

URL: http://llvm.org/viewvc/llvm-project?rev=369607=rev
Log:
[analyzer] CastValueChecker: Rewrite dead header hotfix

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
Wed Aug 21 17:36:42 2019
@@ -27,7 +27,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 
 using namespace clang;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp Wed Aug 21 
17:36:42 2019
@@ -21,7 +21,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp Wed Aug 21 
17:36:42 2019
@@ -71,7 +71,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 
 #include 
 

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=369607=369606=369607=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Wed Aug 21 17:36:42 2019
@@ -24,7 +24,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 
 using namespace clang;
 using namespace clang::ento;

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=369607=369606=369607=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 Wed Aug 21 17:36:42 2019
@@ -18,7 +18,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

See e.g. 
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-gn/builds/4344/steps/ninja%20/logs/stdio
 for errors; I'm guessing most other bots on http://lab.llvm.org:8011/console 
will turn red in a bit too.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66325



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

It looks like this renamed DynamicTypeMap.h but didn't update all users, see 
all the files in Checkers at 
http://llvm-cs.pcc.me.uk/?q=include.*dynamictypemap.h for example.

Which targets did you try to build locally?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66325



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Charusso marked an inline comment as done.
Closed by commit rL369605: [analyzer] CastValueChecker: Store the dynamic types 
and casts (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66325?vs=216513=216530#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66325

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
  cfe/trunk/test/Analysis/Inputs/llvm.h
  cfe/trunk/test/Analysis/cast-value-logic.cpp
  cfe/trunk/test/Analysis/cast-value-notes.cpp
  cfe/trunk/test/Analysis/cast-value-state-dump.cpp
  cfe/trunk/test/Analysis/cast-value.cpp
  cfe/trunk/test/Analysis/dump_egraph.cpp
  cfe/trunk/test/Analysis/expr-inspection.c

Index: cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
+++ cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
@@ -16,7 +16,7 @@
   CommonBugCategories.cpp
   ConstraintManager.cpp
   CoreEngine.cpp
-  DynamicTypeMap.cpp
+  DynamicType.cpp
   Environment.cpp
   ExplodedGraph.cpp
   ExprEngine.cpp
Index: cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
@@ -0,0 +1,223 @@
+//===- DynamicType.cpp - Dynamic type related APIs --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines APIs that track and query dynamic type information. This
+//  information can be used to devirtualize calls during the symbolic execution
+//  or do type checking.
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
+#include "clang/Basic/JsonSupport.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+/// The GDM component containing the dynamic type info. This is a map from a
+/// symbol to its most likely type.
+REGISTER_MAP_WITH_PROGRAMSTATE(DynamicTypeMap, const clang::ento::MemRegion *,
+   clang::ento::DynamicTypeInfo)
+
+/// A set factory of dynamic cast informations.
+REGISTER_SET_FACTORY_WITH_PROGRAMSTATE(CastSet, clang::ento::DynamicCastInfo)
+
+/// A map from symbols to cast informations.
+REGISTER_MAP_WITH_PROGRAMSTATE(DynamicCastMap, const clang::ento::MemRegion *,
+   CastSet)
+
+namespace clang {
+namespace ento {
+
+DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR) {
+  MR = MR->StripCasts();
+
+  // Look up the dynamic type in the GDM.
+  if (const DynamicTypeInfo *DTI = State->get(MR))
+return *DTI;
+
+  // Otherwise, fall back to what we know about the region.
+  if (const auto *TR = dyn_cast(MR))
+return DynamicTypeInfo(TR->getLocationType(), /*CanBeSub=*/false);
+
+  if (const auto *SR = dyn_cast(MR)) {
+SymbolRef Sym = SR->getSymbol();
+return DynamicTypeInfo(Sym->getType());
+  }
+
+  return {};
+}
+
+const DynamicTypeInfo *getRawDynamicTypeInfo(ProgramStateRef State,
+ const MemRegion *MR) {
+  return State->get(MR);
+}
+
+const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State,
+  const MemRegion *MR,
+  QualType CastFromTy,
+  QualType CastToTy) {
+  const auto *Lookup = State->get().lookup(MR);
+  if (!Lookup)
+return nullptr;

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 6 inline comments as done.
Charusso added a comment.

Thanks for the review! The build-bots will fire with that `QualType` fix (1028 
TU on its own). I will look into the exploded-graph-rewriter.py after GSoC to 
fix every stuff like that patch and also invoke my HTML simplification idea.




Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:83-93
+static QualType getRecordType(QualType Ty) {
+  Ty = Ty.getCanonicalType();
+
+  if (Ty->isPointerType())
+return getRecordType(Ty->getPointeeType());
 
+  if (Ty->isReferenceType())

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > Most of the time we should know exactly how many pointer/reference 
> > > > types we need to unwrap. I really prefer we hard-assert this knowledge 
> > > > instead of blindly unwrapping as many pointer/reference types as we 
> > > > want. Because every time we have an unexpected number of unwraps it's 
> > > > an indication that something went horribly wrong. So it's good to have 
> > > > the extra sanity checking.
> > > I think this one is still forgotten. Maybe a FIXME?
> > Now I pattern-match that rule in the `evalCall()`, therefore we cannot try 
> > to evaluate nested references. Would you like to see more checks?
> Oh, i see, you removed the recursion. Great.
I was dumb enough to do not publish my comment six times, sorry.


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

https://reviews.llvm.org/D66325



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


[PATCH] D66569: [analyzer] ccc-analyzer: handle --sysroot=/path in addition to --sysroot /path

2019-08-21 Thread Chris Laplante via Phabricator via cfe-commits
chris.laplante added a comment.

I encountered this issue when trying to integrate scan-build with CMake in a 
cross-compiling environment.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66569



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


r369605 - [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:20:36 2019
New Revision: 369605

URL: http://llvm.org/viewvc/llvm-project?rev=369605=rev
Log:
[analyzer] CastValueChecker: Store the dynamic types and casts

Summary:
This patch introduces `DynamicCastInfo` similar to `DynamicTypeInfo` which
is stored in `CastSets` which are storing the dynamic cast informations of
objects based on memory regions. It could be used to store and check the
casts and prevent infeasible paths.

Reviewed By: NoQ

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

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
cfe/trunk/test/Analysis/Inputs/llvm.h
cfe/trunk/test/Analysis/cast-value-logic.cpp
cfe/trunk/test/Analysis/cast-value-notes.cpp
cfe/trunk/test/Analysis/cast-value-state-dump.cpp
Removed:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=369605=369604=369605=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Aug 21 17:20:36 2019
@@ -972,6 +972,9 @@ public:
   friend bool operator!=(const QualType , const QualType ) {
 return LHS.Value != RHS.Value;
   }
+  friend bool operator<(const QualType , const QualType ) {
+return LHS.Value < RHS.Value;
+  }
 
   static std::string getAsString(SplitQualType split,
  const PrintingPolicy ) {

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=369605=369604=369605=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Wed Aug 21 17:20:36 2019
@@ -234,7 +234,7 @@ public:
   }
 
   /// A shorthand version of getNoteTag that doesn't require you to accept
-  /// the BugReporterContext arguments when you don't need it.
+  /// the 'BugReporterContext' argument when you don't need it.
   ///
   /// @param Cb Callback only with 'BugReport &' parameter.
   /// @param IsPrunable Whether the note is prunable. It allows BugReporter
@@ -247,6 +247,19 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that doesn't require you to accept
+  /// the arguments when you don't need it.
+  ///
+  /// @param Cb Callback without parameters.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(std::function &,
+bool IsPrunable = false) {
+return getNoteTag([Cb](BugReporterContext &, BugReport &) { return Cb(); },
+  IsPrunable);
+  }
+
   /// A shorthand version of getNoteTag that accepts a plain note.
   ///
   /// @param Note The note.

Added: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h?rev=369605=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h 
(added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h 
Wed Aug 21 17:20:36 2019
@@ -0,0 +1,55 @@
+//===- DynamicCastInfo.h - Runtime cast information -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICCASTINFO_H
+#define 

[PATCH] D66267: [analyzer] TrackConstraintBRVisitor: Do not track unknown values

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369604: [analyzer] TrackConstraintBRVisitor: Do not track 
unknown values (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66267?vs=215525=216528#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66267

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/cast-value.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1992,9 +1992,10 @@
   report.markInteresting(V, TKind);
   report.addVisitor(std::make_unique(R));
 
-  // If the contents are symbolic, find out when they became null.
-  if (V.getAsLocSymbol(/*IncludeBaseRegions*/ true))
-report.addVisitor(std::make_unique(
+  // If the contents are symbolic and null, find out when they became null.
+  if (V.getAsLocSymbol(/*IncludeBaseRegions=*/true))
+if (LVState->isNull(V).isConstrainedTrue())
+  report.addVisitor(std::make_unique(
   V.castAs(), false));
 
   // Add visitor, which will suppress inline defensive checks.
Index: cfe/trunk/test/Analysis/cast-value.cpp
===
--- cfe/trunk/test/Analysis/cast-value.cpp
+++ cfe/trunk/test/Analysis/cast-value.cpp
@@ -152,8 +152,7 @@
 void evalNonNullParamNonNullReturnReference(const Shape ) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' 
succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -165,8 +164,7 @@
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
   // expected-note@-1 {{Checked cast from 'Shape' to 'Circle' succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -178,7 +176,6 @@
 void evalNonNullParamNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
-  // expected-note@-2 {{Assuming pointer value is null}}
 
   if (const auto *T = dyn_cast_or_null(S)) {
 // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' 
succeeds}}
@@ -207,9 +204,8 @@
 
 void evalZeroParamNonNullReturnPointer(const Shape *S) {
   const auto *C = S->castAs();
-  // expected-note@-1 {{Assuming pointer value is null}}
-  // expected-note@-2 {{Checked cast to 'Circle' succeeds}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-1 {{Checked cast to 'Circle' succeeds}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}


Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1992,9 +1992,10 @@
   report.markInteresting(V, TKind);
   report.addVisitor(std::make_unique(R));
 
-  // If the contents are symbolic, find out when they became null.
-  if (V.getAsLocSymbol(/*IncludeBaseRegions*/ true))
-report.addVisitor(std::make_unique(
+  // If the contents are symbolic and null, find out when they became null.
+  if (V.getAsLocSymbol(/*IncludeBaseRegions=*/true))
+if (LVState->isNull(V).isConstrainedTrue())
+  report.addVisitor(std::make_unique(
   V.castAs(), false));
 
   // Add visitor, which will suppress inline defensive checks.
Index: cfe/trunk/test/Analysis/cast-value.cpp
===
--- cfe/trunk/test/Analysis/cast-value.cpp
+++ cfe/trunk/test/Analysis/cast-value.cpp
@@ -152,8 +152,7 @@
 void evalNonNullParamNonNullReturnReference(const Shape ) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -165,8 +164,7 @@
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
   // expected-note@-1 

[PATCH] D66569: [analyzer] ccc-analyzer: handle --sysroot=/path in addition to --sysroot /path

2019-08-21 Thread Chris Laplante via Phabricator via cfe-commits
chris.laplante created this revision.
chris.laplante added a reviewer: krememek.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
dexonsmith, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

Current code assumes flags in CompilerLinkerOptionMap don't use =.


Repository:
  rC Clang

https://reviews.llvm.org/D66569

Files:
  clang/tools/scan-build/libexec/ccc-analyzer


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -498,7 +498,8 @@
 # Process the arguments.
 foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
   my $Arg = $ARGV[$i];
-  my ($ArgKey) = split /=/,$Arg,2;
+  my @ArgParts = split /=/,$Arg,2;
+  my $ArgKey = @ArgParts[0];
 
   # Be friendly to "" in the argument list.
   if (!defined($ArgKey)) {
@@ -566,10 +567,12 @@
 push @CompileOpts,$Arg;
 push @LinkOpts,$Arg;
 
-while ($Cnt > 0) {
-  ++$i; --$Cnt;
-  push @CompileOpts, $ARGV[$i];
-  push @LinkOpts, $ARGV[$i];
+if (scalar @ArgParts == 1) {
+  while ($Cnt > 0) {
+++$i; --$Cnt;
+push @CompileOpts, $ARGV[$i];
+push @LinkOpts, $ARGV[$i];
+  }
 }
 next;
   }


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -498,7 +498,8 @@
 # Process the arguments.
 foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
   my $Arg = $ARGV[$i];
-  my ($ArgKey) = split /=/,$Arg,2;
+  my @ArgParts = split /=/,$Arg,2;
+  my $ArgKey = @ArgParts[0];
 
   # Be friendly to "" in the argument list.
   if (!defined($ArgKey)) {
@@ -566,10 +567,12 @@
 push @CompileOpts,$Arg;
 push @LinkOpts,$Arg;
 
-while ($Cnt > 0) {
-  ++$i; --$Cnt;
-  push @CompileOpts, $ARGV[$i];
-  push @LinkOpts, $ARGV[$i];
+if (scalar @ArgParts == 1) {
+  while ($Cnt > 0) {
+++$i; --$Cnt;
+push @CompileOpts, $ARGV[$i];
+push @LinkOpts, $ARGV[$i];
+  }
 }
 next;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66267: [analyzer] TrackConstraintBRVisitor: Do not track unknown values

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Thanks for the reviews! I hope that mentioned error will be visible by the 
`BugReporter` revisions.


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

https://reviews.llvm.org/D66267



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


[PATCH] D66565: [analyzer] pr43036: Fix support for operator `sizeof...'.

2019-08-21 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

LG!


Repository:
  rC Clang

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

https://reviews.llvm.org/D66565



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


r369604 - [analyzer] TrackConstraintBRVisitor: Do not track unknown values

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:06:58 2019
New Revision: 369604

URL: http://llvm.org/viewvc/llvm-project?rev=369604=rev
Log:
[analyzer] TrackConstraintBRVisitor: Do not track unknown values

Summary: -

Reviewers: NoQ, Szelethus

Reviewed By: NoQ, Szelethus

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/cast-value.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369604=369603=369604=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
17:06:58 2019
@@ -1992,9 +1992,10 @@ bool bugreporter::trackExpressionValue(c
   report.markInteresting(V, TKind);
   report.addVisitor(std::make_unique(R));
 
-  // If the contents are symbolic, find out when they became null.
-  if (V.getAsLocSymbol(/*IncludeBaseRegions*/ true))
-report.addVisitor(std::make_unique(
+  // If the contents are symbolic and null, find out when they became null.
+  if (V.getAsLocSymbol(/*IncludeBaseRegions=*/true))
+if (LVState->isNull(V).isConstrainedTrue())
+  report.addVisitor(std::make_unique(
   V.castAs(), false));
 
   // Add visitor, which will suppress inline defensive checks.

Modified: cfe/trunk/test/Analysis/cast-value.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cast-value.cpp?rev=369604=369603=369604=diff
==
--- cfe/trunk/test/Analysis/cast-value.cpp (original)
+++ cfe/trunk/test/Analysis/cast-value.cpp Wed Aug 21 17:06:58 2019
@@ -152,8 +152,7 @@ void evalReferences(const Shape ) {
 void evalNonNullParamNonNullReturnReference(const Shape ) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' 
succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -165,8 +164,7 @@ void evalNonNullParamNonNullReturnRefere
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
   // expected-note@-1 {{Checked cast from 'Shape' to 'Circle' succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -178,7 +176,6 @@ void evalNonNullParamNonNullReturn(const
 void evalNonNullParamNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
-  // expected-note@-2 {{Assuming pointer value is null}}
 
   if (const auto *T = dyn_cast_or_null(S)) {
 // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' 
succeeds}}
@@ -207,9 +204,8 @@ void evalNullParamNullReturn(const Shape
 
 void evalZeroParamNonNullReturnPointer(const Shape *S) {
   const auto *C = S->castAs();
-  // expected-note@-1 {{Assuming pointer value is null}}
-  // expected-note@-2 {{Checked cast to 'Circle' succeeds}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-1 {{Checked cast to 'Circle' succeeds}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}


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


[PATCH] D66502: [clang-doc] Switch Generator::CreateResources to use llvm::Error

2019-08-21 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran accepted this revision.
DiegoAstiazaran added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D66502



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Let's land this then!~~




Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:83-93
+static QualType getRecordType(QualType Ty) {
+  Ty = Ty.getCanonicalType();
+
+  if (Ty->isPointerType())
+return getRecordType(Ty->getPointeeType());
 
+  if (Ty->isReferenceType())

Charusso wrote:
> NoQ wrote:
> > NoQ wrote:
> > > Most of the time we should know exactly how many pointer/reference types 
> > > we need to unwrap. I really prefer we hard-assert this knowledge instead 
> > > of blindly unwrapping as many pointer/reference types as we want. Because 
> > > every time we have an unexpected number of unwraps it's an indication 
> > > that something went horribly wrong. So it's good to have the extra sanity 
> > > checking.
> > I think this one is still forgotten. Maybe a FIXME?
> Now I pattern-match that rule in the `evalCall()`, therefore we cannot try to 
> evaluate nested references. Would you like to see more checks?
Oh, i see, you removed the recursion. Great.


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

https://reviews.llvm.org/D66325



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


[PATCH] D66361: Improve behavior in the case of stack exhaustion.

2019-08-21 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 216520.
rsmith marked 5 inline comments as done.
rsmith added a comment.

- Address review comments from Aaron.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66361

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Stack.h
  include/clang/Sema/Sema.h
  lib/Basic/CMakeLists.txt
  lib/Basic/Stack.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaType.cpp
  test/CMakeLists.txt
  test/SemaTemplate/stack-exhaustion.cpp
  test/lit.cfg.py
  test/lit.site.cfg.py.in
  tools/driver/driver.cpp

Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -13,6 +13,7 @@
 
 #include "clang/Driver/Driver.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/Stack.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -319,6 +320,7 @@
 }
 
 int main(int argc_, const char **argv_) {
+  noteBottomOfStack();
   llvm::InitLLVM X(argc_, argv_);
   SmallVector argv(argv_, argv_ + argc_);
 
Index: test/lit.site.cfg.py.in
===
--- test/lit.site.cfg.py.in
+++ test/lit.site.cfg.py.in
@@ -25,6 +25,7 @@
 config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
 config.enable_experimental_new_pass_manager = @ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER@
+config.enable_threads = @LLVM_ENABLE_THREADS@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
Index: test/lit.cfg.py
===
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -175,6 +175,9 @@
 if config.enable_backtrace:
 config.available_features.add('backtrace')
 
+if config.enable_threads:
+config.available_features.add('thread_support')
+
 # Check if we should allow outputs to console.
 run_console_tests = int(lit_config.params.get('enable_console', '0'))
 if run_console_tests != 0:
Index: test/SemaTemplate/stack-exhaustion.cpp
===
--- /dev/null
+++ test/SemaTemplate/stack-exhaustion.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify %s
+// REQUIRES: thread_support
+
+// expected-warning@* 0-1{{stack nearly exhausted}}
+// expected-note@* 0+{{}}
+
+template struct X : X {};
+template<> struct X<0> {};
+X<1000> x;
+
+template struct tuple {};
+template auto f(tuple t) -> decltype(f(tuple(t))) {} // expected-error {{exceeded maximum depth}}
+void g() { f(tuple()); }
+
+int f(X<0>);
+template auto f(X) -> f(X());
+
+int k = f(X<1000>());
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -26,7 +26,8 @@
   ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER
   HAVE_LIBZ
   LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
-  LLVM_ENABLE_PLUGINS)
+  LLVM_ENABLE_PLUGINS
+  LLVM_ENABLE_THREADS)
 
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7715,7 +7715,9 @@
 auto *Def = Var->getDefinition();
 if (!Def) {
   SourceLocation PointOfInstantiation = E->getExprLoc();
-  InstantiateVariableDefinition(PointOfInstantiation, Var);
+  runWithSufficientStackSpace(PointOfInstantiation, [&] {
+InstantiateVariableDefinition(PointOfInstantiation, Var);
+  });
   Def = Var->getDefinition();
 
   // If we don't already have a point of instantiation, and we managed
@@ -8053,9 +8055,11 @@
 } else if (auto *ClassTemplateSpec =
 dyn_cast(RD)) {
   if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared) {
-Diagnosed = InstantiateClassTemplateSpecialization(
-Loc, ClassTemplateSpec, TSK_ImplicitInstantiation,
-/*Complain=*/Diagnoser);
+runWithSufficientStackSpace(Loc, [&] {
+  Diagnosed = InstantiateClassTemplateSpecialization(
+  Loc, ClassTemplateSpec, TSK_ImplicitInstantiation,
+  /*Complain=*/Diagnoser);
+});
 Instantiated = true;
   }
 } else {
@@ -8066,10 +8070,12 @@
 // This record was instantiated from a class within a template.
 if (MSI->getTemplateSpecializationKind() !=
 TSK_ExplicitSpecialization) {
-  

[PATCH] D66361: Improve behavior in the case of stack exhaustion.

2019-08-21 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:14
 let Component = "Sema" in {
-let CategoryName = "Semantic Issue" in {
+def warn_stack_exhausted : Warning<
+  "stack nearly exhausted; compilation time may suffer, and "

aaron.ballman wrote:
> Should this be a Sema warning as opposed to a Basic warning? It seems to me 
> that we may want to guard against similar stack exhaustion from the parser as 
> well, wouldn't we?
Sure, moved to DiagnosticCommonKinds.td. We have no uses of it outside Sema 
yet, but it's definitely plausible that some would be added.



Comment at: lib/Sema/SemaExpr.cpp:15070-15079
+  // Trivial default constructors and destructors are never actually used.
+  // FIXME: What about other special members?
+  if (Func->isTrivial() && !Func->hasAttr() &&
+  OdrUse == OdrUseContext::Used) {
+if (auto *Constructor = dyn_cast(Func))
+  if (Constructor->isDefaultConstructor())
+OdrUse = OdrUseContext::FormallyOdrUsed;

aaron.ballman wrote:
> This seems unrelated to the patch?
I agree it seems that way, but it is related:

The block of code below that got turned into a lambda contains early exits via 
`return` for the cases that get downgraded to `FormallyOdrUsed` here. We used 
to bail out of the whole function and not mark these trivial special member 
functions as "used" (in the code after the `NeedDefinition && !Func->getBody()` 
condition), which seems somewhat reasonable since we don't actually need 
definitions of them; other parts of Clang (specifically the static analyzer) 
have developed a reliance on that behavior.

So this is preserving the existing behavior and (hopefully) making it more 
obvious what that behavior is, rather than getting that behavior by an early 
exit from the "need a definition?" portion of this function leaking into the 
semantics of the "mark used" portion.

I can split this out and make this change first if you like.



Comment at: test/SemaTemplate/stack-exhaustion.cpp:10
+template struct tuple {};
+template auto f(tuple t) -> decltype(f(tuple(t))) 
{} // expected-error {{exceeded maximum depth}}
+void g() { f(tuple()); }

rsmith wrote:
> rnk wrote:
> > This test seems like it could be fragile. If threads are disabled, it will 
> > probably crash.
> I've handled the "threads are disabled" case. Is there anything else that can 
> meaningfully be detected here? (ASan maybe? Are there any other cases that 
> lead to a non-linear stack layout that we can detect?)
I've read through the ASan UAR design and played with some testcases, and I 
think this is fine. ASan will allocate the locals for some frames on the heap 
instead of on the stack, but that's OK, it just might mean that the stack usage 
grows more slowly. The stack pointer still points to the real stack, 
`__builtin_frame_address(0)` still returns a stack pointer (and critically, not 
a pointer to the ASan-heap-allocated frame), and we can still detect when we're 
getting close to stack exhaustion -- it just happens more slowly in this mode 
because we have another pool of places to allocate frames that's tried before 
we fall back to the stack.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66361



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


[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp:9
+
+#include "../ASTMatchers/ASTMatchersTest.h"
+#include "clang/ASTMatchers/ASTMatchers.h"

mgehre wrote:
> thakis wrote:
> > This weird relative include path is a hint that this isn't the intended use 
> > :)
> True. But ...
> I thought about copying the `matches` function from STMatchersTest.h, but 
> together with all callees, that's many lines of code.
> Alternatively, I could implement my own AST walking and property checking, 
> but then the test would be much less readable.
> As yet another alternative, I though about moving the 
> `GslOwnerPointerInference.cpp` test itself to `unittests/ASTMatchers`,
> but that would also be strange because it actually tests Sema functionality.
> 
> What would be your suggestion? (It's good that we discuss this now because 
> I'm planning to extend this unit test further).
Do you need the full matches() function? With the current test, it's not even 
clear to me what exactly it tests since it looks very integration-testy and not 
very unit-testy. Maybe if you make the test narrower, you don't that much 
scaffolding? (Integration-type tests are supposed to be lit tests, and unit 
tests are supposed to test small details that are difficult to test via lit.)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66179



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


[PATCH] D66564: [clang-tidy] FPGA struct pack align lint check

2019-08-21 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 216516.
ffrankies added a comment.

Noticed that some of the lint checks were missing from 
docs/clang-tidy/checks/list.rst

Added the fpga-struct-pack-align lint check to the update checks list.


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

https://reviews.llvm.org/D66564

Files:
  clang-tidy/fpga/CMakeLists.txt
  clang-tidy/fpga/FPGATidyModule.cpp
  clang-tidy/fpga/StructPackAlignCheck.cpp
  clang-tidy/fpga/StructPackAlignCheck.h
  docs/clang-tidy/checks/fpga-struct-pack-align.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/fpga-struct-pack-align.cpp

Index: test/clang-tidy/fpga-struct-pack-align.cpp
===
--- /dev/null
+++ test/clang-tidy/fpga-struct-pack-align.cpp
@@ -0,0 +1,74 @@
+// RUN: %check_clang_tidy %s fpga-struct-pack-align %t -- -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c 
+
+// Struct needs both alignment and packing
+struct error {
+char a;
+double b;
+char c;
+};
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error' has inefficient access due to padding, only needs 10 bytes but is using 24 bytes, use "__attribute((packed))" [fpga-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: warning: struct 'error' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is explicitly packed, but needs alignment
+struct error_packed {
+char a;
+double b;
+char c;
+} __attribute((packed));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error_packed' has inefficient access due to poor alignment. Currently aligned to 1 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is properly packed, but needs alignment
+struct align_only {
+char a;
+char b;
+char c;
+char d;
+int e;
+double f;
+};
+// CHECK-MESSAGES: :[[@LINE-8]]:8: warning: struct 'align_only' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 16 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is perfectly packed but wrongly aligned
+struct bad_align {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(8)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align2 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(32)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align2' has inefficient access due to poor alignment. Currently aligned to 32 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align3 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(4)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align3' has inefficient access due to poor alignment. Currently aligned to 4 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is both perfectly packed and aligned
+struct success {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(16)));
+//Should take 10 bytes and be aligned to 16 bytes
+
+// Struct is properly packed, and explicitly aligned
+struct success2 {
+int a;
+int b;
+int c;
+} __attribute((aligned(16)));
+
+// If struct is properly aligned, packing not needed
+struct error_aligned {
+char a;
+double b;
+char c;
+} __attribute((aligned(16)));
+
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -64,6 +64,7 @@
 ``cert-``  Checks related to CERT Secure Coding Guidelines.
 ``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
 ``clang-analyzer-``Clang Static Analyzer checks.
+``fpga-``  Checks related to OpenCL programming for FPGAs..
 ``fuchsia-``   Checks related to Fuchsia coding conventions.
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -210,6 +210,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fpga-struct-pack-align
fuchsia-default-arguments-calls
fuchsia-default-arguments-declarations
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
Index: 

[PATCH] D66565: [analyzer] pr43036: Fix support for operator `sizeof...'.

2019-08-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, rnkovacs, Szelethus, 
baloghadamsoftware, Charusso.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, szepet.
Herald added a project: clang.

A tiny fix for https://bugs.llvm.org/show_bug.cgi?id=43036 . We should probably 
double-check other fancy compile-time expressions.


Repository:
  rC Clang

https://reviews.llvm.org/D66565

Files:
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/test/Analysis/sizeofpack.cpp


Index: clang/test/Analysis/sizeofpack.cpp
===
--- /dev/null
+++ clang/test/Analysis/sizeofpack.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
+// RUN:-verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+
+void clang_analyzer_eval(bool);
+
+template  size_t foo() {
+  return sizeof...(N);
+}
+
+void bar() {
+  clang_analyzer_eval(foo<>() == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(foo<1, 2, 3>() == 3); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/Environment.cpp
===
--- clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -108,6 +108,7 @@
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass:
   case Stmt::TypeTraitExprClass:
+  case Stmt::SizeOfPackExprClass:
 // Known constants; defer to SValBuilder.
 return svalBuilder.getConstantVal(cast(S)).getValue();
 


Index: clang/test/Analysis/sizeofpack.cpp
===
--- /dev/null
+++ clang/test/Analysis/sizeofpack.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
+// RUN:-verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+
+void clang_analyzer_eval(bool);
+
+template  size_t foo() {
+  return sizeof...(N);
+}
+
+void bar() {
+  clang_analyzer_eval(foo<>() == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(foo<1, 2, 3>() == 3); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/Environment.cpp
===
--- clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -108,6 +108,7 @@
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass:
   case Stmt::TypeTraitExprClass:
+  case Stmt::SizeOfPackExprClass:
 // Known constants; defer to SValBuilder.
 return svalBuilder.getConstantVal(cast(S)).getValue();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66564: [clang-tidy] FPGA struct pack align lint check

2019-08-21 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies created this revision.
ffrankies added a reviewer: alexfh.
ffrankies created this object with visibility "All Users".
ffrankies added a project: clang-tools-extra.
Herald added subscribers: arphaman, xazax.hun, Anastasia, mgorny, srhines.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

This lint check is a part of the FLOCL (**F**PGA **L**inters for 
**O**pen**CL**) project out of the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code in OpenCL.

The FPGA struct pack align lint check finds structs that are inefficiently 
packed or aligned and recommends packing/aligning of the structs using the 
packed and aligned attributes as needed in a warning.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D66564

Files:
  clang-tidy/fpga/CMakeLists.txt
  clang-tidy/fpga/FPGATidyModule.cpp
  clang-tidy/fpga/StructPackAlignCheck.cpp
  clang-tidy/fpga/StructPackAlignCheck.h
  docs/clang-tidy/checks/fpga-struct-pack-align.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/fpga-struct-pack-align.cpp

Index: test/clang-tidy/fpga-struct-pack-align.cpp
===
--- /dev/null
+++ test/clang-tidy/fpga-struct-pack-align.cpp
@@ -0,0 +1,74 @@
+// RUN: %check_clang_tidy %s fpga-struct-pack-align %t -- -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c 
+
+// Struct needs both alignment and packing
+struct error {
+char a;
+double b;
+char c;
+};
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error' has inefficient access due to padding, only needs 10 bytes but is using 24 bytes, use "__attribute((packed))" [fpga-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: warning: struct 'error' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is explicitly packed, but needs alignment
+struct error_packed {
+char a;
+double b;
+char c;
+} __attribute((packed));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error_packed' has inefficient access due to poor alignment. Currently aligned to 1 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is properly packed, but needs alignment
+struct align_only {
+char a;
+char b;
+char c;
+char d;
+int e;
+double f;
+};
+// CHECK-MESSAGES: :[[@LINE-8]]:8: warning: struct 'align_only' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 16 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is perfectly packed but wrongly aligned
+struct bad_align {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(8)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align2 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(32)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align2' has inefficient access due to poor alignment. Currently aligned to 32 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align3 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(4)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align3' has inefficient access due to poor alignment. Currently aligned to 4 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is both perfectly packed and aligned
+struct success {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(16)));
+//Should take 10 bytes and be aligned to 16 bytes
+
+// Struct is properly packed, and explicitly aligned
+struct success2 {
+int a;
+int b;
+int c;
+} __attribute((aligned(16)));
+
+// If struct is properly aligned, packing not needed
+struct error_aligned {
+char a;
+double b;
+char c;
+} __attribute((aligned(16)));
+
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -64,6 +64,7 @@
 ``cert-``  Checks related to CERT Secure Coding Guidelines.
 ``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
 ``clang-analyzer-``Clang Static Analyzer checks.
+``fpga-``  Checks related to OpenCL programming for FPGAs..
 ``fuchsia-``   Checks related to Fuchsia coding conventions.
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
Index: 

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 216513.
Charusso added a comment.

- Fix printing.


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

https://reviews.llvm.org/D66325

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/CMakeLists.txt
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/test/Analysis/Inputs/llvm.h
  clang/test/Analysis/cast-value-logic.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cast-value.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/expr-inspection.c

Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -38,6 +38,7 @@
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "dynamic_types": null,
+// CHECK-NEXT:   "dynamic_casts": null,
 // CHECK-NEXT:   "constructing_objects": null,
 // CHECK-NEXT:   "checker_messages": null
 // CHECK-NEXT: }
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -24,4 +24,5 @@
 
 // CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
-// CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false\}\l
+// CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false \}\l
+
Index: clang/test/Analysis/cast-value.cpp
===
--- clang/test/Analysis/cast-value.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-// RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN:  -verify=logic %s
-// RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
-// RUN:  -analyzer-output=text -verify %s
-
-void clang_analyzer_numTimesReached();
-void clang_analyzer_warnIfReached();
-void clang_analyzer_eval(bool);
-
-namespace llvm {
-template 
-const X *cast(Y Value);
-
-template 
-const X *dyn_cast(Y *Value);
-template 
-const X _cast(Y );
-
-template 
-const X *cast_or_null(Y Value);
-
-template 
-const X *dyn_cast_or_null(Y *Value);
-template 
-const X *dyn_cast_or_null(Y );
-} // namespace llvm
-
-namespace clang {
-struct Shape {
-  template 
-  const T *castAs() const;
-
-  template 
-  const T *getAs() const;
-};
-class Triangle : public Shape {};
-class Circle : public Shape {};
-} // namespace clang
-
-using namespace llvm;
-using namespace clang;
-
-namespace test_cast {
-void evalLogic(const Shape *S) {
-  const Circle *C = cast(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{1}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // no-warning
-
-  if (!S)
-clang_analyzer_warnIfReached(); // no-warning
-}
-} // namespace test_cast
-
-namespace test_dyn_cast {
-void evalLogic(const Shape *S) {
-  const Circle *C = dyn_cast(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{2}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
-
-  if (!S)
-clang_analyzer_warnIfReached(); // no-warning
-}
-} // namespace test_dyn_cast
-
-namespace test_cast_or_null {
-void evalLogic(const Shape *S) {
-  const Circle *C = cast_or_null(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{2}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // no-warning
-
-  if (!S)
-clang_analyzer_eval(!C); // logic-warning {{TRUE}}
-}
-} // namespace test_cast_or_null
-
-namespace test_dyn_cast_or_null {
-void evalLogic(const Shape *S) {
-  const Circle *C = dyn_cast_or_null(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{3}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // 

[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:83-93
+static QualType getRecordType(QualType Ty) {
+  Ty = Ty.getCanonicalType();
+
+  if (Ty->isPointerType())
+return getRecordType(Ty->getPointeeType());
 
+  if (Ty->isReferenceType())

NoQ wrote:
> NoQ wrote:
> > Most of the time we should know exactly how many pointer/reference types we 
> > need to unwrap. I really prefer we hard-assert this knowledge instead of 
> > blindly unwrapping as many pointer/reference types as we want. Because 
> > every time we have an unexpected number of unwraps it's an indication that 
> > something went horribly wrong. So it's good to have the extra sanity 
> > checking.
> I think this one is still forgotten. Maybe a FIXME?
Now I pattern-match that rule in the `evalCall()`, therefore we cannot try to 
evaluate nested references. Would you like to see more checks?


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

https://reviews.llvm.org/D66325



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


[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre marked an inline comment as done.
mgehre added inline comments.



Comment at: cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp:9
+
+#include "../ASTMatchers/ASTMatchersTest.h"
+#include "clang/ASTMatchers/ASTMatchers.h"

thakis wrote:
> This weird relative include path is a hint that this isn't the intended use :)
True. But ...
I thought about copying the `matches` function from STMatchersTest.h, but 
together with all callees, that's many lines of code.
Alternatively, I could implement my own AST walking and property checking, but 
then the test would be much less readable.
As yet another alternative, I though about moving the 
`GslOwnerPointerInference.cpp` test itself to `unittests/ASTMatchers`,
but that would also be strange because it actually tests Sema functionality.

What would be your suggestion? (It's good that we discuss this now because I'm 
planning to extend this unit test further).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66179



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:126
+} else {
+  Out << "the object";
+}

"The" should be capitalized if there's no "Assuming" before it.


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

https://reviews.llvm.org/D66325



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


[PATCH] D66325: [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 216509.
Charusso marked 4 inline comments as done and an inline comment as not done.
Charusso added a comment.

- Fix


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

https://reviews.llvm.org/D66325

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Core/CMakeLists.txt
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/test/Analysis/Inputs/llvm.h
  clang/test/Analysis/cast-value-logic.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cast-value.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/expr-inspection.c

Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -38,6 +38,7 @@
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "dynamic_types": null,
+// CHECK-NEXT:   "dynamic_casts": null,
 // CHECK-NEXT:   "constructing_objects": null,
 // CHECK-NEXT:   "checker_messages": null
 // CHECK-NEXT: }
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -24,4 +24,5 @@
 
 // CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
-// CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false\}\l
+// CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false \}\l
+
Index: clang/test/Analysis/cast-value.cpp
===
--- clang/test/Analysis/cast-value.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-// RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN:  -verify=logic %s
-// RUN: %clang_analyze_cc1 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue \
-// RUN:  -analyzer-output=text -verify %s
-
-void clang_analyzer_numTimesReached();
-void clang_analyzer_warnIfReached();
-void clang_analyzer_eval(bool);
-
-namespace llvm {
-template 
-const X *cast(Y Value);
-
-template 
-const X *dyn_cast(Y *Value);
-template 
-const X _cast(Y );
-
-template 
-const X *cast_or_null(Y Value);
-
-template 
-const X *dyn_cast_or_null(Y *Value);
-template 
-const X *dyn_cast_or_null(Y );
-} // namespace llvm
-
-namespace clang {
-struct Shape {
-  template 
-  const T *castAs() const;
-
-  template 
-  const T *getAs() const;
-};
-class Triangle : public Shape {};
-class Circle : public Shape {};
-} // namespace clang
-
-using namespace llvm;
-using namespace clang;
-
-namespace test_cast {
-void evalLogic(const Shape *S) {
-  const Circle *C = cast(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{1}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // no-warning
-
-  if (!S)
-clang_analyzer_warnIfReached(); // no-warning
-}
-} // namespace test_cast
-
-namespace test_dyn_cast {
-void evalLogic(const Shape *S) {
-  const Circle *C = dyn_cast(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{2}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
-
-  if (!S)
-clang_analyzer_warnIfReached(); // no-warning
-}
-} // namespace test_dyn_cast
-
-namespace test_cast_or_null {
-void evalLogic(const Shape *S) {
-  const Circle *C = cast_or_null(S);
-  clang_analyzer_numTimesReached(); // logic-warning {{2}}
-
-  if (S && C)
-clang_analyzer_eval(C == S); // logic-warning {{TRUE}}
-
-  if (S && !C)
-clang_analyzer_warnIfReached(); // no-warning
-
-  if (!S)
-clang_analyzer_eval(!C); // logic-warning {{TRUE}}
-}
-} // namespace test_cast_or_null
-
-namespace test_dyn_cast_or_null {
-void evalLogic(const Shape *S) {
-  const Circle *C = dyn_cast_or_null(S);
-  clang_analyzer_numTimesReached(); // 

[PATCH] D66559: [OPENMP] Update the diagnosis message for canonical loop form

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66559



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked 4 inline comments as done.
jdenny added a comment.

Thanks.




Comment at: clang/lib/Sema/SemaExpr.cpp:17748
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
\ No newline at end of file
+}

ABataev wrote:
> jdenny wrote:
> > ABataev wrote:
> > > Restore original code here
> > OK, I did.  What's the reason for no newline at the end of the file?
> Changes not related to the patch, like formatting etc., better to commit in 
> separate patches.
Ah.



Comment at: clang/lib/Sema/SemaExpr.cpp:17749
 }
\ No newline at end of file


ABataev wrote:
> Still marked as changed code, better to restore it completely.
There's no change here.  I checked the diff I uploaded to be sure.


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG




Comment at: clang/lib/Sema/SemaExpr.cpp:17749
 }
\ No newline at end of file


Still marked as changed code, better to restore it completely.


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

https://reviews.llvm.org/D65835



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


[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Similar to




Comment at: cfe/trunk/unittests/Sema/CMakeLists.txt:14
   clangAST
+  clangASTMatchers
   clangBasic

Is it necessary to use ASTMachers to test this? It'd be good if SemaTests 
wouldn't have to depend on ASTMatchers (for linking speed, as well for layering 
hygiene).



Comment at: cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp:9
+
+#include "../ASTMatchers/ASTMatchersTest.h"
+#include "clang/ASTMatchers/ASTMatchers.h"

This weird relative include path is a hint that this isn't the intended use :)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66179



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


[PATCH] D65725: [analyzer] Mention whether an event is about a condition in a bug report part 2

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369596: [analyzer] Mention whether an event is about a 
condition in a bug report part 2 (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65725?vs=216421=216506#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65725

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Index: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
===
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
@@ -443,7 +443,7 @@
   int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
 
   auto lambda = [flag]() {
-if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0{{$
+if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0, which participates in a condition later{{$
// tracking-note-re@-1^}}Taking false branch{{$
   halt();
   };
@@ -474,7 +474,7 @@
   int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
 
   auto lambda = []() {
-if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0{{$
+if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0, which participates in a condition later{{$
// tracking-note-re@-1^}}Taking false branch{{$
   halt();
   };
@@ -486,18 +486,42 @@
 
   if (flag) // expected-note-re^}}'flag' is not equal to 0{{$
 // expected-note-re@-1^}}Taking true branch{{$
-// debug-note-re@-2^}}Tracking condition 'flag'}}
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
 } // end of namespace condition_lambda_capture_by_reference_assumption
 
+namespace collapse_point_not_in_condition_bool {
+
+[[noreturn]] void halt();
+
+void check(bool b) {
+  if (!b) // tracking-note-re^}}Assuming 'b' is true, which participates in a condition later{{$
+  // tracking-note-re@-1^}}Taking false branch{{$
+halt();
+}
+
+void f(bool flag) {
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
+
+  check(flag); // tracking-note-re^}}Calling 'check'{{$
+// tracking-note-re@-1^}}Returning from 'check'{{$
+
+  if (flag) // expected-note-re^}}'flag' is true{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace collapse_point_not_in_condition_bool
+
 namespace collapse_point_not_in_condition {
 
 [[noreturn]] void halt();
 
 void assert(int b) {
-  if (!b) // tracking-note-re^}}Assuming 'b' is not equal to 0{{$
+  if (!b) // tracking-note-re^}}Assuming 'b' is not equal to 0, which participates in a condition later{{$
   // tracking-note-re@-1^}}Taking false branch{{$
 halt();
 }
@@ -522,7 +546,7 @@
 [[noreturn]] void halt();
 
 void assert(int b) {
-  if (!b) // tracking-note-re^}}Assuming 'b' is not equal to 0{{$
+  if (!b) // tracking-note-re^}}Assuming 'b' is not equal to 0, which participates in a condition later{{$
   // tracking-note-re@-1^}}Taking false branch{{$
 halt();
 }
@@ -556,6 +580,31 @@
 
 } // end of namespace dont_crash_on_nonlogical_binary_operator
 
+namespace collapse_point_not_in_condition_binary_op {
+
+[[noreturn]] void halt();
+
+void check(int b) {
+  if (b == 1) // tracking-note-re^}}Assuming 'b' is not equal to 1, which participates in a condition later{{$
+  // tracking-note-re@-1^}}Taking false branch{{$
+halt();
+}
+
+void f(int flag) {
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
+
+  check(flag); // tracking-note-re^}}Calling 'check'{{$
+   // tracking-note-re@-1^}}Returning from 'check'{{$
+
+  if (flag) // expected-note-re^}}Assuming 'flag' is not equal to 0{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+
+} // end of namespace 

r369596 - [analyzer] Mention whether an event is about a condition in a bug report part 2

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 15:38:00 2019
New Revision: 369596

URL: http://llvm.org/viewvc/llvm-project?rev=369596=rev
Log:
[analyzer] Mention whether an event is about a condition in a bug report part 2

In D65724, I do a pretty thorough explanation about how I'm solving this
problem, I think that summary nails whats happening here ;)

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369596=369595=369596=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
15:38:00 2019
@@ -213,6 +213,22 @@ getConcreteIntegerValue(const Expr *Cond
   return None;
 }
 
+static bool isVarAnInterestingCondition(const Expr *CondVarExpr,
+const ExplodedNode *N,
+const BugReport *B) {
+  // Even if this condition is marked as interesting, it isn't *that*
+  // interesting if it didn't happen in a nested stackframe, the user could 
just
+  // follow the arrows.
+  if (!B->getErrorNode()->getStackFrame()->isParentOf(N->getStackFrame()))
+return false;
+
+  if (Optional V = getSValForVar(CondVarExpr, N))
+if (Optional K = B->getInterestingnessKind(*V))
+  return *K == bugreporter::TrackingKind::Condition;
+
+  return false;
+}
+
 static bool isInterestingExpr(const Expr *E, const ExplodedNode *N,
   const BugReport *B) {
   if (Optional V = getSValForVar(E, N))
@@ -2454,6 +2470,10 @@ PathDiagnosticPieceRef ConditionBRVisito
   const LocationContext *LCtx = N->getLocationContext();
   const SourceManager  = BRC.getSourceManager();
 
+  if (isVarAnInterestingCondition(BExpr->getLHS(), N, ) ||
+  isVarAnInterestingCondition(BExpr->getRHS(), N, ))
+Out << WillBeUsedForACondition;
+
   // Convert 'field ...' to 'Field ...' if it is a MemberExpr.
   std::string Message = Out.str();
   Message[0] = toupper(Message[0]);
@@ -2499,6 +2519,9 @@ PathDiagnosticPieceRef ConditionBRVisito
   const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(CondVarExpr, BRC.getSourceManager(), LCtx);
 
+  if (isVarAnInterestingCondition(CondVarExpr, N, ))
+Out << WillBeUsedForACondition;
+
   auto event = std::make_shared(Loc, Out.str());
 
   if (isInterestingExpr(CondVarExpr, N, ))
@@ -2524,6 +2547,9 @@ PathDiagnosticPieceRef ConditionBRVisito
 
   const LocationContext *LCtx = N->getLocationContext();
 
+  if (isVarAnInterestingCondition(DRE, N, ))
+Out << WillBeUsedForACondition;
+
   // If we know the value create a pop-up note to the 'DRE'.
   if (!IsAssuming) {
 PathDiagnosticLocation Loc(DRE, BRC.getSourceManager(), LCtx);
@@ -2563,6 +2589,10 @@ PathDiagnosticPieceRef ConditionBRVisito
   if (!Loc.isValid() || !Loc.asLocation().isValid())
 return nullptr;
 
+  if (isVarAnInterestingCondition(ME, N, ))
+Out << WillBeUsedForACondition;
+
+  // If we know the value create a pop-up note.
   if (!IsAssuming)
 return std::make_shared(Loc, Out.str());
 

Modified: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp?rev=369596=369595=369596=diff
==
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp (original)
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp Wed Aug 21 
15:38:00 2019
@@ -443,7 +443,7 @@ void f(int flag) {
   int *x = 0; // expected-note-re^}}'x' initialized to a null pointer 
value{{$
 
   auto lambda = [flag]() {
-if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 
0{{$
+if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0, 
which participates in a condition later{{$
// tracking-note-re@-1^}}Taking false branch{{$
   halt();
   };
@@ -474,7 +474,7 @@ void f(int flag) {
   int *x = 0; // expected-note-re^}}'x' initialized to a null pointer 
value{{$
 
   auto lambda = []() {
-if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 
0{{$
+if (!flag) // tracking-note-re^}}Assuming 'flag' is not equal to 0, 
which participates in a condition later{{$
// tracking-note-re@-1^}}Taking false branch{{$
   halt();
   };
@@ -486,18 +486,42 @@ void f(int flag) {
 
   if (flag) // expected-note-re^}}'flag' is not equal to 0{{$
 // expected-note-re@-1^}}Taking true 

[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:17748
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
\ No newline at end of file
+}

jdenny wrote:
> ABataev wrote:
> > Restore original code here
> OK, I did.  What's the reason for no newline at the end of the file?
Changes not related to the patch, like formatting etc., better to commit in 
separate patches.


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:17748
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
\ No newline at end of file
+}

ABataev wrote:
> Restore original code here
OK, I did.  What's the reason for no newline at the end of the file?


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 216502.
jdenny marked 8 inline comments as done.
jdenny added a comment.

Make suggested changes to default arguments, comments on literals, and 
parameter names.


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

https://reviews.llvm.org/D65835

Files:
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_firstprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_private_messages.cpp
  clang/test/OpenMP/target_teams_map_codegen.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -1,7 +1,10 @@
-// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=40 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=45 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected -fopenmp-version=50 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
-// RUN: %clang_cc1 -DCCODE -verify -fopenmp -ferror-limit 200 -x c %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-simd -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -DCCODE -verify=expected,le45 -fopenmp -ferror-limit 200 -x c %s -Wno-openmp-target -Wuninitialized
 #ifdef CCODE
 void foo(int arg) {
   const int n = 0;
@@ -536,10 +539,10 @@
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
 
-#pragma omp target teams private(j) map(j) // expected-error {{private variable cannot be in a map clause in '#pragma omp target teams' directive}}  expected-note {{defined as private}}
+#pragma omp target teams private(j) map(j) // le45-error {{private variable cannot be in a map clause in '#pragma omp target teams' directive}}  le45-note {{defined as private}}
   {}
 
-#pragma omp target teams firstprivate(j) map(j)  // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target teams' directive}} expected-note {{defined as firstprivate}}
+#pragma omp target teams firstprivate(j) map(j) // le45-error {{firstprivate variable cannot be in a map clause in '#pragma omp target teams' directive}} le45-note {{defined as firstprivate}}
   {}
 
 #pragma omp target teams map(m)
Index: clang/test/OpenMP/target_teams_map_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_teams_map_codegen.cpp
@@ -0,0 +1,172 @@
+// Test host codegen.
+// RUN: %clang_cc1 -DHAS_INT128 -verify -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefixes=CHECK,HOST,INT128,HOST-INT128
+// RUN: %clang_cc1 -DHAS_INT128 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -DHAS_INT128 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,HOST,INT128,HOST-INT128
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefixes=CHECK,HOST
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,HOST
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -DHAS_INT128 -verify -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -DHAS_INT128 

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-21 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

In the false-positive example, after the `DerivedToBase`, we see a constructor 
call which I think is the copy constructor.

1. We should consider `MutableArrayRef` to be a gsl::Pointer according to the 
paper, because it publicly derives from one.
2. Also in the paper, the copy constructor does should copies the pset of the 
argument instead of making the pointer point at the argument.

What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mgehre marked an inline comment as done.
Closed by commit rL369591: [LifetimeAnalysis] Support more STL idioms (template 
forward declaration and… (authored by mgehre, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66179?vs=216247=216498#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66179

Files:
  cfe/trunk/lib/Sema/SemaAttr.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaInit.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
  cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
  cfe/trunk/unittests/Sema/CMakeLists.txt
  cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp

Index: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -552,6 +552,18 @@
   continue;
 }
 
+if (auto *A = dyn_cast(TmplAttr)) {
+  if (!New->hasAttr())
+New->addAttr(A->clone(Context));
+  continue;
+}
+
+if (auto *A = dyn_cast(TmplAttr)) {
+  if (!New->hasAttr())
+New->addAttr(A->clone(Context));
+  continue;
+}
+
 assert(!TmplAttr->isPackExpansion());
 if (TmplAttr->isLateParsed() && LateAttrs) {
   // Late parsed attributes must be instantiated and attached after the
@@ -711,6 +723,9 @@
 
   SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef);
 
+  if (D->getUnderlyingType()->getAs())
+SemaRef.inferGslPointerAttribute(Typedef);
+
   Typedef->setAccess(D->getAccess());
 
   return Typedef;
Index: cfe/trunk/lib/Sema/SemaInit.cpp
===
--- cfe/trunk/lib/Sema/SemaInit.cpp
+++ cfe/trunk/lib/Sema/SemaInit.cpp
@@ -6561,7 +6561,7 @@
 
 template  static bool isRecordWithAttr(QualType Type) {
   if (auto *RD = Type->getAsCXXRecordDecl())
-return RD->getCanonicalDecl()->hasAttr();
+return RD->hasAttr();
   return false;
 }
 
@@ -6672,7 +6672,7 @@
 
   if (auto *CCE = dyn_cast(Call)) {
 const auto *Ctor = CCE->getConstructor();
-const CXXRecordDecl *RD = Ctor->getParent()->getCanonicalDecl();
+const CXXRecordDecl *RD = Ctor->getParent();
 if (CCE->getNumArgs() > 0 && RD->hasAttr())
   VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0]);
   }
Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -4592,9 +4592,11 @@
   }
   return;
 }
-D->addAttr(::new (S.Context)
-   OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc,
- AL.getAttributeSpellingListIndex()));
+for (Decl *Redecl : D->redecls()) {
+  Redecl->addAttr(::new (S.Context)
+  OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc,
+AL.getAttributeSpellingListIndex()));
+}
   } else {
 if (checkAttrMutualExclusion(S, D, AL))
   return;
@@ -4609,9 +4611,11 @@
   }
   return;
 }
-D->addAttr(::new (S.Context)
-   PointerAttr(AL.getRange(), S.Context, DerefTypeLoc,
-   AL.getAttributeSpellingListIndex()));
+for (Decl *Redecl : D->redecls()) {
+  Redecl->addAttr(::new (S.Context)
+  PointerAttr(AL.getRange(), S.Context, DerefTypeLoc,
+  AL.getAttributeSpellingListIndex()));
+}
   }
 }
 
Index: cfe/trunk/lib/Sema/SemaAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaAttr.cpp
+++ cfe/trunk/lib/Sema/SemaAttr.cpp
@@ -88,13 +88,11 @@
 template 
 static void addGslOwnerPointerAttributeIfNotExisting(ASTContext ,
  CXXRecordDecl *Record) {
-  CXXRecordDecl *Canonical = Record->getCanonicalDecl();
-  if (Canonical->hasAttr() || Canonical->hasAttr())
+  if (Record->hasAttr() || Record->hasAttr())
 return;
 
-  Canonical->addAttr(::new (Context) Attribute(SourceRange{}, Context,
-   /*DerefType*/ nullptr,
-   /*Spelling=*/0));
+  for (Decl *Redecl : Record->redecls())
+Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
 }
 
 void Sema::inferGslPointerAttribute(NamedDecl *ND,
@@ -189,8 +187,7 @@
 
   // Handle classes that directly appear in std namespace.
   if (Record->isInStdNamespace()) {
-CXXRecordDecl *Canonical = Record->getCanonicalDecl();
-if (Canonical->hasAttr() || Canonical->hasAttr())
+if 

[PATCH] D65724: [analyzer] Don't make ConditionBRVisitor events prunable when the condition is an interesting field

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369589: [analyzer] Dont make ConditionBRVisitor events 
prunable when the condition is… (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65724?vs=216283=216497#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65724

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -180,21 +180,44 @@
 RLCV->getStore() == RightNode->getState()->getStore();
 }
 
-static Optional
-getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) {
+static Optional getSValForVar(const Expr *CondVarExpr,
+const ExplodedNode *N) {
   ProgramStateRef State = N->getState();
   const LocationContext *LCtx = N->getLocationContext();
 
+  assert(CondVarExpr);
+  CondVarExpr = CondVarExpr->IgnoreImpCasts();
+
   // The declaration of the value may rely on a pointer so take its l-value.
-  if (const auto *DRE = dyn_cast_or_null(CondVarExpr)) {
-if (const auto *VD = dyn_cast_or_null(DRE->getDecl())) {
-  SVal DeclSVal = State->getSVal(State->getLValue(VD, LCtx));
-  if (auto DeclCI = DeclSVal.getAs())
-return >getValue();
-}
-  }
+  // FIXME: As seen in VisitCommonDeclRefExpr, sometimes DeclRefExpr may
+  // evaluate to a FieldRegion when it refers to a declaration of a lambda
+  // capture variable. We most likely need to duplicate that logic here.
+  if (const auto *DRE = dyn_cast(CondVarExpr))
+if (const auto *VD = dyn_cast(DRE->getDecl()))
+  return State->getSVal(State->getLValue(VD, LCtx));
+
+  if (const auto *ME = dyn_cast(CondVarExpr))
+if (const auto *FD = dyn_cast(ME->getMemberDecl()))
+  if (auto FieldL = State->getSVal(ME, LCtx).getAs())
+return State->getRawSVal(*FieldL, FD->getType());
 
-  return {};
+  return None;
+}
+
+static Optional
+getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) {
+
+  if (Optional V = getSValForVar(CondVarExpr, N))
+if (auto CI = V->getAs())
+  return >getValue();
+  return None;
+}
+
+static bool isInterestingExpr(const Expr *E, const ExplodedNode *N,
+  const BugReport *B) {
+  if (Optional V = getSValForVar(E, N))
+return B->getInterestingnessKind(*V).hasValue();
+  return false;
 }
 
 /// \return name of the macro inside the location \p Loc.
@@ -2475,17 +2498,11 @@
 
   const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(CondVarExpr, BRC.getSourceManager(), LCtx);
+
   auto event = std::make_shared(Loc, Out.str());
 
-  if (const auto *DR = dyn_cast(CondVarExpr)) {
-if (const auto *VD = dyn_cast(DR->getDecl())) {
-  const ProgramState *state = N->getState().get();
-  if (const MemRegion *R = state->getLValue(VD, LCtx).getAsRegion()) {
-if (report.isInteresting(R))
-  event->setPrunable(false);
-  }
-}
-  }
+  if (isInterestingExpr(CondVarExpr, N, ))
+event->setPrunable(false);
 
   return event;
 }
@@ -2515,16 +2532,10 @@
 
   PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
   auto event = std::make_shared(Loc, Out.str());
-  const ProgramState *state = N->getState().get();
-  if (const MemRegion *R = state->getLValue(VD, LCtx).getAsRegion()) {
-if (report.isInteresting(R))
-  event->setPrunable(false);
-else {
-  SVal V = state->getSVal(R);
-  if (report.isInteresting(V))
-event->setPrunable(false);
-}
-  }
+
+  if (isInterestingExpr(DRE, N, ))
+event->setPrunable(false);
+
   return std::move(event);
 }
 
@@ -2555,7 +2566,10 @@
   if (!IsAssuming)
 return std::make_shared(Loc, Out.str());
 
-  return std::make_shared(Loc, Out.str());
+  auto event = std::make_shared(Loc, Out.str());
+  if (isInterestingExpr(ME, N, ))
+event->setPrunable(false);
+  return event;
 }
 
 bool ConditionBRVisitor::printValue(const Expr *CondVarExpr, raw_ostream ,
@@ -2595,10 +2609,8 @@
   return true;
 }
 
-const char *const ConditionBRVisitor::GenericTrueMessage =
-"Assuming the condition is true";
-const char *const ConditionBRVisitor::GenericFalseMessage =
-"Assuming the condition is false";
+constexpr llvm::StringLiteral ConditionBRVisitor::GenericTrueMessage;
+constexpr llvm::StringLiteral ConditionBRVisitor::GenericFalseMessage;
 
 bool ConditionBRVisitor::isPieceMessageGeneric(
 const PathDiagnosticPiece *Piece) {

[PATCH] D66179: [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre marked 3 inline comments as done.
mgehre added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4596
+for (Decl *Redecl : D->redecls()) {
+  Redecl->addAttr(::new (S.Context)
+  OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc,

gribozavr wrote:
> Add it only if it does not already exist?
If a previous decl had that Attribute, then we would have inherited it, and the 
check above for an existing attribute would have led to an early return.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66179



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


r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-21 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Wed Aug 21 15:08:59 2019
New Revision: 369591

URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
Log:
[LifetimeAnalysis] Support more STL idioms (template forward declaration and 
DependentNameType)

Summary:
This fixes inference of gsl::Pointer on std::set::iterator with libstdc++ (the 
typedef for iterator
on the template is a DependentNameType - we can only put the gsl::Pointer 
attribute
on the underlaying record after instantiation)

inference of gsl::Pointer on std::vector::iterator with libc++ (the class was 
forward-declared,
we added the gsl::Pointer on the canonical decl (the forward decl), and later 
when the
template was instantiated, there was no attribute on the definition so it was 
not instantiated).

and a duplicate gsl::Pointer on some class with libstdc++ (we first added an 
attribute to
a incomplete instantiation, and then another was copied from the template 
definition
when the instantiation was completed).

We now add the attributes to all redeclarations to fix thos issues and make 
their usage easier.

Reviewers: gribozavr

Subscribers: Szelethus, xazax.hun, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp
Modified:
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
cfe/trunk/unittests/Sema/CMakeLists.txt

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=369591=369590=369591=diff
==
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Aug 21 15:08:59 2019
@@ -88,13 +88,11 @@ void Sema::AddMsStructLayoutForRecord(Re
 template 
 static void addGslOwnerPointerAttributeIfNotExisting(ASTContext ,
  CXXRecordDecl *Record) {
-  CXXRecordDecl *Canonical = Record->getCanonicalDecl();
-  if (Canonical->hasAttr() || Canonical->hasAttr())
+  if (Record->hasAttr() || Record->hasAttr())
 return;
 
-  Canonical->addAttr(::new (Context) Attribute(SourceRange{}, Context,
-   /*DerefType*/ nullptr,
-   /*Spelling=*/0));
+  for (Decl *Redecl : Record->redecls())
+Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
 }
 
 void Sema::inferGslPointerAttribute(NamedDecl *ND,
@@ -189,8 +187,7 @@ void Sema::inferGslOwnerPointerAttribute
 
   // Handle classes that directly appear in std namespace.
   if (Record->isInStdNamespace()) {
-CXXRecordDecl *Canonical = Record->getCanonicalDecl();
-if (Canonical->hasAttr() || Canonical->hasAttr())
+if (Record->hasAttr() || Record->hasAttr())
   return;
 
 if (StdOwners.count(Record->getName()))

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=369591=369590=369591=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Aug 21 15:08:59 2019
@@ -4592,9 +4592,11 @@ static void handleLifetimeCategoryAttr(S
   }
   return;
 }
-D->addAttr(::new (S.Context)
-   OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc,
- AL.getAttributeSpellingListIndex()));
+for (Decl *Redecl : D->redecls()) {
+  Redecl->addAttr(::new (S.Context)
+  OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc,
+AL.getAttributeSpellingListIndex()));
+}
   } else {
 if (checkAttrMutualExclusion(S, D, AL))
   return;
@@ -4609,9 +4611,11 @@ static void handleLifetimeCategoryAttr(S
   }
   return;
 }
-D->addAttr(::new (S.Context)
-   PointerAttr(AL.getRange(), S.Context, DerefTypeLoc,
-   AL.getAttributeSpellingListIndex()));
+for (Decl *Redecl : D->redecls()) {
+  Redecl->addAttr(::new (S.Context)
+  PointerAttr(AL.getRange(), S.Context, DerefTypeLoc,
+  AL.getAttributeSpellingListIndex()));
+}
   }
 }
 

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=369591=369590=369591=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Aug 21 15:08:59 2019
@@ -6561,7 +6561,7 @@ static void visitLocalsRetainedByReferen
 
 template  static bool 

[PATCH] D66559: [OPENMP] Update the diagnosis message for canonical loop form

2019-08-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Or more specifically, why `!=` is now silently accepted in 4.0 mode?
https://godbolt.org/z/M6iL4H


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66559



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


r369589 - [analyzer] Don't make ConditionBRVisitor events prunable when the condition is an interesting field

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 14:59:22 2019
New Revision: 369589

URL: http://llvm.org/viewvc/llvm-project?rev=369589=rev
Log:
[analyzer] Don't make ConditionBRVisitor events prunable when the condition is 
an interesting field

Exactly what it says on the tin! Note that we're talking about interestingness
in general, hence this isn't a control-dependency-tracking specific patch.

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

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h?rev=369589=369588=369589=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
Wed Aug 21 14:59:22 2019
@@ -211,8 +211,10 @@ public:
 /// Visitor that tries to report interesting diagnostics from conditions.
 class ConditionBRVisitor final : public BugReporterVisitor {
   // FIXME: constexpr initialization isn't supported by MSVC2013.
-  static const char *const GenericTrueMessage;
-  static const char *const GenericFalseMessage;
+  constexpr static llvm::StringLiteral GenericTrueMessage =
+  "Assuming the condition is true";
+  constexpr static llvm::StringLiteral GenericFalseMessage =
+  "Assuming the condition is false";
 
 public:
   void Profile(llvm::FoldingSetNodeID ) const override {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369589=369588=369589=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
14:59:22 2019
@@ -180,21 +180,44 @@ static bool hasVisibleUpdate(const Explo
 RLCV->getStore() == RightNode->getState()->getStore();
 }
 
-static Optional
-getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) {
+static Optional getSValForVar(const Expr *CondVarExpr,
+const ExplodedNode *N) {
   ProgramStateRef State = N->getState();
   const LocationContext *LCtx = N->getLocationContext();
 
+  assert(CondVarExpr);
+  CondVarExpr = CondVarExpr->IgnoreImpCasts();
+
   // The declaration of the value may rely on a pointer so take its l-value.
-  if (const auto *DRE = dyn_cast_or_null(CondVarExpr)) {
-if (const auto *VD = dyn_cast_or_null(DRE->getDecl())) {
-  SVal DeclSVal = State->getSVal(State->getLValue(VD, LCtx));
-  if (auto DeclCI = DeclSVal.getAs())
-return >getValue();
-}
-  }
+  // FIXME: As seen in VisitCommonDeclRefExpr, sometimes DeclRefExpr may
+  // evaluate to a FieldRegion when it refers to a declaration of a lambda
+  // capture variable. We most likely need to duplicate that logic here.
+  if (const auto *DRE = dyn_cast(CondVarExpr))
+if (const auto *VD = dyn_cast(DRE->getDecl()))
+  return State->getSVal(State->getLValue(VD, LCtx));
+
+  if (const auto *ME = dyn_cast(CondVarExpr))
+if (const auto *FD = dyn_cast(ME->getMemberDecl()))
+  if (auto FieldL = State->getSVal(ME, LCtx).getAs())
+return State->getRawSVal(*FieldL, FD->getType());
 
-  return {};
+  return None;
+}
+
+static Optional
+getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) {
+
+  if (Optional V = getSValForVar(CondVarExpr, N))
+if (auto CI = V->getAs())
+  return >getValue();
+  return None;
+}
+
+static bool isInterestingExpr(const Expr *E, const ExplodedNode *N,
+  const BugReport *B) {
+  if (Optional V = getSValForVar(E, N))
+return B->getInterestingnessKind(*V).hasValue();
+  return false;
 }
 
 /// \return name of the macro inside the location \p Loc.
@@ -2475,17 +2498,11 @@ PathDiagnosticPieceRef ConditionBRVisito
 
   const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(CondVarExpr, BRC.getSourceManager(), LCtx);
+
   auto event = std::make_shared(Loc, Out.str());
 
-  if (const auto *DR = dyn_cast(CondVarExpr)) {
-if (const auto *VD = dyn_cast(DR->getDecl())) {
-  const ProgramState *state = N->getState().get();
-  if (const MemRegion *R = state->getLValue(VD, LCtx).getAsRegion()) {
-if (report.isInteresting(R))
-  event->setPrunable(false);
-  }
-}
-  }
+  if (isInterestingExpr(CondVarExpr, N, ))
+event->setPrunable(false);
 
   return event;
 }
@@ -2515,16 +2532,10 @@ PathDiagnosticPieceRef 

[PATCH] D66559: [OPENMP] Update the diagnosis message for canonical loop form

2019-08-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Shouldn't this be OpenMP-version-dependent?
`!=` is only allowed in 4.5+


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66559



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


[PATCH] D66559: [OPENMP] Update the diagnosis message for canonical loop form

2019-08-21 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen created this revision.
Herald added subscribers: cfe-commits, guansong.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

The previous patch (https://reviews.llvm.org/D54441) support the
relational-op != very well for openmp canonical loop form, however,
it didn't update the diagnosis message. So this patch is simply
update the diagnosis message by adding !=, update the test
related to it, and update the section number for canonical loop
form for OpenMP 5.0 in comment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66559

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/distribute_simd_loop_messages.cpp
  clang/test/OpenMP/for_loop_messages.cpp
  clang/test/OpenMP/for_simd_loop_messages.cpp
  clang/test/OpenMP/parallel_for_loop_messages.cpp
  clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/simd_loop_messages.cpp
  clang/test/OpenMP/target_parallel_for_loop_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/target_simd_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_loop_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp
  clang/test/OpenMP/taskloop_simd_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp

Index: clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
===
--- clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
@@ -109,20 +109,20 @@
 
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
   for (int i = 0; i; i++)
 c[i] = a[i];
 
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
+// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
   for (int i = 0; jj < kk; ii++)
 c[i] = a[i];
 
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
   for (int i = 0; !!i; i++)
 c[i] = a[i];
 
@@ -134,7 +134,7 @@
 
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
   for (int i = 0;; i++)
 c[i] = a[i];
 
@@ -466,17 +466,17 @@
 ++begin;
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
   for (GoodIter I = begin; I - I; ++I)
 ++I;
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
   for (GoodIter I = begin; begin < end; ++I)
 ++I;
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
+// expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
   for (GoodIter I = begin; !I; ++I)
 ++I;
 #pragma omp target
Index: 

[PATCH] D65481: NFCI: Simplify SourceManager::translateFile by removing code path that should never be taken

2019-08-21 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369585: NFCI: Simplify SourceManager::translateFile by 
removing code path that should… (authored by arphaman, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65481?vs=212454=216484#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65481

Files:
  cfe/trunk/lib/Basic/SourceManager.cpp

Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -1558,22 +1558,6 @@
 // Other miscellaneous methods.
 //===--===//
 
-/// Retrieve the inode for the given file entry, if possible.
-///
-/// This routine involves a system call, and therefore should only be used
-/// in non-performance-critical code.
-static Optional
-getActualFileUID(const FileEntry *File) {
-  if (!File)
-return None;
-
-  llvm::sys::fs::UniqueID ID;
-  if (llvm::sys::fs::getUniqueID(File->getName(), ID))
-return None;
-
-  return ID;
-}
-
 /// Get the source location for the given file:line:col triplet.
 ///
 /// If the source file is included multiple times, the source location will
@@ -1595,13 +1579,8 @@
 FileID SourceManager::translateFile(const FileEntry *SourceFile) const {
   assert(SourceFile && "Null source file!");
 
-  // Find the first file ID that corresponds to the given file.
-  FileID FirstFID;
-
   // First, check the main file ID, since it is common to look for a
   // location in the main file.
-  Optional SourceFileUID;
-  Optional SourceFileName;
   if (MainFileID.isValid()) {
 bool Invalid = false;
 const SLocEntry  = getSLocEntry(MainFileID, );
@@ -1609,100 +1588,35 @@
   return FileID();
 
 if (MainSLoc.isFile()) {
-  const ContentCache *MainContentCache
-= MainSLoc.getFile().getContentCache();
-  if (!MainContentCache || !MainContentCache->OrigEntry) {
-// Can't do anything
-  } else if (MainContentCache->OrigEntry == SourceFile) {
-FirstFID = MainFileID;
-  } else {
-// Fall back: check whether we have the same base name and inode
-// as the main file.
-const FileEntry *MainFile = MainContentCache->OrigEntry;
-SourceFileName = llvm::sys::path::filename(SourceFile->getName());
-if (*SourceFileName == llvm::sys::path::filename(MainFile->getName())) {
-  SourceFileUID = getActualFileUID(SourceFile);
-  if (SourceFileUID) {
-if (Optional MainFileUID =
-getActualFileUID(MainFile)) {
-  if (*SourceFileUID == *MainFileUID) {
-FirstFID = MainFileID;
-SourceFile = MainFile;
-  }
-}
-  }
-}
-  }
+  const ContentCache *MainContentCache =
+  MainSLoc.getFile().getContentCache();
+  if (MainContentCache && MainContentCache->OrigEntry == SourceFile)
+return MainFileID;
 }
   }
 
-  if (FirstFID.isInvalid()) {
-// The location we're looking for isn't in the main file; look
-// through all of the local source locations.
-for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) {
-  bool Invalid = false;
-  const SLocEntry  = getLocalSLocEntry(I, );
-  if (Invalid)
-return FileID();
+  // The location we're looking for isn't in the main file; look
+  // through all of the local source locations.
+  for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) {
+bool Invalid = false;
+const SLocEntry  = getLocalSLocEntry(I, );
+if (Invalid)
+  return FileID();
 
-  if (SLoc.isFile() &&
-  SLoc.getFile().getContentCache() &&
-  SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {
-FirstFID = FileID::get(I);
-break;
-  }
-}
-// If that still didn't help, try the modules.
-if (FirstFID.isInvalid()) {
-  for (unsigned I = 0, N = loaded_sloc_entry_size(); I != N; ++I) {
-const SLocEntry  = getLoadedSLocEntry(I);
-if (SLoc.isFile() &&
-SLoc.getFile().getContentCache() &&
-SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {
-  FirstFID = FileID::get(-int(I) - 2);
-  break;
-}
-  }
-}
+if (SLoc.isFile() && SLoc.getFile().getContentCache() &&
+SLoc.getFile().getContentCache()->OrigEntry == SourceFile)
+  return FileID::get(I);
   }
 
-  // If we haven't found what we want yet, try again, but this time stat()
-  // each of the files in case the files have changed since we originally
-  // parsed the file.
-  if (FirstFID.isInvalid() &&

r369585 - NFCI: Simplify SourceManager::translateFile by removing code path that should never be taken

2019-08-21 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Aug 21 14:37:09 2019
New Revision: 369585

URL: http://llvm.org/viewvc/llvm-project?rev=369585=rev
Log:
NFCI: Simplify SourceManager::translateFile by removing code path that should 
never be taken

I noticed that SourceManager::translateFile has code that doesn't really make 
sense.
In particular, if it fails to find a FileID by comparing FileEntry * values, it 
tries to
look through files that have the same filename, to see if they have a matching 
inode to try to
find the right FileID. However, the inode comparison seem redundant, as Clang's 
FileManager
already deduplicates FileEntry * values by inode.
Thus the comparisons between inodes should never actually succeed, and the 
comparison between FileEntry * values should be sufficient here.

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

Modified:
cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=369585=369584=369585=diff
==
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Wed Aug 21 14:37:09 2019
@@ -1558,22 +1558,6 @@ unsigned SourceManager::getFileIDSize(Fi
 // Other miscellaneous methods.
 
//===--===//
 
-/// Retrieve the inode for the given file entry, if possible.
-///
-/// This routine involves a system call, and therefore should only be used
-/// in non-performance-critical code.
-static Optional
-getActualFileUID(const FileEntry *File) {
-  if (!File)
-return None;
-
-  llvm::sys::fs::UniqueID ID;
-  if (llvm::sys::fs::getUniqueID(File->getName(), ID))
-return None;
-
-  return ID;
-}
-
 /// Get the source location for the given file:line:col triplet.
 ///
 /// If the source file is included multiple times, the source location will
@@ -1595,13 +1579,8 @@ SourceLocation SourceManager::translateF
 FileID SourceManager::translateFile(const FileEntry *SourceFile) const {
   assert(SourceFile && "Null source file!");
 
-  // Find the first file ID that corresponds to the given file.
-  FileID FirstFID;
-
   // First, check the main file ID, since it is common to look for a
   // location in the main file.
-  Optional SourceFileUID;
-  Optional SourceFileName;
   if (MainFileID.isValid()) {
 bool Invalid = false;
 const SLocEntry  = getSLocEntry(MainFileID, );
@@ -1609,100 +1588,35 @@ FileID SourceManager::translateFile(cons
   return FileID();
 
 if (MainSLoc.isFile()) {
-  const ContentCache *MainContentCache
-= MainSLoc.getFile().getContentCache();
-  if (!MainContentCache || !MainContentCache->OrigEntry) {
-// Can't do anything
-  } else if (MainContentCache->OrigEntry == SourceFile) {
-FirstFID = MainFileID;
-  } else {
-// Fall back: check whether we have the same base name and inode
-// as the main file.
-const FileEntry *MainFile = MainContentCache->OrigEntry;
-SourceFileName = llvm::sys::path::filename(SourceFile->getName());
-if (*SourceFileName == llvm::sys::path::filename(MainFile->getName())) 
{
-  SourceFileUID = getActualFileUID(SourceFile);
-  if (SourceFileUID) {
-if (Optional MainFileUID =
-getActualFileUID(MainFile)) {
-  if (*SourceFileUID == *MainFileUID) {
-FirstFID = MainFileID;
-SourceFile = MainFile;
-  }
-}
-  }
-}
-  }
+  const ContentCache *MainContentCache =
+  MainSLoc.getFile().getContentCache();
+  if (MainContentCache && MainContentCache->OrigEntry == SourceFile)
+return MainFileID;
 }
   }
 
-  if (FirstFID.isInvalid()) {
-// The location we're looking for isn't in the main file; look
-// through all of the local source locations.
-for (unsigned I = 0, N = local_sloc_entry_size(); I != N; ++I) {
-  bool Invalid = false;
-  const SLocEntry  = getLocalSLocEntry(I, );
-  if (Invalid)
-return FileID();
-
-  if (SLoc.isFile() &&
-  SLoc.getFile().getContentCache() &&
-  SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {
-FirstFID = FileID::get(I);
-break;
-  }
-}
-// If that still didn't help, try the modules.
-if (FirstFID.isInvalid()) {
-  for (unsigned I = 0, N = loaded_sloc_entry_size(); I != N; ++I) {
-const SLocEntry  = getLoadedSLocEntry(I);
-if (SLoc.isFile() &&
-SLoc.getFile().getContentCache() &&
-SLoc.getFile().getContentCache()->OrigEntry == SourceFile) {
-  FirstFID = FileID::get(-int(I) - 2);
-  break;
-}
-  }
-}
+  // The location we're looking for isn't in the main file; look
+  // through all of the local source locations.
+  

[PATCH] D65723: [analyzer][NFC] Add different interestingness kinds

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369583: [analyzer][NFC] Add different interestingness kinds 
(authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65723?vs=213258=216483#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65723

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1950,7 +1950,7 @@
   MacroNullReturnSuppressionVisitor::addMacroVisitorIfNecessary(
   LVNode, R, EnableNullFPSuppression, report, V);
 
-  report.markInteresting(V);
+  report.markInteresting(V, TKind);
   report.addVisitor(std::make_unique(R));
 
   // If the contents are symbolic, find out when they became null.
@@ -2011,7 +2011,7 @@
 
 const MemRegion *RegionRVal = RVal.getAsRegion();
 if (RegionRVal && isa(RegionRVal)) {
-  report.markInteresting(RegionRVal);
+  report.markInteresting(RegionRVal, TKind);
   report.addVisitor(std::make_unique(
 loc::MemRegionVal(RegionRVal), /*assumption=*/false));
 }
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2101,30 +2101,61 @@
   }
 }
 
-void BugReport::markInteresting(SymbolRef sym) {
+template 
+static void insertToInterestingnessMap(
+llvm::DenseMap , T Val,
+bugreporter::TrackingKind TKind) {
+  auto Result = InterestingnessMap.insert({Val, TKind});
+
+  if (Result.second)
+return;
+
+  // Even if this symbol/region was already marked as interesting as a
+  // condition, if we later mark it as interesting again but with
+  // thorough tracking, overwrite it. Entities marked with thorough
+  // interestiness are the most important (or most interesting, if you will),
+  // and we wouldn't like to downplay their importance.
+
+  switch (TKind) {
+case bugreporter::TrackingKind::Thorough:
+  Result.first->getSecond() = bugreporter::TrackingKind::Thorough;
+  return;
+case bugreporter::TrackingKind::Condition:
+  return;
+  }
+
+  llvm_unreachable(
+  "BugReport::markInteresting currently can only handle 2 different "
+  "tracking kinds! Please define what tracking kind should this entitiy"
+  "have, if it was already marked as interesting with a different kind!");
+}
+
+void BugReport::markInteresting(SymbolRef sym,
+bugreporter::TrackingKind TKind) {
   if (!sym)
 return;
 
-  InterestingSymbols.insert(sym);
+  insertToInterestingnessMap(InterestingSymbols, sym, TKind);
 
   if (const auto *meta = dyn_cast(sym))
-InterestingRegions.insert(meta->getRegion());
+markInteresting(meta->getRegion(), TKind);
 }
 
-void BugReport::markInteresting(const MemRegion *R) {
+void BugReport::markInteresting(const MemRegion *R,
+bugreporter::TrackingKind TKind) {
   if (!R)
 return;
 
   R = R->getBaseRegion();
-  InterestingRegions.insert(R);
+  insertToInterestingnessMap(InterestingRegions, R, TKind);
 
   if (const auto *SR = dyn_cast(R))
-InterestingSymbols.insert(SR->getSymbol());
+markInteresting(SR->getSymbol(), TKind);
 }
 
-void BugReport::markInteresting(SVal V) {
-  markInteresting(V.getAsRegion());
-  markInteresting(V.getAsSymbol());
+void BugReport::markInteresting(SVal V, bugreporter::TrackingKind TKind) {
+  markInteresting(V.getAsRegion(), TKind);
+  markInteresting(V.getAsSymbol(), TKind);
 }
 
 void BugReport::markInteresting(const LocationContext *LC) {
@@ -2133,28 +2164,68 @@
   InterestingLocationContexts.insert(LC);
 }
 
-bool BugReport::isInteresting(SVal V)  const {
-  return isInteresting(V.getAsRegion()) || isInteresting(V.getAsSymbol());
+Optional
+BugReport::getInterestingnessKind(SVal V) const {
+  auto RKind = getInterestingnessKind(V.getAsRegion());
+  auto SKind = getInterestingnessKind(V.getAsSymbol());
+  if (!RKind)
+return SKind;
+  if (!SKind)
+return RKind;
+
+  // If either is marked with throrough tracking, return that, we wouldn't like
+  // to downplay a note's importance by 'only' mentioning it as a condition.
+  switch(*RKind) {
+case bugreporter::TrackingKind::Thorough:
+  return RKind;
+case bugreporter::TrackingKind::Condition:
+  return SKind;
+  }
+
+  llvm_unreachable(
+  "BugReport::getInterestingnessKind currently 

[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:1419
+   RecordDecl *RD, CapturedRegionKind K,
+   unsigned CaptureLevel);
 

Better to use `OpenMPCaptureLevel` since this param is OpenMP specific.



Comment at: clang/include/clang/Sema/Sema.h:1419
+   RecordDecl *RD, CapturedRegionKind K,
+   unsigned CaptureLevel);
 

ABataev wrote:
> Better to use `OpenMPCaptureLevel` since this param is OpenMP specific.
Add default value for the parameter here too.



Comment at: clang/include/clang/Sema/Sema.h:3977
+ArrayRef Params,
+unsigned CaptureLevel = 0);
   StmtResult ActOnCapturedRegionEnd(Stmt *S);

Same, add prefix `OpenMP`



Comment at: clang/include/clang/Sema/Sema.h:9027
+  bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level,
+ unsigned CaptureLevel) const;
 

Same, `OpenMPCaptureLevel` here and in other places.



Comment at: clang/lib/Sema/SemaExpr.cpp:17748
   ObjCAvailabilityCheckExpr(Version, AtLoc, RParen, Context.BoolTy);
-}
\ No newline at end of file
+}

Restore original code here



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1350
 if (!SemaRef.isOpenMPCapturedByRef(
-D, std::distance(ParentIterTarget, End))) {
+D, std::distance(ParentIterTarget, End), /*CaptureLevel*/ 0)) {
   DVar.RefExpr =

Use `/*param=*/` format, please.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:2973
 ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
- Params);
+ Params, /*CaptureLevel*/ 0);
 // Mark this captured region as inlined, because we don't use outlined

Same for param comment here and other places.



Comment at: clang/lib/Sema/SemaStmt.cpp:4324
   // Enter the capturing scope for this captured region.
-  PushCapturedRegionScope(CurScope, CD, RD, Kind);
+  PushCapturedRegionScope(CurScope, CD, RD, Kind, /*CaptureLevel*/ 0);
 

Use default value of the parameter, no need to pass 0 here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


r369583 - [analyzer][NFC] Add different interestingness kinds

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 14:33:25 2019
New Revision: 369583

URL: http://llvm.org/viewvc/llvm-project?rev=369583=rev
Log:
[analyzer][NFC] Add different interestingness kinds

We defined (on the mailing list and here on phabricator) 2 different cases where
retrieving information about a control dependency condition is very important:

* When the condition's last write happened in a different stack frame
* When the collapse point of the condition (when we can constrain it to be
true/false) didn't happen in the actual condition.

It seems like we solved this problem with the help of expression value tracking,
and have started working on better diagnostics notes about this process.

Expression value tracking is nothing more than registering a variety of visitors
to construct reports about it. Each of the registered visitors (ReturnVisitor,
FindLastStoreVisitor, NoStoreFuncVisitor, etc) have something to go by: a
MemRegion, an SVal, an ExplodedNode, etc. For this reason, better explaining a
last write is super simple, we can always just pass on some more information to
the visitor in question (as seen in D65575).

ConditionBRVisitor is a different beast, as it was built for a different
purpose. It is responsible for constructing events at, well, conditions, and is
registered only once, and isn't a part of the "expression value tracking
family". Unfortunately, it is also the visitor to tinker with for constructing
better diagnostics about the collapse point problem.

This creates a need for alternative way to communicate with ConditionBRVisitor
that a specific condition is being tracked for for the reason of being a control
dependency. Since at almost all PathDiagnosticEventPiece construction the
visitor checks interestingness, it makes sense to pair interestingness with a
reason as to why we marked an entity as such.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h?rev=369583=369582=369583=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Wed 
Aug 21 14:33:25 2019
@@ -102,14 +102,15 @@ protected:
   /// diagnostics to include when constructing the final path diagnostic.
   /// The stack is largely used by BugReporter when generating PathDiagnostics
   /// for multiple PathDiagnosticConsumers.
-  llvm::DenseSet InterestingSymbols;
+  llvm::DenseMap InterestingSymbols;
 
   /// A (stack of) set of regions that are registered with this report as being
   /// "interesting", and thus used to help decide which diagnostics
   /// to include when constructing the final path diagnostic.
   /// The stack is largely used by BugReporter when generating PathDiagnostics
   /// for multiple PathDiagnosticConsumers.
-  llvm::DenseSet InterestingRegions;
+  llvm::DenseMap
+  InterestingRegions;
 
   /// A set of location contexts that correspoind to call sites which should be
   /// considered "interesting".
@@ -209,9 +210,24 @@ public:
   /// Disable all path pruning when generating a PathDiagnostic.
   void disablePathPruning() { DoNotPrunePath = true; }
 
-  void markInteresting(SymbolRef sym);
-  void markInteresting(const MemRegion *R);
-  void markInteresting(SVal V);
+  /// Marks a symbol as interesting. Different kinds of interestingness will
+  /// be processed differently by visitors (e.g. if the tracking kind is
+  /// condition, will append "will be used as a condition" to the message).
+  void markInteresting(SymbolRef sym, bugreporter::TrackingKind TKind =
+  bugreporter::TrackingKind::Thorough);
+
+  /// Marks a region as interesting. Different kinds of interestingness will
+  /// be processed differently by visitors (e.g. if the tracking kind is
+  /// condition, will append "will be used as a condition" to the message).
+  void markInteresting(
+  const MemRegion *R,
+  bugreporter::TrackingKind TKind = bugreporter::TrackingKind::Thorough);
+
+  /// Marks a symbolic value as interesting. Different kinds of interestingness
+  /// will be processed differently by visitors (e.g. if the tracking kind is
+  /// condition, will append "will be used as a condition" to the message).
+  void markInteresting(SVal V, bugreporter::TrackingKind TKind =
+   bugreporter::TrackingKind::Thorough);
   void markInteresting(const LocationContext *LC);
 
   bool isInteresting(SymbolRef sym) const;
@@ -219,6 +235,14 @@ public:
   bool isInteresting(SVal V) 

[PATCH] D66555: [driver] add a new option `-gen-cdb-fragment-path` to emit a fragment of a compilation database for each compilation

2019-08-21 Thread Jan Korous via Phabricator via cfe-commits
jkorous added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1044
+  if (const Arg *A = Args.getLastArg(options::OPT_gen_cdb_fragment_path))
+PathToCDBFragmentDir = A->getValue();
   // FIXME: TargetTriple is used by the target-prefixed calls to as/ld

IIUC this feature might end up being used from some test script. I'm wondering 
- what would happen had the argument been an empty string?

```
clang -c foo.c -gen-cdb-fragment-path ""
```



Comment at: clang/lib/Driver/Driver.cpp:4868
+
+void Driver::emitCompilationDatabaseFragment(StringRef DestDir,
+ StringRef Executable,

I am just wondering whether we shouldn't notice user about failures, possibly 
with some error message.



Comment at: clang/lib/Driver/Driver.cpp:4896
+for (char C : Arg) {
+  if (C == ' ' || C == '\'' || C == '"' || C == '\\')
+OS << '\\';

It feels like this might have been already implemented somewhere else.

Couldn't we use for example `llvm::yaml::escape()`?

https://llvm.org/doxygen/namespacellvm_1_1yaml.html#aefed9cb3f107aee0cff4d325c7d689ae


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66555



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


r369581 - Use C++14 heteregenous lookup for a couple of std::map

2019-08-21 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Aug 21 14:17:34 2019
New Revision: 369581

URL: http://llvm.org/viewvc/llvm-project?rev=369581=rev
Log:
Use C++14 heteregenous lookup for a couple of std::map

These call find with a StringRef, heterogenous lookup saves a temporary
std::string there.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=369581=369580=369581=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Wed Aug 21 
14:17:34 2019
@@ -183,7 +183,8 @@ public:
   /// Note that we're using std::map here, as for memoization:
   /// - we need a comparison operator
   /// - we need an assignment operator
-  using IDToNodeMap = std::map;
+  using IDToNodeMap =
+  std::map>;
 
   const IDToNodeMap () const {
 return NodeMap;


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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

I think everybody should be fine with this now :)


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

https://reviews.llvm.org/D66397



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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Implemented @Quuxplusone's idea to improve silence note.


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

https://reviews.llvm.org/D66397



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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 216478.

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

https://reviews.llvm.org/D66397

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-xor-as-pow.cpp

Index: test/SemaCXX/warn-xor-as-pow.cpp
===
--- test/SemaCXX/warn-xor-as-pow.cpp
+++ test/SemaCXX/warn-xor-as-pow.cpp
@@ -10,8 +10,10 @@
 #define XOR(x, y) (x ^ y)
 #define TWO 2
 #define TEN 10
+#define IOP 64
 #define TWO_ULL 2ULL
 #define EPSILON 10 ^ -300
+#define ALPHA_OFFSET 3
 
 #define flexor 7
 
@@ -21,7 +23,7 @@
 constexpr long long operator"" _0b(unsigned long long v) { return v; }
 constexpr long long operator"" _0X(unsigned long long v) { return v; }
 #else
-#define xor^ // iso646.h
+#define xor ^ // iso646.h
 #endif
 
 void test(unsigned a, unsigned b) {
@@ -32,25 +34,28 @@
   res = 2 ^ -1;
   res = 2 ^ 0; // expected-warning {{result of '2 ^ 0' is 2; did you mean '1 << 0' (1)?}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1"
-   // expected-note@-2 {{replace expression with '0x2 ^ 0' to silence this warning}}
+   // expected-note@-2 {{replace expression with '0x2 ^ 0' or use 'xor' instead of '^' to silence this warning}}
   res = 2 ^ 1; // expected-warning {{result of '2 ^ 1' is 3; did you mean '1 << 1' (2)?}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1 << 1"
-   // expected-note@-2 {{replace expression with '0x2 ^ 1' to silence this warning}}
+   // expected-note@-2 {{replace expression with '0x2 ^ 1' or use 'xor' instead of '^' to silence this warning}}
   res = 2 ^ 2; // expected-warning {{result of '2 ^ 2' is 0; did you mean '1 << 2' (4)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1 << 2"
-  // expected-note@-2 {{replace expression with '0x2 ^ 2' to silence this warning}}
+  // expected-note@-2 {{replace expression with '0x2 ^ 2' or use 'xor' instead of '^' to silence this warning}}
   res = 2 ^ 8; // expected-warning {{result of '2 ^ 8' is 10; did you mean '1 << 8' (256)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1 << 8"
-  // expected-note@-2 {{replace expression with '0x2 ^ 8' to silence this warning}}
+  // expected-note@-2 {{replace expression with '0x2 ^ 8' or use 'xor' instead of '^' to silence this warning}}
   res = TWO ^ 8; // expected-warning {{result of 'TWO ^ 8' is 10; did you mean '1 << 8' (256)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1 << 8"
-  // expected-note@-2 {{replace expression with '0x2 ^ 8' to silence this warning}}
+  // expected-note@-2 {{replace expression with '0x2 ^ 8' or use 'xor' instead of '^' to silence this warning}}
   res = 2 ^ 16; // expected-warning {{result of '2 ^ 16' is 18; did you mean '1 << 16' (65536)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1 << 16"
-  // expected-note@-2 {{replace expression with '0x2 ^ 16' to silence this warning}}
+  // expected-note@-2 {{replace expression with '0x2 ^ 16' or use 'xor' instead of '^' to silence this warning}}
   res = 2 ^ TEN; // expected-warning {{result of '2 ^ TEN' is 8; did you mean '1 << TEN' (1024)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1 << TEN"
-  // expected-note@-2 {{replace expression with '0x2 ^ TEN' to silence this warning}}
+  // expected-note@-2 {{replace expression with '0x2 ^ TEN' or use 'xor' instead of '^' to silence this warning}}
+  res = res + (2 ^ ALPHA_OFFSET); // expected-warning {{result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:32}:"1 << ALPHA_OFFSET"
+  // expected-note@-2 {{replace expression with '0x2 ^ ALPHA_OFFSET' or use 'xor' instead of '^' to silence this warning}}
   res = 0x2 ^ 16;
   res = 2 xor 16;
 
@@ -63,37 +68,59 @@
   res = 0b10 ^ 16;
   res = 0B10 ^ 16;
   res = 2 ^ 0b100;
-  res = XOR(2, 16);
+  res = XOR(2, 16); // expected-warning {{result of '2 ^ 16' is 18; did you mean '1 << 16' (65536)?}}
+  // expected-note@-1 {{replace expression with '0x2 ^ 16' or use 'xor' instead of '^' to silence this warning}}
   unsigned char two = 2;
   res = two ^ 16;
   res = TWO_ULL ^ 16;
   res = 2 ^ 32; // expected-warning {{result of '2 ^ 32' is 34; did you mean '1LL << 32'?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1LL << 32"
-  // expected-note@-2 {{replace expression with '0x2 ^ 32' to silence this warning}}
-  res = 2 ^ 64;
-
-  res = EPSILON;
+  // expected-note@-2 {{replace expression with '0x2 ^ 32' or use 'xor' instead of '^' to silence this warning}}
+  res = (2 ^ 64) - 1; // expected-warning {{result of '2 ^ 64' is 66; did you mean '-1LL'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:21}:"-1LL"
+  // expected-note@-2 {{replace expression with '0x2 ^ 64' or use 'xor' instead of '^' to silence this warning}}

[PATCH] D65906: [clang-scan-deps] Fix edge cases in the minimizer

2019-08-21 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea abandoned this revision.
aganea added a comment.

Please see the other reviews I've sent.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65906



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


[clang-tools-extra] r369578 - Fix documentation build after rL369568

2019-08-21 Thread Yuanfang Chen via cfe-commits
Author: yuanfang
Date: Wed Aug 21 13:59:16 2019
New Revision: 369578

URL: http://llvm.org/viewvc/llvm-project?rev=369578=rev
Log:
Fix documentation build after rL369568

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst?rev=369578=369577=369578=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst
 Wed Aug 21 13:59:16 2019
@@ -17,11 +17,11 @@ problems.
 
 Consider the following code:
 
--- code-block:: c
+.. code-block:: c
 
-int foo() {
-  static int k = bar();
-  return k;
-}
+  int foo() {
+static int k = bar();
+return k;
+  }
 
 When synchronization of static initialization is disabled, if two threads both 
call `foo` for the first time, there is the possibility that `k` will be double 
initialized, creating a race condition.


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


[PATCH] D66381: [analyzer] Enable control dependency condition tracking by default

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D66381#1639679 , @NoQ wrote:

> The code looks good and there seems to be a lot of test coverage :]


Thank you! It would not have been possible on my own! And actually, there are a 
couple minor nits, such as caching the retrieved `CFGBlock` for each 
`ExplodedNode` (at least for the node we're calculating control dependencies 
for), so I'll address that soon™.


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

https://reviews.llvm.org/D66381



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


[PATCH] D66550: [clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include

2019-08-21 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D66550



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


[PATCH] D66556: [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings

2019-08-21 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea updated this revision to Diff 216474.
aganea added a comment.

Use proper test file.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66556

Files:
  lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  test/Lexer/minimize_source_to_dependency_directives_invalid_error.c

Index: test/Lexer/minimize_source_to_dependency_directives_invalid_error.c
===
--- test/Lexer/minimize_source_to_dependency_directives_invalid_error.c
+++ test/Lexer/minimize_source_to_dependency_directives_invalid_error.c
@@ -0,0 +1,16 @@
+// Test CF+LF are properly handled along with quoted, multi-line #error
+// RUN: cat %s | unix2dos | %clang_cc1 -DOTHER -print-dependency-directives-minimized-source 2>&1 | FileCheck %s
+
+#ifndef TEST
+#error "message \
+   more message \
+   even more"
+#endif
+
+#ifdef OTHER
+#include 
+#endif
+
+// CHECK:  #ifdef OTHER
+// CHECK-NEXT: #include 
+// CHECK-NEXT: #endif
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -196,15 +196,27 @@
 ++First; // Finish off the string.
 }
 
-static void skipNewline(const char *, const char *End) {
-  assert(isVerticalWhitespace(*First));
-  ++First;
+// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n)
+static unsigned isEOL(const char *First, const char *const End) {
   if (First == End)
-return;
+return 0;
+  if (End - First > 1 && isVerticalWhitespace(First[0]) &&
+  isVerticalWhitespace(First[1]) && First[0] != First[1])
+return 2;
+  return !!isVerticalWhitespace(First[0]);
+}
 
-  // Check for "\n\r" and "\r\n".
-  if (LLVM_UNLIKELY(isVerticalWhitespace(*First) && First[-1] != First[0]))
-++First;
+// Returns the length of the skipped newline
+static unsigned skipNewline(const char *, const char *End) {
+  assert(isVerticalWhitespace(*First));
+  unsigned Len = isEOL(First, End);
+  assert(Len);
+  First += Len;
+  return Len;
+}
+
+static bool wasLineContinuation(const char *First, unsigned Len) {
+  return *(First - (int)Len - 1) == '\\';
 }
 
 static void skipToNewlineRaw(const char *, const char *const End) {
@@ -212,17 +224,22 @@
 if (First == End)
   return;
 
-if (isVerticalWhitespace(*First))
+unsigned Len = isEOL(First, End);
+if (Len)
   return;
 
-while (!isVerticalWhitespace(*First))
+do {
   if (++First == End)
 return;
+  Len = isEOL(First, End);
+} while (!Len);
+
+First += Len;
 
-if (First[-1] != '\\')
+if (!wasLineContinuation(First, Len))
   return;
 
-++First; // Keep going...
+// Keep skipping lines...
   }
 }
 
@@ -277,7 +294,7 @@
 }
 
 static void skipLine(const char *, const char *const End) {
-  do {
+  for (;;) {
 assert(First <= End);
 if (First == End)
   return;
@@ -322,9 +339,10 @@
   return;
 
 // Skip over the newline.
-assert(isVerticalWhitespace(*First));
-skipNewline(First, End);
-  } while (First[-2] == '\\'); // Continue past line-continuations.
+unsigned Len = skipNewline(First, End);
+if (!wasLineContinuation(First, Len)) // Continue past line-continuations.
+  break;
+  }
 }
 
 static void skipDirective(StringRef Name, const char *,
@@ -379,6 +397,8 @@
 // Print out the string.
 if (Last == End || Last == First || Last[-1] != '\\') {
   append(First, reverseOverSpaces(First, Last));
+  First = Last;
+  skipNewline(First, End);
   return;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66556: [clang-scan-deps] Minimizer: Correctly handle multi-line content with CR+LF line endings

2019-08-21 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea created this revision.
aganea added reviewers: arphaman, dexonsmith, Bigcheese.
aganea added a project: clang.
Herald added a subscriber: tschuett.

Previously, an `#error` directive with quoted, multi-line content, along with 
CR+LF line endings wasn't handled correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D66556

Files:
  lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  test/Lexer/minimize_source_to_dependency_directives_include.c

Index: test/Lexer/minimize_source_to_dependency_directives_include.c
===
--- test/Lexer/minimize_source_to_dependency_directives_include.c
+++ test/Lexer/minimize_source_to_dependency_directives_include.c
@@ -0,0 +1,8 @@
+// Test double slashes in #include directive along with angle brackets. Previously, this was interpreted as comments.
+// RUN: %clang_cc1 -DTEST -print-dependency-directives-minimized-source %s 2>&1 | FileCheck %s
+
+#include "a//b.h"
+#include 
+
+// CHECK: #include "a//b.h"
+// CHECK: #include 
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -196,15 +196,27 @@
 ++First; // Finish off the string.
 }
 
-static void skipNewline(const char *, const char *End) {
-  assert(isVerticalWhitespace(*First));
-  ++First;
+// Returns the length of EOL, either 0 (no end-of-line), 1 (\n) or 2 (\r\n)
+static unsigned isEOL(const char *First, const char *const End) {
   if (First == End)
-return;
+return 0;
+  if (End - First > 1 && isVerticalWhitespace(First[0]) &&
+  isVerticalWhitespace(First[1]) && First[0] != First[1])
+return 2;
+  return !!isVerticalWhitespace(First[0]);
+}
 
-  // Check for "\n\r" and "\r\n".
-  if (LLVM_UNLIKELY(isVerticalWhitespace(*First) && First[-1] != First[0]))
-++First;
+// Returns the length of the skipped newline
+static unsigned skipNewline(const char *, const char *End) {
+  assert(isVerticalWhitespace(*First));
+  unsigned Len = isEOL(First, End);
+  assert(Len);
+  First += Len;
+  return Len;
+}
+
+static bool wasLineContinuation(const char *First, unsigned Len) {
+  return *(First - (int)Len - 1) == '\\';
 }
 
 static void skipToNewlineRaw(const char *, const char *const End) {
@@ -212,17 +224,22 @@
 if (First == End)
   return;
 
-if (isVerticalWhitespace(*First))
+unsigned Len = isEOL(First, End);
+if (Len)
   return;
 
-while (!isVerticalWhitespace(*First))
+do {
   if (++First == End)
 return;
+  Len = isEOL(First, End);
+} while (!Len);
+
+First += Len;
 
-if (First[-1] != '\\')
+if (!wasLineContinuation(First, Len))
   return;
 
-++First; // Keep going...
+// Keep skipping lines...
   }
 }
 
@@ -277,7 +294,7 @@
 }
 
 static void skipLine(const char *, const char *const End) {
-  do {
+  for (;;) {
 assert(First <= End);
 if (First == End)
   return;
@@ -322,9 +339,10 @@
   return;
 
 // Skip over the newline.
-assert(isVerticalWhitespace(*First));
-skipNewline(First, End);
-  } while (First[-2] == '\\'); // Continue past line-continuations.
+unsigned Len = skipNewline(First, End);
+if (!wasLineContinuation(First, Len)) // Continue past line-continuations.
+  break;
+  }
 }
 
 static void skipDirective(StringRef Name, const char *,
@@ -379,6 +397,8 @@
 // Print out the string.
 if (Last == End || Last == First || Last[-1] != '\\') {
   append(First, reverseOverSpaces(First, Last));
+  First = Last;
+  skipNewline(First, End);
   return;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 216469.
jdenny marked 7 inline comments as done.
jdenny set the repository for this revision to rG LLVM Github Monorepo.
jdenny added a comment.

Make suggested changes for passing around the capture level.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835

Files:
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_firstprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_private_messages.cpp
  clang/test/OpenMP/target_teams_map_codegen.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -1,7 +1,10 @@
-// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=40 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-version=45 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected -fopenmp-version=50 -fopenmp -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
-// RUN: %clang_cc1 -DCCODE -verify -fopenmp -ferror-limit 200 -x c %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,le45 -fopenmp-simd -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -DCCODE -verify=expected,le45 -fopenmp -ferror-limit 200 -x c %s -Wno-openmp-target -Wuninitialized
 #ifdef CCODE
 void foo(int arg) {
   const int n = 0;
@@ -536,10 +539,10 @@
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
 
-#pragma omp target teams private(j) map(j) // expected-error {{private variable cannot be in a map clause in '#pragma omp target teams' directive}}  expected-note {{defined as private}}
+#pragma omp target teams private(j) map(j) // le45-error {{private variable cannot be in a map clause in '#pragma omp target teams' directive}}  le45-note {{defined as private}}
   {}
 
-#pragma omp target teams firstprivate(j) map(j)  // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target teams' directive}} expected-note {{defined as firstprivate}}
+#pragma omp target teams firstprivate(j) map(j) // le45-error {{firstprivate variable cannot be in a map clause in '#pragma omp target teams' directive}} le45-note {{defined as firstprivate}}
   {}
 
 #pragma omp target teams map(m)
Index: clang/test/OpenMP/target_teams_map_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_teams_map_codegen.cpp
@@ -0,0 +1,172 @@
+// Test host codegen.
+// RUN: %clang_cc1 -DHAS_INT128 -verify -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefixes=CHECK,HOST,INT128,HOST-INT128
+// RUN: %clang_cc1 -DHAS_INT128 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -DHAS_INT128 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,HOST,INT128,HOST-INT128
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefixes=CHECK,HOST
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,HOST
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -DHAS_INT128 -verify -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown 

[PATCH] D66555: [driver] add a new option `-gen-cdb-fragment-path` to emit a fragment of a compilation database for each compilation

2019-08-21 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: Bigcheese, jkorous, dexonsmith.
Herald added a project: clang.

This patch adds a new option called `-gen-cdb-fragment-path`  to the driver, 
which can be used to specify a directory path to which clang can emit a 
fragment of a CDB for each compilation it needs to invoke.

The CDB fragment is emitted into a unique file in the specified directory. It 
contains the `-cc1` clang invocation in its command. The file itself is 
actually a valid standalone CDB (if you disregard the not yet well supported 
`-cc1` innovation by the CDB, which I'll fix). To load the full CDB that can be 
emitted during a build, I'm going to add a new CDB reader from a directory that 
reads all fragments and aggregates them into one CDB in a follow-up patch.

This is useful to setup verification infrastructure for `clang-scan-deps` for 
some projects that don't have a way of constructing a CDB from their build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66555

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Job.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Compilation.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/gen-cdb-fragment.c

Index: clang/test/Driver/gen-cdb-fragment.c
===
--- /dev/null
+++ clang/test/Driver/gen-cdb-fragment.c
@@ -0,0 +1,18 @@
+// REQUIRES: x86-registered-target
+// RUN: rm -rf %t.cdb
+// RUN: %clang -target x86_64-apple-macos10.15 -c %s -o -  -gen-cdb-fragment-path %t.cdb
+// RUN: ls %t.cdb | FileCheck --check-prefix=CHECK-LS %s
+// CHECK-LS: gen-cdb-fragment.c.{{.*}}.json
+
+// RUN: cat %t.cdb/*.json | FileCheck --check-prefix=CHECK %s
+// CHECK: [{
+// CHECK-NEXT: "directory":"{{.*}}",
+// CHECK-NEXT: "command":"{{.*}} -cc1 -triple x86_64-apple-macosx10.15.0 {{.*}}",
+// CHECK-NEXT: "file":"{{.*}}gen-cdb-fragment.c"
+// CHECK: }]
+
+// RUN: rm -rf %t.cdb
+// RUN: mkdir %t.cdb
+// RUN: ls %t.cdb | not FileCheck --check-prefix=CHECK-LS %s
+// RUN: %clang -target x86_64-apple-macos10.15 -S %s -o -  -gen-cdb-fragment-path %t.cdb
+// RUN: ls %t.cdb | FileCheck --check-prefix=CHECK-LS %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1040,6 +1040,8 @@
   GenReproducer = Args.hasFlag(options::OPT_gen_reproducer,
options::OPT_fno_crash_diagnostics,
!!::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"));
+  if (const Arg *A = Args.getLastArg(options::OPT_gen_cdb_fragment_path))
+PathToCDBFragmentDir = A->getValue();
   // FIXME: TargetTriple is used by the target-prefixed calls to as/ld
   // and getToolChain is const.
   if (IsCLMode()) {
@@ -4862,3 +4864,46 @@
 bool clang::driver::isOptimizationLevelFast(const ArgList ) {
   return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group, false);
 }
+
+void Driver::emitCompilationDatabaseFragment(StringRef DestDir,
+ StringRef Executable,
+ StringRef Filename,
+ const ArgStringList ) const {
+  auto CWD = getVFS().getCurrentWorkingDirectory();
+  if (!CWD)
+return;
+
+  SmallString<256> Path = DestDir;
+  getVFS().makeAbsolute(Path);
+  auto Err = llvm::sys::fs::create_directory(Path, /*IgnoreExisting=*/true);
+  if (Err)
+return;
+
+  llvm::sys::path::append(Path, Twine(llvm::sys::path::filename(Filename)) +
+"..json");
+  int FD;
+  SmallString<256> TempPath;
+  Err = llvm::sys::fs::createUniqueFile(Path, FD, TempPath);
+  if (Err)
+return;
+
+  llvm::raw_fd_ostream OS(FD, /*ShouldClose=*/true);
+  OS << "[{\n";
+  OS << R"("directory":")" << *CWD << "\",\n";
+  OS << R"("command":")";
+  auto EmitCommandLineFragment = [](StringRef Arg) {
+for (char C : Arg) {
+  if (C == ' ' || C == '\'' || C == '"' || C == '\\')
+OS << '\\';
+  OS << C;
+}
+  };
+  EmitCommandLineFragment(Executable);
+  for (const auto  : Args) {
+OS << ' ';
+EmitCommandLineFragment(Arg);
+  }
+  OS << "\",\n";
+  OS << R"("file":")" << Filename << "\"\n";
+  OS << "}]";
+}
Index: clang/lib/Driver/Compilation.cpp
===
--- clang/lib/Driver/Compilation.cpp
+++ clang/lib/Driver/Compilation.cpp
@@ -176,6 +176,14 @@
 
 C.Print(*OS, "\n", /*Quote=*/getDriver().CCPrintOptions);
   }
+  if (auto CDBOutputDir = getDriver().getPathToCDBFragmentDir()) {
+if (isa(C.getSource()) ||
+isa(C.getSource())) {
+  for (const auto  : C.getInputFilenames())
+getDriver().emitCompilationDatabaseFragment(
+*CDBOutputDir, C.getExecutable(), F, C.getArguments());
+}
+  }
 
   std::string Error;
   bool ExecutionFailed;
Index: 

[PATCH] D65575: [analyzer] Mention whether an event is about a condition in a bug report part 1

2019-08-21 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369574: [analyzer] Mention whether an event is about a 
condition in a bug report part 1 (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65575?vs=216273=216467#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65575

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -298,6 +298,7 @@
   MemRegionManager 
   const SourceManager 
   const PrintingPolicy 
+  bugreporter::TrackingKind TKind;
 
   /// Recursion limit for dereferencing fields when looking for the
   /// region of interest.
@@ -318,10 +319,10 @@
   using RegionVector = SmallVector;
 
 public:
-  NoStoreFuncVisitor(const SubRegion *R)
+  NoStoreFuncVisitor(const SubRegion *R, bugreporter::TrackingKind TKind)
   : RegionOfInterest(R), MmrMgr(*R->getMemRegionManager()),
 SM(MmrMgr.getContext().getSourceManager()),
-PP(MmrMgr.getContext().getPrintingPolicy()) {}
+PP(MmrMgr.getContext().getPrintingPolicy()), TKind(TKind) {}
 
   void Profile(llvm::FoldingSetNodeID ) const override {
 static int Tag = 0;
@@ -612,6 +613,9 @@
   } while (N);
 }
 
+static llvm::StringLiteral WillBeUsedForACondition =
+", which participates in a condition later";
+
 PathDiagnosticPieceRef NoStoreFuncVisitor::maybeEmitNote(
 BugReport , const CallEvent , const ExplodedNode *N,
 const RegionVector , const MemRegion *MatchedRegion,
@@ -658,6 +662,8 @@
 return nullptr;
 
   os << "'";
+  if (TKind == bugreporter::TrackingKind::Condition)
+os << WillBeUsedForACondition;
   return std::make_shared(L, os.str());
 }
 
@@ -1068,6 +1074,9 @@
 if (!L.isValid() || !L.asLocation().isValid())
   return nullptr;
 
+if (TKind == bugreporter::TrackingKind::Condition)
+  Out << WillBeUsedForACondition;
+
 auto EventPiece = std::make_shared(L, Out.str());
 
 // If we determined that the note is meaningless, make it prunable, and
@@ -1450,6 +1459,9 @@
   if (os.str().empty())
 showBRDefaultDiagnostics(os, R, V);
 
+  if (TKind == bugreporter::TrackingKind::Condition)
+os << WillBeUsedForACondition;
+
   // Construct a new PathDiagnosticPiece.
   ProgramPoint P = StoreSite->getLocation();
   PathDiagnosticLocation L;
@@ -1933,7 +1945,7 @@
   // Mark both the variable region and its contents as interesting.
   SVal V = LVState->getRawSVal(loc::MemRegionVal(R));
   report.addVisitor(
-  std::make_unique(cast(R)));
+  std::make_unique(cast(R), TKind));
 
   MacroNullReturnSuppressionVisitor::addMacroVisitorIfNecessary(
   LVNode, R, EnableNullFPSuppression, report, V);
Index: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
===
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
@@ -29,24 +29,24 @@
 bool coin();
 
 void foo() {
-  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+  flag = coin(); // tracking-note-re^}}Value assigned to 'flag', which participates in a condition later{{$
 }
 
 void test() {
-  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer value{{$
   flag = 1;
 
   foo(); // TODO: Add nodes here about flag's value being invalidated.
-  if (flag) // expected-note   {{Assuming 'flag' is 0}}
-// expected-note@-1{{Taking false branch}}
+  if (flag) // expected-note-re   ^}}Assuming 'flag' is 0{{$
+// expected-note-re@-1^}}Taking false branch{{$
 x = new int;
 
-  foo(); // tracking-note{{Calling 'foo'}}
- // tracking-note@-1{{Returning from 'foo'}}
+  foo(); // tracking-note-re^}}Calling 'foo'{{$
+ // tracking-note-re@-1^}}Returning from 'foo'{{$
 
-  if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
-// expected-note@-1{{Taking true branch}}
-// debug-note@-2{{Tracking condition 'flag'}}
+  if (flag) // expected-note-re   ^}}Assuming 'flag' is not equal to 0{{$
+// expected-note-re@-1^}}Taking true branch{{$
+// debug-note-re@-2^}}Tracking condition 'flag'{{$
 
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
@@ -58,7 +58,7 @@
 

r369574 - [analyzer] Mention whether an event is about a condition in a bug report part 1

2019-08-21 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Wed Aug 21 13:43:27 2019
New Revision: 369574

URL: http://llvm.org/viewvc/llvm-project?rev=369574=rev
Log:
[analyzer] Mention whether an event is about a condition in a bug report part 1

Can't add much more to the title! This is part 1, the case where the collapse
point isn't in the condition point is the responsibility of ConditionBRVisitor,
which I'm addressing in part 2.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369574=369573=369574=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
13:43:27 2019
@@ -298,6 +298,7 @@ class NoStoreFuncVisitor final : public
   MemRegionManager 
   const SourceManager 
   const PrintingPolicy 
+  bugreporter::TrackingKind TKind;
 
   /// Recursion limit for dereferencing fields when looking for the
   /// region of interest.
@@ -318,10 +319,10 @@ class NoStoreFuncVisitor final : public
   using RegionVector = SmallVector;
 
 public:
-  NoStoreFuncVisitor(const SubRegion *R)
+  NoStoreFuncVisitor(const SubRegion *R, bugreporter::TrackingKind TKind)
   : RegionOfInterest(R), MmrMgr(*R->getMemRegionManager()),
 SM(MmrMgr.getContext().getSourceManager()),
-PP(MmrMgr.getContext().getPrintingPolicy()) {}
+PP(MmrMgr.getContext().getPrintingPolicy()), TKind(TKind) {}
 
   void Profile(llvm::FoldingSetNodeID ) const override {
 static int Tag = 0;
@@ -612,6 +613,9 @@ void NoStoreFuncVisitor::findModifyingFr
   } while (N);
 }
 
+static llvm::StringLiteral WillBeUsedForACondition =
+", which participates in a condition later";
+
 PathDiagnosticPieceRef NoStoreFuncVisitor::maybeEmitNote(
 BugReport , const CallEvent , const ExplodedNode *N,
 const RegionVector , const MemRegion *MatchedRegion,
@@ -658,6 +662,8 @@ PathDiagnosticPieceRef NoStoreFuncVisito
 return nullptr;
 
   os << "'";
+  if (TKind == bugreporter::TrackingKind::Condition)
+os << WillBeUsedForACondition;
   return std::make_shared(L, os.str());
 }
 
@@ -1068,6 +1074,9 @@ public:
 if (!L.isValid() || !L.asLocation().isValid())
   return nullptr;
 
+if (TKind == bugreporter::TrackingKind::Condition)
+  Out << WillBeUsedForACondition;
+
 auto EventPiece = std::make_shared(L, Out.str());
 
 // If we determined that the note is meaningless, make it prunable, and
@@ -1450,6 +1459,9 @@ FindLastStoreBRVisitor::VisitNode(const
   if (os.str().empty())
 showBRDefaultDiagnostics(os, R, V);
 
+  if (TKind == bugreporter::TrackingKind::Condition)
+os << WillBeUsedForACondition;
+
   // Construct a new PathDiagnosticPiece.
   ProgramPoint P = StoreSite->getLocation();
   PathDiagnosticLocation L;
@@ -1933,7 +1945,7 @@ bool bugreporter::trackExpressionValue(c
   // Mark both the variable region and its contents as interesting.
   SVal V = LVState->getRawSVal(loc::MemRegionVal(R));
   report.addVisitor(
-  std::make_unique(cast(R)));
+  std::make_unique(cast(R), TKind));
 
   MacroNullReturnSuppressionVisitor::addMacroVisitorIfNecessary(
   LVNode, R, EnableNullFPSuppression, report, V);

Modified: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp?rev=369574=369573=369574=diff
==
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp (original)
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp Wed Aug 21 
13:43:27 2019
@@ -29,24 +29,24 @@ int flag;
 bool coin();
 
 void foo() {
-  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+  flag = coin(); // tracking-note-re^}}Value assigned to 'flag', which 
participates in a condition later{{$
 }
 
 void test() {
-  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  int *x = 0; // expected-note-re^}}'x' initialized to a null pointer 
value{{$
   flag = 1;
 
   foo(); // TODO: Add nodes here about flag's value being invalidated.
-  if (flag) // expected-note   {{Assuming 'flag' is 0}}
-// expected-note@-1{{Taking false branch}}
+  if (flag) // expected-note-re   ^}}Assuming 'flag' is 0{{$
+// expected-note-re@-1^}}Taking false branch{{$
 x = new int;
 
-  foo(); // tracking-note{{Calling 'foo'}}
- // tracking-note@-1{{Returning from 'foo'}}
+  foo(); // tracking-note-re^}}Calling 'foo'{{$
+ // 

[PATCH] D66122: [CodeGen] Emit dynamic initializers for static TLS vars in outlined scopes

2019-08-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Added a few more minor comments.

It looks like the consensus on std-discussion is actually that your testcase 
has undefined behavior?  That seems like an awful conclusion, and the standard 
text doesn't really seem to support it. (I mean, I guess you could argue that " 
variable with thread storage duration shall be initialized before its first 
odr-use" means if it's not initialized, the behavior is undefined, but that's 
really confusing.)  But given that, I think we should submit a core issue, and 
hold off on merging this until we hear back from the committee.




Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:306
+  if (const auto *InitExpr = VD->getInit()) {
+std::deque frontier;
+

If you don't care about the iteration order, using pop_back on a vector is 
faster.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:317
+  deps.insert(V);
+  auto V_Refs = enumerateVarInitDependencies(V);
+  deps.insert(V_Refs.begin(), V_Refs.end());

Do you need to recurse here?  It looks like the caller should handle that.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:469
+  for (const VarDecl *VD : UniqueVarsToInit)
+  OrderedVarInits.push_back(VD);
+

Indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66122



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


[PATCH] D66550: [clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include

2019-08-21 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea created this revision.
aganea added reviewers: arphaman, dexonsmith, Bigcheese.
aganea added a project: clang.
Herald added a subscriber: tschuett.
aganea retitled this revision from "[clang-scan-deps] Correctly skip over 
double slashes in angle bracket #include" to "[clang-scan-deps] Minimizer: 
Correctly skip over double slashes in angle bracket #include".

Previously, double slashes (//) occurring in angle brackets `#include` were 
incorrectly interpreted as comments. eg. `#include `


Repository:
  rC Clang

https://reviews.llvm.org/D66550

Files:
  lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  test/Lexer/minimize_source_to_dependency_directives_include.c


Index: test/Lexer/minimize_source_to_dependency_directives_include.c
===
--- test/Lexer/minimize_source_to_dependency_directives_include.c
+++ test/Lexer/minimize_source_to_dependency_directives_include.c
@@ -0,0 +1,8 @@
+// Test double slashes in #include directive along with angle brackets. 
Previously, this was interpreted as comments.
+// RUN: %clang_cc1 -DTEST -print-dependency-directives-minimized-source %s 
2>&1 | FileCheck %s
+
+#include "a//b.h"
+#include 
+
+// CHECK: #include "a//b.h"
+// CHECK: #include 
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -186,8 +186,8 @@
 }
 
 static void skipString(const char *, const char *const End) {
-  assert(*First == '\'' || *First == '"');
-  const char Terminator = *First;
+  assert(*First == '\'' || *First == '"' || *First == '<');
+  const char Terminator = *First == '<' ? '>' : *First;
   for (++First; First != End && *First != Terminator; ++First)
 if (*First == '\\')
   if (++First == End)
@@ -344,7 +344,8 @@
 const char *Last = First;
 do {
   // Iterate over strings correctly to avoid comments and newlines.
-  if (*Last == '"' || *Last == '\'') {
+  if (*Last == '"' || *Last == '\'' ||
+  (*Last == '<' && top() == pp_include)) {
 if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
   skipRawString(Last, End);
 else


Index: test/Lexer/minimize_source_to_dependency_directives_include.c
===
--- test/Lexer/minimize_source_to_dependency_directives_include.c
+++ test/Lexer/minimize_source_to_dependency_directives_include.c
@@ -0,0 +1,8 @@
+// Test double slashes in #include directive along with angle brackets. Previously, this was interpreted as comments.
+// RUN: %clang_cc1 -DTEST -print-dependency-directives-minimized-source %s 2>&1 | FileCheck %s
+
+#include "a//b.h"
+#include 
+
+// CHECK: #include "a//b.h"
+// CHECK: #include 
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -186,8 +186,8 @@
 }
 
 static void skipString(const char *, const char *const End) {
-  assert(*First == '\'' || *First == '"');
-  const char Terminator = *First;
+  assert(*First == '\'' || *First == '"' || *First == '<');
+  const char Terminator = *First == '<' ? '>' : *First;
   for (++First; First != End && *First != Terminator; ++First)
 if (*First == '\\')
   if (++First == End)
@@ -344,7 +344,8 @@
 const char *Last = First;
 do {
   // Iterate over strings correctly to avoid comments and newlines.
-  if (*Last == '"' || *Last == '\'') {
+  if (*Last == '"' || *Last == '\'' ||
+  (*Last == '<' && top() == pp_include)) {
 if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
   skipRawString(Last, End);
 else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 216458.
xbolva00 edited the summary of this revision.
xbolva00 added a comment.

Detect digit separators.


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

https://reviews.llvm.org/D66397

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-xor-as-pow.cpp

Index: test/SemaCXX/warn-xor-as-pow.cpp
===
--- test/SemaCXX/warn-xor-as-pow.cpp
+++ test/SemaCXX/warn-xor-as-pow.cpp
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wxor-used-as-pow %s
+// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify -Wxor-used-as-pow %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
@@ -10,8 +11,10 @@
 #define XOR(x, y) (x ^ y)
 #define TWO 2
 #define TEN 10
+#define IOP 64
 #define TWO_ULL 2ULL
 #define EPSILON 10 ^ -300
+#define ALPHA_OFFSET 3
 
 #define flexor 7
 
@@ -21,7 +24,7 @@
 constexpr long long operator"" _0b(unsigned long long v) { return v; }
 constexpr long long operator"" _0X(unsigned long long v) { return v; }
 #else
-#define xor^ // iso646.h
+#define xor ^ // iso646.h
 #endif
 
 void test(unsigned a, unsigned b) {
@@ -51,6 +54,9 @@
   res = 2 ^ TEN; // expected-warning {{result of '2 ^ TEN' is 8; did you mean '1 << TEN' (1024)?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1 << TEN"
   // expected-note@-2 {{replace expression with '0x2 ^ TEN' to silence this warning}}
+  res = res + (2 ^ ALPHA_OFFSET); // expected-warning {{result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:32}:"1 << ALPHA_OFFSET"
+  // expected-note@-2 {{replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning}}
   res = 0x2 ^ 16;
   res = 2 xor 16;
 
@@ -63,16 +69,35 @@
   res = 0b10 ^ 16;
   res = 0B10 ^ 16;
   res = 2 ^ 0b100;
-  res = XOR(2, 16);
+  res = XOR(2, 16); // expected-warning {{result of '2 ^ 16' is 18; did you mean '1 << 16' (65536)?}}
+  // expected-note@-1 {{replace expression with '0x2 ^ 16' to silence this warning}}
   unsigned char two = 2;
   res = two ^ 16;
   res = TWO_ULL ^ 16;
   res = 2 ^ 32; // expected-warning {{result of '2 ^ 32' is 34; did you mean '1LL << 32'?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1LL << 32"
   // expected-note@-2 {{replace expression with '0x2 ^ 32' to silence this warning}}
-  res = 2 ^ 64;
+  res = (2 ^ 64) - 1; // expected-warning {{result of '2 ^ 64' is 66; did you mean '-1LL'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:21}:"-1LL"
+  // expected-note@-2 {{replace expression with '0x2 ^ 64' to silence this warning}}
+#define ULLONG_MAX 18446744073709551615ULL
+  res = (2 ^ 64) - 1; // expected-warning {{result of '2 ^ 64' is 66; did you mean 'ULLONG_MAX'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:21}:"ULLONG_MAX"
+  // expected-note@-2 {{replace expression with '0x2 ^ 64' to silence this warning}}
+  res = (2 ^ 64) - 2;
+  res = (2 ^ IOP) - 1; // expected-warning {{result of '2 ^ IOP' is 66; did you mean 'ULLONG_MAX'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:22}:"ULLONG_MAX"
+  // expected-note@-2 {{replace expression with '0x2 ^ IOP' to silence this warning}}
+  res = (2 ^ 65) - 1;
+  res = (2 + 64) - 1;
+  res = (3 ^ 64) - 1;
+  res = (2 ^ 8) - 1; // expected-warning {{result of '2 ^ 8' is 10; did you mean '1 << 8' (256)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"1 << 8"
+  // expected-note@-2 {{replace expression with '0x2 ^ 8' to silence this warning}}
 
-  res = EPSILON;
+  res = EPSILON; // expected-warning {{result of 'EPSILON' is 294; did you mean '1e-300'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1e-300"
+  // expected-note@-2 {{replace expression with '0xA ^ -300' to silence this warning}}
   res = 10 ^ 0; // expected-warning {{result of '10 ^ 0' is 10; did you mean '1e0'?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1e0"
   // expected-note@-2 {{replace expression with '0xA ^ 0' to silence this warning}}
@@ -91,6 +116,9 @@
   res = TEN ^ 10; // expected-warning {{result of 'TEN ^ 10' is 0; did you mean '1e10'?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:"1e10"
   // expected-note@-2 {{replace expression with '0xA ^ 10' to silence this warning}}
+  res = 10 ^ TEN; // expected-warning {{result of '10 ^ TEN' is 0; did you mean '1e10'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:"1e10"
+  // expected-note@-2 {{replace expression with '0xA ^ TEN' to silence this warning}}
   res = 10 ^ 100; // expected-warning {{result of '10 ^ 100' is 110; did you mean '1e100'?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:"1e100"
   // expected-note@-2 {{replace expression 

[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2108
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K) {
+  CapturedRegionScopeInfo *CSI = new CapturedRegionScopeInfo(

jdenny wrote:
> ABataev wrote:
> > ABataev wrote:
> > > jdenny wrote:
> > > > ABataev wrote:
> > > > > I would suggest adding a new parameter for CapturedLevel and the same 
> > > > > parameter to `ActOnCapturedRegionStart` function. And pass the value 
> > > > > for `CapturedLevel` explicitly at `ActOnCapturedRegionStart` function 
> > > > > call in SemaOpenMP.cpp rather than rely on this solution.
> > > > > Also, for each separate OpenMP directive, this counter must start 
> > > > > from `0`. Currently, I think, it may lead to crash if we have several 
> > > > > directives. Something like:
> > > > > ```
> > > > > #pragma omp parallel
> > > > > #pragma omp target teams
> > > > > ...
> > > > > ```
> > > > > I think it will work incorrectly for this example.
> > > > I think the check that `OpenMPLevel` is the same prevents the problem 
> > > > you mention.
> > > Ah, yes, missed this. Anyway, better to specify this explicitly as 
> > > function parameters, I think, rather than trying to evaluate it here this 
> > > way. We eventually may change the handling of captured regions in OpenMP, 
> > > better to have everything in SemaOpenMP.cpp
> > BTW, here you can use the parameter with the default value `0`.
> OK.
> 
> `CaptureLevel` or `CapturedLevel`?  Do you care?
Up to you


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

https://reviews.llvm.org/D65835



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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

In D66397#1639840 , @xbolva00 wrote:

> Swap trick is cool, we can suggest it always(vs. ‘xor’)


Well, you should avoid suggesting that the user rewrite `2 ^ 10` as `10 ^ 2`.
Anyway, I think some of the observers here might be confusing two aspects of 
the issue.

First there's "how can the programmer shut up this diagnostic?", to which there 
are dozens of answers that all work equally well. `0x2 ^ 3`, `2 ^ 0x3`, `2 xor 
3`, `3 ^ 2` (in this case), `myxorfunction(2, 3)`, `02 ^ 03`, `0b10 ^ 0b11`, 
Richard's suggested de-cleverfication of `3 - 2`, and so on. Basically anything 
that convinces the compiler you're not trying to take an integer power of 2.

Second there's "what advice and/or fixit should Clang produce to push the 
programmer toward //one specific way// of shutting up this diagnostic?". Right 
now, IIUC, Clang always gives an English note suggesting to change the 
left-hand side into hex (preserving the behavior of the code), //and// a 
technical fixit suggesting to use `1 << RHS` or `1eRHS` (changing the behavior 
of the code).

The main trouble we're having with #2 is that when Clang suggests //one// 
possible fix, the Chromium programmers seemed to interpret that as meaning that 
that was the //only// possible fix — they didn't look deeper to see if there 
might be other possible ways to improve the code.

Perhaps you could change the English note to say

> to silence this warning, replace expression with '0x2 ^ ALPHA_OFFSET' **or 
> use the 'xor' keyword**

This would at least give more of a jog to the programmer's brain, by saying 
"you have a choice to make here; don't apply the compiler's suggested fixit 
blindly."


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

https://reviews.llvm.org/D66397



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked an inline comment as done.
jdenny added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2108
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K) {
+  CapturedRegionScopeInfo *CSI = new CapturedRegionScopeInfo(

ABataev wrote:
> ABataev wrote:
> > jdenny wrote:
> > > ABataev wrote:
> > > > I would suggest adding a new parameter for CapturedLevel and the same 
> > > > parameter to `ActOnCapturedRegionStart` function. And pass the value 
> > > > for `CapturedLevel` explicitly at `ActOnCapturedRegionStart` function 
> > > > call in SemaOpenMP.cpp rather than rely on this solution.
> > > > Also, for each separate OpenMP directive, this counter must start from 
> > > > `0`. Currently, I think, it may lead to crash if we have several 
> > > > directives. Something like:
> > > > ```
> > > > #pragma omp parallel
> > > > #pragma omp target teams
> > > > ...
> > > > ```
> > > > I think it will work incorrectly for this example.
> > > I think the check that `OpenMPLevel` is the same prevents the problem you 
> > > mention.
> > Ah, yes, missed this. Anyway, better to specify this explicitly as function 
> > parameters, I think, rather than trying to evaluate it here this way. We 
> > eventually may change the handling of captured regions in OpenMP, better to 
> > have everything in SemaOpenMP.cpp
> BTW, here you can use the parameter with the default value `0`.
OK.

`CaptureLevel` or `CapturedLevel`?  Do you care?


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2108
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K) {
+  CapturedRegionScopeInfo *CSI = new CapturedRegionScopeInfo(

jdenny wrote:
> ABataev wrote:
> > I would suggest adding a new parameter for CapturedLevel and the same 
> > parameter to `ActOnCapturedRegionStart` function. And pass the value for 
> > `CapturedLevel` explicitly at `ActOnCapturedRegionStart` function call in 
> > SemaOpenMP.cpp rather than rely on this solution.
> > Also, for each separate OpenMP directive, this counter must start from `0`. 
> > Currently, I think, it may lead to crash if we have several directives. 
> > Something like:
> > ```
> > #pragma omp parallel
> > #pragma omp target teams
> > ...
> > ```
> > I think it will work incorrectly for this example.
> I think the check that `OpenMPLevel` is the same prevents the problem you 
> mention.
Ah, yes, missed this. Anyway, better to specify this explicitly as function 
parameters, I think, rather than trying to evaluate it here this way. We 
eventually may change the handling of captured regions in OpenMP, better to 
have everything in SemaOpenMP.cpp


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2108
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K) {
+  CapturedRegionScopeInfo *CSI = new CapturedRegionScopeInfo(

ABataev wrote:
> jdenny wrote:
> > ABataev wrote:
> > > I would suggest adding a new parameter for CapturedLevel and the same 
> > > parameter to `ActOnCapturedRegionStart` function. And pass the value for 
> > > `CapturedLevel` explicitly at `ActOnCapturedRegionStart` function call in 
> > > SemaOpenMP.cpp rather than rely on this solution.
> > > Also, for each separate OpenMP directive, this counter must start from 
> > > `0`. Currently, I think, it may lead to crash if we have several 
> > > directives. Something like:
> > > ```
> > > #pragma omp parallel
> > > #pragma omp target teams
> > > ...
> > > ```
> > > I think it will work incorrectly for this example.
> > I think the check that `OpenMPLevel` is the same prevents the problem you 
> > mention.
> Ah, yes, missed this. Anyway, better to specify this explicitly as function 
> parameters, I think, rather than trying to evaluate it here this way. We 
> eventually may change the handling of captured regions in OpenMP, better to 
> have everything in SemaOpenMP.cpp
BTW, here you can use the parameter with the default value `0`.


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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Permit map with DSA on combined directive

2019-08-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked an inline comment as done.
jdenny added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:2108
 void Sema::PushCapturedRegionScope(Scope *S, CapturedDecl *CD, RecordDecl *RD,
CapturedRegionKind K) {
+  CapturedRegionScopeInfo *CSI = new CapturedRegionScopeInfo(

ABataev wrote:
> I would suggest adding a new parameter for CapturedLevel and the same 
> parameter to `ActOnCapturedRegionStart` function. And pass the value for 
> `CapturedLevel` explicitly at `ActOnCapturedRegionStart` function call in 
> SemaOpenMP.cpp rather than rely on this solution.
> Also, for each separate OpenMP directive, this counter must start from `0`. 
> Currently, I think, it may lead to crash if we have several directives. 
> Something like:
> ```
> #pragma omp parallel
> #pragma omp target teams
> ...
> ```
> I think it will work incorrectly for this example.
I think the check that `OpenMPLevel` is the same prevents the problem you 
mention.


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

https://reviews.llvm.org/D65835



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


[PATCH] D62829: [clang-tidy] Check for dynamically initialized statics in headers.

2019-08-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369568: [clang-tidy] Check for dynamically initialized 
statics in headers. (authored by yuanfang, committed by ).
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D62829?vs=214275=216451#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62829

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/test/clang-tidy/bugprone-dynamic-static-initializers.hpp

Index: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BranchCloneCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
+#include "DynamicStaticInitializersCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -73,6 +74,8 @@
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-dangling-handle");
+CheckFactories.registerCheck(
+"bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -0,0 +1,68 @@
+//===--- DynamicStaticInitializersCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DynamicStaticInitializersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
+  const Expr *Init = Node.getInit();
+  if (Init && !Init->isValueDependent()) {
+if (Node.isConstexpr())
+  return true;
+return Node.checkInitIsICE();
+  }
+  return false;
+}
+
+DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
+"HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
+  if (!utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
+HeaderFileExtensions, ',')) {
+llvm::errs() << "Invalid header file extension: "
+ << RawStringHeaderFileExtensions << "\n";
+  }
+}
+
+void DynamicStaticInitializersCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
+}
+
+void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus || getLangOpts().ThreadsafeStatics)
+return;
+  Finder->addMatcher(
+  varDecl(hasGlobalStorage(), unless(hasConstantDeclaration())).bind("var"),
+  this);
+}
+
+void DynamicStaticInitializersCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Var = Result.Nodes.getNodeAs("var");
+  SourceLocation Loc = Var->getLocation();
+  if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(Loc, *Result.SourceManager,
+  HeaderFileExtensions))
+return;
+  // If the initializer is a constant expression, then the compiler
+  // doesn't have to dynamically initialize it.
+  diag(Loc, "static variable %0 may be dynamically initialized in this header file")
+<< Var;
+}
+
+} // namespace bugprone
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
===
--- 

[clang-tools-extra] r369568 - [clang-tidy] Check for dynamically initialized statics in headers.

2019-08-21 Thread Yuanfang Chen via cfe-commits
Author: yuanfang
Date: Wed Aug 21 13:00:01 2019
New Revision: 369568

URL: http://llvm.org/viewvc/llvm-project?rev=369568=rev
Log:
[clang-tidy] Check for dynamically initialized statics in headers.

Finds instances where variables with static storage are initialized dynamically 
in header files.

Reviewed By: aaron.ballman, alexfh

Patch by Charles Zhang!

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

Added:

clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-dynamic-static-initializers.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-dynamic-static-initializers.hpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=369568=369567=369568=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Wed Aug 
21 13:00:01 2019
@@ -16,6 +16,7 @@
 #include "BranchCloneCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
+#include "DynamicStaticInitializersCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -73,6 +74,8 @@ public:
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-dangling-handle");
+CheckFactories.registerCheck(
+"bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=369568=369567=369568=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Wed Aug 21 
13:00:01 2019
@@ -8,6 +8,7 @@ add_clang_library(clangTidyBugproneModul
   BugproneTidyModule.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
+  DynamicStaticInitializersCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp

Added: 
clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp?rev=369568=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp 
Wed Aug 21 13:00:01 2019
@@ -0,0 +1,68 @@
+//===--- DynamicStaticInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DynamicStaticInitializersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
+  const Expr *Init = Node.getInit();
+  if (Init && !Init->isValueDependent()) {
+if (Node.isConstexpr())
+  return true;
+return Node.checkInitIsICE();
+  }
+  return false;
+}
+
+DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(StringRef Name,
+   
ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
+"HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
+  if (!utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
+HeaderFileExtensions, ',')) {
+llvm::errs() << "Invalid header file extension: "
+ << RawStringHeaderFileExtensions << "\n";
+  }
+}
+
+void DynamicStaticInitializersCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
+}

[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Swap trick is cool, we can suggest it always(vs. ‘xor’)


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

https://reviews.llvm.org/D66397



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


  1   2   >