[PATCH] D81392: [clang] Rename Decl::isHidden() to isUnconditionallyVisible()

2020-06-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

In D81392#2088131 , @rsmith wrote:

> I think renaming the flag in the AST dump output would be a good idea, though 
> it'll be a lot of churn in the tests. I would prefer that we continue to dump 
> a marker only if the declaration is not unconditionally visible rather than 
> reversing the sense of the flag in the dump output.


Agree -- I had tried that experimentally, but it does cause a lot of noise in 
the output.

> Maybe we should dump the ModuleOwnershipKind in general, not only an 
> indicator of whether it's Visible or something else?

I like this -- though would we then always dump the ModuleOwnershipKind (i.e. 
causing a lot of churn, as discussed above) or only if it's 
`VisibleWhenImported` or `ModulePrivate` (i.e. not unconditionally visible)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81392



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


[clang] 2e92b39 - [clang] Rename Decl::isHidden() to isUnconditionallyVisible().

2020-06-12 Thread Martin Boehme via cfe-commits
Author: Martin Boehme
Date: 2020-06-12T09:33:42+02:00
New Revision: 2e92b397ae4bd846d34d151749ef09c1a1b81dab

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

LOG: [clang] Rename Decl::isHidden() to isUnconditionallyVisible().

Also invert the sense of the return value.

As pointed out by the FIXME that this change resolves, isHidden() wasn't
a very accurate name for this function.

I haven't yet changed any of the strings that are output in
ASTDumper.cpp / JSONNodeDumper.cpp / TextNodeDumper.cpp in response to
whether isHidden() is set because

a) I'm not sure whether it's actually desired to change these strings
   (would appreciate feedback on this), and

b) In any case, I'd like to get this pure rename out of the way first,
   without any changes to tests. Changing the strings that are output in
   the various ...Dumper.cpp files will require changes to quite a few
   tests, and I'd like to make those in a separate change.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclObjC.h
clang/include/clang/Sema/Lookup.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index da8b25b497b0..f66c5d0f8cd7 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -780,18 +780,19 @@ class alignas(8) Decl {
   /// all declarations in a global module fragment are unowned.
   Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const;
 
-  /// Determine whether this declaration might be hidden from name
-  /// lookup. Note that the declaration might be visible even if this returns
-  /// \c false, if the owning module is visible within the query context.
-  // FIXME: Rename this to make it clearer what it does.
-  bool isHidden() const {
-return (int)getModuleOwnershipKind() > (int)ModuleOwnershipKind::Visible;
+  /// Determine whether this declaration is definitely visible to name lookup,
+  /// independent of whether the owning module is visible.
+  /// Note: The declaration may be visible even if this returns \c false if the
+  /// owning module is visible within the query context. This is a low-level
+  /// helper function; most code should be calling Sema::isVisible() instead.
+  bool isUnconditionallyVisible() const {
+return (int)getModuleOwnershipKind() <= (int)ModuleOwnershipKind::Visible;
   }
 
   /// Set that this declaration is globally visible, even if it came from a
   /// module that is not visible.
   void setVisibleDespiteOwningModule() {
-if (isHidden())
+if (!isUnconditionallyVisible())
   setModuleOwnershipKind(ModuleOwnershipKind::Visible);
   }
 

diff  --git a/clang/include/clang/AST/DeclObjC.h 
b/clang/include/clang/AST/DeclObjC.h
index d48f8d55bf31..5613ed8370c0 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -2883,11 +2883,11 @@ 
ObjCInterfaceDecl::filtered_category_iterator::operator++() {
 }
 
 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
-  return !Cat->isHidden();
+  return Cat->isUnconditionallyVisible();
 }
 
 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
-  return Cat->IsClassExtension() && !Cat->isHidden();
+  return Cat->IsClassExtension() && Cat->isUnconditionallyVisible();
 }
 
 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {

diff  --git a/clang/include/clang/Sema/Lookup.h 
b/clang/include/clang/Sema/Lookup.h
index 0466d06d753b..c6edc2df5b9f 100644
--- a/clang/include/clang/Sema/Lookup.h
+++ b/clang/include/clang/Sema/Lookup.h
@@ -348,7 +348,7 @@ class LookupResult {
   /// program.
   static bool isVisible(Sema &SemaRef, NamedDecl *D) {
 // If this declaration is not hidden, it's visible.
-if (!D->isHidden())
+if (D->isUnconditionallyVisible())
   return true;
 
 // During template instantiation, we can refer to hidden declarations, if

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3416f339768f..266192087d35 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1862,7 +1862,7 @@ class Sema final {
 
   /// Determine whether a declaration is visible to name lookup.
   bool isVisible(const NamedDecl *D) {
-return !D->isHidden() || isVisibleSlow(D);
+return D->isUnconditionallyVi

[PATCH] D81691: [clangd] Set CWD in semaCodeComplete

2020-06-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81691



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


[PATCH] D81392: [clang] Rename Decl::isHidden() to isUnconditionallyVisible()

2020-06-12 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e92b397ae4b: [clang] Rename Decl::isHidden() to 
isUnconditionallyVisible(). (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81392

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTDumper.cpp
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -6057,7 +6057,7 @@
 void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) {
   if (Chain && Chain->isProcessingUpdateRecords()) return;
   assert(!WritingAST && "Already writing the AST!");
-  assert(D->isHidden() && "expected a hidden declaration");
+  assert(!D->isUnconditionallyVisible() && "expected a hidden declaration");
   DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M));
 }
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4038,7 +4038,7 @@
 void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) {
   assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?");
   for (Decl *D : Names) {
-bool wasHidden = D->isHidden();
+bool wasHidden = !D->isUnconditionallyVisible();
 D->setVisibleDespiteOwningModule();
 
 if (wasHidden && SemaObj) {
@@ -4100,9 +4100,9 @@
 /// visible.
 void ASTReader::mergeDefinitionVisibility(NamedDecl *Def,
   NamedDecl *MergedDef) {
-  if (Def->isHidden()) {
+  if (!Def->isUnconditionallyVisible()) {
 // If MergedDef is visible or becomes visible, make the definition visible.
-if (!MergedDef->isHidden())
+if (MergedDef->isUnconditionallyVisible())
   Def->setVisibleDespiteOwningModule();
 else {
   getContext().mergeDefinitionIntoModule(
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1710,7 +1710,8 @@
 /// path (by instantiating a template, you allow it to see the declarations that
 /// your module can see, including those later on in your module).
 bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) {
-  assert(D->isHidden() && "should not call this: not in slow case");
+  assert(!D->isUnconditionallyVisible() &&
+ "should not call this: not in slow case");
 
   Module *DeclModule = SemaRef.getOwningModule(D);
   assert(DeclModule && "hidden decl has no owning module");
Index: clang/lib/Sema/SemaDeclObjC.cpp
===
--- clang/lib/Sema/SemaDeclObjC.cpp
+++ clang/lib/Sema/SemaDeclObjC.cpp
@@ -1272,7 +1272,8 @@
 
 static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
   ObjCProtocolDecl *&UndefinedProtocol) {
-  if (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()) {
+  if (!PDecl->hasDefinition() ||
+  !PDecl->getDefinition()->isUnconditionallyVisible()) {
 UndefinedProtocol = PDecl;
 return true;
   }
@@ -3235,7 +3236,7 @@
 return false;
 
   // If either is hidden, it is not considered to match.
-  if (left->isHidden() || right->isHidden())
+  if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible())
 return false;
 
   if (left->isDirectMethod() != right->isDirectMethod())
@@ -3494,7 +3495,7 @@
   ObjCMethodList &MethList = InstanceFirst ? Pos->second.first :
  Pos->second.second;
   for (ObjCMethodList *M = &MethList; M; M = M->getNext())
-if (M->getMethod() && !M->getMethod()->isHidden()) {
+if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
   if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
 Methods.push_back(M->getMethod());
 }
@@ -3510,7 +3511,7 @@
   ObjCMethodList &MethList2 = InstanceFirst ? Pos->second.second :
   Pos->second.first;
   for (ObjCMethodList *M = &MethList2; M; M = M->getNext())
-if (M->getMethod() && !M->getMethod()->isHidden()) {
+if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
   if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
 Methods.push_back(M->getMethod());
 }
@@ -3557,7 +3558,7 @@
   ObjCMethodList &MethList = instance ? Pos->second.first : Pos->

[PATCH] D79155: [CodeGen] Increase applicability of ffine-grained-bitfield-accesses for targets with limited native integer widths

2020-06-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D79155#2088191 , @efriedma wrote:

> Please add a comment explaining what OffsetInRecord means; then LGTM.


Thanks. It's not easy to follow, but having stepped through it I agree with yu 
that it is the size in bits of the current run. I'll add that comment and 
commit.


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

https://reviews.llvm.org/D79155



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


[PATCH] D78024: [FileCheck] - Fix the false positive when -implicit-check-not is used with an unknown -check-prefix.

2020-06-12 Thread George Rimar via Phabricator via cfe-commits
grimar added a comment.

In D78024#2087800 , @Higuoxing wrote:

> > btw, do you know why FileCheck seems intentionally allows the case when 
> > --check-prefixes=KNOWN,UNKNOWN?
> >  I've mentioned in the description of D78110 
> >  that there are about 1000 tests that have 
> > this. but is it a feature or a something that we might want to fix?>
>
> I noticed this strange behavior of `FileCheck` as well. When I try to fix it, 
> there are lots of test failures. /subscribe


Yeah. To fix it we should prepare patches for those ~1000 tests in

> CodeGen/*
>  DebugInfo/X86/*
>  Instrumentation/*
>  Linker/*
>  MC/*
>  Other/*
>  Transforms/*

(and few other places) first. When I investigated them, I came to conclusion 
they just have unused prefixes
for no solid reason. I am not an expert in those folders/areas though. I  
thought about starting from a patch for one of those folders to see
if it will be approved without problems by people who work on the features 
there. But I had no chance to work on that yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78024



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


[PATCH] D81719: [clangd] Drop usage of PreambleStatCache in scanPreamble

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

It was used inside buildCompilerInvocation to speed up stats. But
preambleStatCache doesn't contain stat information performed while
building compiler invocation. So it was an unnecessary optimization.

This prepares the grounds for changing prepareCompilerInstance to take a
FSProvider instead of a VFS.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81719

Files:
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -207,35 +207,25 @@
 
 /// Scans the preprocessor directives in the preamble section of the file by
 /// running preprocessor over \p Contents. Returned includes do not contain
-/// resolved paths. \p VFS and \p Cmd is used to build the compiler invocation,
-/// which might stat/read files.
+/// resolved paths. \p Cmd is used to build the compiler invocation, which 
might
+/// stat/read files.
 llvm::Expected
-scanPreamble(llvm::StringRef Contents,
- llvm::IntrusiveRefCntPtr VFS,
+scanPreamble(llvm::StringRef Contents, const FileSystemProvider *FSProvider,
  const tooling::CompileCommand &Cmd) {
-  // FIXME: Change PreambleStatCache to operate on FileSystemProvider rather
-  // than vfs::FileSystem, that way we can just use ParseInputs without this
-  // hack.
-  auto GetFSProvider = [](llvm::IntrusiveRefCntPtr FS) {
-class VFSProvider : public FileSystemProvider {
+  auto EmptyFSProvider = [] {
+class EmptyProvider : public FileSystemProvider {
 public:
-  VFSProvider(llvm::IntrusiveRefCntPtr FS)
-  : VFS(std::move(FS)) {}
   llvm::IntrusiveRefCntPtr
   getFileSystem() const override {
-return VFS;
+return new llvm::vfs::InMemoryFileSystem;
   }
-
-private:
-  const llvm::IntrusiveRefCntPtr VFS;
 };
-return std::make_unique(std::move(FS));
+return std::make_unique();
   };
-  auto FSProvider = GetFSProvider(std::move(VFS));
   // Build and run Preprocessor over the preamble.
   ParseInputs PI;
   PI.Contents = Contents.str();
-  PI.FSProvider = FSProvider.get();
+  PI.FSProvider = FSProvider;
   PI.CompileCommand = Cmd;
   IgnoringDiagConsumer IgnoreDiags;
   auto CI = buildCompilerInvocation(PI, IgnoreDiags);
@@ -255,7 +245,7 @@
   std::move(CI), nullptr, std::move(PreambleContents),
   // Provide an empty FS to prevent preprocessor from performing IO. This
   // also implies missing resolved paths for includes.
-  new llvm::vfs::InMemoryFileSystem, IgnoreDiags);
+  EmptyFSProvider()->getFileSystem(), IgnoreDiags);
   if (Clang->getFrontendOpts().Inputs.empty())
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"compiler instance had no inputs");
@@ -409,8 +399,6 @@
   trace::Span Tracer("CreatePreamblePatch");
   SPAN_ATTACH(Tracer, "File", FileName);
   assert(llvm::sys::path::is_absolute(FileName) && "relative FileName!");
-  auto VFS =
-  Baseline.StatCache->getConsumingFS(Modified.FSProvider->getFileSystem());
   // First scan preprocessor directives in Baseline and Modified. These will be
   // used to figure out newly added directives in Modified. Scanning can fail,
   // the code just bails out and creates an empty patch in such cases, as:
@@ -421,14 +409,15 @@
   //   there's nothing to do but generate an empty patch.
   auto BaselineScan = scanPreamble(
   // Contents needs to be null-terminated.
-  Baseline.Preamble.getContents().str(), VFS, Modified.CompileCommand);
+  Baseline.Preamble.getContents().str(), Modified.FSProvider,
+  Modified.CompileCommand);
   if (!BaselineScan) {
 elog("Failed to scan baseline of {0}: {1}", FileName,
  BaselineScan.takeError());
 return PreamblePatch::unmodified(Baseline);
   }
-  auto ModifiedScan =
-  scanPreamble(Modified.Contents, std::move(VFS), Modified.CompileCommand);
+  auto ModifiedScan = scanPreamble(Modified.Contents, Modified.FSProvider,
+   Modified.CompileCommand);
   if (!ModifiedScan) {
 elog("Failed to scan modified contents of {0}: {1}", FileName,
  ModifiedScan.takeError());


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -207,35 +207,25 @@
 
 /// Scans the preprocessor directives in the preamble section of the file by
 /// running preprocessor over \p Contents. Returned includes do not contain
-/// resolved paths. \p VFS and \p Cmd is used to build the compiler invocation,
-/// which might stat/read files.
+/// resolved paths. \p C

[PATCH] D81718: [Analyzer][NFC] Add methods `getReturnObject()` and `getArgObject()` to `CallEvent`

2020-06-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: NoQ.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, martong, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, 
szepet, xazax.hun, whisperity, mgorny.
Herald added a reviewer: Szelethus.

There are cases when a checker cannot know in advance the nature of the return 
value they try to retrieve from a `CallEvent`. If it is a class instance then 
it must use `getReturnValueUnderConstruction()`. If it is not, then it must use 
`getReturnValue()`, because the former function returns `None` since only class 
instances have construction context.

Simlarly, arguments which are class instances passed by value are 
copy-constructed into the parameter. To retrieve them the checker needs to 
invoke `getParameterLocation()` instead of `getArgSVal()`. However, for basic 
types and class instances passed by pointer of reference only the latter can be 
used to track the value of the argument.

To save checkers from doing these branching all over the time this patch 
introduces two methods to `CallEvent`: `getReturnObject()` to get the correct 
return value and `getArgObject()` to get the correct argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81718

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/TestParameterLocation.cpp
  clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp

Index: clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
===
--- clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
+++ clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp
@@ -23,18 +23,46 @@
   : public Checker {
 public:
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const {
-// Only calls with origin expression are checked. These are `returnC()`
-// and C::C().
-if (!Call.getOriginExpr())
+const IdentifierInfo *ID = Call.getCalleeIdentifier();
+if (!ID)
   return;
 
-// Since `returnC` returns an object by value, the invocation results
-// in an object of type `C` constructed into variable `c`. Thus the
-// return value of `CallEvent::getReturnValueUnderConstruction()` must
-// be non-empty and has to be a `MemRegion`.
-Optional RetVal = Call.getReturnValueUnderConstruction();
-ASSERT_TRUE(RetVal);
-ASSERT_TRUE(RetVal->getAsRegion());
+SVal RetVal = Call.getReturnValue();
+Optional RetValUC = Call.getReturnValueUnderConstruction();
+SVal RetObj = Call.getReturnObject();
+
+if (ID->getName() == "returnC") {
+  // Since `returnC` returns an object by value, the invocation results
+  // in an object of type `C` constructed into variable `c`. Thus the
+  // return value of `CallEvent::getReturnValueUnderConstruction()` must
+  // be non-empty and has to be a `MemRegion`.
+  ASSERT_TRUE(RetValUC);
+  ASSERT_TRUE(RetValUC->getAsRegion());
+
+  // In this case `CallEvent::getReturnValue()` returns a `LazyCompoundVal`.
+  ASSERT_TRUE(RetVal.getAs().hasValue());
+
+  // The result of `CallEvent::getReturnObject()` is the same as the result
+  // of `CallEvent::getReturnValueUnderConstruction()`.
+  ASSERT_TRUE(RetObj == *RetValUC);
+  return;
+}
+
+if (ID->getName() == "returnVoidPtr") {
+  // Since `returnVoidPtr` returns a basic value (pointer), it has no
+  // consturcion context.
+  ASSERT_FALSE(RetValUC);
+
+  // In this case `CallEvent::getReturnValue()` returns a `MemRegion`.
+  ASSERT_TRUE(RetVal.getAsRegion());
+
+  // The result of `CallEvent::getReturnObject()` is the same as the result
+  // of `CallEvent::getReturnValueUnderConstruction()`.
+  ASSERT_TRUE(RetObj == RetVal);
+  return;
+}
+
+llvm_unreachable("Unknown callee.");
   }
 };
 
@@ -64,8 +92,13 @@
return c;
  }
 
+ void *returnVoidPtr(int m) {
+   return &m;
+ }
+
  void foo() {
C c = returnC(1); 
+   void *vp = returnVoidPtr(1); 
  })"));
 }
 
Index: clang/unittests/StaticAnalyzer/TestParameterLocation.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/TestParameterLocation.cpp
@@ -0,0 +1,143 @@
+//===- unittests/StaticAnalyzer/TestParameterLocation.cpp -===//
+//
+// 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-ex

[PATCH] D81721: [SVE] Ensure proper mangling of ACLE tuple types

2020-06-12 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen created this revision.
sdesmalen added reviewers: rsandifo-arm, c-rhodes, efriedma.
Herald added subscribers: cfe-commits, psnobl, rkruppe, kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
sdesmalen added a parent revision: D81459: [SveEmitter] Add SVE tuple types and 
builtins for svundef..

The AAPCS specifies that the tuple types such as `svint32x2_t`
should use their `arm_sve.h` names when mangled instead of their
builtin names.

  

This patch also renames the internal types for the tuples to
be prefixed with `__clang_`, so they are not misinterpreted as
specified internal types like the non-tuple types which *are* defined
in the AAPCS. Using a builtin type for the tuples is a purely
a choice of the Clang implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81721

Files:
  clang/include/clang/Basic/AArch64SVEACLETypes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -1069,39 +1069,39 @@
   OS << "typedef __SVFloat16_t svfloat16_t;\n";
   OS << "typedef __SVFloat32_t svfloat32_t;\n";
   OS << "typedef __SVFloat64_t svfloat64_t;\n";
-  OS << "typedef __SVInt8x2_t svint8x2_t;\n";
-  OS << "typedef __SVInt16x2_t svint16x2_t;\n";
-  OS << "typedef __SVInt32x2_t svint32x2_t;\n";
-  OS << "typedef __SVInt64x2_t svint64x2_t;\n";
-  OS << "typedef __SVUint8x2_t svuint8x2_t;\n";
-  OS << "typedef __SVUint16x2_t svuint16x2_t;\n";
-  OS << "typedef __SVUint32x2_t svuint32x2_t;\n";
-  OS << "typedef __SVUint64x2_t svuint64x2_t;\n";
-  OS << "typedef __SVFloat16x2_t svfloat16x2_t;\n";
-  OS << "typedef __SVFloat32x2_t svfloat32x2_t;\n";
-  OS << "typedef __SVFloat64x2_t svfloat64x2_t;\n";
-  OS << "typedef __SVInt8x3_t svint8x3_t;\n";
-  OS << "typedef __SVInt16x3_t svint16x3_t;\n";
-  OS << "typedef __SVInt32x3_t svint32x3_t;\n";
-  OS << "typedef __SVInt64x3_t svint64x3_t;\n";
-  OS << "typedef __SVUint8x3_t svuint8x3_t;\n";
-  OS << "typedef __SVUint16x3_t svuint16x3_t;\n";
-  OS << "typedef __SVUint32x3_t svuint32x3_t;\n";
-  OS << "typedef __SVUint64x3_t svuint64x3_t;\n";
-  OS << "typedef __SVFloat16x3_t svfloat16x3_t;\n";
-  OS << "typedef __SVFloat32x3_t svfloat32x3_t;\n";
-  OS << "typedef __SVFloat64x3_t svfloat64x3_t;\n";
-  OS << "typedef __SVInt8x4_t svint8x4_t;\n";
-  OS << "typedef __SVInt16x4_t svint16x4_t;\n";
-  OS << "typedef __SVInt32x4_t svint32x4_t;\n";
-  OS << "typedef __SVInt64x4_t svint64x4_t;\n";
-  OS << "typedef __SVUint8x4_t svuint8x4_t;\n";
-  OS << "typedef __SVUint16x4_t svuint16x4_t;\n";
-  OS << "typedef __SVUint32x4_t svuint32x4_t;\n";
-  OS << "typedef __SVUint64x4_t svuint64x4_t;\n";
-  OS << "typedef __SVFloat16x4_t svfloat16x4_t;\n";
-  OS << "typedef __SVFloat32x4_t svfloat32x4_t;\n";
-  OS << "typedef __SVFloat64x4_t svfloat64x4_t;\n";
+  OS << "typedef __clang_svint8x2_t svint8x2_t;\n";
+  OS << "typedef __clang_svint16x2_t svint16x2_t;\n";
+  OS << "typedef __clang_svint32x2_t svint32x2_t;\n";
+  OS << "typedef __clang_svint64x2_t svint64x2_t;\n";
+  OS << "typedef __clang_svuint8x2_t svuint8x2_t;\n";
+  OS << "typedef __clang_svuint16x2_t svuint16x2_t;\n";
+  OS << "typedef __clang_svuint32x2_t svuint32x2_t;\n";
+  OS << "typedef __clang_svuint64x2_t svuint64x2_t;\n";
+  OS << "typedef __clang_svfloat16x2_t svfloat16x2_t;\n";
+  OS << "typedef __clang_svfloat32x2_t svfloat32x2_t;\n";
+  OS << "typedef __clang_svfloat64x2_t svfloat64x2_t;\n";
+  OS << "typedef __clang_svint8x3_t svint8x3_t;\n";
+  OS << "typedef __clang_svint16x3_t svint16x3_t;\n";
+  OS << "typedef __clang_svint32x3_t svint32x3_t;\n";
+  OS << "typedef __clang_svint64x3_t svint64x3_t;\n";
+  OS << "typedef __clang_svuint8x3_t svuint8x3_t;\n";
+  OS << "typedef __clang_svuint16x3_t svuint16x3_t;\n";
+  OS << "typedef __clang_svuint32x3_t svuint32x3_t;\n";
+  OS << "typedef __clang_svuint64x3_t svuint64x3_t;\n";
+  OS << "typedef __clang_svfloat16x3_t svfloat16x3_t;\n";
+  OS << "typedef __clang_svfloat32x3_t svfloat32x3_t;\n";
+  OS << "typedef __clang_svfloat64x3_t svfloat64x3_t;\n";
+  OS << "typedef __clang_svint8x4_t svint8x4_t;\n";
+  OS << "typedef __clang_svint16x4_t svint16x4_t;\n";
+  OS << "typedef __clang_svint32x4_t svint32x4_t;\n";
+  OS << "typedef __clang_svint64x4_t svint64x4_t;\n";
+  OS << "typedef __clang_svuint8x4_t svuint8x4_t;\n";
+  OS << "typedef __clang_svuint16x4_t svuint16x4_t;\n";
+  OS << "typedef __clang_svuint32x4_t svuint32x4_t;\n";
+  OS << "typedef __clang_svuint64x4_t svuint64x4_t;\n";
+  OS << "typedef __clang_svfloat16x4_t svfloat16x4_t;\n";
+  OS << "typedef __clang_svfloat32x4_t svfloat32x4_t;\n";
+  OS << "typedef __clang_svfloat64x4_t svfloat64x4_t;\n";
   OS << "typedef __SVBoo

[PATCH] D81720: [clangd] Change prepareCompilerInstance to take an FSProvider

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

This makes API easier to use by moving setcwd and fscache setup into it.
Also ensures no side effects are observable on the VFS used by the
compiler instance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81720

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -70,11 +70,12 @@
   // We don't run PP directly over the patch cotents to test production
   // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
-  auto Clang =
-  prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
-  llvm::MemoryBuffer::getMemBufferCopy(
-  ModifiedContents.slice(0, Bounds.Size).str()),
-  PI.FSProvider->getFileSystem(), Diags);
+  auto Clang = prepareCompilerInstance(
+  std::move(CI),
+  llvm::MemoryBuffer::getMemBufferCopy(
+  ModifiedContents.slice(0, Bounds.Size).str()),
+  Diags, PI.CompileCommand, PI.FSProvider, &BaselinePreamble->Preamble,
+  BaselinePreamble->StatCache.get());
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -52,12 +52,12 @@
 EXPECT_TRUE(static_cast(CI));
 // The diagnostic options must be set before creating a CompilerInstance.
 CI->getDiagnosticOpts().IgnoreWarnings = true;
-auto VFS = FS.getFileSystem();
-VFS->setCurrentWorkingDirectory(Cmd->Directory);
 auto Clang = prepareCompilerInstance(
-std::move(CI), /*Preamble=*/nullptr,
+std::move(CI),
 llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile),
-std::move(VFS), IgnoreDiags);
+IgnoreDiags, *Cmd, &FS,
+/*Preamble=*/nullptr,
+/*FSCache=*/nullptr);
 
 EXPECT_FALSE(Clang->getFrontendOpts().Inputs.empty());
 return Clang;
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -242,11 +242,9 @@
 llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) {
   trace::Span Tracer("BackgroundIndex");
   SPAN_ATTACH(Tracer, "file", Cmd.Filename);
-  auto AbsolutePath = getAbsolutePath(Cmd);
 
-  auto FS = FSProvider.getFileSystem();
-  FS->setCurrentWorkingDirectory(Cmd.Directory);
-  auto Buf = FS->getBufferForFile(AbsolutePath);
+  auto AbsolutePath = getAbsolutePath(Cmd);
+  auto Buf = FSProvider.getFileSystem()->getBufferForFile(AbsolutePath);
   if (!Buf)
 return llvm::errorCodeToError(Buf.getError());
   auto Hash = digest(Buf->get()->getBuffer());
@@ -269,8 +267,10 @@
"Couldn't build compiler invocation");
 
   auto Clang =
-  prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
-  std::move(*Buf), std::move(FS), IgnoreDiags);
+  prepareCompilerInstance(std::move(CI), std::move(*Buf), IgnoreDiags,
+  Inputs.CompileCommand, &FSProvider,
+  /*Preamble=*/nullptr,
+  /*FSCache=*/nullptr);
   if (!Clang)
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Couldn't build compiler instance");
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -242,10 +242,10 @@
   auto PreambleContents =
   llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
   auto Clang = prepareCompilerInstance(
-  std::move(CI), nullptr, std::move(PreambleContents),
+  std::move(CI), std::move(PreambleContents), IgnoreDiags, Cmd,
   // Provide an empty FS to prevent preprocessor from performing IO. This
   // also implies missing resolved pa

[PATCH] D81721: [SVE] Ensure proper mangling of ACLE tuple types

2020-06-12 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

See 
https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-c-mangling
 for details on the mangling rules.

I thought it would be easier to review if I kept these changes separate from 
D81459 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81721



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


[PATCH] D81474: Handle delayed-template-parsing functions imported into a non-dtp TU

2020-06-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks for reviewing! Going to land this now as the bug is surfaced by other 
pending changes.

In D81474#2087095 , @kadircet wrote:

> Looking at this some more, it looks like whenever clang is building a TU 
> prefix(preamble), the assumption is that any delayed templates will be parsed 
> at the end of the TU. That is unfortunately not true, if the rest of the TU 
> is built with no-delayed-template-parsing. (as you've already said in the 
> description)
>
> This suggests that DelayedTemplateParsing shouldn't be a benign langopt. But 
> since it is, we should be setting late template parser at the end of TU if 
> there are any delayed templates coming from either the preamble or in the 
> rest of the TU.
>  The latter is already done by checking for langopt, we can check for the 
> former using `Actions.ExternalSemaSource`. But in the absence of delayed 
> templates, setting the parser is (currently) a no-op. So setting it all the 
> time should hopefully be OK.
>  Hence LGTM.


Yeah I think checking ExternalSemaSource is probably correct. Not checking it 
is simpler though :-)

> Another option would be to change preamble building logic to parse all the 
> late parsed templates at the end, instead of just serializing the tokens. 
> That sounds like a more intrusive change though, so I am more comfortable 
> with current one.

This has different semantics - the point of delayed template parsing is to wait 
for more symbols to be visible. If we parse at the end of the PCH, then symbols 
defined in the main file (but before instantiation) are not visible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81474



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


[PATCH] D81428: [ARM] Moving CMSE handling of half arguments and return to the backend

2020-06-12 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard accepted this revision.
ostannard added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81428



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


[PATCH] D81242: [StackSafety] Run ThinLTO

2020-06-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 270328.
vitalybuka marked 5 inline comments as done.
vitalybuka added a comment.

@eugenis review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81242

Files:
  clang/test/Driver/memtag_lto.c
  llvm/include/llvm/Analysis/StackSafetyAnalysis.h
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
  llvm/test/Analysis/StackSafetyAnalysis/ipa.ll

Index: llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
===
--- llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
+++ llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
@@ -10,6 +10,111 @@
 ; RUN: opt -S -analyze -stack-safety %t.combined.bc | FileCheck %s --check-prefixes=CHECK,GLOBAL,NOLTO
 ; RUN: opt -S -passes="print-stack-safety" -disable-output %t.combined.bc 2>&1 | FileCheck %s --check-prefixes=CHECK,GLOBAL,NOLTO
 
+; Do an end-to-test using the new LTO API
+; TODO: Hideous llvm-lto2 invocation, add a --default-symbol-resolution to llvm-lto2?
+; RUN: opt -module-summary %s -o %t.summ0.bc
+; RUN: opt -module-summary %S/Inputs/ipa.ll -o %t.summ1.bc
+
+; RUN: llvm-lto2 run %t.summ0.bc %t.summ1.bc -o %t.lto -stack-safety-print -stack-safety-run -save-temps -thinlto-threads 1 -O0 \
+; RUN:  -r %t.summ0.bc,Write1, \
+; RUN:  -r %t.summ0.bc,Write4, \
+; RUN:  -r %t.summ0.bc,Write4_2, \
+; RUN:  -r %t.summ0.bc,Write8, \
+; RUN:  -r %t.summ0.bc,WriteAndReturn8, \
+; RUN:  -r %t.summ0.bc,TestUpdateArg,px \
+; RUN:  -r %t.summ0.bc,ExternalCall, \
+; RUN:  -r %t.summ0.bc,PreemptableWrite1, \
+; RUN:  -r %t.summ0.bc,InterposableWrite1, \
+; RUN:  -r %t.summ0.bc,ReturnDependent, \
+; RUN:  -r %t.summ0.bc,Rec2, \
+; RUN:  -r %t.summ0.bc,RecursiveNoOffset, \
+; RUN:  -r %t.summ0.bc,RecursiveWithOffset, \
+; RUN:  -r %t.summ0.bc,f1,px \
+; RUN:  -r %t.summ0.bc,f2,px \
+; RUN:  -r %t.summ0.bc,f3,px \
+; RUN:  -r %t.summ0.bc,f4,px \
+; RUN:  -r %t.summ0.bc,f5,px \
+; RUN:  -r %t.summ0.bc,f6,px \
+; RUN:  -r %t.summ0.bc,PreemptableCall,px \
+; RUN:  -r %t.summ0.bc,InterposableCall,px \
+; RUN:  -r %t.summ0.bc,PrivateCall,px \
+; RUN:  -r %t.summ0.bc,f7,px \
+; RUN:  -r %t.summ0.bc,f8left,px \
+; RUN:  -r %t.summ0.bc,f8right,px \
+; RUN:  -r %t.summ0.bc,f8oobleft,px \
+; RUN:  -r %t.summ0.bc,f8oobright,px \
+; RUN:  -r %t.summ0.bc,TwoArguments,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBOne,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBOther,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBBoth,px \
+; RUN:  -r %t.summ0.bc,TestRecursiveNoOffset,px \
+; RUN:  -r %t.summ0.bc,TestRecursiveWithOffset,px \
+; RUN:  -r %t.summ1.bc,Write1,px \
+; RUN:  -r %t.summ1.bc,Write4,px \
+; RUN:  -r %t.summ1.bc,Write4_2,px \
+; RUN:  -r %t.summ1.bc,Write8,px \
+; RUN:  -r %t.summ1.bc,WriteAndReturn8,px \
+; RUN:  -r %t.summ1.bc,ExternalCall,px \
+; RUN:  -r %t.summ1.bc,PreemptableWrite1,px \
+; RUN:  -r %t.summ1.bc,InterposableWrite1,px \
+; RUN:  -r %t.summ1.bc,ReturnDependent,px \
+; RUN:  -r %t.summ1.bc,Rec0,px \
+; RUN:  -r %t.summ1.bc,Rec1,px \
+; RUN:  -r %t.summ1.bc,Rec2,px \
+; RUN:  -r %t.summ1.bc,RecursiveNoOffset,px \
+; RUN:  -r %t.summ1.bc,RecursiveWithOffset,px \
+; RUN:  -r %t.summ1.bc,ReturnAlloca,px 2>&1 | FileCheck %s --check-prefixes=CHECK,GLOBAL,LTO
+
+; RUN: llvm-lto2 run %t.summ0.bc %t.summ1.bc -o %t-newpm.lto -use-new-pm -stack-safety-print -stack-safety-run -save-temps -thinlto-threads 1 -O0 \
+; RUN:  -r %t.summ0.bc,Write1, \
+; RUN:  -r %t.summ0.bc,Write4, \
+; RUN:  -r %t.summ0.bc,Write4_2, \
+; RUN:  -r %t.summ0.bc,Write8, \
+; RUN:  -r %t.summ0.bc,WriteAndReturn8, \
+; RUN:  -r %t.summ0.bc,TestUpdateArg,px \
+; RUN:  -r %t.summ0.bc,ExternalCall, \
+; RUN:  -r %t.summ0.bc,PreemptableWrite1, \
+; RUN:  -r %t.summ0.bc,InterposableWrite1, \
+; RUN:  -r %t.summ0.bc,ReturnDependent, \
+; RUN:  -r %t.summ0.bc,Rec2, \
+; RUN:  -r %t.summ0.bc,RecursiveNoOffset, \
+; RUN:  -r %t.summ0.bc,RecursiveWithOffset, \
+; RUN:  -r %t.summ0.bc,f1,px \
+; RUN:  -r %t.summ0.bc,f2,px \
+; RUN:  -r %t.summ0.bc,f3,px \
+; RUN:  -r %t.summ0.bc,f4,px \
+; RUN:  -r %t.summ0.bc,f5,px \
+; RUN:  -r %t.summ0.bc,f6,px \
+; RUN:  -r %t.summ0.bc,PreemptableCall,px \
+; RUN:  -r %t.summ0.bc,InterposableCall,px \
+; RUN:  -r %t.summ0.bc,PrivateCall,px \
+; RUN:  -r %t.summ0.bc,f7,px \
+; RUN:  -r %t.summ0.bc,f8left,px \
+; RUN:  -r %t.summ0.bc,f8right,px \
+; RUN:  -r %t.summ0.bc,f8oobleft,px \
+; RUN:  -r %t.summ0.bc,f8oobright,px \
+; RUN:  -r %t.summ0.bc,TwoArguments,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBOne,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBOther,px \
+; RUN:  -r %t.summ0.bc,TwoArgumentsOOBBoth,px \
+; RUN:  -r %t.summ0.bc,TestRecursiveNoOffset,px \
+; RUN:  -r %t.summ0.bc,TestRecursiveWithOffset,px \
+; RUN:  -r %t.summ1.bc,Write1,px \
+; RUN:  -r %t.summ1.bc,Write4,px \
+; RUN:  -r %t.summ1.bc,Write4_2,px \
+; RUN:  -r %t.summ1.bc,Write8,px \
+; R

[PATCH] D81242: [StackSafety] Run ThinLTO

2020-06-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Analysis/StackSafetyAnalysis.cpp:618
+ConstantRange Access = Found->sextOrTrunc(Use.Range.getBitWidth());
+if (Access.signedAddMayOverflow(C.Offset) !=
+ConstantRange::OverflowResult::NeverOverflows)

eugenis wrote:
> Do we have a test for this overflow check?
yes
Example, in bit width 8
[-128,-127)+[-128,-127) = [0,1)
both non-wrapped and result is non-wrapped so we have no way to spot overflow



Comment at: llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll:55
+; RUN:  -r %t.summ1.bc,Write1,px 2>&1 | FileCheck %s 
--check-prefixes=CHECK,GLOBAL,LTO
+
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"

eugenis wrote:
> For my education - how do you come up with these symbol lists?
it complains about each missing  pair
then flags guess and try



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81242



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


[clang] 3dcfd48 - [CodeGen] Increase applicability of ffine-grained-bitfield-accesses for targets with limited native integer widths

2020-06-12 Thread Alex Bradbury via cfe-commits
Author: Alex Bradbury
Date: 2020-06-12T10:33:47+01:00
New Revision: 3dcfd482cb17fad2d641c976b822d1fe36dc1359

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

LOG: [CodeGen] Increase applicability of ffine-grained-bitfield-accesses for 
targets with limited native integer widths

As pointed out in PR45708, -ffine-grained-bitfield-accesses doesn't
trigger in all cases you think it might for RISC-V. The logic in
CGRecordLowering::accumulateBitFields checks OffsetInRecord is a legal
integer according to the datalayout. RISC targets will typically only
have the native width as a legal integer type so this check will fail
for OffsetInRecord of 8 or 16 when you would expect the transformation
is still worthwhile.

This patch changes the logic to check for an OffsetInRecord of a at
least 1 byte, that fits in a legal integer, and is a power of 2. We
would prefer to query whether native load/store operations are
available, but I don't believe that is possible.

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

Added: 


Modified: 
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
clang/test/CodeGenCXX/finegrain-bitfield-type.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index c9a1b1d4fd14..4e5d1d3f16f6 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -406,15 +406,17 @@ 
CGRecordLowering::accumulateBitFields(RecordDecl::field_iterator Field,
 return;
   }
 
-  // Check if OffsetInRecord is better as a single field run. When 
OffsetInRecord
-  // has legal integer width, and its bitfield offset is naturally aligned, it
-  // is better to make the bitfield a separate storage component so as it can 
be
-  // accessed directly with lower cost.
+  // Check if OffsetInRecord (the size in bits of the current run) is better
+  // as a single field run. When OffsetInRecord has legal integer width, and
+  // its bitfield offset is naturally aligned, it is better to make the
+  // bitfield a separate storage component so as it can be accessed directly
+  // with lower cost.
   auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord,
   uint64_t StartBitOffset) {
 if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses)
   return false;
-if (!DataLayout.isLegalInteger(OffsetInRecord))
+if (OffsetInRecord < 8 || !llvm::isPowerOf2_64(OffsetInRecord) ||
+!DataLayout.fitsInLegalInteger(OffsetInRecord))
   return false;
 // Make sure StartBitOffset is natually aligned if it is treated as an
 // IType integer.

diff  --git a/clang/test/CodeGenCXX/finegrain-bitfield-type.cpp 
b/clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
index ff02d46de5e4..2106a6d3e0a9 100644
--- a/clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
+++ b/clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
@@ -1,5 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffine-grained-bitfield-accesses \
 // RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -ffine-grained-bitfield-accesses \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// Note: This test checks the X86-64 and RISC-V targets in order to explore
+// behaviour when i8/i16 are native integer widths (X86-64) and when they're
+// not (RISC-V).
+
 struct S4 {
   unsigned long f1:28;
   unsigned long f2:4;
@@ -19,4 +26,4 @@ struct S5 a5;
 // CHECK: %struct.S4 = type { i32, i16 }
 // CHECK-NOT: %struct.S4 = type { i48 }
 // CHECK: %struct.S5 = type { i32, i32, i16, [6 x i8] }
-// CHECK-NOT: %struct.S5 = type { i80 }
\ No newline at end of file
+// CHECK-NOT: %struct.S5 = type { i80 }



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


[PATCH] D77229: [Analyzer] Avoid handling of LazyCompundVals in IteratorModeling

2020-06-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 270335.
baloghadamsoftware retitled this revision from "[Analyzer][WIP] Avoid handling 
of LazyCompundVals in IteratorModeling" to "[Analyzer] Avoid handling of 
LazyCompundVals in IteratorModeling".
baloghadamsoftware edited the summary of this revision.
baloghadamsoftware added a comment.

Rebased to previous patches and updated according to them.


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

https://reviews.llvm.org/D77229

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/InvalidatedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
  clang/test/Analysis/iterator-modeling.cpp

Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -1862,7 +1862,7 @@
 void clang_analyzer_printState();
 
 void print_state(std::vector &V) {
-  const auto i0 = V.cbegin();
+  auto i0 = V.cbegin();
   clang_analyzer_printState();
 
 // CHECK:  "checker_messages": [
@@ -1871,12 +1871,15 @@
 // CHECK-NEXT: "i0 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
 
-  const auto i1 = V.cend();
+  ++i0;
+  auto i1 = V.cend();
   clang_analyzer_printState();
-  
+
 // CHECK:  "checker_messages": [
 // CHECK:   { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
 // CHECK-NEXT: "Iterator Positions :",
 // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
+
+  --i1;
 }
Index: clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
@@ -24,12 +24,12 @@
 namespace {
 
 class STLAlgorithmModeling : public Checker {
-  bool evalFind(CheckerContext &C, const CallExpr *CE) const;
+  void evalFind(CheckerContext &C, const CallExpr *CE, SVal Begin,
+SVal End) const;
 
-  void Find(CheckerContext &C, const CallExpr *CE, unsigned paramNum) const;
-
-  using FnCheck = bool (STLAlgorithmModeling::*)(CheckerContext &,
-const CallExpr *) const;
+  using FnCheck = void (STLAlgorithmModeling::*)(CheckerContext &,
+ const CallExpr *, SVal Begin,
+ SVal End) const;
 
   const CallDescriptionMap Callbacks = {
 {{{"std", "find"}, 3}, &STLAlgorithmModeling::evalFind},
@@ -67,51 +67,53 @@
 
 bool STLAlgorithmModeling::evalCall(const CallEvent &Call,
 CheckerContext &C) const {
-  const auto *CE = dyn_cast_or_null(Call.getOriginExpr());
-  if (!CE)
-return false;
-
-  const FnCheck *Handler = Callbacks.lookup(Call);
-  if (!Handler)
-return false;
-
-  return (this->**Handler)(C, CE);
-}
-
-bool STLAlgorithmModeling::evalFind(CheckerContext &C,
-const CallExpr *CE) const {
   // std::find()-like functions either take their primary range in the first
   // two parameters, or if the first parameter is "execution policy" then in
   // the second and third. This means that the second parameter must always be
   // an iterator.
-  if (!isIteratorType(CE->getArg(1)->getType()))
+  if (Call.getNumArgs() < 2 || !isIteratorType(Call.getArgExpr(1)->getType()))
 return false;
 
+  unsigned ArgNum = 999;
+
   // If no "execution policy" parameter is used then the first argument is the
   // beginning of the range.
-  if (isIteratorType(CE->getArg(0)->getType())) {
-Find(C, CE, 0);
-return true;
+  if (isIteratorType(Call.getArgExpr(0)->getType())) {
+ArgNum = 0;
   }
 
   // If "execution policy" parameter is used then the second argument is the
   // beginning of the range.
-  if (isIteratorType(CE->getArg(2)->getType())) {
-Find(C, CE, 1);
-return true;
+  if (ArgNum > 0 &&
+  Call.getNumArgs() > 2 && isIteratorType(Call.getArgExpr(2)->getType())) {
+ArgNum = 1;
   }
 
-  return false;
+  if (ArgNum == 999)
+return false;
+
+  SVal ArgB = Call.getArgObject(ArgNum, C.blockCount());
+  SVal ArgE = Call.getArgObject(ArgNum + 1, C.blockCount());
+
+  const auto *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return false;
+
+  const FnCheck *Handler = Callbacks.lookup(Call);
+  if (!Handler)
+return false;
+
+  (this->**Handler)(C, CE, ArgB, ArgE);
+  retur

[PATCH] D81720: [clangd] Change prepareCompilerInstance to take an FSProvider

2020-06-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 270333.
kadircet added a comment.

- Use Cmd.Directory when creating includefixer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81720

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -70,11 +70,12 @@
   // We don't run PP directly over the patch cotents to test production
   // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
-  auto Clang =
-  prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
-  llvm::MemoryBuffer::getMemBufferCopy(
-  ModifiedContents.slice(0, Bounds.Size).str()),
-  PI.FSProvider->getFileSystem(), Diags);
+  auto Clang = prepareCompilerInstance(
+  std::move(CI),
+  llvm::MemoryBuffer::getMemBufferCopy(
+  ModifiedContents.slice(0, Bounds.Size).str()),
+  Diags, PI.CompileCommand, PI.FSProvider, &BaselinePreamble->Preamble,
+  BaselinePreamble->StatCache.get());
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -52,12 +52,12 @@
 EXPECT_TRUE(static_cast(CI));
 // The diagnostic options must be set before creating a CompilerInstance.
 CI->getDiagnosticOpts().IgnoreWarnings = true;
-auto VFS = FS.getFileSystem();
-VFS->setCurrentWorkingDirectory(Cmd->Directory);
 auto Clang = prepareCompilerInstance(
-std::move(CI), /*Preamble=*/nullptr,
+std::move(CI),
 llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile),
-std::move(VFS), IgnoreDiags);
+IgnoreDiags, *Cmd, &FS,
+/*Preamble=*/nullptr,
+/*FSCache=*/nullptr);
 
 EXPECT_FALSE(Clang->getFrontendOpts().Inputs.empty());
 return Clang;
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -243,9 +243,7 @@
   trace::Span Tracer("BackgroundIndex");
   SPAN_ATTACH(Tracer, "file", Cmd.Filename);
   auto AbsolutePath = getAbsolutePath(Cmd);
-
   auto FS = FSProvider.getFileSystem();
-  FS->setCurrentWorkingDirectory(Cmd.Directory);
   auto Buf = FS->getBufferForFile(AbsolutePath);
   if (!Buf)
 return llvm::errorCodeToError(Buf.getError());
@@ -269,8 +267,10 @@
"Couldn't build compiler invocation");
 
   auto Clang =
-  prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
-  std::move(*Buf), std::move(FS), IgnoreDiags);
+  prepareCompilerInstance(std::move(CI), std::move(*Buf), IgnoreDiags,
+  Inputs.CompileCommand, &FSProvider,
+  /*Preamble=*/nullptr,
+  /*FSCache=*/nullptr);
   if (!Clang)
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"Couldn't build compiler instance");
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -242,10 +242,10 @@
   auto PreambleContents =
   llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
   auto Clang = prepareCompilerInstance(
-  std::move(CI), nullptr, std::move(PreambleContents),
+  std::move(CI), std::move(PreambleContents), IgnoreDiags, Cmd,
   // Provide an empty FS to prevent preprocessor from performing IO. This
   // also implies missing resolved paths for includes.
-  EmptyFSProvider()->getFileSystem(), IgnoreDiags);
+  EmptyFSProvider().get(), nullptr, nullptr);
   if (Clang->getFrontendOpts().Inputs.empty())
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"compiler instance had no inputs");
Index: clang-tools-extra/clangd/ParsedAST.h
=

[PATCH] D79155: [CodeGen] Increase applicability of ffine-grained-bitfield-accesses for targets with limited native integer widths

2020-06-12 Thread Alex Bradbury 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 rG3dcfd482cb17: [CodeGen] Increase applicability of 
ffine-grained-bitfield-accesses for targets… (authored by asb).

Changed prior to commit:
  https://reviews.llvm.org/D79155?vs=261138&id=270344#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79155

Files:
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/test/CodeGenCXX/finegrain-bitfield-type.cpp


Index: clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
===
--- clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
+++ clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
@@ -1,5 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffine-grained-bitfield-accesses \
 // RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -ffine-grained-bitfield-accesses \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// Note: This test checks the X86-64 and RISC-V targets in order to explore
+// behaviour when i8/i16 are native integer widths (X86-64) and when they're
+// not (RISC-V).
+
 struct S4 {
   unsigned long f1:28;
   unsigned long f2:4;
@@ -19,4 +26,4 @@
 // CHECK: %struct.S4 = type { i32, i16 }
 // CHECK-NOT: %struct.S4 = type { i48 }
 // CHECK: %struct.S5 = type { i32, i32, i16, [6 x i8] }
-// CHECK-NOT: %struct.S5 = type { i80 }
\ No newline at end of file
+// CHECK-NOT: %struct.S5 = type { i80 }
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -406,15 +406,17 @@
 return;
   }
 
-  // Check if OffsetInRecord is better as a single field run. When 
OffsetInRecord
-  // has legal integer width, and its bitfield offset is naturally aligned, it
-  // is better to make the bitfield a separate storage component so as it can 
be
-  // accessed directly with lower cost.
+  // Check if OffsetInRecord (the size in bits of the current run) is better
+  // as a single field run. When OffsetInRecord has legal integer width, and
+  // its bitfield offset is naturally aligned, it is better to make the
+  // bitfield a separate storage component so as it can be accessed directly
+  // with lower cost.
   auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord,
   uint64_t StartBitOffset) {
 if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses)
   return false;
-if (!DataLayout.isLegalInteger(OffsetInRecord))
+if (OffsetInRecord < 8 || !llvm::isPowerOf2_64(OffsetInRecord) ||
+!DataLayout.fitsInLegalInteger(OffsetInRecord))
   return false;
 // Make sure StartBitOffset is natually aligned if it is treated as an
 // IType integer.


Index: clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
===
--- clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
+++ clang/test/CodeGenCXX/finegrain-bitfield-type.cpp
@@ -1,5 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffine-grained-bitfield-accesses \
 // RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -ffine-grained-bitfield-accesses \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+
+// Note: This test checks the X86-64 and RISC-V targets in order to explore
+// behaviour when i8/i16 are native integer widths (X86-64) and when they're
+// not (RISC-V).
+
 struct S4 {
   unsigned long f1:28;
   unsigned long f2:4;
@@ -19,4 +26,4 @@
 // CHECK: %struct.S4 = type { i32, i16 }
 // CHECK-NOT: %struct.S4 = type { i48 }
 // CHECK: %struct.S5 = type { i32, i32, i16, [6 x i8] }
-// CHECK-NOT: %struct.S5 = type { i80 }
\ No newline at end of file
+// CHECK-NOT: %struct.S5 = type { i80 }
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -406,15 +406,17 @@
 return;
   }
 
-  // Check if OffsetInRecord is better as a single field run. When OffsetInRecord
-  // has legal integer width, and its bitfield offset is naturally aligned, it
-  // is better to make the bitfield a separate storage component so as it can be
-  // accessed directly with lower cost.
+  // Check if OffsetInRecord (the size in bits of the current run) is better
+  // as a single field run. When OffsetInRecord has legal integer width, and
+  // its bitfield offset is naturally aligned, it is better to make the
+  // bitfield a separate storage component so as it can be accessed directly
+  // with lower cost.
   auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord,
  

[PATCH] D81718: [Analyzer][NFC] Add methods `getReturnObject()` and `getArgObject()` to `CallEvent`

2020-06-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

No, please don't do this.

The checker should *always* know the nature of the object in advance. If you 
look at the SVal in order to figure out the nature of the object, you are 
unable to discriminate between objects of completely different nature that are 
intentionally represented by the same SVal. For example, if you receive a 
SymbolicRegion value as a return value from your `getReturnObject()`, this can 
be for two reasons: (1) you're returning a pointer, (2) you're returning an 
object into that region. And you can't discriminate between those cases by 
looking at the SVal.

Both arbitrary glvalues and pointer prvalues are represented by Loc values but 
any code that fails to discriminate between the value of expression E and the 
value of ImplicitCastExpr(E, CK_LValueToRValue) is bonkers.

See also D77062#inline-744287 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81718



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


[PATCH] D75169: [ARM] Supporting lowering of half-precision FP arguments and returns in AArch32's backend

2020-06-12 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added a comment.

Perhaps we could move to making half a valid type for the arm back-end as 
follow up patches. Allowing half as argument through the IR is already a step 
to that direction.
IMO this patch is already quite big and it excels in fixing the bugs it 
proposed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75169



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


[PATCH] D80301: [yaml][clang-tidy] Fix new line YAML serialization

2020-06-12 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 270351.
DmitryPolukhin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80301

Files:
  clang/include/clang/Tooling/ReplacementsYaml.h
  llvm/lib/Support/YAMLTraits.cpp
  llvm/unittests/Support/YAMLIOTest.cpp

Index: llvm/unittests/Support/YAMLIOTest.cpp
===
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -274,8 +274,8 @@
 
 TEST(YAMLIO, MultilineStrings) {
   WithStringField Original;
-  Original.str1 = "a multiline string\nfoobarbaz";
-  Original.str2 = "another one\rfoobarbaz";
+  Original.str1 = "a\n\nmultiline\nstring\nfoobarbaz ";
+  Original.str2 = "another one\rfoobarbaz\n";
   Original.str3 = "a one-line string";
 
   std::string Serialized;
@@ -285,10 +285,10 @@
 YOut << Original;
   }
   auto Expected = "---\n"
-  "str1:'a multiline string\n"
-  "foobarbaz'\n"
+  "str1:'a\n\n\n\nmultiline\n\nstring\n\n"
+  "foobarbaz '\n"
   "str2:'another one\r"
-  "foobarbaz'\n"
+  "foobarbaz\n\n'\n"
   "str3:a one-line string\n"
   "...\n";
   ASSERT_EQ(Serialized, Expected);
@@ -305,6 +305,25 @@
   EXPECT_EQ(Original.str1, Deserialized.str1);
   EXPECT_EQ(Original.str2, Deserialized.str2);
   EXPECT_EQ(Original.str3, Deserialized.str3);
+
+  // Check deserialization of single '\n' that should be converted to space.
+  Serialized = "---\n"
+   "str1:'a\n\n\n\nmultiline\n\nstring\n\n"
+   "foobarbaz\n'\n"
+   "str2:'another\none\r"
+   "foobarbaz\n\n'\n"
+   "str3:a one-line string\n"
+   "...\n";
+  {
+Input YIn(Serialized);
+YIn >> Deserialized;
+ASSERT_FALSE(YIn.error())
+<< "Parsing error occurred during deserialization. Serialized string:\n"
+<< Serialized;
+  }
+  EXPECT_EQ(Original.str1, Deserialized.str1);
+  EXPECT_EQ(Original.str2, Deserialized.str2);
+  EXPECT_EQ(Original.str3, Deserialized.str3);
 }
 
 TEST(YAMLIO, NoQuotesForTab) {
Index: llvm/lib/Support/YAMLTraits.cpp
===
--- llvm/lib/Support/YAMLTraits.cpp
+++ llvm/lib/Support/YAMLTraits.cpp
@@ -876,13 +876,38 @@
 }
 
 void ScalarTraits::output(const std::string &Val, void *,
- raw_ostream &Out) {
-  Out << Val;
+   raw_ostream &Out) {
+  SmallVector Lines;
+  StringRef(Val).split(Lines, '\n');
+  bool First = true;
+  for (StringRef Line : Lines) {
+if (First)
+  First = false;
+else
+  Out << "\n\n";
+Out << Line;
+  }
 }
 
 StringRef ScalarTraits::input(StringRef Scalar, void *,
- std::string &Val) {
-  Val = Scalar.str();
+   std::string &Val) {
+  Val.clear();
+  SmallVector Lines;
+  Scalar.split(Lines, '\n');
+  size_t C = Lines.size();
+  for (size_t I = 0; I < C; ++I) {
+Val += Lines[I];
+// Next empty line means that it was '\n\n' that should convert to '\n'.
+// +2 here because we need separator only if more elements will be added.
+if (I + 2 < C && Lines[I + 1].empty()) {
+  Val += '\n';
+  ++I;
+} else if ((I + 1 < C && !Lines[I + 1].empty()) ||
+   (I + 2 == C && Lines[I + 1].empty())) {
+  // Single '\n' should be converted to space ' '.
+  Val += ' ';
+}
+  }
   return StringRef();
 }
 
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,13 +35,7 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
-  size_t lineBreakPos = ReplacementText.find('\n');
-  while (lineBreakPos != std::string::npos) {
-ReplacementText.replace(lineBreakPos, 1, "\n\n");
-lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
-  }
-}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80901: [analyzer][NFC] Change checker dependency unit tests to check for the registration order

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

I hesitated on whether to make a revision out of this rather than just 
committing it -- its nothing clever and is clearly superior the the previous 
state of the file. I hope you don't mind if I commit this as-is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80901



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


[clang] d61b1f8 - [analyzer][NFC] Change checker dependency unit tests to check for the registration order

2020-06-12 Thread Kirstóf Umann via cfe-commits
Author: Kirstóf Umann
Date: 2020-06-12T12:43:56+02:00
New Revision: d61b1f8534c6ee0f9dad528cda641d1429920ed4

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

LOG: [analyzer][NFC] Change checker dependency unit tests to check for the 
registration order

Exactly what it says on the tin! "Strong" dependencies are mentioned in contrast
to a new kind of dependency introduced in a followup patch.

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

Added: 


Modified: 
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp 
b/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
index 51d52c45c1c8..c88dfca224b3 100644
--- a/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
+++ b/clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
@@ -16,7 +16,9 @@
 #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace ento {
@@ -60,7 +62,7 @@ class LocIncDecChecker : public Checker {
 public:
   void checkLocation(SVal Loc, bool IsLoad, const Stmt *S,
  CheckerContext &C) const {
-auto UnaryOp = dyn_cast(S);
+const auto *UnaryOp = dyn_cast(S);
 if (UnaryOp && !IsLoad) {
   EXPECT_FALSE(UnaryOp->isIncrementOp());
 }
@@ -85,62 +87,90 @@ TEST(RegisterCustomCheckers, CheckLocationIncDec) {
 // Unsatisfied checker dependency
 
//===--===//
 
-class PrerequisiteChecker : public Checker {
+class CheckerRegistrationOrderPrinter
+: public Checker> {
+  std::unique_ptr BT =
+  std::make_unique(this, "Registration order");
+
 public:
-  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
-BugReporter &BR) const {
-BR.EmitBasicReport(D, this, "Prerequisite", categories::LogicError,
-   "This is the prerequisite checker",
-   PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+  void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {
+ExplodedNode *N = nullptr;
+N = C.generateErrorNode();
+llvm::SmallString<200> Buf;
+llvm::raw_svector_ostream OS(Buf);
+C.getAnalysisManager()
+.getCheckerManager()
+->getCheckerRegistry()
+.printEnabledCheckerList(OS);
+// Strip a newline off.
+auto R =
+std::make_unique(*BT, OS.str().drop_back(1), 
N);
+C.emitReport(std::move(R));
   }
 };
 
-void registerPrerequisiteChecker(CheckerManager &mgr) {
-  mgr.registerChecker();
+void registerCheckerRegistrationOrderPrinter(CheckerManager &mgr) {
+  mgr.registerChecker();
 }
 
-bool shouldRegisterPrerequisiteChecker(const CheckerManager &mgr) {
-  return false;
+bool shouldRegisterCheckerRegistrationOrderPrinter(const CheckerManager &mgr) {
+  return true;
 }
 
-class DependentChecker : public Checker {
-public:
-  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
-BugReporter &BR) const {
-BR.EmitBasicReport(D, this, "Dependent", categories::LogicError,
-   "This is the Dependent Checker",
-   PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+void addCheckerRegistrationOrderPrinter(CheckerRegistry &Registry) {
+  Registry.addChecker(registerCheckerRegistrationOrderPrinter,
+  shouldRegisterCheckerRegistrationOrderPrinter,
+  "custom.RegistrationOrder", "Description", "", false);
+}
+
+#define UNITTEST_CHECKER(CHECKER_NAME, DIAG_MSG)   
\
+  class CHECKER_NAME : public Checker> {  
\
+std::unique_ptr BT =   
\
+std::make_unique(this, DIAG_MSG);  
\
+   
\
+  public:  
\
+void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {}  
\
+  };   
\
+   
\
+  void register##CHECKER_NAME(CheckerManager &mgr) {   
\
+mgr.registerChecker();   
\
+  }
\
+   
\
+  bool shouldRegister##CHECKER_

[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a reviewer: aqjune.
efriedma added a comment.
Herald added a subscriber: wuzish.

I usually like to start reading this sort of patch with the proposed LangRef 
change, but I'm not seeing one.

There are a couple of related issues here in the existing representation of IR:

1. The way that call argument coercion works is unsound in the presence of 
poison.  An integer can't be partially poisoned: it's either poison, or not 
poison.  We probably need to come up with some safer way to pass structs/unions.
2. We don't currently have a way for frontends to indicate that a value is 
guaranteed not to be poison, so we have to conservatively assume arguments 
might be poison.  Whatever solution we come up with here should apply whether 
or not msan is enabled.  An attribute like this will probably be useful for 
"freeze" optimizations.

The partialinit attribute is, in some sense, backwards: the definition is 
essentially "an argument *not* marked partialinit must not contain any poison 
values".  We usually try to avoid negative reasoning like this; I'm afraid 
it'll make transforms harder to reason about.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

In D81678#2088284 , @efriedma wrote:

> I usually like to start reading this sort of patch with the proposed LangRef 
> change, but I'm not seeing one.
>
> There are a couple of related issues here in the existing representation of 
> IR:
>
> 1. The way that call argument coercion works is unsound in the presence of 
> poison.  An integer can't be partially poisoned: it's either poison, or not 
> poison.  We probably need to come up with some safer way to pass 
> structs/unions.
> 2. We don't currently have a way for frontends to indicate that a value is 
> guaranteed not to be poison, so we have to conservatively assume arguments 
> might be poison.  Whatever solution we come up with here should apply whether 
> or not msan is enabled.  An attribute like this will probably be useful for 
> "freeze" optimizations.
>
>   The partialinit attribute is, in some sense, backwards: the definition is 
> essentially "an argument *not* marked partialinit must not contain any poison 
> values".  We usually try to avoid negative reasoning like this; I'm afraid 
> it'll make transforms harder to reason about.


Yes, this is a bit awkward. There is a module flag 
"DisallowPoisonedCallArguments" that basically confirms that the frontend is 
aware of partialinit and any arguments not marked as such can be assumed strict 
(no-poison).

An alternative is to invert the meaning of the attribute and put it on all 
arguments that must be not poison. Those are a lot more common though.

The idea is that MSan can apply strict checking to arguments that are not 
"partialinit", and propagate the shadow to the callee for the rest.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Gui Andrade via Phabricator via cfe-commits
guiand added a comment.

As it stands, this attribute is applied whether or not msan is enabled, 
specifically because we think it can be useful in other contexts.

As for the negativity of this attribute, it's true that it would be more 
intuitive to have it be something like `fullinit` instead. I did it this way 
because passing arguments which are `partialinit` is orders of magnitude less 
common than the inverse. So this avoids polluting most generated code with a 
new attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

It's not entirely clear to me what `partialinit` means. Does it mean that some 
bytes of the parameter might be undef / poison? Or does it mean that some bytes 
of the parameter that (for a struct parameter or array thereof) correspond to a 
struct member might be undef / poison? (Eg, if I pass a `{ i8, i32 }` to a 
function, do we need to explicitly say that the three padding bytes are not 
initialized?)

I agree with @efriedma that a positive property, something like "these byte / 
bit ranges within the parameter are not undef", would probably fit better, and 
are likely usable by optimization passes as well as by msan. (Can we put 
metadata on parameters yet? This would seem well-suited to being modeled as 
metadata.)




Comment at: clang/include/clang/AST/Type.h:2139-2141
+  /// Check if this type has only two possible values, and so may be lowered to
+  /// a bool.
+  bool hasBooleanRepresentation() const;

This seems like a CodeGen-specific concern; I'm not sure this makes sense as a 
query on the Type.



Comment at: clang/lib/AST/Type.cpp:2752-2753
+
+  if (const EnumType *ET = getAs())
+return ET->getDecl()->getIntegerType()->isBooleanType();
+

Under `-fstrict-enums` in C++, `enum E { a = 0, b = 1 };` has only two distinct 
valid values. Should we consider that case?



Comment at: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:679
 
+void CGRecordLowering::determineMemberPartialInit() {
+  auto hasTailPadding = [&](QualType FieldTypePtr) {

We already have support for C++'s `__has_unique_object_representations` 
(`ASTContext::hasUniqueObjectRepresentations`), which does something very 
similar to this. Do we need both? (Are there cases where this is intentionally 
diverging from `__has_unique_object_representations`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

Hi, this is really interesting. I was interested in statically analyzing 
whether a value is undef/poison, so I also thought about the existence of this 
attribute, but I never imagined that MSan would benefit from this attribute as 
well.

> The partialinit attribute is, in some sense, backwards: the definition is 
> essentially "an argument *not* marked partialinit must not contain any poison 
> values". We usually try to avoid negative reasoning like this; I'm afraid 
> it'll make transforms harder to reason about.



> An alternative is to invert the meaning of the attribute and put it on all 
> arguments that must be not poison. Those are a lot more common though.

I agree with these two opinions. IIUC, in LLVM IR, attaching attribute to an 
argument imposes more restriction to the value.
Changing the semantics of IR to raise UB when poison or undef is passed to a 
function call will affect soundness of optimizations as well: for example, 
function outlining or dead arg elimination can introduce such function calls.
If the change is big, maybe we can split the patch to (1) implement the 
attribute (2) enable adding the attribute, so (2) contains all the big & 
mechanical diffs.

> @efriedma 
>  The way that call argument coercion works is unsound in the presence of 
> poison. An integer can't be partially poisoned: it's either poison, or not 
> poison. We probably need to come up with some safer way to pass 
> structs/unions.

This is true, clang frontend may lower an argument with aggregate type into one 
with large int type (such as i64).
However, can poison value be safely generated in C? Paddings or union with 
different size may contain undef bits, but not poison. Signed overflow is UB.
Undef value can exist bitwisely, so I think this is an orthogonal issue.

> @rsmith 
> It's not entirely clear to me what partialinit means. Does it mean that some 
> bytes of the parameter might be undef / poison? Or does it mean that some 
> bytes of the parameter that (for a struct parameter or array thereof) 
> correspond to a struct member might be undef / poison? (Eg, if I pass a { i8, 
> i32 } to a function, do we need to explicitly say that the three padding 
> bytes are not initialized?)

For poison, I believe it is now used as a valuewise concept in LLVM, so if the 
argument is a non-aggregate type such as i32/float/i8* it should be just binary 
(whether it is poison or not).

If it is agreed that we should have inverted version of `partialinit`, I'd like 
to suggest calling it `frozen` instead... :)
We have the notion of frozen value in LangRef already: it is used as e.g. `the 
branch condition should be frozen, otherwise it is undefined behavior`.
If an argument is frozen, it does not have any undef bits or poison value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D80901: [analyzer][NFC] Change checker dependency unit tests to check for the registration order

2020-06-12 Thread Kristóf Umann 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 rGd61b1f8534c6: [analyzer][NFC] Change checker dependency unit 
tests to check for the… (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80901

Files:
  clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp

Index: clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
===
--- clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
+++ clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
@@ -16,7 +16,9 @@
 #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace ento {
@@ -60,7 +62,7 @@
 public:
   void checkLocation(SVal Loc, bool IsLoad, const Stmt *S,
  CheckerContext &C) const {
-auto UnaryOp = dyn_cast(S);
+const auto *UnaryOp = dyn_cast(S);
 if (UnaryOp && !IsLoad) {
   EXPECT_FALSE(UnaryOp->isIncrementOp());
 }
@@ -85,62 +87,90 @@
 // Unsatisfied checker dependency
 //===--===//
 
-class PrerequisiteChecker : public Checker {
+class CheckerRegistrationOrderPrinter
+: public Checker> {
+  std::unique_ptr BT =
+  std::make_unique(this, "Registration order");
+
 public:
-  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
-BugReporter &BR) const {
-BR.EmitBasicReport(D, this, "Prerequisite", categories::LogicError,
-   "This is the prerequisite checker",
-   PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+  void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {
+ExplodedNode *N = nullptr;
+N = C.generateErrorNode();
+llvm::SmallString<200> Buf;
+llvm::raw_svector_ostream OS(Buf);
+C.getAnalysisManager()
+.getCheckerManager()
+->getCheckerRegistry()
+.printEnabledCheckerList(OS);
+// Strip a newline off.
+auto R =
+std::make_unique(*BT, OS.str().drop_back(1), N);
+C.emitReport(std::move(R));
   }
 };
 
-void registerPrerequisiteChecker(CheckerManager &mgr) {
-  mgr.registerChecker();
+void registerCheckerRegistrationOrderPrinter(CheckerManager &mgr) {
+  mgr.registerChecker();
 }
 
-bool shouldRegisterPrerequisiteChecker(const CheckerManager &mgr) {
-  return false;
+bool shouldRegisterCheckerRegistrationOrderPrinter(const CheckerManager &mgr) {
+  return true;
 }
 
-class DependentChecker : public Checker {
-public:
-  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
-BugReporter &BR) const {
-BR.EmitBasicReport(D, this, "Dependent", categories::LogicError,
-   "This is the Dependent Checker",
-   PathDiagnosticLocation(D, Mgr.getSourceManager()), {});
+void addCheckerRegistrationOrderPrinter(CheckerRegistry &Registry) {
+  Registry.addChecker(registerCheckerRegistrationOrderPrinter,
+  shouldRegisterCheckerRegistrationOrderPrinter,
+  "custom.RegistrationOrder", "Description", "", false);
+}
+
+#define UNITTEST_CHECKER(CHECKER_NAME, DIAG_MSG)   \
+  class CHECKER_NAME : public Checker> {  \
+std::unique_ptr BT =   \
+std::make_unique(this, DIAG_MSG);  \
+   \
+  public:  \
+void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const {}  \
+  };   \
+   \
+  void register##CHECKER_NAME(CheckerManager &mgr) {   \
+mgr.registerChecker();   \
+  }\
+   \
+  bool shouldRegister##CHECKER_NAME(const CheckerManager &mgr) {   \
+return true;   \
+  }\
+  void add##CHECKER_NAME(CheckerRegistry &Registry) {  \
+Registry.addChecker(register##CHECKER_NAME, shouldRegister##CHECKER_NAME,  \
+"custom." #CHECKER_NAME, "Description", 

[PATCH] D80699: [Analyzer][StreamChecker] Add check for pointer escape.

2020-06-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:439-441
+  // Do not handle untracked stream. It is probably escaped.
+  if (!State->get(StreamSym))
+return;

balazske wrote:
> Szelethus wrote:
> > How does this interact with D78280?
> That change needs to be updated after this. A new "escaped" stream state is 
> needed to avoid recognizing an escaped stream again.
Why not take that approach now? I mean that instead of deleting the stream from 
the map set its state to "escaped".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80699



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


[PATCH] D78350: [AST] Build recovery expressions by default for C++.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

ok, the current status seems quite stable now. We rolled it out to all our 
internal users for a while, didn't see big crashes. I'm going to land it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78350



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


[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-06-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@xazax.hun,
I've made performance measurements you concerned about. Could you look at it 
and make decision on this patch?


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

https://reviews.llvm.org/D78933



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


[PATCH] D81719: [clangd] Drop usage of PreambleStatCache in scanPreamble

2020-06-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

As discussed offline, the cache is always missing today, but we do have reason 
to believe we're doing a fair amount of IO in `buildCompilerInvocation` and it 
should be very cacheable.
So dropping the cache here might be the wrong direction vs fixing it.
I don't know:

- for sure how much IO is there or what it is
- whether it's mostly stats and so could be handled by this mechanism
- exactly what scope we should be filling the cache at (it's really tempting to 
do it on startup, which is a bigger change)

If the plan is to make the statcache wrap providers instead of/as well as FSes, 
do we actually need this change? (Then we can avoid having to decide right now)




Comment at: clang-tools-extra/clangd/Preamble.cpp:215
  const tooling::CompileCommand &Cmd) {
-  // FIXME: Change PreambleStatCache to operate on FileSystemProvider rather
-  // than vfs::FileSystem, that way we can just use ParseInputs without this
-  // hack.
-  auto GetFSProvider = [](llvm::IntrusiveRefCntPtr FS) {
-class VFSProvider : public FileSystemProvider {
+  auto EmptyFSProvider = [] {
+class EmptyProvider : public FileSystemProvider {

This is confusing - this class is essentially unused (move to next patch?) and 
erasing the class with a lambda seems unnecessarily obscure.



Comment at: clang-tools-extra/clangd/Preamble.cpp:248
   // also implies missing resolved paths for includes.
-  new llvm::vfs::InMemoryFileSystem, IgnoreDiags);
+  EmptyFSProvider()->getFileSystem(), IgnoreDiags);
   if (Clang->getFrontendOpts().Inputs.empty())

(This change isn't related to the description, which threw me for a loop - may 
want to defer it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81719



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


[clang] e22f1c0 - [analyzer] Introduce weak dependencies to express *preferred* checker callback evaluation order

2020-06-12 Thread Kirstóf Umann via cfe-commits
Author: Kirstóf Umann
Date: 2020-06-12T14:08:38+02:00
New Revision: e22f1c02a27f4471af1b9ae3aa6d8324b86ab2d0

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

LOG: [analyzer] Introduce weak dependencies to express *preferred* checker 
callback evaluation order

Checker dependencies were added D54438 to solve a bug where the checker names
were incorrectly registered, for example, InnerPointerChecker would incorrectly
emit diagnostics under the name MallocChecker, or vice versa [1]. Since the
system over the course of about a year matured, our expectations of what a role
of a dependency and a dependent checker should be crystallized a bit more --
D77474 and its summary, as well as a variety of patches in the stack
demonstrates how we try to keep dependencies to play a purely modeling role. In
fact, D78126 outright forbids diagnostics under a dependency checkers name.

These dependencies ensured the registration order and enabling only when all
dependencies are satisfied. This was a very "strong" contract however, that
doesn't fit the dependency added in D79420. As its summary suggests, this
relation is directly in between diagnostics, not modeling -- we'd prefer a more
specific warning over a general one.

To support this, I added a new dependency kind, weak dependencies. These are not
as strict of a contract, they only express a preference in registration order.
If a weak dependency isn't satisfied, the checker may still be enabled, but if
it is, checker registration, and transitively, checker callback evaluation order
is ensured.

If you are not familiar with the TableGen changes, a rather short description
can be found in the summary of D75360. A lengthier one is in D58065.

[1] https://www.youtube.com/watch?v=eqKeqHRAhQM

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

Added: 
clang/test/Analysis/weak-dependencies.c

Modified: 
clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
clang/test/Analysis/analyzer-enabled-checkers.c
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
clang/utils/TableGen/ClangSACheckersEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td 
b/clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td
index 6625d79559f5..98d26aaa637d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/CheckerBase.td
@@ -112,6 +112,8 @@ class Checker {
   list CheckerOptions;
   // This field is optional.
   list   Dependencies;
+  // This field is optional.
+  list   WeakDependencies;
   bits<2> Documentation;
   Package ParentPackage;
   bit Hidden = 0;
@@ -122,8 +124,13 @@ class CheckerOptions opts> {
   list CheckerOptions = opts;
 }
 
-/// Describes dependencies in between checkers. For example, 
InnerPointerChecker
-/// relies on information MallocBase gathers.
+/// Describes (strong) dependencies in between checkers. This is important for
+/// modeling checkers, for example, MallocBase depends on the proper modeling 
of
+/// string operations, so it depends on CStringBase. A checker may only be
+/// enabled if none of its dependencies (transitively) is disabled. 
Dependencies
+/// are always registered before the dependent checker, and its checker
+/// callbacks are also evaluated sooner.
+/// One may only depend on a purely modeling checker (that emits no 
diagnostis).
 /// Example:
 ///   def InnerPointerChecker : Checker<"InnerPointer">,
 /// HelpText<"Check for inner pointers of C++ containers used after "
@@ -133,6 +140,24 @@ class Dependencies Deps = []> {
   list Dependencies = Deps;
 }
 
+/// Describes preferred registration and evaluation order in between checkers.
+/// Unlike strong dependencies, this expresses dependencies in between
+/// diagnostics, and *not* modeling. In the case of an unsatisfied (disabled)
+/// weak dependency, the dependent checker might still be registered. If the
+/// weak dependency is satisfied, it'll be registered, and its checker
+/// callbacks will be evaluated before the dependent checker. This can be used
+/// to ensure that a more specific warning would be displayed in place of a
+/// generic one, should multiple checkers detect the same bug. For example,
+/// non-null parameter bugs are detected by NonNullParamChecker due to the
+/// nonnull attribute, and StdLibraryFunctionsChecker as it models standard
+/// functions, and the former is the more specific one. While freeing a
+/// dangling pointer is a bug, if it is also a double free, 

[PATCH] D81732: [clang] Replace Decl::isUnconditionallyVisible() with Sema::isVisible()

2020-06-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
mboehme added a reviewer: rsmith.
mboehme added a project: clang.
Herald added a subscriber: cfe-commits.

For context, see
https://bugs.llvm.org/show_bug.cgi?id=46248

This handles only the easy cases in Sema/SemaDeclObjC.cpp. The cases in 
AST/DeclObjC.{h,cpp} will require much more work, but there's no reason not to 
get the easy work out of the way now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81732

Files:
  clang/lib/Sema/SemaDeclObjC.cpp


Index: clang/lib/Sema/SemaDeclObjC.cpp
===
--- clang/lib/Sema/SemaDeclObjC.cpp
+++ clang/lib/Sema/SemaDeclObjC.cpp
@@ -1270,16 +1270,16 @@
   return ActOnObjCContainerStartDefinition(PDecl);
 }
 
-static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
-  ObjCProtocolDecl 
*&UndefinedProtocol) {
-  if (!PDecl->hasDefinition() ||
-  !PDecl->getDefinition()->isUnconditionallyVisible()) {
+static bool
+NestedProtocolHasNoDefinition(Sema &SemaRef, ObjCProtocolDecl *PDecl,
+  ObjCProtocolDecl *&UndefinedProtocol) {
+  if (!PDecl->hasDefinition() || !SemaRef.isVisible(PDecl->getDefinition())) {
 UndefinedProtocol = PDecl;
 return true;
   }
 
   for (auto *PI : PDecl->protocols())
-if (NestedProtocolHasNoDefinition(PI, UndefinedProtocol)) {
+if (NestedProtocolHasNoDefinition(SemaRef, PI, UndefinedProtocol)) {
   UndefinedProtocol = PI;
   return true;
 }
@@ -1325,7 +1325,7 @@
 ObjCProtocolDecl *UndefinedProtocol;
 
 if (WarnOnDeclarations &&
-NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) {
+NestedProtocolHasNoDefinition(*this, PDecl, UndefinedProtocol)) {
   Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first;
   Diag(UndefinedProtocol->getLocation(), 
diag::note_protocol_decl_undefined)
 << UndefinedProtocol;
@@ -1461,7 +1461,7 @@
   // FIXME: Recover nicely in the hidden case.
   ObjCProtocolDecl *forwardDecl = nullptr;
   if (warnOnIncompleteProtocols &&
-  NestedProtocolHasNoDefinition(proto, forwardDecl)) {
+  NestedProtocolHasNoDefinition(*this, proto, forwardDecl)) {
 Diag(identifierLocs[i], diag::warn_undef_protocolref)
   << proto->getDeclName();
 Diag(forwardDecl->getLocation(), diag::note_protocol_decl_undefined)
@@ -3236,7 +3236,7 @@
 return false;
 
   // If either is hidden, it is not considered to match.
-  if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible())
+  if (!isVisible(left) || !isVisible(right))
 return false;
 
   if (left->isDirectMethod() != right->isDirectMethod())
@@ -3495,7 +3495,7 @@
   ObjCMethodList &MethList = InstanceFirst ? Pos->second.first :
  Pos->second.second;
   for (ObjCMethodList *M = &MethList; M; M = M->getNext())
-if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
+if (M->getMethod() && isVisible(M->getMethod())) {
   if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
 Methods.push_back(M->getMethod());
 }
@@ -3511,7 +3511,7 @@
   ObjCMethodList &MethList2 = InstanceFirst ? Pos->second.second :
   Pos->second.first;
   for (ObjCMethodList *M = &MethList2; M; M = M->getNext())
-if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
+if (M->getMethod() && isVisible(M->getMethod())) {
   if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
 Methods.push_back(M->getMethod());
 }
@@ -3558,7 +3558,7 @@
   ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
   SmallVector Methods;
   for (ObjCMethodList *M = &MethList; M; M = M->getNext()) {
-if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
+if (M->getMethod() && isVisible(M->getMethod()))
   return M->getMethod();
   }
   return nullptr;


Index: clang/lib/Sema/SemaDeclObjC.cpp
===
--- clang/lib/Sema/SemaDeclObjC.cpp
+++ clang/lib/Sema/SemaDeclObjC.cpp
@@ -1270,16 +1270,16 @@
   return ActOnObjCContainerStartDefinition(PDecl);
 }
 
-static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
-  ObjCProtocolDecl *&UndefinedProtocol) {
-  if (!PDecl->hasDefinition() ||
-  !PDecl->getDefinition()->isUnconditionallyVisible()) {
+static bool
+NestedProtocolHasNoDefinition(Sema &SemaRef, ObjCProtocolDecl *PDecl,
+  ObjCProtocolDecl *&UndefinedProtocol) {
+  if (!PDecl->hasDefinition() || !SemaRef.isVisible(PDecl->getDefinition())) {
 UndefinedProtocol = PDecl;
 return true;
   }
 
   for (auto *PI : PDecl->protocols())
-if (NestedProtocolHasNoDefinition(PI, UndefinedProtocol)) {
+if (NestedProtocolHasNoDefinition(SemaRef, PI, UndefinedProtocol)) {
   UndefinedP

[PATCH] D80905: [analyzer] Introduce weak dependencies to express *preferred* checker callback evaluation order

2020-06-12 Thread Kristóf Umann via Phabricator via cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82a2122 - (PR46111) Properly handle elaborated types in an implicit deduction guide

2020-06-12 Thread Erich Keane via cfe-commits
Author: Erich Keane
Date: 2020-06-12T05:32:13-07:00
New Revision: 82a21229da36bc53004dc54203e3bdeea718c942

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

LOG: (PR46111) Properly handle elaborated types in an implicit  deduction guide

As reported in PR46111, implicit instantiation of a deduction guide
causes us to have an elaborated type as the parameter, rather than the
dependent type.

After review and feedback from @rsmith, this patch solves this problem
by wrapping the value in an uninstantiated typedef/type-alias that is
instantiated when required later.

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

Added: 
clang/test/AST/deduction-guides.cpp

Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c2324f976eba..073b4e818a24 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1947,16 +1947,46 @@ namespace {
 /// constructor to a deduction guide.
 class ExtractTypeForDeductionGuide
   : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
 public:
   typedef TreeTransform Base;
-  ExtractTypeForDeductionGuide(Sema &SemaRef) : Base(SemaRef) {}
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
 
   TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
 
   QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
-return TransformType(
-TLB,
-TL.getTypedefNameDecl()->getTypeSourceInfo()->getTypeLoc());
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypeLocBuilder InnerTLB;
+QualType Transformed =
+TransformType(InnerTLB, OrigDecl->getTypeSourceInfo()->getTypeLoc());
+TypeSourceInfo *TSI =
+TransformType(InnerTLB.getTypeSourceInfo(Context, Transformed));
+
+TypedefNameDecl *Decl = nullptr;
+
+if (isa(OrigDecl))
+  Decl = TypeAliasDecl::Create(
+  Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),
+  OrigDecl->getLocation(), OrigDecl->getIdentifier(), TSI);
+else {
+  assert(isa(OrigDecl) && "Not a Type alias or typedef");
+  Decl = TypedefDecl::Create(
+  Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),
+  OrigDecl->getLocation(), OrigDecl->getIdentifier(), TSI);
+}
+
+MaterializedTypedefs.push_back(Decl);
+
+QualType TDTy = Context.getTypedefType(Decl);
+TypedefTypeLoc TypedefTL = TLB.push(TDTy);
+TypedefTL.setNameLoc(TL.getNameLoc());
+
+return TDTy;
   }
 };
 
@@ -2041,14 +2071,16 @@ struct ConvertConstructorToDeductionGuideTransform {
 // new ones.
 TypeLocBuilder TLB;
 SmallVector Params;
-QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args);
+SmallVector MaterializedTypedefs;
+QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args,
+  MaterializedTypedefs);
 if (NewType.isNull())
   return nullptr;
 TypeSourceInfo *NewTInfo = TLB.getTypeSourceInfo(SemaRef.Context, NewType);
 
 return buildDeductionGuide(TemplateParams, CD->getExplicitSpecifier(),
NewTInfo, CD->getBeginLoc(), CD->getLocation(),
-   CD->getEndLoc());
+   CD->getEndLoc(), MaterializedTypedefs);
   }
 
   /// Build a deduction guide with the specified parameter types.
@@ -2143,16 +2175,18 @@ struct ConvertConstructorToDeductionGuideTransform {
 return NewParam;
   }
 
-  QualType transformFunctionProtoType(TypeLocBuilder &TLB,
-  FunctionProtoTypeLoc TL,
-  SmallVectorImpl &Params,
-  MultiLevelTemplateArgumentList &Args) {
+  QualType transformFunctionProtoType(
+  TypeLocBuilder &TLB, FunctionProtoTypeLoc TL,
+  SmallVectorImpl &Params,
+  MultiLevelTemplateArgumentList &Args,
+  SmallVectorImpl &MaterializedTypedefs) {
 SmallVector ParamTypes;
 const FunctionProtoType *T = TL.getTypePtr();
 
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
-  ParmVarDecl *NewParam = transformFunctionTypeParam(OldParam, Args);
+  ParmVarDecl *NewParam =
+  transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
   if (!NewParam)
 return

[PATCH] D80743: (PR46111) Properly handle elaborated types in an implicit deduction guide

2020-06-12 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82a21229da36: (PR46111) Properly handle elaborated types in 
an implicit  deduction guide (authored by erichkeane).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D80743?vs=268822&id=270368#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80743

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/deduction-guides.cpp

Index: clang/test/AST/deduction-guides.cpp
===
--- /dev/null
+++ clang/test/AST/deduction-guides.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only %s -ast-dump -std=c++17 | FileCheck %s
+
+namespace PR46111 {
+template 
+struct S;
+
+template 
+struct HasDeductionGuide {
+  typedef PR46111::S STy;
+  HasDeductionGuide(typename STy::Child);
+};
+
+// This causes deduction guides to be generated for all constructors.
+HasDeductionGuide()->HasDeductionGuide;
+
+template 
+struct HasDeductionGuideTypeAlias {
+  using STy = PR46111::S;
+  HasDeductionGuideTypeAlias(typename STy::Child);
+};
+
+// This causes deduction guides to be generated for all constructors.
+HasDeductionGuideTypeAlias()->HasDeductionGuideTypeAlias;
+
+// The parameter to this one shouldn't be an elaborated type.
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (typename STy::Child) -> HasDeductionGuide'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (HasDeductionGuide) -> HasDeductionGuide'
+// CHECK: CXXDeductionGuideDecl {{.*}}  'auto () -> HasDeductionGuide'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (typename STy::Child) -> HasDeductionGuideTypeAlias'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (HasDeductionGuideTypeAlias) -> HasDeductionGuideTypeAlias'
+// CHECK: CXXDeductionGuideDecl {{.*}}  'auto () -> HasDeductionGuideTypeAlias'
+} // namespace PR46111
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5702,6 +5702,9 @@
 bool NeedInstantiate = false;
 if (CXXRecordDecl *RD = dyn_cast(D))
   NeedInstantiate = RD->isLocalClass();
+else if (isa(D) &&
+ isa(D->getDeclContext()))
+  NeedInstantiate = true;
 else
   NeedInstantiate = isa(D);
 if (NeedInstantiate) {
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3579,6 +3579,12 @@
   if (isa(D))
 return nullptr;
 
+  // Materialized typedefs/type alias for implicit deduction guides may require
+  // instantiation.
+  if (isa(D) &&
+  isa(D->getDeclContext()))
+return nullptr;
+
   // If we didn't find the decl, then we either have a sema bug, or we have a
   // forward reference to a label declaration.  Return null to indicate that
   // we have an uninstantiated label.
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1947,16 +1947,46 @@
 /// constructor to a deduction guide.
 class ExtractTypeForDeductionGuide
   : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
 public:
   typedef TreeTransform Base;
-  ExtractTypeForDeductionGuide(Sema &SemaRef) : Base(SemaRef) {}
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
 
   TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
 
   QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
-return TransformType(
-TLB,
-TL.getTypedefNameDecl()->getTypeSourceInfo()->getTypeLoc());
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypeLocBuilder InnerTLB;
+QualType Transformed =
+TransformType(InnerTLB, OrigDecl->getTypeSourceInfo()->getTypeLoc());
+TypeSourceInfo *TSI =
+TransformType(InnerTLB.getTypeSourceInfo(Context, Transformed));
+
+TypedefNameDecl *Decl = nullptr;
+
+if (isa(OrigDecl))
+  Decl = TypeAliasDecl::Create(
+  Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),
+  OrigDecl->getLocation(), OrigDecl->getIdentifier(), TSI);
+else {
+  assert(isa(OrigDecl) && "Not a Type alias or typedef");
+  Decl = TypedefDecl::Create(
+  Context, Context.getTranslationUnitDecl(), OrigDecl->getBeginLoc(),
+  OrigDecl->getLoc

[clang] 33fb9cb - [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

2020-06-12 Thread Kirstóf Umann via cfe-commits
Author: Kirstóf Umann
Date: 2020-06-12T14:59:48+02:00
New Revision: 33fb9cbe211d1b43d4b84edf34e11001f04cddf0

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

LOG: [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

The thrilling conclusion to the barrage of patches I uploaded lately! This is a
big milestone towards the goal set out in 
http://lists.llvm.org/pipermail/cfe-dev/2019-August/063070.html.
I hope to accompany this with a patch where the a coreModeling package is added,
from which package diagnostics aren't allowed either, is an implicit dependency
of all checkers, and the core package for the first time can be safely disabled.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index 51565524db1e..27bc0dda1f1c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -135,7 +136,7 @@ class BugReport {
   SmallVector Fixits;
 
   BugReport(Kind kind, const BugType &bt, StringRef desc)
-  : K(kind), BT(bt), Description(desc) {}
+  : BugReport(kind, bt, "", desc) {}
 
   BugReport(Kind K, const BugType &BT, StringRef ShortDescription,
 StringRef Description)
@@ -369,16 +370,13 @@ class PathSensitiveBugReport : public BugReport {
 public:
   PathSensitiveBugReport(const BugType &bt, StringRef desc,
  const ExplodedNode *errorNode)
-  : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
-ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
- : SourceRange()) {}
+  : PathSensitiveBugReport(bt, desc, desc, errorNode) {}
 
   PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef 
desc,
  const ExplodedNode *errorNode)
-  : BugReport(Kind::PathSensitive, bt, shortDesc, desc),
-ErrorNode(errorNode),
-ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
- : SourceRange()) {}
+  : PathSensitiveBugReport(bt, shortDesc, desc, errorNode,
+   /*LocationToUnique*/ {},
+   /*DeclToUnique*/ nullptr) {}
 
   /// Create a PathSensitiveBugReport with a custom uniqueing location.
   ///
@@ -391,11 +389,13 @@ class PathSensitiveBugReport : public BugReport {
  const ExplodedNode *errorNode,
  PathDiagnosticLocation LocationToUnique,
  const Decl *DeclToUnique)
-  : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
-ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : 
SourceRange()),
-UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
-assert(errorNode);
-  }
+  : PathSensitiveBugReport(bt, desc, desc, errorNode, LocationToUnique,
+   DeclToUnique) {}
+
+  PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef 
desc,
+ const ExplodedNode *errorNode,
+ PathDiagnosticLocation LocationToUnique,
+ const Decl *DeclToUnique);
 
   static bool classof(const BugReport *R) {
 return R->getKind() == Kind::PathSensitive;

diff  --git a/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h 
b/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
index 7b72fae0fefe..795067cba582 100644
--- a/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ b/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -135,7 +135,7 @@ class CheckerRegistry {
  "Invalid development status!");
 }
 
-LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+LLVM_DUMP_METHOD void dump() const;
 LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out) const;
   };
 
@@ -195,7 +195,7 @@ class Check

[clang-tools-extra] 58ea105 - [AST][RecoveryExpr] Build recovery expressions by default for C++.

2020-06-12 Thread Haojian Wu via cfe-commits
Author: Haojian Wu
Date: 2020-06-12T15:21:38+02:00
New Revision: 58ea1059df97c71c023ec9de3940040c2c9bbc64

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

LOG: [AST][RecoveryExpr] Build recovery expressions by default for C++.

Reland https://reviews.llvm.org/D76696
All known crashes have been fixed, another attemption.

We have rolled out this to all internal users for a while, didn't see
big issues, we consider it is stable enough.

Reviewed By: sammccall

Subscribers: rsmith, hubert.reinterpretcast, ebevhan, jkorous, arphaman, 
kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
clang/test/CXX/class.access/p4.cpp
clang/test/CXX/special/class.ctor/p5-0x.cpp
clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
clang/test/OpenMP/declare_variant_messages.cpp
clang/test/OpenMP/target_update_from_messages.cpp
clang/test/OpenMP/target_update_to_messages.cpp
clang/test/Parser/objcxx0x-lambda-expressions.mm
clang/test/Parser/objcxx11-invalid-lambda.cpp
clang/test/SemaCXX/cast-conversion.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constructor-initializer.cpp
clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
clang/test/SemaCXX/cxx1y-deduced-return-type.cpp
clang/test/SemaCXX/cxx1z-copy-omission.cpp
clang/test/SemaCXX/decltype-crash.cpp
clang/test/SemaCXX/enable_if.cpp
clang/test/SemaCXX/for-range-dereference.cpp
clang/test/SemaCXX/varargs.cpp
clang/test/SemaCXX/virtual-base-used.cpp
clang/test/SemaObjCXX/arc-0x.mm
clang/test/SemaOpenCLCXX/address-space-references.cl
clang/test/SemaTemplate/instantiate-function-params.cpp
clang/test/SemaTemplate/instantiate-init.cpp

Removed: 
clang/test/SemaCXX/recovery-default-init.cpp
clang/test/SemaCXX/recovery-initializer.cpp



diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index b060e67e848f..909ffce9df59 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1197,7 +1197,9 @@ TEST(SignatureHelpTest, OpeningParen) {
 int foo(int a, int b, int c);
 int main() {
 #define ID(X) X
-  ID(foo $p^( foo(10), ^ ))
+  // FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
+  // the recovery expression.
+  ID(foo $p^( 10, ^ ))
 })cpp"};
 
   for (auto Test : Tests) {

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 3aea9164046c..c7180779d973 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2885,10 +2885,11 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   !Args.hasArg(OPT_fno_concept_satisfaction_caching);
   if (Args.hasArg(OPT_fconcepts_ts))
 Diags.Report(diag::warn_fe_concepts_ts_flag);
+  // Recovery AST still heavily relies on dependent-type machinery.
   Opts.RecoveryAST =
-  Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, false);
+  Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, Opts.CPlusPlus);
   Opts.RecoveryASTType =
-+  Args.hasFlag(OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, false);
+  Args.hasFlag(OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, false);
   Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
   Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
   Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);

diff  --git 
a/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp 
b/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
index 3cad174feac0..3c94a8f1c4e2 100644
--- a/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
@@ -134,6 +134,8 @@ int main() {
 // CHECK-NEXT: |   | `-UsingDirectiveDecl [[ADDR_65:0x[a-z0-9]*]]  col:19 Namespace [[ADDR_0]] 'A'
 // CHECK-NEXT: |   |-DeclStmt [[ADDR_66:0x[a-z0-9]*]] 
 // CHECK-NEXT: |   | `-UsingDirectiveDecl [[ADDR_67:0x[a-z0-9]*]]  col:19 Namespace [[ADDR_5]] 'B'
+// CHECK-NEXT: |   |-RecoveryExpr {{.*}} 
+// CHECK-NEXT: |   | `-UnresolvedLookupExpr {{.*}} 
 // CHECK-NEXT: |   `-ReturnStmt [[ADDR_68:0x[a-z0-9]*]] 
 // CHECK-NEXT: | `-BinaryOperator [[ADDR_69:0x[a-z0-9]*]]  
'int' '+'
 // CHECK-NEXT: |   |-PseudoObjectExpr [[ADDR_70:0x[a-z0-9]*]]  'int'

[PATCH] D69599: [analyzer] DynamicSize: Remove 'getSizeInElements()' from store

2020-06-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.
Herald added subscribers: martong, steakhal.

@Charusso 
I think this patch may fix this bug https://bugs.llvm.org/show_bug.cgi?id=25284
Could you please verify and close it if so?
At least I couldn't reproduce it on the latest build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69599



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


[PATCH] D81718: [Analyzer][NFC] Add methods `getReturnObject()` and `getArgObject()` to `CallEvent`

2020-06-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Thank you for taking a look on this!

Let me explain! An iterator may be implemented by multiple ways. It can be a 
simple pointer, which means that it is a basic type passed by value both as 
argument and return value. Thus here `getArgSVal()` and `getReturnValue()` are 
the correct methods to invoke. It can be something small (e.g. a pointer) 
wrapped into a class. It is also passed by value both as argument (maybe also 
for comparison operators ) and return value, but since it is a class instance, 
both require copy construction. This means that here `getParameterLocation()` 
and `getReturnValueUnderConstruction()` are the right methods. Furthermore, it 
can be a somewhat larger class that is passed by constant reference as 
argument, but of course by value as return value. In this case `getArgSVal()` 
and `getReturnValueUnderConstruction()` are the winners. Also the same class 
can be a value parameter in one function and a reference parameter in another 
one. The checker does not know this in advance, but must work correctly for all 
these cases.

In this patch `getReturnObject()` uses a "trial and failure" approach, thus it 
tries to assume that we are handling a class instance, which is copy 
constructed, so it tries to retrieve it from the construction context of the 
call. If no such context exists then it means that the value is not copy 
constructed. I think this approach is correct.

On the other hand, I agree with you that in `getArgObject()` checking the 
`SVal` is insufficient/incorrect. (I also planned to make a self-comment there, 
but I forgot.) Is it OK, if I look at the callee instead, and examine the type 
of its parameter? If it is passed by value, and is a `C++` class instance, then 
I use `getParameterLocation()`, otherwise `getArgSVal()`. Of course, I can do 
the same for `getReturnObject()`, but the result is exactly the same as the 
current "trial and failure" approach.

It is also possible to put these functions into `Iterator.h`, but I think that 
other checkers may also benefit from such functionality. One thing is sure: I 
need such wrapper functions somewhere, without them all the iterator-related 
checkers will be unreadable because of the code multiplication. There are lots 
of places where we retrieve one of the arguments or the return value, and 
checking the nature of the value everywhere almost duplicates the size of the 
code and makes it unreadable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81718



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


[PATCH] D78350: [AST] Build recovery expressions by default for C++.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 270370.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78350

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  clang/test/OpenMP/declare_variant_messages.cpp
  clang/test/OpenMP/target_update_from_messages.cpp
  clang/test/OpenMP/target_update_to_messages.cpp
  clang/test/Parser/objcxx0x-lambda-expressions.mm
  clang/test/Parser/objcxx11-invalid-lambda.cpp
  clang/test/SemaCXX/cast-conversion.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constructor-initializer.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/cxx1y-deduced-return-type.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp
  clang/test/SemaCXX/decltype-crash.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/for-range-dereference.cpp
  clang/test/SemaCXX/recovery-default-init.cpp
  clang/test/SemaCXX/recovery-initializer.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm
  clang/test/SemaOpenCLCXX/address-space-references.cl
  clang/test/SemaTemplate/instantiate-function-params.cpp
  clang/test/SemaTemplate/instantiate-init.cpp

Index: clang/test/SemaTemplate/instantiate-init.cpp
===
--- clang/test/SemaTemplate/instantiate-init.cpp
+++ clang/test/SemaTemplate/instantiate-init.cpp
@@ -108,7 +108,7 @@
 integral_c<1> ic1 = array_lengthof(Description::data);
 (void)sizeof(array_lengthof(Description::data));
 
-sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
+(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
   Description::data // expected-note{{in instantiation of static data member 'PR7985::Description::data' requested here}}
   ));
 
Index: clang/test/SemaTemplate/instantiate-function-params.cpp
===
--- clang/test/SemaTemplate/instantiate-function-params.cpp
+++ clang/test/SemaTemplate/instantiate-function-params.cpp
@@ -3,32 +3,32 @@
 // PR6619
 template struct if_c { };
 template struct if_ {
-  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
+  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
 };
 template  struct wrap_constraints { };
 template  
 inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}}
-   wrap_constraints* = 0); // expected-note 2{{in instantiation}}
+   wrap_constraints* = 0); // expected-note 4{{in instantiation}}
 
 template  struct not_satisfied {
   static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}} \
-  // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
+  // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
 };
 template  struct requirement_;
 template  struct instantiate {
 };
-template  struct requirement_   : if_<   not_satisfied >::type { // expected-note 5{{in instantiation}}
+template  struct requirement_   : if_<   not_satisfied >::type { // expected-error 3{{no type named 'type' in}} expected-note 7{{in instantiation}}
 };
 template  struct usage_requirements {
 };
 template < typename TT > struct InputIterator{
-typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
+typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
 };
-template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note {{in instantiation}}
-  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
+template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note 2{{in instantiation}}
+  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note 2{{in instantiation}}
 
 };
-typedef instantiate< &requirement_ x)>::failed> boost_concept_checkX;// expected-note 3{{in instantiation}}
+typedef instantiate< &requir

[PATCH] D81552: [ASTMatchers] Added hasDirectBase and hasClass Matchers

2020-06-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3553
+/// \endcode
+AST_MATCHER_P(CXXBaseSpecifier, hasClass, internal::Matcher,
+  InnerMatcher) {

njames93 wrote:
> jkorous wrote:
> > aaron.ballman wrote:
> > > jkorous wrote:
> > > > Nit: while "[base specifier] `hasType`" sounds natural to me for some 
> > > > reason `hasClass` doesn't. English is not my first language though.
> > > I agree that `hasClass` seems unnatural here. Out of curiosity, could we 
> > > modify the `hasName` matcher to work on base specifiers so you can write: 
> > > `cxxRecordDecl(hasAnyBase(hasName("Base")))` as shorthand for the more 
> > > wordy version 
> > > `cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")`?
> > Wouldn't it be strange to treat `hasName` differently than all the other 
> > narrowing matchers? Honest question - I feel that `hasName` might be the 
> > most commonly used, just don't know if that's enough to justify this.
> > https://clang.llvm.org/docs/LibASTMatchersReference.html#narrowing-matchers
> Repurposing `hasName` would be a pain especially considering 99% of its use 
> cases wont be for base class matching.
> Wouldn't it be strange to treat hasName differently than all the other 
> narrowing matchers? Honest question - I feel that hasName might be the most 
> commonly used, just don't know if that's enough to justify this. 
> https://clang.llvm.org/docs/LibASTMatchersReference.html#narrowing-matchers

Different how? I'm suggesting to overload `hasName` to work on a 
`CXXBaseSpecifier` since those have a name.

> Repurposing hasName would be a pain especially considering 99% of its use 
> cases wont be for base class matching.

I'm asking what the right API is for users, though, which is a bit different. 
Base specifiers have names (there are no unnamed base specifiers), so to me, it 
makes more sense for `hasName` to work with them directly since that is the 
thing that does name matching.

I think you can accomplish this by using a `PolymorphicMatcherWithParam1` like 
we do for `hasOverloadedOperatorName` which can narrow to either a 
`CXXOperatorCallExpr` or a `FunctionDecl`.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3621
+/// \endcode
+AST_MATCHER_P(CXXBaseSpecifier, hasClassOrClassTemplate,
+  internal::Matcher, InnerMatcher) {

jkorous wrote:
> I think we should just use `eachOf` matcher for this kind of composition.
> 
> https://clang.llvm.org/docs/LibASTMatchersReference.html#traversal-matchers
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81552



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


[PATCH] D78350: [AST] Build recovery expressions by default for C++.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58ea1059df97: [AST][RecoveryExpr] Build recovery expressions 
by default for C++. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78350

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  clang/test/OpenMP/declare_variant_messages.cpp
  clang/test/OpenMP/target_update_from_messages.cpp
  clang/test/OpenMP/target_update_to_messages.cpp
  clang/test/Parser/objcxx0x-lambda-expressions.mm
  clang/test/Parser/objcxx11-invalid-lambda.cpp
  clang/test/SemaCXX/cast-conversion.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constructor-initializer.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/cxx1y-deduced-return-type.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp
  clang/test/SemaCXX/decltype-crash.cpp
  clang/test/SemaCXX/enable_if.cpp
  clang/test/SemaCXX/for-range-dereference.cpp
  clang/test/SemaCXX/recovery-default-init.cpp
  clang/test/SemaCXX/recovery-initializer.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm
  clang/test/SemaOpenCLCXX/address-space-references.cl
  clang/test/SemaTemplate/instantiate-function-params.cpp
  clang/test/SemaTemplate/instantiate-init.cpp

Index: clang/test/SemaTemplate/instantiate-init.cpp
===
--- clang/test/SemaTemplate/instantiate-init.cpp
+++ clang/test/SemaTemplate/instantiate-init.cpp
@@ -108,7 +108,7 @@
 integral_c<1> ic1 = array_lengthof(Description::data);
 (void)sizeof(array_lengthof(Description::data));
 
-sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
+(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
   Description::data // expected-note{{in instantiation of static data member 'PR7985::Description::data' requested here}}
   ));
 
Index: clang/test/SemaTemplate/instantiate-function-params.cpp
===
--- clang/test/SemaTemplate/instantiate-function-params.cpp
+++ clang/test/SemaTemplate/instantiate-function-params.cpp
@@ -3,32 +3,32 @@
 // PR6619
 template struct if_c { };
 template struct if_ {
-  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
+  typedef if_c< static_cast(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
 };
 template  struct wrap_constraints { };
 template  
 inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}}
-   wrap_constraints* = 0); // expected-note 2{{in instantiation}}
+   wrap_constraints* = 0); // expected-note 4{{in instantiation}}
 
 template  struct not_satisfied {
   static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}} \
-  // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
+  // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
 };
 template  struct requirement_;
 template  struct instantiate {
 };
-template  struct requirement_   : if_<   not_satisfied >::type { // expected-note 5{{in instantiation}}
+template  struct requirement_   : if_<   not_satisfied >::type { // expected-error 3{{no type named 'type' in}} expected-note 7{{in instantiation}}
 };
 template  struct usage_requirements {
 };
 template < typename TT > struct InputIterator{
-typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
+typedef  instantiate< & requirement_ x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
 };
-template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note {{in instantiation}}
-  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
+template < typename TT > struct ForwardIterator  : InputIterator  { // expected-note 2{{in instantiation}}
+  typedef instantiate< & requirement_ x)>::failed> boost_concept_check2; // expected-note 2{{in instantiation}}
 
 };
-typedef instantiat

[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Can you add tests for this? Is this also sufficient with the directory layout 
change?


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

https://reviews.llvm.org/D81713



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


[PATCH] D78126: [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

2020-06-12 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33fb9cbe211d: [analyzer][NFC] Don't allow dependency 
checkers to emit diagnostics (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D78126?vs=262387&id=270372#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78126

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -94,6 +94,10 @@
 // Methods of CmdLineOption, PackageInfo and CheckerInfo.
 //===--===//
 
+LLVM_DUMP_METHOD void CheckerRegistry::CmdLineOption::dump() const {
+  dumpToStream(llvm::errs());
+}
+
 LLVM_DUMP_METHOD void
 CheckerRegistry::CmdLineOption::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -115,6 +119,10 @@
   llvm_unreachable("Unhandled CheckerRegistry::StateFromCmdLine enum");
 }
 
+LLVM_DUMP_METHOD void CheckerRegistry::CheckerInfo::dump() const {
+  dumpToStream(llvm::errs());
+}
+
 LLVM_DUMP_METHOD void
 CheckerRegistry::CheckerInfo::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -137,6 +145,10 @@
   }
 }
 
+LLVM_DUMP_METHOD void CheckerRegistry::PackageInfo::dump() const {
+  dumpToStream(llvm::errs());
+}
+
 LLVM_DUMP_METHOD void
 CheckerRegistry::PackageInfo::dumpToStream(llvm::raw_ostream &Out) const {
   Out << FullName << "\n";
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -40,6 +40,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -2106,6 +2107,32 @@
 // Methods for BugReport and subclasses.
 //===--===//
 
+static bool isDependency(const CheckerRegistry &Registry,
+ StringRef CheckerName) {
+  for (const std::pair &Pair : Registry.Dependencies) {
+if (Pair.second == CheckerName)
+  return true;
+  }
+  return false;
+}
+
+PathSensitiveBugReport::PathSensitiveBugReport(
+const BugType &bt, StringRef shortDesc, StringRef desc,
+const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
+const Decl *DeclToUnique)
+: BugReport(Kind::PathSensitive, bt, shortDesc, desc), ErrorNode(errorNode),
+  ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : SourceRange()),
+  UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
+  assert(!isDependency(ErrorNode->getState()
+   ->getAnalysisManager()
+   .getCheckerManager()
+   ->getCheckerRegistry(),
+   bt.getCheckerName()) &&
+ "Some checkers depend on this one! We don't allow dependency "
+ "checkers to emit warnings, because checkers should depend on "
+ "*modeling*, not *diagnostics*.");
+}
+
 void PathSensitiveBugReport::addVisitor(
 std::unique_ptr visitor) {
   if (!visitor)
@@ -2194,12 +2221,12 @@
   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!");
+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 PathSensitiveBugReport::markInteresting(SymbolRef sym,
Index: clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===
--- clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -135,7 +135,7 @@
  "Invalid devel

[clang] e4b3fc1 - Get rid of -Wunused warnings in release build, NFC.

2020-06-12 Thread Haojian Wu via cfe-commits
Author: Haojian Wu
Date: 2020-06-12T15:42:29+02:00
New Revision: e4b3fc18d33199e2081d300f14687d81be48b6a0

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

LOG: Get rid of -Wunused warnings in release build, NFC.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp 
b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index c2ca9c12b025..4a7e0d91ea23 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -285,6 +285,7 @@ CheckerRegistry::CheckerRegistry(
   resolveDependencies();
   resolveDependencies();
 
+#ifndef NDEBUG // avoid -Wunused warnings in release build.
   for (auto &DepPair : Dependencies) {
 for (auto &WeakDepPair : WeakDependencies) {
   // Some assertions to enforce that strong dependencies are relations in
@@ -298,6 +299,7 @@ CheckerRegistry::CheckerRegistry(
  "A strong dependency mustn't be a weak dependency as well!");
 }
   }
+#endif
 
   resolveCheckerAndPackageOptions();
 



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


[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D81713#2089672 , @arsenm wrote:

> Can you add tests for this? Is this also sufficient with the directory layout 
> change?


You mean does this work after we move device lib from /opt/rocm/lib to 
/opt/rocm/amdgcn/bitcode ?


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

https://reviews.llvm.org/D81713



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


[PATCH] D81734: Initial smart pointer check

2020-06-12 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar abandoned this revision.
vrnithinkumar added a comment.

It was a mistake 
I was supposed to update an existing review.
first time use of arc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81734



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


[PATCH] D74166: [AIX][Frontend] Static init implementation for AIX considering no priority

2020-06-12 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/test/CodeGen/static-init.cpp:8
+// RUN:   FileCheck %s
 
 struct test {

Looks like the non-inline comments are easier to get ignored and missed, so I 
will copy paste the non-inlined comment I previously had:
```
-fregister_global_dtors_with_atexit does not seem to work properly in current 
implementation.
We should consider somehow disabling/report_fatal_error it instead of letting 
it generate invalid code on AIX.
```


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

https://reviews.llvm.org/D74166



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


[PATCH] D81734: Initial smart pointer check

2020-06-12 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar created this revision.
Herald added subscribers: cfe-commits, martong.
Herald added a project: clang.
vrnithinkumar abandoned this revision.
vrnithinkumar added a comment.

It was a mistake 
I was supposed to update an existing review.
first time use of arc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81734

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -10,7 +10,7 @@
   std::unique_ptr Q = std::move(P);
   if (Q)
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
-  *Q.get() = 1; // no-warning
+  *Q.get() = 1; // no-warning
   if (P)
 clang_analyzer_warnIfReached(); // no-warning
   // TODO: Report a null dereference (instead).
@@ -26,3 +26,64 @@
   (s->*func)(); // no-crash
 }
 } // namespace testUnknownCallee
+
+class A {
+public:
+  A(){};
+  void foo();
+};
+
+A *return_null() {
+  return nullptr;
+}
+
+void derefAfterValidCtr() {
+  std::unique_ptr P(new A());
+  P->foo(); // No warning.
+}
+
+void derefAfterDefaultCtr() {
+  std::unique_ptr P;
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterCtrWithNull() {
+  std::unique_ptr P(nullptr);
+  *P; // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterCtrWithNullReturnMethod() {
+  std::unique_ptr P(return_null());
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterRelease() {
+  std::unique_ptr P(new A());
+  P.release();
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterReset() {
+  std::unique_ptr P(new A());
+  P.reset();
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterResetWithNull() {
+  std::unique_ptr P(new A());
+  P.reset(nullptr);
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterResetWithNonNull() {
+  std::unique_ptr P;
+  P.reset(new A());
+  P->foo(); // No warning.
+}
+
+void derefAfterReleaseAndResetWithNonNull() {
+  std::unique_ptr P(new A());
+  P.release();
+  P.reset(new A());
+  P->foo(); // No warning.
+}
\ No newline at end of file
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -946,10 +946,15 @@
   template  // TODO: Implement the stub for deleter.
   class unique_ptr {
   public:
+unique_ptr() {}
+unique_ptr(T *) {}
 unique_ptr(const unique_ptr &) = delete;
 unique_ptr(unique_ptr &&);
 
 T *get() const;
+T *release() const;
+void reset(T *p = nullptr) const;
+void swap(unique_ptr &p) const;
 
 typename std::add_lvalue_reference::type operator*() const;
 T *operator->() const;
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -13,26 +13,60 @@
 
 #include "Move.h"
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #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/SVals.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class SmartPtrModeling : public Checker {
+class SmartPtrModeling
+: public Checker {
   bool isNullAfterMoveMethod(const CallEvent &Call) const;
+  BugType NullDereferenceBugType{this, "Null-smartPtr-deref",
+ "C++ smart pointer"};
 
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkPostCall(const CallEvent &MC, CheckerContext &C) const;
+  void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
+
+private:
+  void reportBug(CheckerContext &C, const CallEvent &Call) const;
+  bool isStdSmartPointerClass(const CXXRecordDecl *RD) const;
+  void updateTrackedRegion(const CallEvent &Call, CheckerContext &C,
+   const MemRegion *Region) const;
+  void 

[PATCH] D60620: [HIP] Support target id by --offload-arch

2020-06-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D60620#2067134 , @tra wrote:

> Do you expect users to specify these IDs? How do you see it being used in 
> practice? I think you do need to implement a user-friendly shortcut and 
> expand it to the detailed offload-id internally. I'm fine with allowing 
> explicit offload id as a hidden argument, but I don't think it's suitable for 
> something that will be used by everyone who can't be expected to be aware of 
> all the gory details of particular GPU features.


The good thing about this target id is that it is backward compatible with GPU 
arch. For common users who are not concerned with specific GPU configurations, 
they can just use the old GPU arch and nothing changes. This is because GPU 
arch without features implies default value for these features, which work on 
all configurations. For advanced users who do need to build for specific GPU 
configurations, they should already have the knowledge about the name and 
meaning of these configurations by reading the AMDGPU user guide 
(http://llvm.org/docs/AMDGPUUsage.html). Therefore a target id in the form of 
gfx908:xnack+ is not something cryptic to them. On the other hand, an encoded 
GPU arch like gfx908a is cryptic since it has no meaning at all.


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

https://reviews.llvm.org/D60620



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


[PATCH] D75169: [ARM] Supporting lowering of half-precision FP arguments and returns in AArch32's backend

2020-06-12 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas added a comment.

Hi @efriedma,

From @SjoerdMeijer's comment and the links he pointed to, it seems to me that 
making `f16` types legal for all ARM subtargets would be a major undertaking 
and far from trivial to implement. It's also not clear to me how significant 
would be the returns of this effort.
My feeling is that we could proceed with the current approach and discuss the 
possbility of making `f16` legal in a separate follow up effort, as mentioned 
by @dnsampaio.

What's your view on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75169



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


[clang] 05ed3ef - Handle delayed-template-parsing functions imported into a non-dtp TU

2020-06-12 Thread Sam McCall via cfe-commits
Author: Sam McCall
Date: 2020-06-12T16:09:38+02:00
New Revision: 05ed3efc2ac7b34bd62b1cbac88ff9a47b649cc5

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

LOG: Handle delayed-template-parsing functions imported into a non-dtp TU

Summary:
DelayedTemplateParsing is marked as BENIGN_LANGOPT, so we are allowed to
use a delayed template in a non-delayed TU.
(This is clangd's default configuration on windows: delayed-template-parsing
is on for the preamble and forced off for the current file)

However today clang fails to parse implicit instantiations in a non-dtp
TU of templates defined in a dtp PCH file (and presumably module?).
In this case the delayed parser is not registered, so the function is
simply marked "delayed" again. We then hit an assert:
end of TU template instantiation should not create more late-parsed templates

Reviewers: rsmith

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

Tags: #clang

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

Added: 
clang/test/PCH/delayed-template-parsing.cpp

Modified: 
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 2cea7307b3ac..764d4e8e9d52 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -652,9 +652,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, bool 
IsFirstDecl) {
 }
 
 // Late template parsing can begin.
-if (getLangOpts().DelayedTemplateParsing)
-  Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr,
-this);
+Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
 if (!PP.isIncrementalProcessingEnabled())
   Actions.ActOnEndOfTranslationUnit();
 //else don't tell Sema that we ended parsing: more input might come.

diff  --git a/clang/test/PCH/delayed-template-parsing.cpp 
b/clang/test/PCH/delayed-template-parsing.cpp
new file mode 100644
index ..b4404c757634
--- /dev/null
+++ b/clang/test/PCH/delayed-template-parsing.cpp
@@ -0,0 +1,14 @@
+// Check any combination of delayed-template-parsing between PCH and TU works.
+// RUN: %clang_cc1 %s -emit-pch -o %t.pch
+// RUN: %clang_cc1 -fdelayed-template-parsing %s -emit-pch -o %t.delayed.pch
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.pch 
%s
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.delayed.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch 
%t.delayed.pch %s
+
+#ifndef MAIN_FILE
+template 
+T successor(T Value) { return Value + 1; }
+#else
+int x = successor(42);
+#endif



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


[clang-tools-extra] 4160f4c - Reland [clangd] Parse std::make_unique, and emit template diagnostics at expansion.

2020-06-12 Thread Sam McCall via cfe-commits
Author: Sam McCall
Date: 2020-06-12T16:18:26+02:00
New Revision: 4160f4c37615f6d5b7615666eb202d9cbb58f4bb

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

LOG: Reland [clangd] Parse std::make_unique, and emit template diagnostics at 
expansion.

This was originally 658af9435071 and reverted in 665dbe91f2ed.
The clang bug this triggered was fixed in 05ed3efc2ac.

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang/include/clang/Frontend/PrecompiledPreamble.h
clang/lib/Frontend/PrecompiledPreamble.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index f1fbaf4646ba..da554ff8c331 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -120,49 +121,96 @@ Range diagnosticRange(const clang::Diagnostic &D, const 
LangOptions &L) {
   return halfOpenToRange(M, R);
 }
 
-// Returns whether the \p D is modified.
-bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
-  const LangOptions &LangOpts) {
-  // We only report diagnostics with at least error severity from headers.
-  // Use default severity to avoid noise with -Werror.
-  if (!Info.getDiags()->getDiagnosticIDs()->isDefaultMappingAsError(
-  Info.getID()))
-return false;
-
-  const SourceManager &SM = Info.getSourceManager();
-  const SourceLocation &DiagLoc = SM.getExpansionLoc(Info.getLocation());
-  SourceLocation IncludeInMainFile;
+// Try to find a location in the main-file to report the diagnostic D.
+// Returns a description like "in included file", or nullptr on failure.
+const char *getMainFileRange(const Diag &D, const SourceManager &SM,
+ SourceLocation DiagLoc, Range &R) {
+  // Look for a note in the main file indicating template instantiation.
+  for (const auto &N : D.Notes) {
+if (N.InsideMainFile) {
+  switch (N.ID) {
+  case diag::note_template_class_instantiation_was_here:
+  case diag::note_template_class_explicit_specialization_was_here:
+  case diag::note_template_class_instantiation_here:
+  case diag::note_template_member_class_here:
+  case diag::note_template_member_function_here:
+  case diag::note_function_template_spec_here:
+  case diag::note_template_static_data_member_def_here:
+  case diag::note_template_variable_def_here:
+  case diag::note_template_enum_def_here:
+  case diag::note_template_nsdmi_here:
+  case diag::note_template_type_alias_instantiation_here:
+  case diag::note_template_exception_spec_instantiation_here:
+  case diag::note_template_requirement_instantiation_here:
+  case diag::note_evaluating_exception_spec_here:
+  case diag::note_default_arg_instantiation_here:
+  case diag::note_default_function_arg_instantiation_here:
+  case diag::note_explicit_template_arg_substitution_here:
+  case diag::note_function_template_deduction_instantiation_here:
+  case diag::note_deduced_template_arg_substitution_here:
+  case diag::note_prior_template_arg_substitution:
+  case diag::note_template_default_arg_checking:
+  case diag::note_concept_specialization_here:
+  case diag::note_nested_requirement_here:
+  case diag::note_checking_constraints_for_template_id_here:
+  case diag::note_checking_constraints_for_var_spec_id_here:
+  case diag::note_checking_constraints_for_class_spec_id_here:
+  case diag::note_checking_constraints_for_function_here:
+  case diag::note_constraint_substitution_here:
+  case diag::note_constraint_normalization_here:
+  case diag::note_parameter_mapping_substitution_here:
+R = N.Range;
+return "in template";
+  default:
+break;
+  }
+}
+  }
+  // Look for where the file with the error was #included.
   auto GetIncludeLoc = [&SM](SourceLocation SLoc) {
 return SM.getIncludeLoc(SM.getFileID(SLoc));
   };
-  for (auto IncludeLocation = GetIncludeLoc(DiagLoc); 
IncludeLocation.isValid();
+  for (auto IncludeLocation = GetIncludeLoc(SM.getExpansionLoc(DiagLoc));
+   IncludeLocation.isValid();
IncludeLocation = GetIncludeLoc(IncludeLocation)) {
 if (clangd::isInsideMainFile(IncludeLocation, SM)) {
-  IncludeInMainFile = IncludeLocation;
-  break;
+  R.start = sourceLocToPosition

[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D81713#2089680 , @yaxunl wrote:

> In D81713#2089672 , @arsenm wrote:
>
> > Can you add tests for this? Is this also sufficient with the directory 
> > layout change?
>
>
> You mean does this work after we move device lib from /opt/rocm/lib to 
> /opt/rocm/amdgcn/bitcode ?


Yes


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

https://reviews.llvm.org/D81713



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


cfe-commits@lists.llvm.org

2020-06-12 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson updated this revision to Diff 270387.
LukeGeeson added a comment.

- removed unnecessary contents of test


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

https://reviews.llvm.org/D80716

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-bf16-dotprod-intrinsics.ll
@@ -0,0 +1,176 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple aarch64-arm-none-eabi  -mattr=+bf16 %s -o - | FileCheck %s
+
+define <2 x float> @test_vbfdot_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.2s, v1.4h, v2.4h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %a to <8 x i8>
+  %1 = bitcast <4 x bfloat> %b to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %0, <8 x i8> %1)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.4s, v1.8h, v2.8h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %a to <16 x i8>
+  %1 = bitcast <8 x bfloat> %b to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %0, <16 x i8> %1)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <2 x float> @test_vbfdot_lane_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_lane_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK:bfdot v0.2s, v1.4h, v2.2h[0]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %b to <2 x float>
+  %shuffle = shufflevector <2 x float> %0, <2 x float> undef, <2 x i32> zeroinitializer
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %1, <8 x i8> %2)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_laneq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_laneq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.4s, v1.8h, v2.2h[3]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <4 x i32> 
+  %1 = bitcast <8 x bfloat> %a to <16 x i8>
+  %2 = bitcast <4 x float> %shuffle to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %1, <16 x i8> %2)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <2 x float> @test_vbfdot_laneq_f32(<2 x float> %r, <4 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdot_laneq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfdot v0.2s, v1.4h, v2.2h[3]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <2 x i32> 
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.aarch64.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %1, <8 x i8> %2)
+  ret <2 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfdotq_lane_f32(<4 x float> %r, <8 x bfloat> %a, <4 x bfloat> %b) {
+; CHECK-LABEL: test_vbfdotq_lane_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK:bfdot v0.4s, v1.8h, v2.2h[0]
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <4 x bfloat> %b to <2 x float>
+  %shuffle = shufflevector <2 x float> %0, <2 x float> undef, <4 x i32> zeroinitializer
+  %1 = bitcast <8 x bfloat> %a to <16 x i8>
+  %2 = bitcast <4 x float> %shuffle to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.aarch64.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %1, <16 x i8> %2)
+  ret <4 x float> %vbfdot1.i
+}
+
+define <4 x float> @test_vbfmmlaq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfmmlaq_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:bfmmla v0.4s, v1.8h, v2.8h
+; CHECK-NEXT:ret
+entry:
+  %0 = bitcast <8 x bfloat> %a to <16 x i8>
+  %1 = bitcast <8 x bfloat> %b to <16 x i8>
+  %vbfmmla1.i = tail call <4 x float> @llvm.aarch64.neon.bfmmla.v4f32.v16i8(<4 x float> %r, <16 x i8> %0, <16 x i8> %1)
+  ret <4 x float> %vbfmmla1.i
+}
+
+define <4 x float> @test_vbfmlalbq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) {
+; CHECK-LABEL: test_vbfmlalbq_f32:
+; CHECK:

[PATCH] D81739: [clangd] Turn on RecoveryAST for clangd by default.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81739

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -281,11 +281,10 @@
 opt RecoveryAST{
 "recovery-ast",
 cat(Features),
-desc("Preserve expressions in AST for broken code (C++ only). Note that "
- "this feature is experimental and may lead to crashes"),
-init(false),
-Hidden,
+desc("Preserve expressions in AST for broken code (C++ only)."),
+init(true),
 };
+
 opt RecoveryASTType{
 "recovery-ast-type",
 cat(Features),


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -281,11 +281,10 @@
 opt RecoveryAST{
 "recovery-ast",
 cat(Features),
-desc("Preserve expressions in AST for broken code (C++ only). Note that "
- "this feature is experimental and may lead to crashes"),
-init(false),
-Hidden,
+desc("Preserve expressions in AST for broken code (C++ only)."),
+init(true),
 };
+
 opt RecoveryASTType{
 "recovery-ast-type",
 cat(Features),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81315: [analyzer] Warning for default constructed unique pointer dereferences

2020-06-12 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar updated this revision to Diff 270391.
vrnithinkumar retitled this revision from "[analyzer][Draft] [Prototype] 
warning for default constructed unique pointer dereferences" to "[analyzer] 
Warning for default constructed unique pointer dereferences".
vrnithinkumar added a comment.

Addressing the review comments


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

https://reviews.llvm.org/D81315

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -10,7 +10,7 @@
   std::unique_ptr Q = std::move(P);
   if (Q)
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
-  *Q.get() = 1; // no-warning
+  *Q.get() = 1; // no-warning
   if (P)
 clang_analyzer_warnIfReached(); // no-warning
   // TODO: Report a null dereference (instead).
@@ -26,3 +26,64 @@
   (s->*func)(); // no-crash
 }
 } // namespace testUnknownCallee
+
+class A {
+public:
+  A(){};
+  void foo();
+};
+
+A *return_null() {
+  return nullptr;
+}
+
+void derefAfterValidCtr() {
+  std::unique_ptr P(new A());
+  P->foo(); // No warning.
+}
+
+void derefAfterDefaultCtr() {
+  std::unique_ptr P;
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterCtrWithNull() {
+  std::unique_ptr P(nullptr);
+  *P; // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterCtrWithNullReturnMethod() {
+  std::unique_ptr P(return_null());
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterRelease() {
+  std::unique_ptr P(new A());
+  P.release();
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterReset() {
+  std::unique_ptr P(new A());
+  P.reset();
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterResetWithNull() {
+  std::unique_ptr P(new A());
+  P.reset(nullptr);
+  P->foo(); // expected-warning {{Dereference of null smart pointer [cplusplus.SmartPtr]}}
+}
+
+void derefAfterResetWithNonNull() {
+  std::unique_ptr P;
+  P.reset(new A());
+  P->foo(); // No warning.
+}
+
+void derefAfterReleaseAndResetWithNonNull() {
+  std::unique_ptr P(new A());
+  P.release();
+  P.reset(new A());
+  P->foo(); // No warning.
+}
\ No newline at end of file
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -946,10 +946,15 @@
   template  // TODO: Implement the stub for deleter.
   class unique_ptr {
   public:
+unique_ptr() {}
+unique_ptr(T *) {}
 unique_ptr(const unique_ptr &) = delete;
 unique_ptr(unique_ptr &&);
 
 T *get() const;
+T *release() const;
+void reset(T *p = nullptr) const;
+void swap(unique_ptr &p) const;
 
 typename std::add_lvalue_reference::type operator*() const;
 T *operator->() const;
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -13,26 +13,60 @@
 
 #include "Move.h"
 
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #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/SVals.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class SmartPtrModeling : public Checker {
+class SmartPtrModeling
+: public Checker {
   bool isNullAfterMoveMethod(const CallEvent &Call) const;
+  BugType NullDereferenceBugType{this, "Null-smartPtr-deref",
+ "C++ smart pointer"};
 
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkPostCall(const CallEvent &MC, CheckerContext &C) const;
+  void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
+
+private:
+  void reportBug(CheckerContext &C, const CallEvent &Call) const;
+  bool isStdSmartPointerClass(const CXXRecordDecl *RD) const;
+  void updateTrackedRegion(const CallEvent &Call, Chec

cfe-commits@lists.llvm.org

2020-06-12 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson created this revision.
LukeGeeson added reviewers: stuij, t.p.northover, SjoerdMeijer, sdesmalen, 
fpetrogalli.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls.
Herald added projects: clang, LLVM.
LukeGeeson added a parent revision: D81486: [ARM][BFloat] Implement lowering of 
bf16 load/store intrinsics.

This patch upstreams support for BFloat Matrix Multiplication Intrinsics
and Code Generation from __bf16 to AArch32. This includes IR intrinsics. 
Unittests are
provided as needed.

This patch is part of a series implementing the Bfloat16 extension of
the
Armv8.6-a architecture, as detailed here:

https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/arm-architecture-developments-armv8-6-a

The bfloat type, and its properties are specified in the Arm
Architecture
Reference Manual:

https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile

The following people contributed to this patch:

- Luke Geeson
- Momchil Velikov
- Mikhail Maltsev
- Luke Cheeseman


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81740

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-bf16-dotprod-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/test/CodeGen/ARM/arm-bf16-dotprod-intrinsics.ll

Index: llvm/test/CodeGen/ARM/arm-bf16-dotprod-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARM/arm-bf16-dotprod-intrinsics.ll
@@ -0,0 +1,164 @@
+; RUN: llc -mtriple armv8.6a-arm-none-eabi  -mattr=+bf16 -float-abi=hard %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-BF16
+; RUN: llc -mtriple armv8.6a-arm-none-eabi  -mattr=+bf16 -float-abi=hard %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-BF16
+
+; CHECK-LABEL: test_vbfdot_f32
+; CHECK-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
+; CHECK-NO-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}
+define arm_aapcs_vfpcc <2 x float> @test_vbfdot_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) local_unnamed_addr #0 {
+entry:
+  %0 = bitcast <4 x bfloat> %a to <8 x i8>
+  %1 = bitcast <4 x bfloat> %b to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.arm.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %0, <8 x i8> %1) #3
+  ret <2 x float> %vbfdot1.i
+}
+
+; CHECK-LABEL: test_vbfdotq_f32
+; CHECK-BF16: vdot.bf16   q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}
+; CHECK-NO-BF16: vdot.bf16   q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}
+define <4 x float> @test_vbfdotq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) local_unnamed_addr #1 {
+entry:
+  %0 = bitcast <8 x bfloat> %a to <16 x i8>
+  %1 = bitcast <8 x bfloat> %b to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.arm.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %0, <16 x i8> %1) #3
+  ret <4 x float> %vbfdot1.i
+}
+
+; CHECK-LABEL: test_vbfdot_lane_f32
+; CHECK-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}[0]
+; CHECK-NO-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}[0]
+define <2 x float> @test_vbfdot_lane_f32(<2 x float> %r, <4 x bfloat> %a, <4 x bfloat> %b) local_unnamed_addr #0 {
+entry:
+  %0 = bitcast <4 x bfloat> %b to <2 x float>
+  %shuffle = shufflevector <2 x float> %0, <2 x float> undef, <2 x i32> zeroinitializer
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.arm.neon.bfdot.v2f32.v8i8(<2 x float> %r, <8 x i8> %1, <8 x i8> %2) #3
+  ret <2 x float> %vbfdot1.i
+}
+
+; CHECK-LABEL: test_vbfdotq_laneq_f32
+; CHECK-BF16: vdup.32 q{{[0-9]+}}, d{{[0-9]+}}[1]
+; CHECK-BF16: vdot.bf16   q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}
+; CHECK-NO-BF16: vdot.bf16   q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}
+define <4 x float> @test_vbfdotq_laneq_f32(<4 x float> %r, <8 x bfloat> %a, <8 x bfloat> %b) local_unnamed_addr #1 {
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <4 x i32> 
+  %1 = bitcast <8 x bfloat> %a to <16 x i8>
+  %2 = bitcast <4 x float> %shuffle to <16 x i8>
+  %vbfdot1.i = tail call <4 x float> @llvm.arm.neon.bfdot.v4f32.v16i8(<4 x float> %r, <16 x i8> %1, <16 x i8> %2) #3
+  ret <4 x float> %vbfdot1.i
+}
+
+; CHECK-LABEL: test_vbfdot_laneq_f32
+; CHECK-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}[1]
+; CHECK-NO-BF16: vdot.bf16   d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}[1]
+define <2 x float> @test_vbfdot_laneq_f32(<2 x float> %r, <4 x bfloat> %a, <8 x bfloat> %b) local_unnamed_addr #1 {
+entry:
+  %0 = bitcast <8 x bfloat> %b to <4 x float>
+  %shuffle = shufflevector <4 x float> %0, <4 x float> undef, <2 x i32> 
+  %1 = bitcast <4 x bfloat> %a to <8 x i8>
+  %2 = bitcast <2 x float> %shuffle to <8 x i8>
+  %vbfdot1.i = tail call <2 x float> @llvm.arm.neon.bfdot.v2f32.v

cfe-commits@lists.llvm.org

2020-06-12 Thread Ties Stuij via Phabricator via cfe-commits
stuij accepted this revision.
stuij added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


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

https://reviews.llvm.org/D80716



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


[PATCH] D81315: [analyzer] Warning for default constructed unique pointer dereferences

2020-06-12 Thread Nithin VR via Phabricator via cfe-commits
vrnithinkumar marked 38 inline comments as done.
vrnithinkumar added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:31
 namespace {
-class SmartPtrModeling : public Checker {
+struct RegionState {
+private:

vsavchenko wrote:
> xazax.hun wrote:
> > I think `RegionState` is not very descriptive. I'd call it something like 
> > `RegionNullness`.
> linter: LLVM coding standards require to use `class` keyword in situations 
> like this 
> (https://llvm.org/docs/CodingStandards.html#use-of-class-and-struct-keywords).
>   I would even say that `struct` is good for POD types.
With the new changes, the struct is removed.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:31
 namespace {
-class SmartPtrModeling : public Checker {
+struct RegionState {
+private:

vrnithinkumar wrote:
> vsavchenko wrote:
> > xazax.hun wrote:
> > > I think `RegionState` is not very descriptive. I'd call it something like 
> > > `RegionNullness`.
> > linter: LLVM coding standards require to use `class` keyword in situations 
> > like this 
> > (https://llvm.org/docs/CodingStandards.html#use-of-class-and-struct-keywords).
> >   I would even say that `struct` is good for POD types.
> With the new changes, the struct is removed.
With the new changes, the struct is removed.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:33
+private:
+  enum Kind { Null, NonNull, Unknown } K;
+  RegionState(Kind InK) : K(InK) {}

vsavchenko wrote:
> I think that it would be better to put declarations for `enum` and for a 
> field separately.
> Additionally, I don't think that `K` is a very good name for a data member.  
> It should be evident from the name of the member what is it.  Shot names like 
> that can be fine only for iterators or for certain `clang`-specific 
> structures because of existing traditions (like `SM` for `SourceManager` and 
> `LO` for `LanguageOptions`).
With the new changes, the `enum`  is removed.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:46
+};
+} // end of anonymous namespace
+

Szelethus wrote:
> xazax.hun wrote:
> > You can merge the two anonymous namespaces, this and the one below.
> [[https://llvm.org/docs/CodingStandards.html#anonymous-namespaces | I prefer 
> them like this. ]]
with new change only one anonymous namespace is there



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:60
+private:
+  mutable std::unique_ptr BT;
+  void reportBug(CheckerContext &C, const CallEvent &Call) const;

xazax.hun wrote:
> This is how we used to do it, but we did not update all the checks yet. 
> Nowadays we can just initialize bugtypes immediately, see 
> https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp#L169
updated to initialize bugtype immediately



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:65
+
+  // STL smart pointers which we are trying to model
+  const llvm::StringSet<> StdSmartPtrs = {

xazax.hun wrote:
> In LLVM we aim for full sentences as comments with a period at the end.
Updated the comments as LLVM style



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:72-76
+  // STL smart pointer methods which resets to null
+  const llvm::StringSet<> ResetMethods = {"reset", "release", "swap"};
+
+  // STL smart pointer methods which resets to null via null argument
+  const llvm::StringSet<> NullResetMethods = {"reset", "swap"};

NoQ wrote:
> Please consider `CallDescription` and `CallDescriptionMap`!
Made changes to use `CallDescription` and `CallDescriptionMap`



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:81
+// to track the mem region and curresponding states
+REGISTER_MAP_WITH_PROGRAMSTATE(TrackedRegionMap, const MemRegion *, 
RegionState)
+// to track the Symbols which will get inner raw pointer via unique_ptr.get()

NoQ wrote:
> I ultimately believe this map should go away. The only thing we really need 
> is the map from smart pointer region to the symbol for its current raw 
> pointer. As long as we have such data we can discover the nullness of that 
> symbol (which *is* the nullness of the smart pointer as well) from Range 
> Constraints.
Removed this map.
Now maping region to SVal



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:119
+  ProgramStateRef State = C.getState();
+  const auto OC = dyn_cast(&Call);
+  if (!OC)

vsavchenko wrote:
> xazax.hun wrote:
> > Here the const applies for the pointer, not the pointee. We usually do 
> > `const auto *OC` instead.
> As I said above, I think we should be really careful about abbreviated and 
> extremely short variable na

[PATCH] D81474: Handle delayed-template-parsing functions imported into a non-dtp TU

2020-06-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05ed3efc2ac7: Handle delayed-template-parsing functions 
imported into a non-dtp TU (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81474

Files:
  clang/lib/Parse/Parser.cpp
  clang/test/PCH/delayed-template-parsing.cpp


Index: clang/test/PCH/delayed-template-parsing.cpp
===
--- /dev/null
+++ clang/test/PCH/delayed-template-parsing.cpp
@@ -0,0 +1,14 @@
+// Check any combination of delayed-template-parsing between PCH and TU works.
+// RUN: %clang_cc1 %s -emit-pch -o %t.pch
+// RUN: %clang_cc1 -fdelayed-template-parsing %s -emit-pch -o %t.delayed.pch
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.pch 
%s
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.delayed.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch 
%t.delayed.pch %s
+
+#ifndef MAIN_FILE
+template 
+T successor(T Value) { return Value + 1; }
+#else
+int x = successor(42);
+#endif
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -652,9 +652,7 @@
 }
 
 // Late template parsing can begin.
-if (getLangOpts().DelayedTemplateParsing)
-  Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr,
-this);
+Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
 if (!PP.isIncrementalProcessingEnabled())
   Actions.ActOnEndOfTranslationUnit();
 //else don't tell Sema that we ended parsing: more input might come.


Index: clang/test/PCH/delayed-template-parsing.cpp
===
--- /dev/null
+++ clang/test/PCH/delayed-template-parsing.cpp
@@ -0,0 +1,14 @@
+// Check any combination of delayed-template-parsing between PCH and TU works.
+// RUN: %clang_cc1 %s -emit-pch -o %t.pch
+// RUN: %clang_cc1 -fdelayed-template-parsing %s -emit-pch -o %t.delayed.pch
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -include-pch %t.delayed.pch %s
+// RUN: %clang_cc1 -DMAIN_FILE -fdelayed-template-parsing -include-pch %t.delayed.pch %s
+
+#ifndef MAIN_FILE
+template 
+T successor(T Value) { return Value + 1; }
+#else
+int x = successor(42);
+#endif
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -652,9 +652,7 @@
 }
 
 // Late template parsing can begin.
-if (getLangOpts().DelayedTemplateParsing)
-  Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr,
-this);
+Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
 if (!PP.isIncrementalProcessingEnabled())
   Actions.ActOnEndOfTranslationUnit();
 //else don't tell Sema that we ended parsing: more input might come.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81090: [AST][RecoveryExpr] Preserve the AST for invalid class constructions.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 270402.
hokein added a comment.

rebase to master and adjust the diagnostic tests after "-frecovery-ast" is 
flipped on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81090

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp


Index: clang/test/SemaCXX/cxx1z-copy-omission.cpp
===
--- clang/test/SemaCXX/cxx1z-copy-omission.cpp
+++ clang/test/SemaCXX/cxx1z-copy-omission.cpp
@@ -106,7 +106,7 @@
   sizeof(Indestructible{}); // expected-error {{deleted}}
   sizeof(make_indestructible()); // expected-error {{deleted}}
   sizeof(make_incomplete()); // expected-error {{incomplete}}
-  typeid(Indestructible{}); // expected-error {{deleted}}
+  typeid(Indestructible{}); // expected-error {{deleted}} expected-error {{you 
need to include }}
   typeid(make_indestructible()); // expected-error {{deleted}} \
  // expected-error {{need to include 
}}
   typeid(make_incomplete()); // expected-error {{incomplete}} \
Index: clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
===
--- clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
+++ clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
@@ -163,7 +163,7 @@
 // (for the second phase, no constructor is viable)
 G g1{1, 2, 3}; // expected-error {{no matching constructor}}
 (void) new G{1, 2, 3}; // expected-error {{no matching constructor}}
-(void) G{1, 2, 3} // expected-error {{no matching constructor}}
+(void) G{1, 2, 3}; // expected-error {{no matching constructor}}
 
 // valid (T deduced to <>).
 G g2({1, 2, 3});
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2043,14 +2043,11 @@
 X::n; // expected-note {{in evaluation of exception 
specification for 'BadDefaultInit::A::A' needed here}}
   };
 
-  // FIXME: The "constexpr constructor must initialize all members" diagnostic
-  // here is bogus (we discard the k(k) initializer because the parameter 'k'
-  // has been marked invalid).
   struct B {
-constexpr B( // expected-warning {{initialize all members}}
+constexpr B(
 int k = X::n) : // expected-error {{default argument to 
function 'B' that is declared later}} expected-note {{here}}
   k(k) {}
-int k; // expected-note {{not initialized}}
+int k;
   };
 }
 
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -159,11 +159,18 @@
   // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT:  `-InitListExpr
   Bar b2 = {1};
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' 
contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}}  'const Bar' 
contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors lvalue
+  // CHECK-NEXT:`-DeclRefExpr {{.*}} 'x' 'int'
   Bar b3 = Bar(x);
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}}  'Bar' 
contains-errors
+  // CHECK-NEXT:`-ImplicitCastExpr {{.*}} 'const Bar' contains-errors
+  // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:`-InitListExpr {{.*}} 'void'
+  // CHECK-NEXT:  `-DeclRefExpr {{.*}} 'x' 'int'
   Bar b4 = Bar{x};
   // CHECK: `-VarDecl {{.*}} b5 'Bar'
   // CHECK-NEXT: `-CXXUnresolvedConstructExpr {{.*}} 'Bar' contains-errors 
'Bar'
@@ -176,6 +183,10 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} 'invalid'
   Bar b6 = Bar{invalid()};
+
+  // CHECK: `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 1
+  Bar(1);
 }
 void InitializerForAuto() {
   // CHECK: `-VarDecl {{.*}} invalid a 'auto'
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1389,6 +1389,9 @@
   if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
   !Result.get()->isTypeDependent())
 Result = CorrectDelayedTyposInExpr(Result.get());
+  else if (Result.isInvalid())
+Result = CreateRecovery

[clang] b2a37cf - [Analyzer] Replace `assert` with `ASSERT_TRUE` in a unit test to silence warnings

2020-06-12 Thread Adam Balogh via cfe-commits
Author: Adam Balogh
Date: 2020-06-12T17:09:34+02:00
New Revision: b2a37cfe2bda0bc8c4d2e981922b5ac59c429bdc

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

LOG: [Analyzer] Replace `assert` with `ASSERT_TRUE` in a unit test to silence 
warnings

Added: 


Modified: 
clang/unittests/StaticAnalyzer/ParamRegionTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/ParamRegionTest.cpp 
b/clang/unittests/StaticAnalyzer/ParamRegionTest.cpp
index 7ec032a7beae..3dbbc7ba1578 100644
--- a/clang/unittests/StaticAnalyzer/ParamRegionTest.cpp
+++ b/clang/unittests/StaticAnalyzer/ParamRegionTest.cpp
@@ -19,7 +19,7 @@ class ParamRegionTestConsumer : public ExprEngineConsumer {
   void checkForSameParamRegions(MemRegionManager &MRMgr,
 const StackFrameContext *SFC,
 const ParmVarDecl *PVD) {
-assert(llvm::all_of(PVD->redecls(), [&](const clang::VarDecl *D2) {
+ASSERT_TRUE(llvm::all_of(PVD->redecls(), [&](const clang::VarDecl *D2) {
   return MRMgr.getVarRegion(PVD, SFC) ==
  MRMgr.getVarRegion(cast(D2), SFC);
 }));



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


[PATCH] D81163: [AST][RecoveryExpr] Preserve the AST for invalid conditions.

2020-06-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 270413.
hokein added a comment.

rebase and adjust the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81163

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaTemplate/instantiate-expr-3.cpp


Index: clang/test/SemaTemplate/instantiate-expr-3.cpp
===
--- clang/test/SemaTemplate/instantiate-expr-3.cpp
+++ clang/test/SemaTemplate/instantiate-expr-3.cpp
@@ -65,7 +65,7 @@
   void f(T t) {
 (void)({
 if (t) // expected-error{{contextually convertible}}
-  t = t + 17;
+  t = t + 17; // expected-error {{invalid operands to binary 
expression ('N1::X' and 'int')}}
 t + 12; // expected-error{{invalid operands}}
   });
   }
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -211,3 +211,30 @@
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+void InvalidCondition() {
+  // CHECK:  IfStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}}  '' 
contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  if (invalid()) {}
+
+  // CHECK:  WhileStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}}  '' 
contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  while (invalid()) {}
+
+  // CHECK:  SwitchStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  switch(invalid()) {
+case 1:
+  break;
+  }
+  // FIXME: figure out why the type of ConditionalOperator is not int.
+  // CHECK:  ConditionalOperator {{.*}} '' contains-errors
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}}
+  // CHECK-NEXT: |-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 2
+  invalid() ? 1 : 2;
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18466,9 +18466,12 @@
 Cond = CheckSwitchCondition(Loc, SubExpr);
 break;
   }
-  if (Cond.isInvalid())
-return ConditionError();
-
+  if (Cond.isInvalid()) {
+Cond = CreateRecoveryExpr(SubExpr->getBeginLoc(), SubExpr->getEndLoc(),
+  {SubExpr});
+if (!Cond.get())
+  return ConditionError();
+  }
   // FIXME: FullExprArg doesn't have an invalid bit, so check nullness instead.
   FullExprArg FullExpr = MakeFullExpr(Cond.get(), Loc);
   if (!FullExpr.get())


Index: clang/test/SemaTemplate/instantiate-expr-3.cpp
===
--- clang/test/SemaTemplate/instantiate-expr-3.cpp
+++ clang/test/SemaTemplate/instantiate-expr-3.cpp
@@ -65,7 +65,7 @@
   void f(T t) {
 (void)({
 if (t) // expected-error{{contextually convertible}}
-  t = t + 17;
+  t = t + 17; // expected-error {{invalid operands to binary expression ('N1::X' and 'int')}}
 t + 12; // expected-error{{invalid operands}}
   });
   }
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -211,3 +211,30 @@
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+void InvalidCondition() {
+  // CHECK:  IfStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}}  '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  if (invalid()) {}
+
+  // CHECK:  WhileStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}}  '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  while (invalid()) {}
+
+  // CHECK:  SwitchStmt {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} 
+  switch(invalid()) {
+case 1:
+  break;
+  }
+  // FIXME: figure out why the type of ConditionalOperator is not int.
+  // CHECK:  ConditionalOperator {{.*}} '' contains-errors
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}}
+  // CHECK-NEXT: |-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 2
+  invalid() ? 1 : 2;
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18466,9 +18466,12 @@
 Cond = CheckSwitchCondition(Loc, SubExpr);
 break;
   }
-  if (Cond.isInvalid())
-return ConditionError();
-
+  if (Cond.isInvalid()) {
+Cond = CreateRecoveryExpr(SubExpr->getBeginLoc(), SubExpr->getEndLoc(),
+  {SubExpr});
+i

[PATCH] D81745: [analyzer][MallocChecker] PR46253: Correctly recognize standard realloc

2020-06-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, hokein, baloghadamsoftware, balazske, 
xazax.hun, dcoughlin, vsavchenko, martong.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
whisperity.

https://bugs.llvm.org/show_bug.cgi?id=46253

This is an obvious hack because `realloc` isn't any more affected than other 
functions modeled by MallocChecker (or any user of `CallDescription` really), 
but the nice solution will take some time to implement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81745

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/malloc.cpp


Index: clang/test/Analysis/malloc.cpp
===
--- clang/test/Analysis/malloc.cpp
+++ clang/test/Analysis/malloc.cpp
@@ -172,3 +172,21 @@
   // ZERO_SIZE_PTR is specially handled but only for malloc family
   delete Ptr; // expected-warning{{Argument to 'delete' is a constant address 
(16)}}
 }
+
+namespace pr46253_class {
+class a {
+  void *realloc(int, bool = false) { realloc(1); } // no-crash
+};
+} // namespace pr46253_class
+
+namespace pr46253_retty{
+void realloc(void *ptr, size_t size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_retty
+
+namespace pr46253_paramty{
+void *realloc(void **ptr, size_t size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_paramty
+
+namespace pr46253_paramty2{
+void *realloc(void *ptr, int size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_paramty2
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -47,6 +47,7 @@
 #include "AllocationState.h"
 #include "InterCheckerAPI.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ParentMap.h"
@@ -1037,9 +1038,44 @@
   C.addTransition(State);
 }
 
-void MallocChecker::checkRealloc(const CallEvent &Call,
- CheckerContext &C,
+static bool isStandardRealloc(const CallEvent &Call) {
+  const FunctionDecl *FD = dyn_cast(Call.getDecl());
+  assert(FD);
+  ASTContext &AC = FD->getASTContext();
+
+  if (isa(FD))
+return false;
+
+  return FD->getDeclaredReturnType().getDesugaredType(AC) == AC.VoidPtrTy &&
+ FD->getParamDecl(0)->getType().getDesugaredType(AC) == AC.VoidPtrTy &&
+ FD->getParamDecl(1)->getType().getDesugaredType(AC) ==
+ AC.getSizeType();
+}
+
+static bool isGRealloc(const CallEvent &Call) {
+  const FunctionDecl *FD = dyn_cast(Call.getDecl());
+  assert(FD);
+  ASTContext &AC = FD->getASTContext();
+
+  if (isa(FD))
+return false;
+
+  return FD->getDeclaredReturnType().getDesugaredType(AC) == AC.VoidPtrTy &&
+ FD->getParamDecl(0)->getType().getDesugaredType(AC) == AC.VoidPtrTy &&
+ FD->getParamDecl(1)->getType().getDesugaredType(AC) ==
+ AC.UnsignedLongTy;
+}
+
+void MallocChecker::checkRealloc(const CallEvent &Call, CheckerContext &C,
  bool ShouldFreeOnFail) const {
+  // HACK: CallDescription currently recognizes non-standard realloc functions
+  // as standard because it doesn't check the type, or wether its a non-method
+  // function. This should be solved by making CallDescription smarter.
+  // Mind that this came from a bug report, and all other functions suffer from
+  // this.
+  // https://bugs.llvm.org/show_bug.cgi?id=46253
+  if (!isStandardRealloc(Call) && !isGRealloc(Call))
+return;
   ProgramStateRef State = C.getState();
   State = ReallocMemAux(C, Call, ShouldFreeOnFail, State, AF_Malloc);
   State = ProcessZeroAllocCheck(Call, 1, State);


Index: clang/test/Analysis/malloc.cpp
===
--- clang/test/Analysis/malloc.cpp
+++ clang/test/Analysis/malloc.cpp
@@ -172,3 +172,21 @@
   // ZERO_SIZE_PTR is specially handled but only for malloc family
   delete Ptr; // expected-warning{{Argument to 'delete' is a constant address (16)}}
 }
+
+namespace pr46253_class {
+class a {
+  void *realloc(int, bool = false) { realloc(1); } // no-crash
+};
+} // namespace pr46253_class
+
+namespace pr46253_retty{
+void realloc(void *ptr, size_t size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_retty
+
+namespace pr46253_paramty{
+void *realloc(void **ptr, size_t size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_paramty
+
+namespace pr46253_paramty2{
+void *realloc(void *ptr, int size) { realloc(ptr, size); } // no-crash
+} // namespace pr46253_paramty2
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

[clang] 1eddce4 - Fix non-determinism issue with implicit lambda captures.

2020-06-12 Thread Erich Keane via cfe-commits
Author: Erich Keane
Date: 2020-06-12T09:16:43-07:00
New Revision: 1eddce4177cfddc86d4696b758904443b0b4f193

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

LOG: Fix non-determinism issue with implicit lambda captures.

We were using llvm::SmallPtrSet for our ODR-use set which was also used
for instantiating the implicit lambda captures. The order in which the
captures are added depends on this, so the lambda's layout ended up
changing.  The test just uses floats, but this was noticed with other
types as well.

This test replaces the short-lived SmallPtrSet (it lasts only for an
expression, which, though is a long time for lambdas, is at least not
forever) with a SmallSetVector.

Added: 
clang/test/CodeGenCXX/lambda-deterministic-captures.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 266192087d35..a3f4313c0d65 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -627,7 +627,7 @@ class Sema final {
   /// we won't know until all lvalue-to-rvalue and discarded value conversions
   /// have been applied to all subexpressions of the enclosing full expression.
   /// This is cleared at the end of each full expression.
-  using MaybeODRUseExprSet = llvm::SmallPtrSet;
+  using MaybeODRUseExprSet = llvm::SmallSetVector;
   MaybeODRUseExprSet MaybeODRUseExprs;
 
   std::unique_ptr CachedFunctionScope;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6477979e92fe..6965acdb6163 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17553,7 +17553,7 @@ static ExprResult 
rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
 
   // Mark that this expression does not constitute an odr-use.
   auto MarkNotOdrUsed = [&] {
-S.MaybeODRUseExprs.erase(E);
+S.MaybeODRUseExprs.remove(E);
 if (LambdaScopeInfo *LSI = S.getCurLambda())
   LSI->markVariableExprAsNonODRUsed(E);
   };

diff  --git a/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp 
b/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
new file mode 100644
index ..d025a431d5c5
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm --std=c++17 %s 
-o - | FileCheck %s
+
+struct stream {
+  friend const stream &operator<<(const stream &, const float &);
+};
+
+void foo() {
+  constexpr float f_zero = 0.0f;
+  constexpr float f_one = 1.0f;
+  constexpr float f_two = 2.0f;
+
+  stream s;
+  [=]() {
+s << f_zero << f_one << f_two;
+  }();
+}
+
+// CHECK: define void @_Z3foov
+// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
+// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 1
+// CHECK-NEXT: store float 0.000
+// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
+// CHECK-NEXT: store float 1.000
+// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 3
+// CHECK-NEXT: store float 2.000
+
+// The lambda body.  Reverse iteration when the captures aren't deterministic
+// causes these to be laid out 
diff erently in the lambda.
+// CHECK: define internal void
+// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
+// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 1
+// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
+// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 3



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


[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-06-12 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.

I would not call the results of the measurement within the margin of error but 
the results do not look bad. Unless there is some objection from someone else I 
am ok with committing this but please change the title of revision before 
committing. When one says optimization we often think about performance.  It 
should say something like reasoning about more comparison operations.


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

https://reviews.llvm.org/D78933



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


[clang] 270d580 - [analyzer] Avoid unused variable warning in opt build

2020-06-12 Thread Jacques Pienaar via cfe-commits
Author: Jacques Pienaar
Date: 2020-06-12T09:48:49-07:00
New Revision: 270d580a0e9ff2f2e1b6240fccedee7c25dc3bfa

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

LOG: [analyzer] Avoid unused variable warning in opt build

Added: 


Modified: 
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp 
b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index 4a7e0d91ea23..461d08f3d2c7 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -297,7 +297,9 @@ CheckerRegistry::CheckerRegistry(
  "A strong dependency mustn't have weak dependencies!");
   assert(WeakDepPair.second != DepPair.second &&
  "A strong dependency mustn't be a weak dependency as well!");
+  (void)WeakDepPair;
 }
+(void)DepPair;
   }
 #endif
 



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


Re: [clang] 1eddce4 - Fix non-determinism issue with implicit lambda captures.

2020-06-12 Thread Richard Smith via cfe-commits
On Fri, 12 Jun 2020 at 09:17, Erich Keane via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Erich Keane
> Date: 2020-06-12T09:16:43-07:00
> New Revision: 1eddce4177cfddc86d4696b758904443b0b4f193
>
> URL:
> https://github.com/llvm/llvm-project/commit/1eddce4177cfddc86d4696b758904443b0b4f193
> DIFF:
> https://github.com/llvm/llvm-project/commit/1eddce4177cfddc86d4696b758904443b0b4f193.diff
>
> LOG: Fix non-determinism issue with implicit lambda captures.
>
> We were using llvm::SmallPtrSet for our ODR-use set which was also used
> for instantiating the implicit lambda captures. The order in which the
> captures are added depends on this, so the lambda's layout ended up
> changing.  The test just uses floats, but this was noticed with other
> types as well.
>
> This test replaces the short-lived SmallPtrSet (it lasts only for an
> expression, which, though is a long time for lambdas, is at least not
> forever) with a SmallSetVector.
>

Wow, that's bad. Nice catch.


> Added:
> clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
>
> Modified:
> clang/include/clang/Sema/Sema.h
> clang/lib/Sema/SemaExpr.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/include/clang/Sema/Sema.h
> b/clang/include/clang/Sema/Sema.h
> index 266192087d35..a3f4313c0d65 100644
> --- a/clang/include/clang/Sema/Sema.h
> +++ b/clang/include/clang/Sema/Sema.h
> @@ -627,7 +627,7 @@ class Sema final {
>/// we won't know until all lvalue-to-rvalue and discarded value
> conversions
>/// have been applied to all subexpressions of the enclosing full
> expression.
>/// This is cleared at the end of each full expression.
> -  using MaybeODRUseExprSet = llvm::SmallPtrSet;
> +  using MaybeODRUseExprSet = llvm::SmallSetVector;
>MaybeODRUseExprSet MaybeODRUseExprs;
>
>std::unique_ptr CachedFunctionScope;
>
> diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
> index 6477979e92fe..6965acdb6163 100644
> --- a/clang/lib/Sema/SemaExpr.cpp
> +++ b/clang/lib/Sema/SemaExpr.cpp
> @@ -17553,7 +17553,7 @@ static ExprResult
> rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
>
>// Mark that this expression does not constitute an odr-use.
>auto MarkNotOdrUsed = [&] {
> -S.MaybeODRUseExprs.erase(E);
> +S.MaybeODRUseExprs.remove(E);
>  if (LambdaScopeInfo *LSI = S.getCurLambda())
>LSI->markVariableExprAsNonODRUsed(E);
>};
>
> diff  --git a/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
> b/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
> new file mode 100644
> index ..d025a431d5c5
> --- /dev/null
> +++ b/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp
> @@ -0,0 +1,33 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm
> --std=c++17 %s -o - | FileCheck %s
> +
> +struct stream {
> +  friend const stream &operator<<(const stream &, const float &);
> +};
> +
> +void foo() {
> +  constexpr float f_zero = 0.0f;
> +  constexpr float f_one = 1.0f;
> +  constexpr float f_two = 2.0f;
> +
> +  stream s;
> +  [=]() {
> +s << f_zero << f_one << f_two;
> +  }();
> +}
> +
> +// CHECK: define void @_Z3foov
> +// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
> +// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0,
> i32 1
> +// CHECK-NEXT: store float 0.000
> +// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0,
> i32 2
> +// CHECK-NEXT: store float 1.000
> +// CHECK-NEXT: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0,
> i32 3
> +// CHECK-NEXT: store float 2.000
> +
> +// The lambda body.  Reverse iteration when the captures aren't
> deterministic
> +// causes these to be laid out
> diff erently in the lambda.
> +// CHECK: define internal void
> +// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
> +// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 1
> +// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
> +// CHECK: getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 3
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74166: [AIX][Frontend] Static init implementation for AIX considering no priority

2020-06-12 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/CodeGen/static-init.cpp:12
   ~test();
-} t;
+} t1, t2;
 

I suggest adding also one each of the following:

  - a dynamic initialization of a non-local variable of type `int`
  - a `constinit` initialization of a non-local variable with non-constant 
destruction



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

https://reviews.llvm.org/D74166



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


[PATCH] D81392: [clang] Rename Decl::isHidden() to isUnconditionallyVisible()

2020-06-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D81392#2089251 , @mboehme wrote:

> In D81392#2088131 , @rsmith wrote:
>
> > Maybe we should dump the ModuleOwnershipKind in general, not only an 
> > indicator of whether it's Visible or something else?
>
>
> I like this -- though would we then always dump the ModuleOwnershipKind (i.e. 
> causing a lot of churn, as discussed above) or only if it's 
> `VisibleWhenImported` or `ModulePrivate` (i.e. not unconditionally visible)?


I think only producing output for the "non-default" state (not Visible) would 
be best, both too minimize the test churn and to keep the dump smaller and 
simpler in simple cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81392



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


[PATCH] D74166: [AIX][Frontend] Static init implementation for AIX considering no priority

2020-06-12 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:807
 
 void CodeGenFunction::GenerateCXXGlobalDtorsFunc(
 llvm::Function *Fn,

This function is to be renamed.



Comment at: clang/lib/CodeGen/CodeGenModule.h:401
+  /// A unique trailing identifier as a part of sinit/sterm function when
+  /// UseSinitAndSterm of CXXABI set as true.
+  std::string GlobalUniqueModuleId;

Minor nit: s/set/is set/;


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

https://reviews.llvm.org/D74166



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


[PATCH] D79796: Sketch support for generating CC1 command line from CompilerInvocation

2020-06-12 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 270445.
dang edited the summary of this revision.
dang added a comment.

Implemented a draft of normalizer generation for simple enum based options


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79796

Files:
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
@@ -33,6 +34,50 @@
   return OS;
 }
 
+static void emitMarshallingInfoFlag(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsBit("IsPositive");
+}
+
+static void emitMarshallingInfoString(raw_ostream &OS, const Record &R) {
+  OS << R.getValueAsString("Normalizer");
+  OS << ", ";
+  OS << R.getValueAsString("Denormalizer");
+}
+
+static void emitScopedNormalizedValue(raw_ostream &OS,
+  StringRef NormalizedValuesScope,
+  StringRef NormalizedValue) {
+  if (!NormalizedValuesScope.empty())
+OS << NormalizedValuesScope << "::";
+  OS << NormalizedValue;
+}
+
+static void emitValueTable(raw_ostream &OS, StringRef OptionID,
+   StringRef Values, StringRef NormalizedValuesScope,
+   std::vector NormalizedValues) {
+  SmallVector SplitValues;
+  Values.split(SplitValues, ',');
+  assert(SplitValues.size() == NormalizedValues.size() &&
+ "The number of associated definitions doesn't match the number of "
+ "values");
+
+  SmallString<64> MacroName("HANDLE_");
+  MacroName += OptionID.upper();
+  MacroName += "_VALUES";
+  OS << "#ifdef " << MacroName << "\n";
+  for (unsigned I = 0, E = SplitValues.size(); I != E; ++I) {
+OS << MacroName << "(\"" << SplitValues[I] << "\",";
+emitScopedNormalizedValue(OS, NormalizedValuesScope, NormalizedValues[I]);
+OS << ")\n";
+  }
+  OS << "#endif\n";
+}
+
+struct MarshallingKindInfo {
+  const char *MacroName;
+  void (*Emit)(raw_ostream &OS, const Record &R);
+};
+
 /// OptParserEmitter - This tablegen backend takes an input .td file
 /// describing a list of options and emits a data structure for parsing and
 /// working with those options when given an input command line.
@@ -135,12 +180,8 @@
 
   OS << "//\n";
   OS << "// Options\n\n";
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
-
-// Start a single option entry.
-OS << "OPTION(";
 
+  auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
@@ -223,11 +264,119 @@
   write_cstring(OS, R.getValueAsString("Values"));
 else
   OS << "nullptr";
+  };
 
+  std::vector OptsWithMarshalling;
+  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
+const Record &R = *Opts[i];
+
+// Start a single option entry.
+OS << "OPTION(";
+WriteOptRecordFields(OS, R);
 OS << ")\n";
+if (!isa(R.getValueInit("MarshallingKind")))
+  OptsWithMarshalling.push_back(&R);
   }
   OS << "#endif // OPTION\n";
 
+  std::vector AutoNormalizableOpts;
+  for (unsigned I = 0, E = OptsWithMarshalling.size(); I != E; ++I) {
+const Record &R = *OptsWithMarshalling[I];
+assert(!isa(R.getValueInit("KeyPath")) &&
+   !isa(R.getValueInit("DefaultValue")) &&
+   "Must provide at least a key-path and a default value for emitting "
+   "marshalling information");
+StringRef KindStr = R.getValueAsString("MarshallingKind");
+auto KindInfo = StringSwitch(KindStr)
+.Case("flag", {"OPTION_WITH_MARSHALLING_FLAG",
+   &emitMarshallingInfoFlag})
+.Case("string", {"OPTION_WITH_MARSHALLING_STRING",
+ &emitMarshallingInfoString})
+.Default({"", nullptr});
+StringRef NormalizedValuesScope;
+if (!isa(R.getValueInit("NormalizedValuesScope")))
+  NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
+
+OS << "#ifdef " << KindInfo.MacroName << "\n";
+OS << KindInfo.MacroName << "(";
+WriteOptRecordFields(OS, R);
+OS << ", ";
+OS << R.getValueAsBit("Should

[PATCH] D80681: [clang][SourceManager] cache Macro Expansions

2020-06-12 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Bumping for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80681



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


[clang] c32d261 - Don't diagnose a redeclaration of a deduction guide if the prior

2020-06-12 Thread Richard Smith via cfe-commits
Author: Richard Smith
Date: 2020-06-12T10:29:01-07:00
New Revision: c32d261e27c8c63653799fa6e411c373bd81d519

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

LOG: Don't diagnose a redeclaration of a deduction guide if the prior
declaration is not visible.

In passing, add a test for a similar case of conflicting redeclarations
of internal-linkage structured bindings. (This case already works).

Added: 
clang/test/Modules/Inputs/cxx17/unimported.h
clang/test/Modules/Inputs/cxx20/decls.h
clang/test/Modules/Inputs/cxx20/module.modulemap
clang/test/Modules/Inputs/cxx20/unimported.h
clang/test/Modules/cxx20.cpp

Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/Modules/Inputs/cxx17/module.modulemap
clang/test/Modules/cxx17.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a77f7a460242..f1ade752e2fe 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -678,7 +678,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   //   for the same class template shall not have equivalent
   //   parameter-declaration-clauses.
   if (isa(New) &&
-  !New->isFunctionTemplateSpecialization()) {
+  !New->isFunctionTemplateSpecialization() && isVisible(Old)) {
 Diag(New->getLocation(), diag::err_deduction_guide_redeclared);
 Diag(Old->getLocation(), diag::note_previous_declaration);
   }

diff  --git a/clang/test/Modules/Inputs/cxx17/module.modulemap 
b/clang/test/Modules/Inputs/cxx17/module.modulemap
index 2339e49e03bd..c80e6e7b13eb 100644
--- a/clang/test/Modules/Inputs/cxx17/module.modulemap
+++ b/clang/test/Modules/Inputs/cxx17/module.modulemap
@@ -1 +1,4 @@
-module Decls { header "decls.h" }
+module Decls {
+  header "decls.h"
+  explicit module Unimported { header "unimported.h" }
+}

diff  --git a/clang/test/Modules/Inputs/cxx17/unimported.h 
b/clang/test/Modules/Inputs/cxx17/unimported.h
new file mode 100644
index ..97c75e635d83
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx17/unimported.h
@@ -0,0 +1,2 @@
+template struct DeductionGuide {};
+DeductionGuide() -> DeductionGuide;

diff  --git a/clang/test/Modules/Inputs/cxx20/decls.h 
b/clang/test/Modules/Inputs/cxx20/decls.h
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Modules/Inputs/cxx20/module.modulemap 
b/clang/test/Modules/Inputs/cxx20/module.modulemap
new file mode 100644
index ..c80e6e7b13eb
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx20/module.modulemap
@@ -0,0 +1,4 @@
+module Decls {
+  header "decls.h"
+  explicit module Unimported { header "unimported.h" }
+}

diff  --git a/clang/test/Modules/Inputs/cxx20/unimported.h 
b/clang/test/Modules/Inputs/cxx20/unimported.h
new file mode 100644
index ..226b087c0848
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx20/unimported.h
@@ -0,0 +1,4 @@
+namespace StructuredBinding {
+  struct Q { int p, q; };
+  static auto [a, b] = Q();
+}

diff  --git a/clang/test/Modules/cxx17.cpp b/clang/test/Modules/cxx17.cpp
index 1efb490828db..87039ef76656 100644
--- a/clang/test/Modules/cxx17.cpp
+++ b/clang/test/Modules/cxx17.cpp
@@ -9,3 +9,7 @@ struct MergeExceptionSpec {
 #include "decls.h"
 
 MergeExceptionSpec mergeExceptionSpec2;
+
+template struct DeductionGuide {};
+DeductionGuide() -> DeductionGuide;
+DeductionGuide a;

diff  --git a/clang/test/Modules/cxx20.cpp b/clang/test/Modules/cxx20.cpp
new file mode 100644
index ..e85bc9ad8a8f
--- /dev/null
+++ b/clang/test/Modules/cxx20.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules-cache-path=%t -fmodules 
-fimplicit-module-maps -I %S/Inputs/cxx20 %s -verify -fno-modules-error-recovery
+
+// expected-no-diagnostics
+
+#include "decls.h"
+
+namespace StructuredBinding {
+  struct R { int x, y; };
+  static auto [a, b] = R();
+}



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


[PATCH] D78126: [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

2020-06-12 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:43
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "llvm/ADT/ArrayRef.h"

Unfortunately, this include creates a circular dependency from 
StaticAnalyzer/Core to StaticAnalyzer/Frontend back to StaticAnalyzer/Core.

I'm hoping to figure out a fix that doesn't involve reverting it, but if you 
have a quick fix, that would be really great.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78126



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


[PATCH] D80961: Ignore template instantiations if not in AsIs mode

2020-06-12 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D80961#2079419 , @aaron.ballman 
wrote:

> In D80961#2079044 , @klimek wrote:
>
> > In D80961#2076242 , @aaron.ballman 
> > wrote:
> >
> > > In D80961#2073049 , @klimek 
> > > wrote:
> > >
> > > > Without jumping into the discussion whether it should be the default, I 
> > > > think we should be able to control template instantiation visitation 
> > > > separately from other implicit nodes.
> > > >  Having to put AsIs on a matcher every time you need to match template 
> > > > instantiations is a rather big change (suddenly you have to change all 
> > > > the matchers you've written so far).
> > >
> > >
> > > I think that's the intended meaning of `AsIs` though. Template 
> > > instantiations are not source code the user wrote, they're source code 
> > > the compiler stamped out from code the user wrote. I hope 
> > > `IgnoreUnlessSpelledInSource` isn't a misnomer.
> > >
> > > > I love the idea of being able to control visitation of template 
> > > > instantiation.
> > > >  I am somewhat torn on whether it should be the default, and would like 
> > > > to see more data.
> > > >  I feel more strongly about needing AsIs when I want to match template 
> > > > instantiations.
> > >
> > > FWIW, my experience in clang-tidy has been that template instantiations 
> > > are ignored far more often than they're desired. In fact, instantiations 
> > > tend to be a source of bugs for us because they're easy to forget about 
> > > when writing matchers without keeping templates in mind. The times when 
> > > template instantiations become important to *not* ignore within the 
> > > checks is when the check is specific to template behavior, but that's a 
> > > minority of the public checks thus far.
> >
> >
> > So I assume the idea is that this will work & be what we'll want people to 
> > write?
> >  traverse(AsIs, decl(traverse(IgnoreImplicit, hasFoo)))
>
>
> I believe so, yes. It's explicit about which traversal mode you want any 
> given set of matchers to match with, so it is more flexible at the expense of 
> being more verbose. Alternatively, you could be in `AsIs` mode for all of it 
> and explicitly ignore the implicit nodes you wish to ignore (which may be 
> even more verbose with the same results, depending on the matchers involved).


As far as I can tell, the people who had "standing objections" to fixing this 
bug have been convinced that it makes sense. At least that is implied.

The problem is they haven't explicitly reversed so progress is still blocked.

Please respond to either say you're no longer blocking this or say why you 
continue to block it.

There is no reason not to fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80961



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


[PATCH] D81678: Introduce partialinit attribute at call sites for stricter poison analysis

2020-06-12 Thread Gui Andrade via Phabricator via cfe-commits
guiand added inline comments.



Comment at: clang/include/clang/AST/Type.h:2139-2141
+  /// Check if this type has only two possible values, and so may be lowered to
+  /// a bool.
+  bool hasBooleanRepresentation() const;

rsmith wrote:
> This seems like a CodeGen-specific concern; I'm not sure this makes sense as 
> a query on the Type.
Makes sense, I can move it.



Comment at: clang/lib/AST/Type.cpp:2752-2753
+
+  if (const EnumType *ET = getAs())
+return ET->getDecl()->getIntegerType()->isBooleanType();
+

rsmith wrote:
> Under `-fstrict-enums` in C++, `enum E { a = 0, b = 1 };` has only two 
> distinct valid values. Should we consider that case?
I factored this code out of CGExpr.cpp, as it looked like this function 
governed whether `i1` values were lifted to `i8` (to meet the requirements of 
`bool`). I wanted to avoid struct `bool` members being marked `partialinit`. Do 
you think that would be a worthwhile separate change?



Comment at: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:679
 
+void CGRecordLowering::determineMemberPartialInit() {
+  auto hasTailPadding = [&](QualType FieldTypePtr) {

rsmith wrote:
> We already have support for C++'s `__has_unique_object_representations` 
> (`ASTContext::hasUniqueObjectRepresentations`), which does something very 
> similar to this. Do we need both? (Are there cases where this is 
> intentionally diverging from `__has_unique_object_representations`?)
For the purposes of this commit, I think I can change the decisions made in 
CGRecordLayoutBuilder to defer to `ASTContext::hasUniqueObjectRepresentations`. 
In an upcoming change though, I'd like to determine exactly what *kind* of 
padding is present in the field, most importantly between basic field padding 
and bitfield/union padding. The reasoning is as follows:

- Union padding (e.g. `union { i32 a; i8 b; }`) is completely erased from the 
outgoing LLVM type, as it's lowered to a `{ i32 }`; same thing goes for 
bitfield tail padding.
- On the other hand, field padding (e.g. in `struct { i8 a; i16 b; }`) is 
preserved in the lowered LLVM type `{ i8, i16 }`.

This means that under certain CGCall conventions, if we only observe field 
padding, we can get away with not using `partialinit`.
- If we're flattening a struct (without coercion) that contains no "lost" 
padding, then each function argument will be a fully initialized field of the 
struct.
- Same thing goes if we're returning an uncoerced LLVM type such as `{ i8, i16 
}`: each individual field is still present and fully initialized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678



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


[PATCH] D81750: [analyzer] Don't allow hidden checkers to emit diagnostics

2020-06-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, vsavchenko, dcoughlin, martong, balazske, 
baloghadamsoftware, xazax.hun.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
whisperity.

Exactly what it says on the tin! I moved `StdLibraryFunctionsArg` checker to 
the `unix` package from `apiModeling` as it violated this rule. I believe this 
change doesn't deserve a different revision because it is in alpha, and the 
name is so bad anyways I don't immediately care where it is, because we'll have 
to revisit it soon enough.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81750

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/weak-dependencies.c

Index: clang/test/Analysis/weak-dependencies.c
===
--- clang/test/Analysis/weak-dependencies.c
+++ clang/test/Analysis/weak-dependencies.c
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 %s -verify \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=core
 
 typedef __typeof(sizeof(int)) size_t;
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false \
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -2,7 +2,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
@@ -12,7 +12,7 @@
 // RUN: %clang_analyze_cc1 %s \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
-// RUN:   -analyzer-checker=alpha.apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -triple x86_64-unknown-linux-gnu \
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2107,7 +2107,7 @@
 // Methods for BugReport and subclasses.
 //===--===//
 
-static bool isDependency(const CheckerRegistry &Registry,
+LLVM_ATTRIBUTE_USED static bool isDependency(const CheckerRegistry &Registry,
  StringRef CheckerName) {
   for (const std::pair &Pair : Registry.Dependencies) {
 if (Pair.second == CheckerName)
@@ -2116,6 +2116,17 @@
   return false;
 }
 
+LLVM_ATTRIBUTE_USED static bool isHidden(const CheckerRegistry &Registry,
+ StringRef CheckerName) {
+  for (const CheckerRegistry::CheckerInfo &Checker : Registry.Checkers) {
+if (Checker.FullName == CheckerName)
+  return Checker.IsHidden;
+  }
+  llvm_unreachable(
+  "Checker name not found in CheckerRegistry -- did you retrieve it "
+  "correctly from CheckerManager::getCurrentCheckerName?");
+}
+
 PathSensitiveBugReport::PathSensitiveBugReport(
 const BugType &bt, StringRef shortDesc, StringRef desc,
 const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
@@ -2131,6 +2142,16 @@
  "Some checkers depend on this one! We don't allow dependency "
  "checkers to emit warnings, because checkers should depend on "
  "*modeling*, not *diagnostics*.");
+
+  assert(
+  bt.getCheckerName

[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D81713#2089760 , @arsenm wrote:

> In D81713#2089680 , @yaxunl wrote:
>
> > In D81713#2089672 , @arsenm wrote:
> >
> > > Can you add tests for this? Is this also sufficient with the directory 
> > > layout change?
> >
> >
> > You mean does this work after we move device lib from /opt/rocm/lib to 
> > /opt/rocm/amdgcn/bitcode ?
>
>
> Yes


I can tell that it does not. We're still looking under `/opt/rocm` by default. 
I've ran into it trying to get comgr working with the recent LLVM which 
prompted my comment on Github 



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

https://reviews.llvm.org/D81713



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


[PATCH] D81739: [clangd] Turn on RecoveryAST for clangd by default.

2020-06-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:285
+desc("Preserve expressions in AST for broken code (C++ only)."),
+init(true),
 };

Ah actually in other options, we set the default in the struct and reference it 
here. Can we do that here too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81739



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


[PATCH] D80681: [clang][SourceManager] cache Macro Expansions

2020-06-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

I am not the best person to review this, but dig a little bit into your issues 
and history of this file. Your diagnosis and fix seems reasonable, AFAICT the 
existing caching behavior was chosen to optimize files with many macro 
invocations that are expanding into relatively few tokens. So this case will 
definitely regress after this patch, proportional to 
`number_of_macro_name_tokens/number_of_total_tokens` but I would expect that 
ratio to be quite small in any sane file hence regression to be negligible.

OTOH, when that ratio is low, if number of tokens coming from each/some macro 
expansions is huge (which IIUC is your case) updating that cache makes a lot of 
sense.

Also your claim on `builds of LLVM itself don't change due to this patch.` 
sounds promising. I've seen quite nice benchmarks for kernel build times in the 
issues you've mentioned it would be nice if you could back that claim with 
similar data(not that I don't take your word for it, I just love tables and I 
am jealous that kernel has some but we don't :( )

Apart from all of this, I believe this patch (even though has relatively few 
lines) contains 3 distinct patches that should be split:

- Changing caching behaviour to apply to macro expansions
- Adding a more optimized way of checking if an offset is inside a local file
- Getting rid of some "dead" code.

I can say this patch LG from my side, but my understanding of this code isn't 
quite strong so I would wait for a couple more days to see if someone else will 
chime in.




Comment at: clang/include/clang/Basic/SourceManager.h:1747
   return getLoadedSLocEntryByID(ID, Invalid);
-return getLocalSLocEntry(static_cast(ID), Invalid);
+return getLocalSLocEntry(static_cast(ID));
   }

i think this deserves its separate patch.

We still can satisfy the interface requirements of libclang by introducing 
another member `getLocalSLocEntryWithInvalid` and change the assertion into an 
if check, populating `Invalid` in case of failure, what to return is more 
tricky though it is a const ref, I suppose we can return a dummy entry.

Feel free to keep the newly added calls without an `Invalid` argument, but I 
wouldn't modify the already existing ones in this patch.



Comment at: clang/lib/Basic/SourceManager.cpp:896
+FileID Res = FileID::get(MiddleIndex);
+if (isOffsetInLocalFileID(Res, SLocOffset)) {
+  // Remember it.  We have good locality across FileID lookups.

we already call getLocalSLocEntry for `MiddleIndex` above, moreover we even 
early exit `if (SlocOffset < MidOffset)` which is the second case in your new 
function. So I would say we could even gain more by:

```
const auto &SLocForMiddle = getLocalSLocEntry(MiddleIndex);
auto MidOffset = SLocForMiddle.getOffset();
.
.
.
if (MiddleIndex + 1 ==LocalSLocEntryTable.size() || SLocOffset < 
getLocalSLocEntry(MiddleIndex + 1).getOffset()) {
// we've got a hit!
}
```

That way you also wouldn't need to introduce a new function.

Even though there's value in new helpers, IMO `SourceManager` is already 
complicated and has enough variants of each function to shoot yourself in the 
foot. If you want feel free to put a FIXME saying `we can extract a 
isOffsetInLocalFile helper from these lines if usage is more spread`.


Again I would say this is worth doing in a separate patch. As it should be a 
clear win for all.



Comment at: clang/lib/Basic/SourceManager.cpp:967
 
 if (isOffsetInFileID(FileID::get(-int(MiddleIndex) - 2), SLocOffset)) {
   FileID Res = FileID::get(-int(MiddleIndex) - 2);

my comments above for `isOffsetnLocalFileID` applies to here as well, in case 
you decide to move them into a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80681



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


[PATCH] D81751: [SemaObjC] Fix a -Wobjc-signed-char-bool false-positive with binary conditional operator

2020-06-12 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added a reviewer: rjmccall.
Herald added subscribers: ributzka, dexonsmith, jkorous.

We were previously bypassing the conditional expression special case for binary 
conditional expressions. Also, dig through the OpaqueValueExpr on the left of 
the ?:.

rdar://64134411


https://reviews.llvm.org/D81751

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaObjC/signed-char-bool-conversion.m


Index: clang/test/SemaObjC/signed-char-bool-conversion.m
===
--- clang/test/SemaObjC/signed-char-bool-conversion.m
+++ clang/test/SemaObjC/signed-char-bool-conversion.m
@@ -108,3 +108,15 @@
   f(); // expected-note {{in instantiation of function template 
specialization 'f' requested here}}
 }
 #endif
+
+void t5(BOOL b) {
+  int i;
+  b = b ?: YES; // no warning
+  b = b ?: i; // expected-warning {{implicit conversion from integral type 
'int' to 'BOOL'}}
+  b = (b = i) // expected-warning {{implicit conversion from integral type 
'int' to 'BOOL'}}
+   ?: YES;
+  b = (1 ? YES : i) ?: YES; // expected-warning {{implicit conversion from 
integral type 'int' to 'BOOL'}}
+  b = b ?: (1 ? i : i); // expected-warning 2 {{implicit conversion from 
integral type 'int' to 'BOOL'}}
+
+  b = b ? YES : (i ?: 0); // expected-warning {{implicit conversion from 
integral type 'int' to 'BOOL'}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11803,27 +11803,33 @@
   }
 }
 
-static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
+static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
  SourceLocation CC, QualType T);
 
 static void CheckConditionalOperand(Sema &S, Expr *E, QualType T,
 SourceLocation CC, bool &ICContext) {
   E = E->IgnoreParenImpCasts();
 
-  if (isa(E))
-return CheckConditionalOperator(S, cast(E), CC, T);
+  if (auto *CO = dyn_cast(E))
+return CheckConditionalOperator(S, CO, CC, T);
 
   AnalyzeImplicitConversions(S, E, CC);
   if (E->getType() != T)
 return CheckImplicitConversion(S, E, T, CC, &ICContext);
 }
 
-static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
+static void CheckConditionalOperator(Sema &S, AbstractConditionalOperator *E,
  SourceLocation CC, QualType T) {
   AnalyzeImplicitConversions(S, E->getCond(), E->getQuestionLoc());
 
+  Expr *TrueExpr = E->getTrueExpr();
+  if (isa(E))
+if (auto *OVE = dyn_cast(TrueExpr))
+  if (Expr *SourceExpr = OVE->getSourceExpr())
+TrueExpr = SourceExpr;
+
   bool Suspicious = false;
-  CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
+  CheckConditionalOperand(S, TrueExpr, T, CC, Suspicious);
   CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
 
   if (T->isBooleanType())
@@ -11842,7 +11848,7 @@
   if (E->getType() == T) return;
 
   Suspicious = false;
-  CheckImplicitConversion(S, E->getTrueExpr()->IgnoreParenImpCasts(),
+  CheckImplicitConversion(S, TrueExpr->IgnoreParenImpCasts(),
   E->getType(), CC, &Suspicious);
   if (!Suspicious)
 CheckImplicitConversion(S, E->getFalseExpr()->IgnoreParenImpCasts(),
@@ -11905,7 +11911,7 @@
 
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
-  if (auto *CO = dyn_cast(SourceExpr)) {
+  if (auto *CO = dyn_cast(SourceExpr)) {
 CheckConditionalOperator(S, CO, CC, T);
 return;
   }


Index: clang/test/SemaObjC/signed-char-bool-conversion.m
===
--- clang/test/SemaObjC/signed-char-bool-conversion.m
+++ clang/test/SemaObjC/signed-char-bool-conversion.m
@@ -108,3 +108,15 @@
   f(); // expected-note {{in instantiation of function template specialization 'f' requested here}}
 }
 #endif
+
+void t5(BOOL b) {
+  int i;
+  b = b ?: YES; // no warning
+  b = b ?: i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
+  b = (b = i) // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
+   ?: YES;
+  b = (1 ? YES : i) ?: YES; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
+  b = b ?: (1 ? i : i); // expected-warning 2 {{implicit conversion from integral type 'int' to 'BOOL'}}
+
+  b = b ? YES : (i ?: 0); // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11803,27 +11803,33 @@
   }
 }
 
-static void CheckConditionalOperator(Sema &S, ConditionalOperator *E,
+static void CheckCon

[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D81713#2090265 , @tra wrote:

> In D81713#2089760 , @arsenm wrote:
>
> > In D81713#2089680 , @yaxunl wrote:
> >
> > > In D81713#2089672 , @arsenm 
> > > wrote:
> > >
> > > > Can you add tests for this? Is this also sufficient with the directory 
> > > > layout change?
> > >
> > >
> > > You mean does this work after we move device lib from /opt/rocm/lib to 
> > > /opt/rocm/amdgcn/bitcode ?
> >
> >
> > Yes
>
>
> I can tell that it does not. We're still looking under `/opt/rocm` by 
> default. I've ran into it trying to get comgr working with the recent LLVM 
> which prompted my comment on Github 
> 


Not sure how that would be related to comgr? comgr doesn't rely on the dynamic 
path and embeds the bitcode in the library. The comgr build finds the libraries 
through cmake and doesn't care where they're located


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

https://reviews.llvm.org/D81713



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


[PATCH] D80681: [clang][SourceManager] cache Macro Expansions

2020-06-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Also forgot to say, thanks a lot for taking your time to investigate this issue 
and coming up with a patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80681



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


[PATCH] D81752: Revert "[analyzer][NFC] Don't allow dependency checkers to emit diagnostics"

2020-06-12 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine created this revision.
saugustine added reviewers: echristo, Szelethus, martong.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a project: clang.

This reverts commit 33fb9cbe211d1b43d4b84edf34e11001f04cddf0 
.

That commit violates layering by adding a dependency from StaticAnalyzer/Core
back to StaticAnalyzer/FrontEnd, creating a circular dependency.

I can't see a clean way to fix it except refactoring.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81752

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -94,10 +94,6 @@
 // Methods of CmdLineOption, PackageInfo and CheckerInfo.
 //===--===//
 
-LLVM_DUMP_METHOD void CheckerRegistry::CmdLineOption::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::CmdLineOption::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -119,10 +115,6 @@
   llvm_unreachable("Unhandled CheckerRegistry::StateFromCmdLine enum");
 }
 
-LLVM_DUMP_METHOD void CheckerRegistry::CheckerInfo::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::CheckerInfo::dumpToStream(llvm::raw_ostream &Out) const {
   // The description can be just checked in Checkers.inc, the point here is to
@@ -145,10 +137,6 @@
   }
 }
 
-LLVM_DUMP_METHOD void CheckerRegistry::PackageInfo::dump() const {
-  dumpToStream(llvm::errs());
-}
-
 LLVM_DUMP_METHOD void
 CheckerRegistry::PackageInfo::dumpToStream(llvm::raw_ostream &Out) const {
   Out << FullName << "\n";
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -40,7 +40,6 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
-#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -2107,32 +2106,6 @@
 // Methods for BugReport and subclasses.
 //===--===//
 
-static bool isDependency(const CheckerRegistry &Registry,
- StringRef CheckerName) {
-  for (const std::pair &Pair : Registry.Dependencies) {
-if (Pair.second == CheckerName)
-  return true;
-  }
-  return false;
-}
-
-PathSensitiveBugReport::PathSensitiveBugReport(
-const BugType &bt, StringRef shortDesc, StringRef desc,
-const ExplodedNode *errorNode, PathDiagnosticLocation LocationToUnique,
-const Decl *DeclToUnique)
-: BugReport(Kind::PathSensitive, bt, shortDesc, desc), ErrorNode(errorNode),
-  ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : SourceRange()),
-  UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
-  assert(!isDependency(ErrorNode->getState()
-   ->getAnalysisManager()
-   .getCheckerManager()
-   ->getCheckerRegistry(),
-   bt.getCheckerName()) &&
- "Some checkers depend on this one! We don't allow dependency "
- "checkers to emit warnings, because checkers should depend on "
- "*modeling*, not *diagnostics*.");
-}
-
 void PathSensitiveBugReport::addVisitor(
 std::unique_ptr visitor) {
   if (!visitor)
@@ -2221,12 +2194,12 @@
   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!");
+  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 PathSensitiveBugReport::markInteresting(SymbolRef sym,
Index: clang/include/clang/StaticAnalyzer/Fronte

[clang] 58de24c - [AMDGPU] Sorted targets in amdgpu-features.cl. NFC.

2020-06-12 Thread Stanislav Mekhanoshin via cfe-commits
Author: Stanislav Mekhanoshin
Date: 2020-06-12T11:57:40-07:00
New Revision: 58de24ce6cb413afea1470ec183f3fc5d9ca6817

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

LOG: [AMDGPU] Sorted targets in amdgpu-features.cl. NFC.

Added: 


Modified: 
clang/test/CodeGenOpenCL/amdgpu-features.cl

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 7529a4d4abb1..344d4bca44c9 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -3,26 +3,26 @@
 // Check that appropriate features are defined for every supported AMDGPU
 // "-target" and "-mcpu" options.
 
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx600 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX600 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx601 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX601 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx700 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX700 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx801 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX801 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx904 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX904 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx906 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX906 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx908 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX908 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1010 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1010 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1011 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1011 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1012 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1012 %s
-// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx801 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX801 %s
-// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx700 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX700 %s
-// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx600 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX600 %s
-// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx601 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX601 %s
 
+// GFX600-NOT: "target-features"
+// GFX601-NOT: "target-features"
+// GFX700: "target-features"="+ci-insts,+flat-address-space"
+// GFX801: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
 // GFX904: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX906: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX908: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+mai-insts,+s-memrealtime"
 // GFX1010: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX1011: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX1012: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
-// GFX801: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime"
-// GFX700: "target-features"="+ci-insts,+flat-address-space"
-// GFX600-NOT: "target-features"
-// GFX601-NOT: "target-features"
 
 kernel void test() {}



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


[PATCH] D78126: [analyzer][NFC] Don't allow dependency checkers to emit diagnostics

2020-06-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/BugReporter.cpp:43
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "llvm/ADT/ArrayRef.h"

saugustine wrote:
> Unfortunately, this include creates a circular dependency from 
> StaticAnalyzer/Core to StaticAnalyzer/Frontend back to StaticAnalyzer/Core.
> 
> I'm hoping to figure out a fix that doesn't involve reverting it, but if you 
> have a quick fix, that would be really great.
Yup, this is a common theme with these changes, the divide in between the 
analyzer's libraries isn't too well defined.

`CheckerRegistry` definitely belongs to the frontend, and `BugReporter` isn't 
really moving anywhere either. The registry is responsible for parsing the 
command line arguments (which checker is enabled, values of checker options, 
resolving dependencies, etc), but this information is really desired in the 
rest of the analyzer as well.

I think the obvious (to me, that is) solution would be to move the containers 
to the Core library, and leave the rest of the logic in the frontend. While I 
dare claiming that I have great knowledge about this part of the codebase (its 
usually just me maintaining it), I would be more comfortable doing that without 
needing to rush the solution :)

An uncomfortable hack would be to simply implement the new functions in the 
frontend library -- but the former solution better describes where the data 
CheckerRegistry holds should lie.

I'll revert this. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78126



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


[PATCH] D81752: Revert "[analyzer][NFC] Don't allow dependency checkers to emit diagnostics"

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

Yup, I agree. Detailed my answer here a bit: D78126#inline-751477 
. Thanks for taking initiative!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81752



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


[PATCH] D80961: Ignore template instantiations if not in AsIs mode

2020-06-12 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 270472.
steveire edited the summary of this revision.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80961

Files:
  clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
  clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
  clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
  clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/AST/ASTDumper.cpp
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTContextParentMapTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/AST/SourceLocationTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
  clang/unittests/Sema/GslOwnerPointerInference.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -695,6 +695,70 @@
   EXPECT_EQ(ErrorCount, 0);
 }
 
+TEST_F(TransformerTest, TemplateInstantiation) {
+
+  std::string NonTemplatesInput = R"cpp(
+struct S {
+  int m_i;
+};
+)cpp";
+  std::string NonTemplatesExpected = R"cpp(
+struct S {
+  safe_int m_i;
+};
+)cpp";
+
+  std::string TemplatesInput = R"cpp(
+template
+struct TemplStruct {
+  TemplStruct() {}
+  ~TemplStruct() {}
+
+private:
+  T m_t;
+};
+
+void instantiate()
+{
+  TemplStruct ti;
+}
+)cpp";
+
+  auto MatchedField = fieldDecl(hasType(asString("int"))).bind("theField");
+
+  // Changes the 'int' in 'S', but not the 'T' in 'TemplStruct':
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedField),
+changeTo(cat("safe_int ", name("theField",
+   NonTemplatesInput + TemplatesInput,
+   NonTemplatesExpected + TemplatesInput);
+
+  // In AsIs mode, template instantiations are modified, which is
+  // often not desired:
+
+  std::string IncorrectTemplatesExpected = R"cpp(
+template
+struct TemplStruct {
+  TemplStruct() {}
+  ~TemplStruct() {}
+
+private:
+  safe_int m_t;
+};
+
+void instantiate()
+{
+  TemplStruct ti;
+}
+)cpp";
+
+  // Changes the 'int' in 'S', and (incorrectly) the 'T' in 'TemplStruct':
+  testRule(makeRule(traverse(TK_AsIs, MatchedField),
+changeTo(cat("safe_int ", name("theField",
+
+   NonTemplatesInput + TemplatesInput,
+   NonTemplatesExpected + IncorrectTemplatesExpected);
+}
+
 // Transformation of macro source text when the change encompasses the entirety
 // of the expanded text.
 TEST_F(TransformerTest, SimpleMacro) {
Index: clang/unittests/Sema/GslOwnerPointerInference.cpp
===
--- clang/unittests/Sema/GslOwnerPointerInference.cpp
+++ clang/unittests/Sema/GslOwnerPointerInference.cpp
@@ -14,42 +14,45 @@
 using namespace ast_matchers;
 
 TEST(OwnerPointer, BothHaveAttributes) {
-  EXPECT_TRUE(matches("template"
-  "class [[gsl::Owner]] C;"
+  EXPECT_TRUE(matches(
+  "template"
+  "class [[gsl::Owner]] C;"
 
-  "template"
-  "class [[gsl::Owner]] C {};"
+  "template"
+  "class [[gsl::Owner]] C {};"
 
-  "C c;",
-  classTemplateSpecializationDecl(
-  hasName("C"), hasAttr(clang::attr::Owner;
+  "C c;",
+ 

[PATCH] D60620: [HIP] Support target id by --offload-arch

2020-06-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D60620#2089722 , @yaxunl wrote:

> In D60620#2067134 , @tra wrote:
>
> > Do you expect users to specify these IDs? How do you see it being used in 
> > practice? I think you do need to implement a user-friendly shortcut and 
> > expand it to the detailed offload-id internally. I'm fine with allowing 
> > explicit offload id as a hidden argument, but I don't think it's suitable 
> > for something that will be used by everyone who can't be expected to be 
> > aware of all the gory details of particular GPU features.
>
>
> The good thing about this target id is that it is backward compatible with 
> GPU arch. For common users who are not concerned with specific GPU 
> configurations, they can just use the old GPU arch and nothing changes. This 
> is because GPU arch without features implies default value for these 
> features, which work on all configurations. For advanced users who do need to 
> build for specific GPU configurations, they should already have the knowledge 
> about the name and meaning of these configurations by reading the AMDGPU user 
> guide (http://llvm.org/docs/AMDGPUUsage.html). Therefore a target id in the 
> form of gfx908:xnack+ is not something cryptic to them. On the other hand, an 
> encoded GPU arch like gfx908a is cryptic since it has no meaning at all.


I don't quite agree with the `gfx908:xnack+ is not something cryptic` 
assertion. I've looked at the AMDGPUUsage.html and I am pretty sure that I 
still have no clue which ID will be correct for my WX8200. It does not mention 
the card, nor does it specify the offload format. Having to type the IDs with 
the features ordered just so (i.e. without normalization) puts a fair amount of 
burden on the user. Not only they must remember which features must be on or 
off, but they also need to specify them in a very specific order (it's not even 
lexicographically ordered) . I think adding normalization to make it possible 
to specify features in arbitrary order would mitigate some of it.

As it's implemented now, my bet is that it will be *very* annoying to use in 
practice.

At the very least,  you should document the requirements for the offload ID 
format with the specific examples. It would also be useful to provide specific 
offload IDs for particular GPU cards as that's what regular users will have 
info about. Right now the AMDGPUUsage doc does not provide sufficient details 
to derive correct offload ID if all you have is a name of the GPU card. That's 
going to be the case for most of clang users who just want to build things for 
their GPU.

That said, the scheme in the current version of the patch is flexible enough to 
retrofit simplified names later, so I'm overall OK with proceeding with the 
patch once documentation has been updated.


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

https://reviews.llvm.org/D60620



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


[PATCH] D81627: [HIP] Do not call opt/llc for -fno-gpu-rdc

2020-06-12 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM.  Good to go if @arsenm is OK with fixing -fgpu-rdc in a separate patch.


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

https://reviews.llvm.org/D81627



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


[PATCH] D81713: [HIP] Fix rocm not found on rocm3.5

2020-06-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D81713#2090309 , @arsenm wrote:

> > I can tell that it does not. We're still looking under `/opt/rocm` by 
> > default. I've ran into it trying to get comgr working with the recent LLVM 
> > which prompted my comment on Github 
> > 
>
> Not sure how that would be related to comgr? comgr doesn't rely on the 
> dynamic path and embeds the bitcode in the library. The comgr build finds the 
> libraries through cmake and doesn't care where they're located


The version I have  (~3.2. I should update it, maybe 3.5 is different) uses 
libclang (built from LLVM tree close to HEAD), creates Driver() instance and 
that driver instance goes through the motions trying to find ROCm installation 
and fails. Clang itself also fails the same way -- there's no 
/opt/rocm/amdgcn/bitcode/ it's looking for.


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

https://reviews.llvm.org/D81713



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


[PATCH] D81736: [openmp] Base of tablegen generated OpenMP common declaration

2020-06-12 Thread Valentin Clement via Phabricator via cfe-commits
clementval updated this revision to Diff 270481.
clementval added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Keep same ordering than OMPKinds.def + add dependency


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81736

Files:
  clang/lib/Tooling/CMakeLists.txt
  llvm/include/llvm/CMakeLists.txt
  llvm/include/llvm/Frontend/Directive/DirectiveBase.td
  llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/test/TableGen/directive.td
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/DirectiveEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -90,6 +90,7 @@
 void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS);
 void EmitExegesis(RecordKeeper &RK, raw_ostream &OS);
 void EmitAutomata(RecordKeeper &RK, raw_ostream &OS);
+void EmitDirectives(RecordKeeper &RK, raw_ostream &OS);
 
 } // End llvm namespace
 
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -54,6 +54,7 @@
   GenRegisterBank,
   GenExegesis,
   GenAutomata,
+  GenDirectives,
 };
 
 namespace llvm {
@@ -128,7 +129,9 @@
"Generate registers bank descriptions"),
 clEnumValN(GenExegesis, "gen-exegesis",
"Generate llvm-exegesis tables"),
-clEnumValN(GenAutomata, "gen-automata", "Generate generic automata")));
+clEnumValN(GenAutomata, "gen-automata", "Generate generic automata"),
+clEnumValN(GenDirectives, "gen-directive-decls",
+   "Generate directive related declaration code")));
 
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
@@ -253,6 +256,8 @@
   case GenAutomata:
 EmitAutomata(Records, OS);
 break;
+  case GenDirectives:
+EmitDirectives(Records, OS);
   }
 
   return false;
Index: llvm/utils/TableGen/DirectiveEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -0,0 +1,103 @@
+//===- DirectiveEmitter.cpp - Directive Language Emitter --===//
+//
+// 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
+//
+//===--===//
+//
+// DirectiveEmitter uses the descriptions of directives and clauses to construct
+// common code declarations to be used in Frontends.
+//
+//===--===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+namespace llvm {
+void EmitDirectives(RecordKeeper &Records, raw_ostream &OS) {
+
+  const auto &directiveLanguages =
+  Records.getAllDerivedDefinitions("DirectiveLanguage");
+
+  if (directiveLanguages.size() != 1) {
+PrintError("A single definition of DirectiveLanguage is needed.");
+return;
+  }
+
+  const auto &directiveLanguage = directiveLanguages[0];
+  StringRef directivePrefix =
+  directiveLanguage->getValueAsString("directivePrefix");
+  StringRef clausePrefix = directiveLanguage->getValueAsString("clausePrefix");
+  StringRef cppNamespace = directiveLanguage->getValueAsString("cppNamespace");
+  bool makeEnumAvailableInNamespace =
+  directiveLanguage->getValueAsBit("makeEnumAvailableInNamespace");
+  bool enableBitmaskEnumInNamespace =
+  directiveLanguage->getValueAsBit("enableBitmaskEnumInNamespace");
+
+  if (enableBitmaskEnumInNamespace)
+OS << "#include \"llvm/ADT/BitmaskEnum.h\"\n";
+
+  OS << "namespace llvm {\n";
+
+  // Open namespaces defined in the directive language
+  llvm::SmallVector namespaces;
+  llvm::SplitString(cppNamespace, namespaces, "::");
+  for (auto ns : namespaces)
+OS << "namespace " << ns << " {\n";
+
+  if (enableBitmaskEnumInNamespace)
+OS << "LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n";
+
+  // Emit Directive enumeration
+  OS << "enum class Directive {\n";
+  const auto &directives = Records.getAllDerivedDefinitions("Directive");
+  for (const auto &d : directives) {
+const auto name = d->getValueAsString("name");
+std::string n = name.str();
+std::replace(n.begin(), n

[clang] e640598 - Revert "[analyzer][NFC] Don't allow dependency checkers to emit diagnostics"

2020-06-12 Thread Sterling Augustine via cfe-commits
Author: Sterling Augustine
Date: 2020-06-12T12:10:13-07:00
New Revision: e64059828f19f629081220bffeb3ef7582870111

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

LOG: Revert "[analyzer][NFC] Don't allow dependency checkers to emit 
diagnostics"

Summary:
This reverts commit 33fb9cbe211d1b43d4b84edf34e11001f04cddf0.

That commit violates layering by adding a dependency from StaticAnalyzer/Core
back to StaticAnalyzer/FrontEnd, creating a circular dependency.

I can't see a clean way to fix it except refactoring.

Reviewers: echristo, Szelethus, martong

Subscribers: xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, 
mikhail.ramalho, donat.nagy, dkrupp, Charusso, ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index 27bc0dda1f1c..51565524db1e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -19,7 +19,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -136,7 +135,7 @@ class BugReport {
   SmallVector Fixits;
 
   BugReport(Kind kind, const BugType &bt, StringRef desc)
-  : BugReport(kind, bt, "", desc) {}
+  : K(kind), BT(bt), Description(desc) {}
 
   BugReport(Kind K, const BugType &BT, StringRef ShortDescription,
 StringRef Description)
@@ -370,13 +369,16 @@ class PathSensitiveBugReport : public BugReport {
 public:
   PathSensitiveBugReport(const BugType &bt, StringRef desc,
  const ExplodedNode *errorNode)
-  : PathSensitiveBugReport(bt, desc, desc, errorNode) {}
+  : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
+ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+ : SourceRange()) {}
 
   PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef 
desc,
  const ExplodedNode *errorNode)
-  : PathSensitiveBugReport(bt, shortDesc, desc, errorNode,
-   /*LocationToUnique*/ {},
-   /*DeclToUnique*/ nullptr) {}
+  : BugReport(Kind::PathSensitive, bt, shortDesc, desc),
+ErrorNode(errorNode),
+ErrorNodeRange(getStmt() ? getStmt()->getSourceRange()
+ : SourceRange()) {}
 
   /// Create a PathSensitiveBugReport with a custom uniqueing location.
   ///
@@ -389,13 +391,11 @@ class PathSensitiveBugReport : public BugReport {
  const ExplodedNode *errorNode,
  PathDiagnosticLocation LocationToUnique,
  const Decl *DeclToUnique)
-  : PathSensitiveBugReport(bt, desc, desc, errorNode, LocationToUnique,
-   DeclToUnique) {}
-
-  PathSensitiveBugReport(const BugType &bt, StringRef shortDesc, StringRef 
desc,
- const ExplodedNode *errorNode,
- PathDiagnosticLocation LocationToUnique,
- const Decl *DeclToUnique);
+  : BugReport(Kind::PathSensitive, bt, desc), ErrorNode(errorNode),
+ErrorNodeRange(getStmt() ? getStmt()->getSourceRange() : 
SourceRange()),
+UniqueingLocation(LocationToUnique), UniqueingDecl(DeclToUnique) {
+assert(errorNode);
+  }
 
   static bool classof(const BugReport *R) {
 return R->getKind() == Kind::PathSensitive;

diff  --git a/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h 
b/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
index 795067cba582..7b72fae0fefe 100644
--- a/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ b/clang/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -135,7 +135,7 @@ class CheckerRegistry {
  "Invalid development status!");
 }
 
-LLVM_DUMP_METHOD void dump() const;
+LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
 LLVM_DUMP_METHOD void dumpToStream(llvm::raw_o

[clang] f8d87ce - [CMake] Use 'ssh.py' executor to run the remote library tests.

2020-06-12 Thread Vladimir Vereschaka via cfe-commits
Author: Vladimir Vereschaka
Date: 2020-06-12T12:31:59-07:00
New Revision: f8d87ce9ca23a696dbcc52b4b3458272a2ba8091

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

LOG: [CMake] Use 'ssh.py' executor to run the remote library tests.

In order to support the libcxx new format changes SSHExecutor was
replaced with ssh.py script in the following way:

LIBxxx_EXECUTOR="/libcxx/utils/ssh.py --host @"

See 96e6cbbf941d0f937b7e823433d4c222967a1817 commit for details.

Added: 


Modified: 
clang/cmake/caches/CrossWinToARMLinux.cmake

Removed: 




diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 3d1e961ada8d..41ddb836f60e 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -102,7 +102,7 @@ set(RUNTIMES_CMAKE_ARGS 
"-DCMAKE_SYSTEM_NAME=Linux;-DCMAKE_A
 
 # Remote test configuration.
 if(DEFINED REMOTE_TEST_HOST)
-  set(DEFAULT_TEST_EXECUTOR 
"SSHExecutor('${REMOTE_TEST_HOST}', '${REMOTE_TEST_USER}')")
+  set(DEFAULT_TEST_EXECUTOR 
"${LLVM_PROJECT_DIR}/libcxx/utils/ssh.py 
--host='${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}'")
   set(DEFAULT_TEST_TARGET_INFO  
"libcxx.test.target_info.LinuxRemoteTI")
 
   # Allow override with the custom values.



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


  1   2   >