[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247805.
kadircet added a comment.

- Use spelledTokenAt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447

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


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,39 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager &SM) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansion(L))
+return {};
+  // Tokens expanded from macro args are potentially highlightable.
+  return getHighlightableSpellingToken(SM.getImmediateSpellingLoc(L), SM);
+}
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(const ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
+Loc = getHighlightableSpellingToken(Loc, SourceMgr);
 if (Loc.isInvalid())
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
-  return;
+const auto *Tok = TB.spelledTokenAt(Loc);
+assert(Tok);
 
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+auto Range = halfOpenToRange(SourceMgr,
+ Tok->range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST &AST) && {
@@ -211,6 +211,7 @@
   }
 
 private:
+  const syntax::TokenBuffer &TB;
   const SourceManager &SourceMgr;
   const LangOptions &LangOpts;
   std::vector Tokens;
@@ -311,7 +312,7 @@
 std::vector getSemanticHighlightings(ParsedAST &AST) {
   auto &C = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,39 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager &SM) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansion(L))
+return {};
+  // Tokens expanded from macro args are potentially highlightable.
+  re

[PATCH] D75503: [clang][Syntax] Add spelledTokenAt helper to TokenBuffer

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75503

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -59,6 +59,7 @@
 using ::testing::Field;
 using ::testing::Matcher;
 using ::testing::Not;
+using ::testing::Pointee;
 using ::testing::StartsWith;
 
 namespace {
@@ -363,6 +364,12 @@
   AllOf(Kind(tok::equal), RangeIs(Code.range("r3"))),
   AllOf(Kind(tok::string_literal), RangeIs(Code.range("r4"))),
   AllOf(Kind(tok::semi), RangeIs(Code.range("r5");
+
+  auto StartLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+  for (auto &R : Code.ranges()) {
+EXPECT_THAT(Buffer.spelledTokenAt(StartLoc.getLocWithOffset(R.Begin)),
+Pointee(RangeIs(R)));
+  }
 }
 
 TEST_F(TokenCollectorTest, MacroDirectives) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,6 +183,16 @@
   return It->second.SpelledTokens;
 }
 
+const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
+  assert(Loc.isFileID());
+  const auto *Tok = llvm::partition_point(
+  spelledTokens(SourceMgr->getFileID(Loc)),
+  [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  if (!Tok || Tok->location() != Loc)
+return nullptr;
+  return Tok;
+}
+
 std::string TokenBuffer::Mapping::str() const {
   return std::string(
   llvm::formatv("spelled tokens: [{0},{1}), expanded tokens: [{2},{3})",
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -245,6 +245,10 @@
   /// "DECL", "(", "a", ")", ";"}
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  /// Returns the spelled Token starting at Loc, if there are no such tokens
+  /// returns nullptr.
+  const syntax::Token *spelledTokenAt(SourceLocation Loc) const;
+
   /// Get all tokens that expand a macro in \p FID. For the following input
   /// #define FOO B
   /// #define FOO2(X) int X


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -59,6 +59,7 @@
 using ::testing::Field;
 using ::testing::Matcher;
 using ::testing::Not;
+using ::testing::Pointee;
 using ::testing::StartsWith;
 
 namespace {
@@ -363,6 +364,12 @@
   AllOf(Kind(tok::equal), RangeIs(Code.range("r3"))),
   AllOf(Kind(tok::string_literal), RangeIs(Code.range("r4"))),
   AllOf(Kind(tok::semi), RangeIs(Code.range("r5");
+
+  auto StartLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+  for (auto &R : Code.ranges()) {
+EXPECT_THAT(Buffer.spelledTokenAt(StartLoc.getLocWithOffset(R.Begin)),
+Pointee(RangeIs(R)));
+  }
 }
 
 TEST_F(TokenCollectorTest, MacroDirectives) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,6 +183,16 @@
   return It->second.SpelledTokens;
 }
 
+const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
+  assert(Loc.isFileID());
+  const auto *Tok = llvm::partition_point(
+  spelledTokens(SourceMgr->getFileID(Loc)),
+  [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  if (!Tok || Tok->location() != Loc)
+return nullptr;
+  return Tok;
+}
+
 std::string TokenBuffer::Mapping::str() const {
   return std::string(
   llvm::formatv("spelled tokens: [{0},{1}), expanded tokens: [{2},{3})",
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -245,6 +245,10 @@
   /// "DECL", "(", "a", ")", ";"}
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  /// Returns the spelled Token starting at Loc, if there are no such tokens
+  /// returns nullptr.
+  const syntax::Token *spelledTokenAt(SourceLocation Loc) const;
+
   /// Get all tokens that expand a macro in \p FID. For the following input
   /// #define FOO B
   /// #define FOO2(X) int X

[PATCH] D75410: [clang-format] Fixed BraceWrapping.AfterExternBlock

2020-03-03 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 abandoned this revision.
MarcusJohnson91 added a comment.

I'm moving the intended change to a new clang-format option instead of 
modifying an established one.


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

https://reviews.llvm.org/D75410



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247808.
kadircet added a comment.

- Also get rid of the call in collectmacros by using clang::Token's endlocation 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -152,7 +152,12 @@
 llvm::Optional makeLocation(ASTContext &AST, SourceLocation TokLoc,
   llvm::StringRef TUPath) {
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());
+  if (Tok.empty())
+return None;
+  auto Range = Tok.front().range(SourceMgr);
+  const FileEntry *F = SourceMgr.getFileEntryForID(Range.file());
   if (!F)
 return None;
   auto FilePath = getCanonicalPath(F, SourceMgr);
@@ -160,14 +165,10 @@
 log("failed to get path!");
 return None;
   }
-  if (auto Range =
-  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
-Location L;
-L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-L.range = *Range;
-return L;
-  }
-  return None;
+  Location L;
+  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+  L.range = halfOpenToRange(SourceMgr, Range.toCharRange(SourceMgr));
+  return L;
 }
 
 } // namespace
@@ -351,11 +352,11 @@
 class ReferenceFinder : public index::IndexDataConsumer {
 public:
   struct Reference {
-SourceLocation Loc;
+syntax::Token Tok;
 index::SymbolRoleSet Role;
   };
 
-  ReferenceFinder(ASTContext &AST, Preprocessor &PP,
+  ReferenceFinder(const ParsedAST &AST,
   const std::vector &TargetDecls)
   : AST(AST) {
 for (const NamedDecl *D : TargetDecls)
@@ -364,13 +365,17 @@
 
   std::vector take() && {
 llvm::sort(References, [](const Reference &L, const Reference &R) {
-  return std::tie(L.Loc, L.Role) < std::tie(R.Loc, R.Role);
+  auto LTok = L.Tok.location();
+  auto RTok = R.Tok.location();
+  return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
 });
 // We sometimes see duplicates when parts of the AST get traversed twice.
 References.erase(std::unique(References.begin(), References.end(),
  [](const Reference &L, const Reference &R) {
-   return std::tie(L.Loc, L.Role) ==
-  std::tie(R.Loc, R.Role);
+   auto LTok = L.Tok.location();
+   auto RTok = R.Tok.location();
+   return std::tie(LTok, L.Role) ==
+  std::tie(RTok, R.Role);
  }),
  References.end());
 return std::move(References);
@@ -382,22 +387,27 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
+if (!CanonicalTargets.count(D))
+  return true;
+const auto &TB = AST.getTokens();
 const SourceManager &SM = AST.getSourceManager();
-Loc = SM.getFileLoc(Loc);
-if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
-  References.push_back({Loc, Roles});
+auto Toks = TB.spelledForExpanded(TB.expandedTokens(Loc));
+if (!Toks || Toks->empty() ||
+!isInsideMainFile(Toks->front().location(), SM))
+  return true;
+References.push_back({Toks->front(), Roles});
 return true;
   }
 
 private:
   llvm::SmallSet CanonicalTargets;
   std::vector References;
-  const ASTContext &AST;
+  const ParsedAST &AST;
 };
 
 std::vector
 findRefs(const std::vector &Decls, ParsedAST &AST) {
-  ReferenceFinder RefFinder(AST.getASTContext(), AST.getPreprocessor(), Decls);
+  ReferenceFinder RefFinder(AST, Decls);
   index::IndexingOptions IndexOpts;
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
@@ -428,18 +438,15 @@
   // different kinds, deduplicate them.
   std::vector Result;
   for (const auto &Ref : References) {
-if (auto Range =
-getTokenRange(AST.getSourceManager(), AST.getLangOpts(), Ref.Loc)) {
-  DocumentHighlight DH;
-  

[PATCH] D75503: [clang][Syntax] Add spelledTokenAt helper to TokenBuffer

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

Thanks for doing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75503



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

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



Comment at: clang-tools-extra/clangd/Hover.cpp:542
+  CharSourceRange HighlightRange =
+  TokensTouchingCursor.front().range(SM).toCharRange(SM);
   llvm::Optional HI;

nit: back() would fit better with the biases elsewhere



Comment at: clang-tools-extra/clangd/XRefs.cpp:155
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = 
SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());

so this is just running the raw lexer...

both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
(syntax::Token*, SourceMgr, TUPath).



Comment at: clang-tools-extra/clangd/XRefs.cpp:155
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = 
SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());

sammccall wrote:
> so this is just running the raw lexer...
> 
> both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
> passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
> (syntax::Token*, SourceMgr, TUPath).
It *seems* to always be the case that TokLoc is a spelled token, but this seems 
slightly subtle and the previous code defended against marco locations. Worth a 
comment



Comment at: clang-tools-extra/clangd/XRefs.cpp:355
   struct Reference {
-SourceLocation Loc;
+syntax::Token Tok;
 index::SymbolRoleSet Role;

document spelled or expanded.

It seems to be spelled, but I don't know why - expanded is more similar to the 
old code, allows us to defer more work, and doesn't require the dubious front().

You could add a function here range(SourceMgr) --> Range



Comment at: clang-tools-extra/clangd/XRefs.cpp:396
+if (!Toks || Toks->empty() ||
+!isInsideMainFile(Toks->front().location(), SM))
+  return true;

why is it safe to discard the rest of toks?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474



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


[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:92-125
+class MakeRetVal {
+  const CallExpr *CE = nullptr;
+  std::unique_ptr RetVal;
+  SymbolRef RetSym;
+
+public:
+  MakeRetVal(const CallEvent &Call, CheckerContext &C)

Szelethus wrote:
> balazske wrote:
> > Szelethus wrote:
> > > Do you have other patches that really crave the need for this class? Why 
> > > isn't `CallEvent::getReturnValue` sufficient? This is a legitimate 
> > > question, I really don't know. :)
> > This is an "interesting" solution for the problem that there is need for a 
> > function with 3 return values. The constructor performs the task of the 
> > function: Create a conjured value (and get the various objects for it). The 
> > output values are RetVal and RetSym, and the success state, and the call 
> > expr that is computed here anyway. It could be computed independently but 
> > if the value was retrieved once it is better to store it for later use. (I 
> > did not check how costly that operation is.)
> > 
> > I had some experience that using only `getReturnValue` and make constraints 
> > on that does not work as intended, and the reason can be that we need to 
> > bind a value for the call expr otherwise it is an unknown (undefined?) 
> > value (and not the conjured symbol)?
> I suspect that `getReturnValue` might only work in `postCall`, but I'm not 
> sure.
> 
> I think instead of this class, a function returning a `std::tuple` would be 
> nicer, with `std::tie` on the call site. You seem to use all 3 returns values 
> in the functions that instantiate `MakeRetVal` anyways :).
> 
> In `StdLibraryFunctionsChecker`'s `evalCall`, the return value is 
> [[https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L403|explicitly
>  constructed]], and further constraints on it are only imposed in `postCall`. 
> I wonder why that is. @martong, any idea why we don't `apply` the constraints 
> for pure functions in `evalCall?`
The return value case is not as simple because the `DefinedSVal` has no default 
constructor, but it is not as bad to return only the `RetVal` and have a `CE` 
argument.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:383
+  // Record the failed status, only if failed.
+  // fseek clears the EOF flag, sets only error flag.
+  StateFailed = StateFailed->set(RV.getRetSym(),

Szelethus wrote:
> According to the C'98 standard 
> [[http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf|§7.19.9.2.5]]:
> > After determining the new position, a successful call to the fseek function 
> > undoes any effects of the `ungetc` function on the stream, clears the 
> > end-of-file indicator for the stream, and then establishes the new 
> > position. After a successful fseek call, the next operation on an update 
> > stream may be either input or output.
> 
> So it definitely doesn't clear the `EOF` flag on failure.
Yes it does say nothing about what happens with **EOF** flag on failure, so it 
should be is better to not change it. And we do not know if it is possible to 
get an **EOF** error (seek to after the end of file?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

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

Removed `MakeRetVal`, fixed a bug in evalFseek.

`evalFseek` is to be updated further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -47,6 +47,26 @@
   void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
 };
 
+struct StreamErrorState {
+  // The error state of an opened stream.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError
+  enum Kind { EofError, OtherError, AnyError } K;
+
+  StreamErrorState(Kind k) : K(k) {}
+
+  bool isEof() const { return K == EofError; }
+  bool isOther() const { return K == OtherError; }
+  bool isAny() const { return K == AnyError; }
+
+  bool operator==(const StreamErrorState &X) const { return K == X.K; }
+
+  static StreamErrorState getOther() { return StreamErrorState(OtherError); }
+
+  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
+};
+
 class StreamChecker;
 struct FnDescription;
 using FnCheck = std::functionStreamArgNo);
 }
 
+/// Create a conjured symbol return value for a call expression.
+DefinedSVal makeRetVal(CheckerContext &C, const CallExpr *CE) {
+  assert(CE && "Expecting a call expression.");
+
+  const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
+  return C.getSValBuilder()
+  .conjureSymbolVal(nullptr, CE, LCtx, C.blockCount())
+  .castAs();
+}
+
 class StreamChecker
 : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -89,7 +119,7 @@
{&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
   {{"fread", 4}, {&StreamChecker::preDefault, nullptr, 3}},
   {{"fwrite", 4}, {&StreamChecker::preDefault, nullptr, 3}},
-  {{"fseek", 3}, {&StreamChecker::preFseek, nullptr, 0}},
+  {{"fseek", 3}, {&StreamChecker::preFseek, &StreamChecker::evalFseek, 0}},
   {{"ftell", 1}, {&StreamChecker::preDefault, nullptr, 0}},
   {{"rewind", 1}, {&StreamChecker::preDefault, nullptr, 0}},
   {{"fgetpos", 2}, {&StreamChecker::preDefault, nullptr, 0}},
@@ -102,15 +132,20 @@
 
   void preDefault(const FnDescription *Desc, const CallEvent &Call,
   CheckerContext &C) const;
-  void preFseek(const FnDescription *Desc, const CallEvent &Call,
-CheckerContext &C) const;
-  void preFreopen(const FnDescription *Desc, const CallEvent &Call,
-  CheckerContext &C) const;
 
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
+
+  void preFreopen(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C) const;
   void evalFreopen(const FnDescription *Desc, const CallEvent &Call,
CheckerContext &C) const;
+
+  void preFseek(const FnDescription *Desc, const CallEvent &Call,
+CheckerContext &C) const;
+  void evalFseek(const FnDescription *Desc, const CallEvent &Call,
+ CheckerContext &C) const;
+
   void evalFclose(const FnDescription *Desc, const CallEvent &Call,
   CheckerContext &C) const;
 
@@ -156,8 +191,14 @@
 
 } // end anonymous namespace
 
+// Store the state of the stream.
 REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
 
+// Store the error state of the stream.
+// Used only for streams in opened state.
+// The entry exists only if there is error for the stream.
+REGISTER_MAP_WITH_PROGRAMSTATE(StreamErrorMap, SymbolRef, StreamErrorState)
+
 void StreamChecker::checkPreCall(const CallEvent &Call,
  CheckerContext &C) const {
   const FnDescription *Desc = lookupFn(Call);
@@ -191,48 +232,15 @@
   C.addTransition(State);
 }
 
-void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
- CheckerContext &C) const {
-  ProgramStateRef State = C.getState();
-  SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, C, State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-  State = ensureFseekWhenceCorrect(Call.getArgSVal(2), C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
-}
-
-void StreamChecker::preFreopen(const FnDescription *Desc, const CallEvent &Call,
-   CheckerContext &C) const {
-  // Do not allow NULL as passed stream pointer but allow a closed stream.
-  ProgramStateRef State = C.getState();
-  State = ensureStreamNonNull(getStreamArg(Desc, Cal

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp:40
+SrcMgr::CharacteristicKind FileType) {
+  if (SrcMgr::isSystem(FileType)) {
+if (!SM.isInMainFile(HashLoc)) {

PaulkaToast wrote:
> aaron.ballman wrote:
> > njames93 wrote:
> > > abrachet wrote:
> > > > Could you whitelist the freestanding/compiler provided headers like 
> > > > stddef, stdatomic...
> > > Or have a user configurable whitelist 
> > It should be configurable and named something other than whitelist. I'd 
> > recommend `AllowedHeaders` or something along those lines.
> Maintaining a list of acceptable and blacklisted headers would produce a fair 
> bit of maintenance burden. We have a specific use-case in mind here for 
> llvm-libc which is to avoid use of system libc headers that aren't provided 
> by the compiler. I've added a check to allow for compiler provided headers 
> without necessitating a black/white list. 
> 
> If a general check is desirable then my suggestion is to pull out [[ 
> https://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
>  | fuchsia-restrict-system-includes ]] which already implements the features 
> mentioned.
> I've added a check to allow for compiler provided headers without 
> necessitating a black/white list.

This is a much better solution for sure.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst:11-13
+   #include // Not allowed because it is part of system 
libc
+   #include// Allowed because it is provided by the 
compiler
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system 
libc

Nit: We do periods at the end of comments in real code so for parity I think it 
makes sense here too.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst:16-20
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `FILE *` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.

To be annoyingly pedantic, `FILE` is opaque so it would actually be ok in this 
situation. It is undefined to allocate your own `FILE` I believe. Something 
like `jmp_buf` or `thrd_t` might be better examples? Or macros like `assert` or 
`errno`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332



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


[clang] 0a9fc92 - [Driver] Default to -fno-common for all targets

2020-03-03 Thread Sjoerd Meijer via cfe-commits

Author: Sjoerd Meijer
Date: 2020-03-03T09:15:07Z
New Revision: 0a9fc9233e172601e26381810d093e02ef410f65

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

LOG: [Driver] Default to -fno-common for all targets

This makes -fno-common the default for all targets because this has performance
and code-size benefits and is more language conforming for C code.
Additionally, GCC10 also defaults to -fno-common and so we get consistent
behaviour with GCC.

With this change, C code that uses tentative definitions as definitions of a
variable in multiple translation units will trigger multiple-definition linker
errors. Generally, this occurs when the use of the extern keyword is neglected
in the declaration of a variable in a header file. In some cases, no specific
translation unit provides a definition of the variable. The previous behavior
can be restored by specifying -fcommon.

As GCC has switched already, we benefit from applications already being ported
and existing documentation how to do this. For example:
- https://gcc.gnu.org/gcc-10/porting_to.html
- https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common

Differential revision: https://reviews.llvm.org/D75056

Added: 
clang/test/Driver/no-common.c

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
clang/test/CodeGen/2009-10-20-GlobalDebug.c
clang/test/CodeGen/aarch64-sve.c
clang/test/CodeGen/address-space.c
clang/test/CodeGen/alias.c
clang/test/CodeGen/align-systemz.c
clang/test/CodeGen/alignment.c
clang/test/CodeGen/asm-label.c
clang/test/CodeGen/attr-weak-import.c
clang/test/CodeGen/attr-weakref2.c
clang/test/CodeGen/attributes.c
clang/test/CodeGen/blocks-windows.c
clang/test/CodeGen/bool-convert.c
clang/test/CodeGen/c11atomics.c
clang/test/CodeGen/cfstring-elf-cfbuild-x86_64.c
clang/test/CodeGen/cfstring-windows.c
clang/test/CodeGen/default-address-space.c
clang/test/CodeGen/dllexport-1.c
clang/test/CodeGen/dllexport.c
clang/test/CodeGen/dllimport.c
clang/test/CodeGen/microsoft-no-common-align.c
clang/test/CodeGen/no-common.c
clang/test/CodeGen/pr25786.c
clang/test/CodeGen/pragma-pack-1.c
clang/test/CodeGen/pragma-weak.c
clang/test/CodeGen/private-extern-redef.c
clang/test/CodeGen/tentative-decls.c
clang/test/CodeGen/tls-model.c
clang/test/CodeGen/visibility.c
clang/test/CodeGen/vlt_to_pointer.c
clang/test/CodeGen/volatile-1.c
clang/test/CodeGen/windows-on-arm-dllimport-dllexport.c
clang/test/CodeGenCXX/clang-sections-tentative.c
clang/test/CodeGenObjC/constant-string-class.m
clang/test/CodeGenObjC/tentative-cfconstantstring.m
clang/test/CodeGenOpenCL/address-spaces.cl
clang/test/CodeGenOpenCL/amdgcn-large-globals.cl
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
clang/test/Driver/apple-kext-mkernel.c
clang/test/Driver/clang_f_opts.c
clang/test/Driver/fuchsia.c
clang/test/Driver/xcore-opts.c
clang/test/Frontend/ast-codegen.c
clang/test/Headers/xmmintrin.c
clang/test/PCH/chain-external-defs.c
clang/test/PCH/external-defs.c
clang/test/PCH/tentative-defs.c
clang/test/Parser/pragma-visibility2.c

Removed: 
clang/test/CodeGen/weak-global.c



diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 609e7fa66c00..5af9d64ae0fc 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -1307,6 +1307,10 @@ Use colors in diagnostics
 
 .. option:: -fcommon, -fno-common
 
+Place definitions of variables with no storage class and no initializer
+(tentative definitions) in a common block, instead of generating individual
+zero-initialized definitions (default -fno-common).
+
 .. option:: -fcompile-resource=, --resource , --resource=
 
 .. option:: -fconstant-cfstrings, -fno-constant-cfstrings

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce121ebe6055..664ae4e4167c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -84,6 +84,13 @@ future versions of Clang.
 Modified Compiler Flags
 ---
 
+- -fno-common has been enabled as the default for all targets.  Therefore, C
+  code that uses tentative definitions as definitions of a variable in multiple
+  translation units will trigger multiple-definition linker errors.  Generally,
+  this occurs when the use of the ``extern`` keyword is neglected in the 
declaration
+  of a variable in a header file. In some cases, no specific tr

[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 247818.
hokein added a comment.

- rebase to master
- address my comments
- added a FIXME about the RequiresExpr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920

Files:
  clang/include/clang/AST/DependencyFlags.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/AST/NestedNameSpecifier.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp

Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -11,7 +11,6 @@
 //
 //===--===//
 
-#include "clang/Serialization/ASTRecordReader.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/AttrIterator.h"
@@ -22,6 +21,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -49,6 +49,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Serialization/ASTRecordReader.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -511,10 +512,23 @@
 void ASTStmtReader::VisitExpr(Expr *E) {
   VisitStmt(E);
   E->setType(Record.readType());
-  E->setTypeDependent(Record.readInt());
-  E->setValueDependent(Record.readInt());
-  E->setInstantiationDependent(Record.readInt());
-  E->ExprBits.ContainsUnexpandedParameterPack = Record.readInt();
+
+  // FIXME: write and read all DependentFlags with a single call.
+  bool TypeDependent = Record.readInt();
+  bool ValueDependent = Record.readInt();
+  bool InstantiationDependent = Record.readInt();
+  bool ContainsUnexpandedTemplateParameters = Record.readInt();
+  auto Deps = ExprDependence::None;
+  if (TypeDependent)
+Deps |= ExprDependence::Type;
+  if (ValueDependent)
+Deps |= ExprDependence::Value;
+  if (InstantiationDependent)
+Deps |= ExprDependence::Instantiation;
+  if (ContainsUnexpandedTemplateParameters)
+Deps |= ExprDependence::UnexpandedPack;
+  E->setDependence(Deps);
+
   E->setValueKind(static_cast(Record.readInt()));
   E->setObjectKind(static_cast(Record.readInt()));
   assert(Record.getIdx() == NumExprFields &&
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10,10 +10,10 @@
 //
 //===--===//
 
-#include "clang/Sema/Overload.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -25,6 +25,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/Overload.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateDeduction.h"
@@ -12719,9 +12720,7 @@
   // base classes.
   CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy,
   VK_RValue, RParenLoc);
-  CE->setTypeDependent(true);
-  CE->setValueDependent(true);
-  CE->setInstantiationDependent(true);
+  CE->addDependence(ExprDependence::TypeValueInstantiation);
   *Result = CE;
   return true;
 }
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -11,8 +11,10 @@
 //===--===//
 
 #include "clang/AST/TemplateName.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
@@ -168,52 +170,53 @@
   return TemplateName(Decl);
 }
 
-bool TemplateName::isDependent() const {
+TemplateNameDependence Te

[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein commandeered this revision.
hokein edited reviewers, added: sammccall; removed: hokein.
hokein added inline comments.



Comment at: clang/lib/AST/TemplateName.cpp:173
+TemplateNameDependence TemplateName::getDependence() const {
+  auto F = TemplateNameDependence::None;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) {

hokein wrote:
> This part of refactoring seems a little scary to me,  I think it is correct 
> by comparing with the previous version. but the getDependence() now is very 
> **complicated**, I have no idea what it is doing.
> 
> instead of merging three different non-trivial if branches into a single 
> function, maybe keep them as it-is.
I have restructured the code, let me know whether it is clear now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75467: [instcombine] remove fsub to fneg hacks; only emit fneg

2020-03-03 Thread Simon Moll via Phabricator via cfe-commits
simoll updated this revision to Diff 247820.
simoll marked an inline comment as done.
simoll added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Thanks for the review!

- rebased
- fixed clang test
- added FIXME for correct DTZ, DAZ handling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75467

Files:
  clang/test/CodeGen/fma-builtins-constrained.c
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/cos-1.ll
  llvm/test/Transforms/InstCombine/fadd.ll
  llvm/test/Transforms/InstCombine/fast-math.ll
  llvm/test/Transforms/InstCombine/fdiv.ll
  llvm/test/Transforms/InstCombine/fmul.ll
  llvm/test/Transforms/InstCombine/fneg.ll
  llvm/test/Transforms/InstCombine/fpextend.ll
  llvm/test/Transforms/InstCombine/fsub.ll
  llvm/test/Transforms/InstCombine/maximum.ll
  llvm/test/Transforms/InstCombine/maxnum.ll
  llvm/test/Transforms/InstCombine/minimum.ll
  llvm/test/Transforms/InstCombine/minnum.ll
  llvm/test/Transforms/InstCombine/operand-complexity.ll
  llvm/test/Transforms/InstCombine/vec_shuffle.ll

Index: llvm/test/Transforms/InstCombine/vec_shuffle.ll
===
--- llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -1263,7 +1263,7 @@
 
 define <2 x float> @fneg(<2 x float> %x) {
 ; CHECK-LABEL: @fneg(
-; CHECK-NEXT:[[TMP1:%.*]] = fsub <2 x float> , [[X:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = fneg <2 x float> [[X:%.*]]
 ; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
 ; CHECK-NEXT:ret <2 x float> [[R]]
 ;
Index: llvm/test/Transforms/InstCombine/operand-complexity.ll
===
--- llvm/test/Transforms/InstCombine/operand-complexity.ll
+++ llvm/test/Transforms/InstCombine/operand-complexity.ll
@@ -92,7 +92,7 @@
 define float @fneg(float %x) {
 ; CHECK-LABEL: @fneg(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv float [[X:%.*]], 4.20e+01
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub float -0.00e+00, [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg float [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul float [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use(float [[FNEGX]])
 ; CHECK-NEXT:ret float [[R]]
@@ -122,7 +122,7 @@
 define <2 x float> @fneg_vec(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_vec(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv <2 x float> [[X:%.*]], 
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub <2 x float> , [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg <2 x float> [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use_vec(<2 x float> [[FNEGX]])
 ; CHECK-NEXT:ret <2 x float> [[R]]
@@ -137,7 +137,7 @@
 define <2 x float> @fneg_vec_undef(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_vec_undef(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv <2 x float> [[X:%.*]], 
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub <2 x float> , [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg <2 x float> [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use_vec(<2 x float> [[FNEGX]])
 ; CHECK-NEXT:ret <2 x float> [[R]]
Index: llvm/test/Transforms/InstCombine/minnum.ll
===
--- llvm/test/Transforms/InstCombine/minnum.ll
+++ llvm/test/Transforms/InstCombine/minnum.ll
@@ -301,7 +301,7 @@
 declare void @use(double)
 define double @neg_neg_extra_use_x(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x(
-; CHECK-NEXT:[[NEGX:%.*]] = fsub double -0.00e+00, [[X:%.*]]
+; CHECK-NEXT:[[NEGX:%.*]] = fneg double [[X:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.maxnum.f64(double [[X]], double [[Y:%.*]])
 ; CHECK-NEXT:[[R:%.*]] = fneg double [[TMP1]]
 ; CHECK-NEXT:call void @use(double [[NEGX]])
@@ -331,7 +331,7 @@
 
 define double @neg_neg_extra_use_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_y(
-; CHECK-NEXT:[[NEGY:%.*]] = fsub double -0.00e+00, [[Y:%.*]]
+; CHECK-NEXT:[[NEGY:%.*]] = fneg double [[Y:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.maxnum.f64(double [[X:%.*]], double [[Y]])
 ; CHECK-NEXT:[[R:%.*]] = fneg double [[TMP1]]
 ; CHECK-NEXT:call void @use(double [[NEGY]])
@@ -361,8 +361,8 @@
 
 define double @neg_neg_extra_use_x_and_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
-; CHECK-NEXT:[[NEGX:%.*]] = fsub double -0.00e+00, [[X:%.*]]
-; CHECK-NEXT:[[NEGY:%.*]] = fsub double -0.00e+00, [[Y:%.*]]
+; CHECK-NEXT:[[NEGX:%.*]] = fneg double [[X:%

[PATCH] D75056: [Driver] Default to -fno-common for all targets

2020-03-03 Thread Sjoerd Meijer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a9fc9233e17: [Driver] Default to -fno-common for all 
targets (authored by SjoerdMeijer).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D75056?vs=246917&id=247822#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75056

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
  clang/test/CodeGen/2009-10-20-GlobalDebug.c
  clang/test/CodeGen/aarch64-sve.c
  clang/test/CodeGen/address-space.c
  clang/test/CodeGen/alias.c
  clang/test/CodeGen/align-systemz.c
  clang/test/CodeGen/alignment.c
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/attr-weak-import.c
  clang/test/CodeGen/attr-weakref2.c
  clang/test/CodeGen/attributes.c
  clang/test/CodeGen/blocks-windows.c
  clang/test/CodeGen/bool-convert.c
  clang/test/CodeGen/c11atomics.c
  clang/test/CodeGen/cfstring-elf-cfbuild-x86_64.c
  clang/test/CodeGen/cfstring-windows.c
  clang/test/CodeGen/default-address-space.c
  clang/test/CodeGen/dllexport-1.c
  clang/test/CodeGen/dllexport.c
  clang/test/CodeGen/dllimport.c
  clang/test/CodeGen/microsoft-no-common-align.c
  clang/test/CodeGen/no-common.c
  clang/test/CodeGen/pr25786.c
  clang/test/CodeGen/pragma-pack-1.c
  clang/test/CodeGen/pragma-weak.c
  clang/test/CodeGen/private-extern-redef.c
  clang/test/CodeGen/tentative-decls.c
  clang/test/CodeGen/tls-model.c
  clang/test/CodeGen/visibility.c
  clang/test/CodeGen/vlt_to_pointer.c
  clang/test/CodeGen/volatile-1.c
  clang/test/CodeGen/weak-global.c
  clang/test/CodeGen/windows-on-arm-dllimport-dllexport.c
  clang/test/CodeGenCXX/clang-sections-tentative.c
  clang/test/CodeGenObjC/constant-string-class.m
  clang/test/CodeGenObjC/tentative-cfconstantstring.m
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/amdgcn-large-globals.cl
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
  clang/test/Driver/apple-kext-mkernel.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fuchsia.c
  clang/test/Driver/no-common.c
  clang/test/Driver/xcore-opts.c
  clang/test/Frontend/ast-codegen.c
  clang/test/Headers/xmmintrin.c
  clang/test/PCH/chain-external-defs.c
  clang/test/PCH/external-defs.c
  clang/test/PCH/tentative-defs.c
  clang/test/Parser/pragma-visibility2.c

Index: clang/test/Parser/pragma-visibility2.c
===
--- clang/test/Parser/pragma-visibility2.c
+++ clang/test/Parser/pragma-visibility2.c
@@ -6,14 +6,14 @@
 #pragma GCC visibility push(hidden)
 
 int v1;
-// CHECK: @v1 = common hidden global i32 0, align 4
+// CHECK: @v1 = hidden global i32 0, align 4
 
 #pragma GCC visibility pop
 
 int v2;
-// CHECK: @v2 = common global i32 0, align 4
+// CHECK: @v2 = global i32 0, align 4
 
 _Pragma("GCC visibility push(hidden)");
 
 int v3;
-// CHECK: @v3 = common hidden global i32 0, align 4
+// CHECK: @v3 = hidden global i32 0, align 4
Index: clang/test/PCH/tentative-defs.c
===
--- clang/test/PCH/tentative-defs.c
+++ clang/test/PCH/tentative-defs.c
@@ -1,6 +1,6 @@
 // Test with pch.
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/tentative-defs.h
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -verify -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -emit-pch -o %t.pch %S/tentative-defs.h
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fcommon -include-pch %t.pch -verify -emit-llvm -o %t %s
 // REQUIRES: x86-registered-target
 
 // RUN: grep "@variable = common global i32 0" %t | count 1
Index: clang/test/PCH/external-defs.c
===
--- clang/test/PCH/external-defs.c
+++ clang/test/PCH/external-defs.c
@@ -3,16 +3,16 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-pch -o %t.pch %S/external-defs.h
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -include-pch %t.pch -emit-llvm -o %t %s
 
-// RUN: grep "@x = common global i32 0" %t | count 1
+// RUN: grep "@x = global i32 0" %t | count 1
 // RUN: not grep "@z" %t
 
 // RUN: grep "@x2 = global i32 19" %t | count 1
 int x2 = 19;
 
-// RUN: grep "@incomplete_array = common global .*1 x i32" %t | count 1
-// RUN: grep "@incomplete_array2 = common global .*17 x i32" %t | count 1
+// RUN: grep "@incomplete_array = global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array2 = global .*17 x i32" %t | count 1
 int incomplete_array2[17];
-// RUN: grep "@incomplete_array3 = common global .*1 x i32" %t | count 1
+// RUN: grep "@incomplete_array3 = global .*1 x i32" %t | count 1
 int incomplete_array3[];
 
 struct S {
Index: clan

[PATCH] D75467: [instcombine] remove fsub to fneg hacks; only emit fneg

2020-03-03 Thread Simon Moll via Phabricator via cfe-commits
simoll marked an inline comment as done.
simoll added inline comments.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:2137
+  if (match(&I, m_FNeg(m_Value(Op
+return UnaryOperator::CreateFNegFMF(Op, &I);
 

cameron.mcinally wrote:
> Just noticed that this is a bug -- it needs a guard for denormal flushing. 
> 
> When FTZ or DAZ:
>   fsub -0.0, Denorm ==> +-0
>   fneg Denorm ==> -Denorm
> 
> Handling denormals correctly is an ongoing project. If you'd like to leave 
> this for later, we'll get to it. I see that it's currently broken, so no harm 
> in continuing that way for now.
> 
> Could you add a brief FIXME here?
Added a FIXME for now.
I suppose this should be fixed in PatternMatch.h by making `m_FNeg` refuse to 
match the fsub idiom for FTZ/DAZ if fneg does not preserve denormal semantics 
under those settings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75467



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


[clang-tools-extra] b2666cc - [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-03 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-03-03T09:59:14Z
New Revision: b2666ccca0277371a09e43a0a5a0f78029ba81e5

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

LOG: [clangd] DefineOutline won't copy virtual specifiers on methods

Summary:
The define out of line refactor tool previously would copy the `virtual`, 
`override` and `final` specifier into the out of line method definition.
This results in malformed code as those specifiers aren't allowed outside the 
class definition.

Reviewers: hokein, kadircet

Reviewed By: kadircet

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

Tags: #clang, #clang-tools-extra

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index bdfd0e4743d6..398b6f29dba8 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -16,6 +16,7 @@
 #include "SourceCode.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -156,7 +157,7 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
 "define outline: couldn't find a context for target");
 
   llvm::Error Errors = llvm::Error::success();
-  tooling::Replacements QualifierInsertions;
+  tooling::Replacements DeclarationCleanups;
 
   // Finds the first unqualified name in function return type and name, then
   // qualifies those to be valid in TargetContext.
@@ -181,7 +182,7 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
 const NamedDecl *ND = Ref.Targets.front();
 const std::string Qualifier = getQualification(
 AST, *TargetContext, SM.getLocForStartOfFile(SM.getMainFileID()), ND);
-if (auto Err = QualifierInsertions.add(
+if (auto Err = DeclarationCleanups.add(
 tooling::Replacement(SM, Ref.NameLoc, 0, Qualifier)))
   Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
   });
@@ -206,14 +207,72 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
   assert(Tok != Tokens.rend());
   DelRange.setBegin(Tok->location());
   if (auto Err =
-  QualifierInsertions.add(tooling::Replacement(SM, DelRange, "")))
+  DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
 Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
 }
   }
 
+  auto DelAttr = [&](const Attr *A) {
+if (!A)
+  return;
+auto AttrTokens =
+TokBuf.spelledForExpanded(TokBuf.expandedTokens(A->getRange()));
+assert(A->getLocation().isValid());
+if (!AttrTokens || AttrTokens->empty()) {
+  Errors = llvm::joinErrors(
+  std::move(Errors),
+  llvm::createStringError(
+  llvm::inconvertibleErrorCode(),
+  llvm::StringRef("define outline: Can't move out of line as "
+  "function has a macro `") +
+  A->getSpelling() + "` specifier."));
+  return;
+}
+CharSourceRange DelRange =
+syntax::Token::range(SM, AttrTokens->front(), AttrTokens->back())
+.toCharRange(SM);
+if (auto Err =
+DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+  };
+
+  DelAttr(FD->getAttr());
+  DelAttr(FD->getAttr());
+
+  if (FD->isVirtualAsWritten()) {
+SourceRange SpecRange{FD->getBeginLoc(), FD->getLocation()};
+bool HasErrors = true;
+
+// Clang allows duplicating virtual specifiers so check for multiple
+// occurances.
+for (const auto &Tok : TokBuf.expandedTokens(SpecRange)) {
+  if (Tok.kind() != tok::kw_virtual)
+continue;
+  auto Spelling = TokBuf.spelledForExpanded(llvm::makeArrayRef(Tok));
+  if (!Spelling) {
+HasErrors = true;
+break;
+  }
+  HasErrors = false;
+  CharSourceRange DelRange =
+  syntax::Token::range(SM, Spelling->front(), Spelling->back())
+  .toCharRange(SM);
+  if (auto Err =
+  DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+}
+if (HasErrors) {
+  Errors = llvm::joinErrors(
+  std::move(Errors),
+  llvm::createStringError(llvm::inconvertibl

[clang] 4e36356 - Revert "[Driver] Default to -fno-common for all targets"

2020-03-03 Thread Sjoerd Meijer via cfe-commits

Author: Sjoerd Meijer
Date: 2020-03-03T10:00:36Z
New Revision: 4e363563fa149321514389a031fa063e998d7422

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

LOG: Revert "[Driver] Default to -fno-common for all targets"

This reverts commit 0a9fc9233e172601e26381810d093e02ef410f65.

Going to look at the asan failures.

I find the failures in the test suite weird, because they look
like compile time test and I don't understand how that can be
failing, but will have a brief look at that too.

Added: 
clang/test/CodeGen/weak-global.c

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/2008-07-21-mixed-var-fn-decl.c
clang/test/CodeGen/2009-10-20-GlobalDebug.c
clang/test/CodeGen/aarch64-sve.c
clang/test/CodeGen/address-space.c
clang/test/CodeGen/alias.c
clang/test/CodeGen/align-systemz.c
clang/test/CodeGen/alignment.c
clang/test/CodeGen/asm-label.c
clang/test/CodeGen/attr-weak-import.c
clang/test/CodeGen/attr-weakref2.c
clang/test/CodeGen/attributes.c
clang/test/CodeGen/blocks-windows.c
clang/test/CodeGen/bool-convert.c
clang/test/CodeGen/c11atomics.c
clang/test/CodeGen/cfstring-elf-cfbuild-x86_64.c
clang/test/CodeGen/cfstring-windows.c
clang/test/CodeGen/default-address-space.c
clang/test/CodeGen/dllexport-1.c
clang/test/CodeGen/dllexport.c
clang/test/CodeGen/dllimport.c
clang/test/CodeGen/microsoft-no-common-align.c
clang/test/CodeGen/no-common.c
clang/test/CodeGen/pr25786.c
clang/test/CodeGen/pragma-pack-1.c
clang/test/CodeGen/pragma-weak.c
clang/test/CodeGen/private-extern-redef.c
clang/test/CodeGen/tentative-decls.c
clang/test/CodeGen/tls-model.c
clang/test/CodeGen/visibility.c
clang/test/CodeGen/vlt_to_pointer.c
clang/test/CodeGen/volatile-1.c
clang/test/CodeGen/windows-on-arm-dllimport-dllexport.c
clang/test/CodeGenCXX/clang-sections-tentative.c
clang/test/CodeGenObjC/constant-string-class.m
clang/test/CodeGenObjC/tentative-cfconstantstring.m
clang/test/CodeGenOpenCL/address-spaces.cl
clang/test/CodeGenOpenCL/amdgcn-large-globals.cl
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
clang/test/Driver/apple-kext-mkernel.c
clang/test/Driver/clang_f_opts.c
clang/test/Driver/fuchsia.c
clang/test/Driver/xcore-opts.c
clang/test/Frontend/ast-codegen.c
clang/test/Headers/xmmintrin.c
clang/test/PCH/chain-external-defs.c
clang/test/PCH/external-defs.c
clang/test/PCH/tentative-defs.c
clang/test/Parser/pragma-visibility2.c

Removed: 
clang/test/Driver/no-common.c



diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 5af9d64ae0fc..609e7fa66c00 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -1307,10 +1307,6 @@ Use colors in diagnostics
 
 .. option:: -fcommon, -fno-common
 
-Place definitions of variables with no storage class and no initializer
-(tentative definitions) in a common block, instead of generating individual
-zero-initialized definitions (default -fno-common).
-
 .. option:: -fcompile-resource=, --resource , --resource=
 
 .. option:: -fconstant-cfstrings, -fno-constant-cfstrings

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 664ae4e4167c..ce121ebe6055 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -84,13 +84,6 @@ future versions of Clang.
 Modified Compiler Flags
 ---
 
-- -fno-common has been enabled as the default for all targets.  Therefore, C
-  code that uses tentative definitions as definitions of a variable in multiple
-  translation units will trigger multiple-definition linker errors.  Generally,
-  this occurs when the use of the ``extern`` keyword is neglected in the 
declaration
-  of a variable in a header file. In some cases, no specific translation unit
-  provides a definition of the variable. The previous behavior can be restored 
by
-  specifying ``-fcommon``.
 
 New Pragmas in Clang
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8d6256580615..f1801e3e89e7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -848,8 +848,7 @@ def fno_record_command_line : Flag<["-"], 
"fno-record-command-line">,
   Group;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
-def fcommon : Flag<["-"], "fcommon">, Group,
-  Flags<[CoreOption, CC1Option]>, HelpText

[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 247824.
balazske marked 2 inline comments as done.
balazske added a comment.

Updated `StreamState` to include the error state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -28,23 +28,42 @@
 namespace {
 
 struct StreamState {
-  enum Kind { Opened, Closed, OpenFailed, Escaped } K;
-
-  StreamState(Kind k) : K(k) {}
-
-  bool isOpened() const { return K == Opened; }
-  bool isClosed() const { return K == Closed; }
-  bool isOpenFailed() const { return K == OpenFailed; }
-  // bool isEscaped() const { return K == Escaped; }
-
-  bool operator==(const StreamState &X) const { return K == X.K; }
+  // State of a stream symbol.
+  // In any non-opened state the stream really does not exist.
+  // The OpenFailed means a previous open has failed, the stream is not open.
+  enum KindTy { Opened, Closed, OpenFailed } State;
+
+  // The error state of a stream.
+  // NoError: No error flag is set or stream is not open.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError
+  enum ErrorKindTy {
+NoError,
+EofError,
+OtherError,
+AnyError
+  } ErrorState = NoError;
+
+  bool isOpened() const { return State == Opened; }
+  bool isClosed() const { return State == Closed; }
+  bool isOpenFailed() const { return State == OpenFailed; }
+
+  bool operator==(const StreamState &X) const {
+return State == X.State && ErrorState == X.ErrorState;
+  }
 
-  static StreamState getOpened() { return StreamState(Opened); }
-  static StreamState getClosed() { return StreamState(Closed); }
-  static StreamState getOpenFailed() { return StreamState(OpenFailed); }
-  static StreamState getEscaped() { return StreamState(Escaped); }
+  static StreamState getOpened() { return StreamState{Opened}; }
+  static StreamState getClosed() { return StreamState{Closed}; }
+  static StreamState getOpenFailed() { return StreamState{OpenFailed}; }
+  static StreamState getOpenedWithError() {
+return StreamState{Opened, AnyError};
+  }
 
-  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
+  void Profile(llvm::FoldingSetNodeID &ID) const {
+ID.AddInteger(State);
+ID.AddInteger(ErrorState);
+  }
 };
 
 class StreamChecker;
@@ -69,6 +88,16 @@
   return Call.getArgSVal(Desc->StreamArgNo);
 }
 
+/// Create a conjured symbol return value for a call expression.
+DefinedSVal makeRetVal(CheckerContext &C, const CallExpr *CE) {
+  assert(CE && "Expecting a call expression.");
+
+  const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
+  return C.getSValBuilder()
+  .conjureSymbolVal(nullptr, CE, LCtx, C.blockCount())
+  .castAs();
+}
+
 class StreamChecker
 : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -89,7 +118,7 @@
{&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
   {{"fread", 4}, {&StreamChecker::preDefault, nullptr, 3}},
   {{"fwrite", 4}, {&StreamChecker::preDefault, nullptr, 3}},
-  {{"fseek", 3}, {&StreamChecker::preFseek, nullptr, 0}},
+  {{"fseek", 3}, {&StreamChecker::preFseek, &StreamChecker::evalFseek, 0}},
   {{"ftell", 1}, {&StreamChecker::preDefault, nullptr, 0}},
   {{"rewind", 1}, {&StreamChecker::preDefault, nullptr, 0}},
   {{"fgetpos", 2}, {&StreamChecker::preDefault, nullptr, 0}},
@@ -102,15 +131,20 @@
 
   void preDefault(const FnDescription *Desc, const CallEvent &Call,
   CheckerContext &C) const;
-  void preFseek(const FnDescription *Desc, const CallEvent &Call,
-CheckerContext &C) const;
-  void preFreopen(const FnDescription *Desc, const CallEvent &Call,
-  CheckerContext &C) const;
 
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
+
+  void preFreopen(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C) const;
   void evalFreopen(const FnDescription *Desc, const CallEvent &Call,
CheckerContext &C) const;
+
+  void preFseek(const FnDescription *Desc, const CallEvent &Call,
+CheckerContext &C) const;
+  void evalFseek(const FnDescription *Desc, const CallEvent &Call,
+ CheckerContext &C) const;
+
   void evalFclose(const FnDescription *Desc, const CallEvent &Call,
   CheckerContext &C) const;
 
@@ -156,6 +190,7 @@
 
 } // end anonymous namespace
 
+// Store the state of the stream.
 REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, Strea

[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-03 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

In D73852#1901895 , @rsmith wrote:

> Thank you, Luboš, and sorry for the process problems here.


FWIW, the Clang repository here in Phabricator is still 'Inactive', so even 
though 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface
 does say to use it, reviews may again not get sent to the correct commits list 
if somebody else gets confused by that too (especially for projects other than 
LLVM itself or Clang, as the page doesn't even mention what the mailing lists 
for those are).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

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



Comment at: clang-tools-extra/clangd/XRefs.cpp:155
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = 
SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());

sammccall wrote:
> sammccall wrote:
> > so this is just running the raw lexer...
> > 
> > both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
> > passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
> > (syntax::Token*, SourceMgr, TUPath).
> It *seems* to always be the case that TokLoc is a spelled token, but this 
> seems slightly subtle and the previous code defended against marco locations. 
> Worth a comment
> can we call spelledTokenAt

as you pointed out offline, we only have spelled tokens for the main file.
I think we have to lex here to get the token length, and the clearest thing is 
to do this completely directly (`Lexer::measureTokenLength` -> 
`Loc.getLocWithOffset`) rather than obfuscating with tokenbuffer.
We should have a comment *why* we lex here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474



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


[PATCH] D70764: build: reduce CMake handling for zlib

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

There were some concerns raised on this patch, and also in PR44780.

I think at this point it's safer to revert these changes and start over. I've 
pushed the revert in 916be8fd6a0a0feea4cefcbeb0c22c65848d7a2e 
 and will 
merge that to 10.x after it's baked a little.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70764



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-03 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2666ccca027: [clangd] DefineOutline won't copy virtual 
specifiers on methods (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D75429?vs=247779&id=247828#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

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

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2068,6 +2068,80 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual virtual void virtual f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual virtual void virtual foo() ;
+};)cpp",
+  "  void  A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2155,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2194,48 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+   " void A::foo() {}\n"},
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+   " void A::foo() {}\n"},
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+   "void B::foo()  {}\n"},
+  {R"cpp(#define STUPID_MACRO(X) virtual
+  struct A {
+STUPID_MACRO(sizeof sizeof int) void f^oo() {}
+  };)cpp",
+   R"cpp(#define STUPID_MACRO(X) virtual
+  struct A {
+STUPID_MACRO(sizeof sizeof int) void foo() ;
+  };)cpp",
+   " void A::foo() {}\n"},
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2347,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A

[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

2020-03-03 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:391
 if (!AttrTok)
-  return false;
+  return true;
 

This is needed to avoid 

```
[assembly:InternalsVisibleTo("SomeAssembly, 
PublicKey=SomePublicKeyThatExceedsTheColumnLimit")]
```

being classified as a ObjCMethodExpr (as seen when running clang-format with 
-debug).

The formatting results are currently the same for ObjCMethodExpr and 
CSharpAttributes.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:281
   Style.ColumnLimit = 10;
-  verifyFormat(R"([assembly:InternalsVisibleTo(
+  verifyFormat(R"([assembly: InternalsVisibleTo(
 "SomeAssembly, PublicKey=SomePublicKeyThatExceedsTheColumnLimit")])",

krasimir wrote:
> krasimir wrote:
> > isn't the space after the `:` a regression?
> > Looking at
> > https://docs.microsoft.com/en-us/dotnet/standard/assembly/set-attributes
> > it looks like such attributes are spelled `[assembly:Blah]`
> > 
> > How is an example where such an attribute is not the last thing in the file?
> > 
> > I'm not entirely clear on which edit caused this.
> The space maybe is coming from
> [[ 
> https://github.com/llvm/llvm-project/blob/ff9f4b5489cda4d9b31595b54ec0296dc012588d/clang/lib/Format/TokenAnnotator.h#L177
>  | TokenAnnotator.spaceRequiredBetween ]], which may need to be adjusted for 
> C#.
There seems to be some inconsistency between the docs you linked (which has no 
space) and code that forms part of projects like Roslyn (which has the space).

I'll defer making this change (if we want it until later).


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

https://reviews.llvm.org/D75465



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


[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

2020-03-03 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 247832.
jbcoe marked 2 inline comments as done.
jbcoe added a comment.

Do not allow spaces around C# attribute colons.


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

https://reviews.llvm.org/D75465

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp

Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -384,11 +384,11 @@
 
 if (!AttrTok)
   return false;
-
-// Move past the end of ']'.
+
+// Allow an attribute to be the only content of a file.
 AttrTok = AttrTok->Next;
 if (!AttrTok)
-  return false;
+  return true;
 
 // Limit this to being an access modifier that follows.
 if (AttrTok->isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
@@ -460,7 +460,7 @@
  Contexts.back().InCpp11AttributeSpecifier;
 
 // Treat C# Attributes [STAThread] much like C++ attributes [[...]].
-bool IsCSharp11AttributeSpecifier =
+bool IsCSharpAttributeSpecifier =
 isCSharpAttributeSpecifier(*Left) ||
 Contexts.back().InCSharpAttributeSpecifier;
 
@@ -469,7 +469,8 @@
 bool StartsObjCMethodExpr =
 !IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
 Style.isCpp() && !IsCpp11AttributeSpecifier &&
-Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
+!IsCSharpAttributeSpecifier && Contexts.back().CanBeExpression &&
+Left->isNot(TT_LambdaLSquare) &&
 !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
 (!Parent ||
  Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
@@ -496,7 +497,7 @@
   } else if (Style.isCpp() && Contexts.back().ContextKind == tok::l_brace &&
  Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->Type = TT_DesignatedInitializerLSquare;
-  } else if (IsCSharp11AttributeSpecifier) {
+  } else if (IsCSharpAttributeSpecifier) {
 Left->Type = TT_AttributeSquare;
   } else if (CurrentToken->is(tok::r_square) && Parent &&
  Parent->is(TT_TemplateCloser)) {
@@ -559,13 +560,13 @@
 
 Contexts.back().ColonIsObjCMethodExpr = StartsObjCMethodExpr;
 Contexts.back().InCpp11AttributeSpecifier = IsCpp11AttributeSpecifier;
-Contexts.back().InCSharpAttributeSpecifier = IsCSharp11AttributeSpecifier;
+Contexts.back().InCSharpAttributeSpecifier = IsCSharpAttributeSpecifier;
 
 while (CurrentToken) {
   if (CurrentToken->is(tok::r_square)) {
 if (IsCpp11AttributeSpecifier)
   CurrentToken->Type = TT_AttributeSquare;
-if (IsCSharp11AttributeSpecifier)
+if (IsCSharpAttributeSpecifier)
   CurrentToken->Type = TT_AttributeSquare;
 else if (((CurrentToken->Next &&
CurrentToken->Next->is(tok::l_paren)) ||
@@ -777,6 +778,10 @@
   break;
 }
   } else if (Style.isCSharp()) {
+if (Contexts.back().InCSharpAttributeSpecifier) {
+  Tok->Type = TT_AttributeColon;
+  break;
+}
 if (Contexts.back().ContextKind == tok::l_paren) {
   Tok->Type = TT_CSharpNamedArgumentColon;
   break;
@@ -2922,6 +2927,10 @@
 if (Left.is(TT_JsFatArrow) || Right.is(TT_JsFatArrow))
   return true;
 
+// No spaces around attribute target colons
+if (Left.is(TT_AttributeColon) || Right.is(TT_AttributeColon))
+  return false;
+
 // space between type and variable e.g. Dictionary foo;
 if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
   return true;
@@ -3550,8 +3559,8 @@
   const FormatToken &Left = *Right.Previous;
   // Language-specific stuff.
   if (Style.isCSharp()) {
-if (Left.is(TT_CSharpNamedArgumentColon) ||
-Right.is(TT_CSharpNamedArgumentColon))
+if (Left.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon) ||
+Right.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon))
   return false;
   } else if (Style.Language == FormatStyle::LK_Java) {
 if (Left.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -55,7 +55,6 @@
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
-  bool tryMergeCSharpAttributeAndTarget();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -76,8 +76,6 @@
 return;
 
   if (Styl

[PATCH] D75229: [clang-tidy] Add signal-in-multithreaded-program check

2020-03-03 Thread Kocsis Ábel via Phabricator via cfe-commits
abelkocsis updated this revision to Diff 247833.
abelkocsis added a comment.

Configurable callers option and new test cases add.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D75229

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SignalInMultithreadedProgramCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalInMultithreadedProgramCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-in-multithreaded-program.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-con37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-std::thread.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std::thread.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-thrd_create.cpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t)(void *);
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { return 0; };
+enum {
+  thrd_success = 0,
+};
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+int func(void *data) {
+  while (!flag) {
+  }
+  return 0;
+}
+
+int main(void) {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: singal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+  thrd_t tid;
+
+  if (thrd_success != thrd_create(&tid, func, NULL)) {
+  }
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std::thread.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-noconfig-std::thread.cpp
@@ -0,0 +1,37 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t)(void *);
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+void threadFunction() {}
+
+namespace std {
+class thread {
+public:
+  thread() noexcept;
+  template 
+  explicit thread(Function &&f, Args &&... args);
+  thread(const thread &) = delete;
+  thread(thread &&) noexcept;
+};
+} // namespace std
+
+int main(void) {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: singal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+
+  std::thread threadObj(threadFunction);
+
+  return 0;
+}
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-in-multithreaded-program-config-thrd_create.cpp
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy %s bugprone-signal-in-multithreaded-program %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: bugprone-signal-in-multithreaded-program.ThreadList, value: "thrd_create"}]}'
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t)(void *);
+typedef int sig_atomic_t;
+#define SIGUSR1 30
+#define NULL 0
+
+void (*signal(int sig, void (*handler)(int)))(int);
+
+int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { return 0; };
+enum {
+  thrd_success = 0,
+};
+
+volatile sig_atomic_t flag = 0;
+
+void handler(int signum) {
+  flag = 1;
+}
+
+int func(void *data) {
+  while (!flag) {
+  }
+  return 0;
+}
+
+int main(void) {
+  signal(SIGUSR1, handler);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: singal function should not be called in a multithreaded program [bugprone-signal-in-multithreaded-program]
+  thrd_t tid;
+
+  if (thrd_success != thrd_create(&tid, func, NULL)) {
+  }
+  return 0;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signa

[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-03 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:92-125
+class MakeRetVal {
+  const CallExpr *CE = nullptr;
+  std::unique_ptr RetVal;
+  SymbolRef RetSym;
+
+public:
+  MakeRetVal(const CallEvent &Call, CheckerContext &C)

balazske wrote:
> Szelethus wrote:
> > balazske wrote:
> > > Szelethus wrote:
> > > > Do you have other patches that really crave the need for this class? 
> > > > Why isn't `CallEvent::getReturnValue` sufficient? This is a legitimate 
> > > > question, I really don't know. :)
> > > This is an "interesting" solution for the problem that there is need for 
> > > a function with 3 return values. The constructor performs the task of the 
> > > function: Create a conjured value (and get the various objects for it). 
> > > The output values are RetVal and RetSym, and the success state, and the 
> > > call expr that is computed here anyway. It could be computed 
> > > independently but if the value was retrieved once it is better to store 
> > > it for later use. (I did not check how costly that operation is.)
> > > 
> > > I had some experience that using only `getReturnValue` and make 
> > > constraints on that does not work as intended, and the reason can be that 
> > > we need to bind a value for the call expr otherwise it is an unknown 
> > > (undefined?) value (and not the conjured symbol)?
> > I suspect that `getReturnValue` might only work in `postCall`, but I'm not 
> > sure.
> > 
> > I think instead of this class, a function returning a `std::tuple` would be 
> > nicer, with `std::tie` on the call site. You seem to use all 3 returns 
> > values in the functions that instantiate `MakeRetVal` anyways :).
> > 
> > In `StdLibraryFunctionsChecker`'s `evalCall`, the return value is 
> > [[https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L403|explicitly
> >  constructed]], and further constraints on it are only imposed in 
> > `postCall`. I wonder why that is. @martong, any idea why we don't `apply` 
> > the constraints for pure functions in `evalCall?`
> The return value case is not as simple because the `DefinedSVal` has no 
> default constructor, but it is not as bad to return only the `RetVal` and 
> have a `CE` argument.
I like the current solution very much!



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:31-33
+  // State of a stream symbol.
+  // In any non-opened state the stream really does not exist.
+  // The OpenFailed means a previous open has failed, the stream is not open.

Could you please move these to the individual enums please? :) I have an 
indexer that can query those as documentation.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:37-40
+  // NoError: No error flag is set or stream is not open.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError

These too. Also, I'm not yet sure whether we need `OtherError` and `AnyError`, 
as stated in a later inline.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:333-335
+  // Ignore the call if the stream is is not tracked.
+  if (!State->get(StreamSym))
+return;

If we check in `preCall` whether the stream is opened why don't we 
conservatively assume it to be open?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:351-354
+  // Set state to any error.
+  // Assume that EOF and other error is possible after the call.
+  StateFailed =
+  StateFailed->set(StreamSym, 
StreamState::getOpenedWithError());

But why? The standard suggests that the error state isn't changed upon failure. 
I think we should leave it as-is.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:438-439
   const StreamState *SS = State->get(Sym);
   if (!SS)
 return State;
 

Right here, should we just assume a stream to be opened when we can't prove 
otherwise? `ensureStreamOpened` is only called when we are about to evaluate a 
function that assumes the stream to be opened anyways, so I don't expect many 
false positive lack of `fclose` reports.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


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

2020-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D71524#1889566 , @boga95 wrote:

> @steakhal's revision is on the top of this. Changing the order will only 
> cause unnecessary work on both sides.


I would happily rebase this patch if you want.




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:139
 
+  /// Add taint sources for extraction operator on pre-visit.
+  bool addOverloadedOpPre(const CallExpr *CE, CheckerContext &C) const;

boga95 wrote:
> Szelethus wrote:
> > Extraction operator? Is that a thing?
> I can call it `operator>>` if you think that is better.
I think `extraction operator` is the right term for this.
It is used in the standard: 
http://eel.is/c++draft/input.streams#istream.extractors





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

balazske wrote:
> These `std` declarations are at a better place in 
> `system-header-simulator-cxx.h` or a similar file.
In the current form, it seems to be a bit verbose.
Why don't we create a minimal `std::string` which does not inherit from 
anything and implements the features and behavior only what is necessary.

After minimizing this class there would be no benefit moving to the 
`system-header-simulator-cxx.h` header.


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

https://reviews.llvm.org/D71524



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


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

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



Comment at: clang/lib/AST/TemplateName.cpp:174
+TemplateNameDependence TemplateName::getDependence() const {
+  auto Dependency = TemplateNameDependence::None;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())

nit: please don't use "Dependency" to mean "Dependence" :-)

I find this easier to read with a short name here (like `D` or the previous 
`F`, but up to you.



Comment at: clang/lib/AST/TemplateName.cpp:175
+  auto Dependency = TemplateNameDependence::None;
+  if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
+Dependency |=

I think it would add some useful structure to put everything except the 
getAsTemplateDecl() in a `switch (getKind())` rather than ifs scattered around. 
This would make it clearer which cases are disjoint.



Comment at: clang/lib/AST/TemplateName.cpp:193
+  } else {
+assert(!getAsOverloadedTemplate() &&
+   "overloaded templates shouldn't survive to here");

As far as I can tell, an overloaded template will always return null for 
getAsTemplateDecl(). So this assert can be hoisted to the top, which I think 
would be clearer.



Comment at: clang/lib/AST/TemplateName.cpp:201
+DTN->getQualifier()->containsUnexpandedParameterPack())
+  Dependency |= TemplateNameDependence::UnexpandedPack;
+  if (getAsSubstTemplateTemplateParmPack())

Why are we querying/propagating individual bits here rather than converting and 
adding DTN->getQualifier()->getDependence()? Are we deliberately dropping some 
of the bits?

(Checking individual bits makes adding new bits e.g. errors harder, as they 
won't be propagated by default)



Comment at: clang/lib/AST/TemplateName.cpp:205
+  // Dependent template name is always instantiation dependent.
+  if (Dependency & TemplateNameDependence::Dependent)
+Dependency |= TemplateNameDependence::DependentInstantiation;

why not just add DependentInstantiation above in the first place?
Tracking incorrect bits and then fixing them at the end seems a bit confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75441: [clang-tidy] Add helper base check classes that only run on specific language versions

2020-03-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D75441#1901071 , @gribozavr2 wrote:

> > I think my preference is to go with isLanguageVersionSupported() and not 
> > use base classes.
>
> +1, I can see this working, but the introduction of new concepts does not 
> seem like it pulls its weight given the tiny amount of boilerplate that they 
> eliminate.


+1, I'm definitely against adding base classes for supported language versions. 
The increase in the API surface doesn't seem to pay off here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75441



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


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

2020-03-03 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:932
+  const CXXConstructExpr *getInheritingConstructor() const {
+return cast(getInheritingStackFrame()->getCallSite());
+  }

martong wrote:
> This line causes a regression in our CTU jobs, because it seems `getCallSite` 
> can return with a null Stmt*. And then cast fires an assertion. I am going to 
> do a simple fix by changing `cast` to `cast_or_null` if there is no objection.
Hmm, it is not that simple unfortunately. The use of `cast_or_null` would 
result in a null dereference in `getNumArgs()`. I started to investigate how is 
it possible that `getCallSite()` returns with a nullptr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74735



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


[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

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

This feels better than merging

I think visual studio tends to create files via the new project wizard that do 
not have a space before but do have a space after the `:`

[assembly: ComVisible(false)]


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

https://reviews.llvm.org/D75465



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


[clang-tools-extra] 8a2d294 - [clangd] Handle `initialized` notification (no-op to suppress log message)

2020-03-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-03T12:12:30+01:00
New Revision: 8a2d294ed0e1603c8e4d8198e46f436d2612884e

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

LOG: [clangd] Handle `initialized` notification (no-op to suppress log message)

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 55e63c71b23e..18682866d800 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -600,6 +600,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   Reply(std::move(Result));
 }
 
+void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
+
 void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
  Callback Reply) {
   // Do essentially nothing, just say we're ready to exit.
@@ -1243,6 +1245,7 @@ ClangdLSPServer::ClangdLSPServer(
   NegotiatedOffsetEncoding(ForcedOffsetEncoding) {
   // clang-format off
   MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
+  MsgHandler->bind("initialized", &ClangdLSPServer::onInitialized);
   MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
   MsgHandler->bind("sync", &ClangdLSPServer::onSync);
   MsgHandler->bind("textDocument/rangeFormatting", 
&ClangdLSPServer::onDocumentRangeFormatting);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index f30fbf6b5149..09167ca39a0f 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -67,6 +67,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).
   void onInitialize(const InitializeParams &, Callback);
+  void onInitialized(const InitializedParams &);
   void onShutdown(const ShutdownParams &, Callback);
   void onSync(const NoParams &, Callback);
   void onDocumentDidOpen(const DidOpenTextDocumentParams &);

diff  --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index a376e5f39e79..b706e07e5686 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -239,6 +239,7 @@ bool fromJSON(const llvm::json::Value &E, TraceLevel &Out);
 
 struct NoParams {};
 inline bool fromJSON(const llvm::json::Value &, NoParams &) { return true; }
+using InitializedParams = NoParams;
 using ShutdownParams = NoParams;
 using ExitParams = NoParams;
 



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


[clang-tools-extra] 1454c27 - Syndicate, test and fix base64 implementation

2020-03-03 Thread via cfe-commits

Author: serge-sans-paille
Date: 2020-03-03T12:17:53+01:00
New Revision: 1454c27b60447d969d0c1ecaf20b2186fe9d85ec

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

LOG: Syndicate, test and fix base64 implementation

llvm/Support/Base64, fix its implementation and provide a decent test suite.

Previous implementation code was using + operator instead of | to combine

results, which is a problem when shifting signed values. (0xFF << 16) is
implicitly converted to a (signed) int, and thus results in 0x,
h is
negative. Combining negative numbers with a + in that context is not what we
want to do.

This is a recommit of 5a1958f2673f8c771e406a7e309e160b432c9a79 with UB removved.

This fixes https://github.com/llvm/llvm-project/issues/149.

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

Added: 
llvm/include/llvm/Support/Base64.h
llvm/unittests/Support/Base64Test.cpp

Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp
compiler-rt/lib/fuzzer/FuzzerUtil.cpp
llvm/unittests/Support/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 5c71db5d80b3..e7b1618fd2d4 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Base64.h"
 #include "llvm/Support/Casting.h"
 #include 
 
@@ -283,37 +284,6 @@ class CollectExtraHighlightings
   HighlightingsBuilder &H;
 };
 
-// Encode binary data into base64.
-// This was copied from compiler-rt/lib/fuzzer/FuzzerUtil.cpp.
-// FIXME: Factor this out into llvm/Support?
-std::string encodeBase64(const llvm::SmallVectorImpl &Bytes) {
-  static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-  "abcdefghijklmnopqrstuvwxyz"
-  "0123456789+/";
-  std::string Res;
-  size_t I;
-  for (I = 0; I + 2 < Bytes.size(); I += 3) {
-uint32_t X = (Bytes[I] << 16) + (Bytes[I + 1] << 8) + Bytes[I + 2];
-Res += Table[(X >> 18) & 63];
-Res += Table[(X >> 12) & 63];
-Res += Table[(X >> 6) & 63];
-Res += Table[X & 63];
-  }
-  if (I + 1 == Bytes.size()) {
-uint32_t X = (Bytes[I] << 16);
-Res += Table[(X >> 18) & 63];
-Res += Table[(X >> 12) & 63];
-Res += "==";
-  } else if (I + 2 == Bytes.size()) {
-uint32_t X = (Bytes[I] << 16) + (Bytes[I + 1] << 8);
-Res += Table[(X >> 18) & 63];
-Res += Table[(X >> 12) & 63];
-Res += Table[(X >> 6) & 63];
-Res += "=";
-  }
-  return Res;
-}
-
 void write32be(uint32_t I, llvm::raw_ostream &OS) {
   std::array Buf;
   llvm::support::endian::write32be(Buf.data(), I);

diff  --git a/compiler-rt/lib/fuzzer/FuzzerUtil.cpp 
b/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
index 7aa84a1faad7..87180d1ea85d 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
@@ -151,32 +151,36 @@ bool ParseDictionaryFile(const std::string &Text, 
Vector *Units) {
   return true;
 }
 
+// Code duplicated (and tested) in llvm/include/llvm/Support/Base64.h
 std::string Base64(const Unit &U) {
   static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
   "abcdefghijklmnopqrstuvwxyz"
   "0123456789+/";
-  std::string Res;
-  size_t i;
-  for (i = 0; i + 2 < U.size(); i += 3) {
-uint32_t x = (U[i] << 16) + (U[i + 1] << 8) + U[i + 2];
-Res += Table[(x >> 18) & 63];
-Res += Table[(x >> 12) & 63];
-Res += Table[(x >> 6) & 63];
-Res += Table[x & 63];
+  std::string Buffer;
+  Buffer.resize(((U.size() + 2) / 3) * 4);
+
+  size_t i = 0, j = 0;
+  for (size_t n = U.size() / 3 * 3; i < n; i += 3, j += 4) {
+uint32_t x = (U[i] << 16) | (U[i + 1] << 8) | U[i + 2];
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = Table[(x >> 6) & 63];
+Buffer[j + 3] = Table[x & 63];
   }
   if (i + 1 == U.size()) {
 uint32_t x = (U[i] << 16);
-Res += Table[(x >> 18) & 63];
-Res += Table[(x >> 12) & 63];
-Res += "==";
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = '=';
+Buffer[j + 3] = '=';
   } else if (i + 2 == U.size()) {
-uint32_t x = (U[i] << 16) + (U[i + 1] << 8);
-Res += Table[(x >> 18) & 63];
-Res += Table[(x >> 12) & 63];
-Res += Table[(x >> 6) & 63];
-Res += "=";
+uint32_t x = (U[i] << 16) | (U[i + 1] << 8);
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = Table[(x >> 6) & 63];
+Buffer[j + 3] = '=';
   }
-  re

[clang-tools-extra] 6f7dca9 - [clangd] Send InitializeResult.serverInfo

2020-03-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-03T12:25:58+01:00
New Revision: 6f7dca97fb3c07ffae0c39b9754a387ca014d5ff

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

LOG: [clangd] Send InitializeResult.serverInfo

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/test/initialize-params.test

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 18682866d800..e6d077b11885 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -18,6 +18,7 @@
 #include "Trace.h"
 #include "URI.h"
 #include "refactor/Tweak.h"
+#include "clang/Basic/Version.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
@@ -546,7 +547,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   CodeAction::INFO_KIND}}};
 
   llvm::json::Object Result{
-  {{"capabilities",
+  {{"serverInfo",
+llvm::json::Object{{"name", "clangd"},
+   {"version", getClangToolFullVersion("clangd")}}},
+   {"capabilities",
 llvm::json::Object{
 {"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
 {"documentFormattingProvider", true},

diff  --git a/clang-tools-extra/clangd/test/initialize-params.test 
b/clang-tools-extra/clangd/test/initialize-params.test
index 68e3ebc24a21..2b5c02fc8ce2 100644
--- a/clang-tools-extra/clangd/test/initialize-params.test
+++ b/clang-tools-extra/clangd/test/initialize-params.test
@@ -47,6 +47,10 @@
 # CHECK-NEXT:  "textDocumentSync": 2,
 # CHECK-NEXT:  "typeHierarchyProvider": true
 # CHECK-NEXT:  "workspaceSymbolProvider": true
+# CHECK-NEXT:},
+# CHECK-NEXT:"serverInfo": {
+# CHECK-NEXT:  "name": "clangd",
+# CHECK-NEXT:  "version": "{{.*}}clangd version {{.*}}"
 # CHECK-NEXT:}
 # CHECK-NEXT:  }
 ---



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


[clang-tools-extra] 6525a6b - [clangd] Use structured PublishDiagnosticsParams. NFC

2020-03-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-03T12:44:40+01:00
New Revision: 6525a6b7b2afc62edc6c2425b1e845c99f3c94fe

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

LOG: [clangd] Use structured PublishDiagnosticsParams. NFC

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index e6d077b11885..9d93b8592fdc 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -814,7 +814,9 @@ void ClangdLSPServer::onDocumentDidClose(
   // VSCode). Note that this cannot race with actual diagnostics responses
   // because removeDocument() guarantees no diagnostic callbacks will be
   // executed after it returns.
-  publishDiagnostics(URIForFile::canonicalize(File, /*TUPath=*/File), {});
+  PublishDiagnosticsParams Notification;
+  Notification.uri = URIForFile::canonicalize(File, /*TUPath=*/File);
+  publishDiagnostics(Notification);
 }
 
 void ClangdLSPServer::onDocumentOnTypeFormatting(
@@ -1151,18 +1153,13 @@ void ClangdLSPServer::applyConfiguration(
 }
 
 void ClangdLSPServer::publishSemanticHighlighting(
-SemanticHighlightingParams Params) {
+const SemanticHighlightingParams &Params) {
   notify("textDocument/semanticHighlighting", Params);
 }
 
 void ClangdLSPServer::publishDiagnostics(
-const URIForFile &File, std::vector Diagnostics) {
-  // Publish diagnostics.
-  notify("textDocument/publishDiagnostics",
- llvm::json::Object{
- {"uri", File},
- {"diagnostics", std::move(Diagnostics)},
- });
+const PublishDiagnosticsParams &Params) {
+  notify("textDocument/publishDiagnostics", Params);
 }
 
 // FIXME: This function needs to be properly tested.
@@ -1368,15 +1365,15 @@ void ClangdLSPServer::onHighlightingsReady(
 
 void ClangdLSPServer::onDiagnosticsReady(PathRef File,
  std::vector Diagnostics) {
-  auto URI = URIForFile::canonicalize(File, /*TUPath=*/File);
-  std::vector LSPDiagnostics;
+  PublishDiagnosticsParams Notification;
+  Notification.uri = URIForFile::canonicalize(File, /*TUPath=*/File);
   DiagnosticToReplacementMap LocalFixIts; // Temporary storage
   for (auto &Diag : Diagnostics) {
-toLSPDiags(Diag, URI, DiagOpts,
+toLSPDiags(Diag, Notification.uri, DiagOpts,
[&](clangd::Diagnostic Diag, llvm::ArrayRef Fixes) {
  auto &FixItsForDiagnostic = LocalFixIts[Diag];
  llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic));
- LSPDiagnostics.push_back(std::move(Diag));
+ Notification.diagnostics.push_back(std::move(Diag));
});
   }
 
@@ -1387,7 +1384,7 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File,
   }
 
   // Send a notification to the LSP client.
-  publishDiagnostics(URI, std::move(LSPDiagnostics));
+  publishDiagnostics(Notification);
 }
 
 void ClangdLSPServer::onBackgroundIndexProgress(

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 09167ca39a0f..4ab0354ead72 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -133,11 +133,10 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
   void applyConfiguration(const ConfigurationSettings &Settings);
 
   /// Sends a "publishSemanticHighlighting" notification to the LSP client.
-  void publishSemanticHighlighting(SemanticHighlightingParams Params);
+  void publishSemanticHighlighting(const SemanticHighlightingParams &);
 
   /// Sends a "publishDiagnostics" notification to the LSP client.
-  void publishDiagnostics(const URIForFile &File,
-  std::vector Diagnostics);
+  void publishDiagnostics(const PublishDiagnosticsParams &);
 
   /// Since initialization of CDBs and ClangdServer is done lazily, the
   /// following context captures the one used while creating ClangdLSPServer 
and

diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index 8e89c1f45f3a..5a867c52c1ed 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -531,6 +531,13 @@ bool fromJSON(const llvm::json::Value &Params, Diagnostic 
&R) {
   return true;
 }
 
+llvm::json::Value toJSON(const PublishDiagnosticsParams &PDP) {
+  return llvm::json::Object{
+{"uri", PDP.uri},
+{"diagnostics", PDP.diagnostics},
+  };
+}
+
 bool fromJSON(const llvm::json::Value &Params, CodeActionContext &R) {
   llvm::json::Obj

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 6 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:64-70
+/// Get the value of the stream argument out of the passed call event.
+/// The call should contain a function that is described by Desc.
+SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
+  assert(Desc && Desc->StreamArgNo != ArgNone &&
+ "Try to get a non-existing stream argument.");
+  return Call.getArgSVal(Desc->StreamArgNo);
+}

Szelethus wrote:
> You could make this a method of `FnDescription`.
Originally I wanted it too but there is no strong relation to it, somehow I 
like better to have it as separate function.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:148-151
+// Ensure that not a member function is called.
+const auto *FD = dyn_cast_or_null(Call.getDecl());
+if (!FD || FD->getKind() != Decl::Function)
+  return nullptr;

Szelethus wrote:
> I vaguely recall us having this conversation once, but isn't this redundant 
> with 
> 
> ```lang=c++
> if (!Call.isGlobalCFunction())
>   return nullptr;
> ```
> ? I don't mind not addressing this before commiting.
According to the documentation `isGlobalCFunction` should filter out member 
functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D68165: [analyzer][MallocChecker][NFC] Split checkPostCall up, deploy CallDescriptionMap

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

I wish for a third map, something like `ReallocationMap`. Other than that it is 
a great direction, I love it. Thanks!




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:355
+  template 
+  void checkRealloc(CheckerContext &C, const CallExpr *CE,
+ProgramStateRef State) const;

balazske wrote:
> The `CHECK_FN` could be used even here?
> ```
> template 
> CHECK_FN(checkRealloc)
> ```
I think about the opposite, passing around arguments by templates is not cool. 
They meant to be arguments.

This type of callback simply could be a third `CallDescriptionMap` for future 
profeness.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68165



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


[PATCH] D75430: [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Cool! May it worth to mention the corresponding mail from the mailing list in 
the Summary: http://lists.llvm.org/pipermail/cfe-dev/2020-February/064754.html




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:941
+  CXXDeallocatorCall(const CXXDeleteExpr *E, ProgramStateRef St,
+ const LocationContext *LCtx)
+  : AnyFunctionCall(E, St, LCtx) {}

`St` -> `State`



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:958
+
+  unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
+

`return getOriginExpr()->getNumArgs()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75430



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


[PATCH] D75432: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

> Also... as to why I added so much `LLVM_UNREACHABLE` annotations

I believe it is not necessary to add `LLVM_NODISCARD`, but as it perfectly 
works here, I like it.

I would mention the mailing list here as well: 
http://lists.llvm.org/pipermail/cfe-dev/2020-February/064754.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75432



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


[PATCH] D75431: [analyzer][NFC] Merge checkNewAllocator's paramaters into CXXAllocatorCall

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

> look for a solution better then demonstrated in this patch.

I believe this solution exactly what Artem suggested, so there is nothing to 
feel bad about. Cool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75431



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


[PATCH] D75432: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

I have added green markers to all of your patches as well. I really appreciate 
the simplification of the `MallocChecker`. May you would commit it as soon as 
possible, given that you have nailed what Artem has suggested. Cool^2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75432



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247849.
kadircet marked 8 inline comments as done.
kadircet added a comment.

- Use getFileLoc instead of spelledForExpanded


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -29,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/IndexDataConsumer.h"
@@ -149,25 +150,28 @@
   return Result;
 }
 
-llvm::Optional makeLocation(ASTContext &AST, SourceLocation TokLoc,
+// Expects Loc to be a SpellingLocation, will bail out otherwise as it can't
+// figure out a filename.
+llvm::Optional makeLocation(const ASTContext &AST, SourceLocation Loc,
   llvm::StringRef TUPath) {
-  const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  const auto &SM = AST.getSourceManager();
+  const FileEntry *F = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!F)
 return None;
-  auto FilePath = getCanonicalPath(F, SourceMgr);
+  auto FilePath = getCanonicalPath(F, SM);
   if (!FilePath) {
 log("failed to get path!");
 return None;
   }
-  if (auto Range =
-  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
-Location L;
-L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-L.range = *Range;
-return L;
-  }
-  return None;
+  Location L;
+  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+  // We call MeasureTokenLength here as TokenBuffer doesn't store spelled tokens
+  // outside the main file.
+  L.range = halfOpenToRange(
+  SM, CharSourceRange::getCharRange(
+  Loc, Loc.getLocWithOffset(
+   Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts();
+  return L;
 }
 
 } // namespace
@@ -351,11 +355,15 @@
 class ReferenceFinder : public index::IndexDataConsumer {
 public:
   struct Reference {
-SourceLocation Loc;
+syntax::Token SpelledTok;
 index::SymbolRoleSet Role;
+
+Range range(const SourceManager &SM) {
+  return halfOpenToRange(SM, SpelledTok.range(SM).toCharRange(SM));
+}
   };
 
-  ReferenceFinder(ASTContext &AST, Preprocessor &PP,
+  ReferenceFinder(const ParsedAST &AST,
   const std::vector &TargetDecls)
   : AST(AST) {
 for (const NamedDecl *D : TargetDecls)
@@ -364,13 +372,17 @@
 
   std::vector take() && {
 llvm::sort(References, [](const Reference &L, const Reference &R) {
-  return std::tie(L.Loc, L.Role) < std::tie(R.Loc, R.Role);
+  auto LTok = L.SpelledTok.location();
+  auto RTok = R.SpelledTok.location();
+  return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
 });
 // We sometimes see duplicates when parts of the AST get traversed twice.
 References.erase(std::unique(References.begin(), References.end(),
  [](const Reference &L, const Reference &R) {
-   return std::tie(L.Loc, L.Role) ==
-  std::tie(R.Loc, R.Role);
+   auto LTok = L.SpelledTok.location();
+   auto RTok = R.SpelledTok.location();
+   return std::tie(LTok, L.Role) ==
+  std::tie(RTok, R.Role);
  }),
  References.end());
 return std::move(References);
@@ -382,22 +394,27 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
+if (!CanonicalTargets.count(D))
+  return true;
+const auto &TB = AST.getTokens();
 const SourceManager &SM = AST.getSourceManager();
 Loc = SM.getFileLoc(Loc);
-if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
-  References.push_back({Loc, Roles});
+// We are only traversing decls *inside* the main file, so this should hold.
+assert(isInsideMainFile(Loc, SM));
+if (const auto *Tok = TB.spelledTokenAt(Loc))
+  References.push_back({*Tok, Roles});
 return true

[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:155
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = 
SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());

sammccall wrote:
> sammccall wrote:
> > sammccall wrote:
> > > so this is just running the raw lexer...
> > > 
> > > both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
> > > passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
> > > (syntax::Token*, SourceMgr, TUPath).
> > It *seems* to always be the case that TokLoc is a spelled token, but this 
> > seems slightly subtle and the previous code defended against marco 
> > locations. Worth a comment
> > can we call spelledTokenAt
> 
> as you pointed out offline, we only have spelled tokens for the main file.
> I think we have to lex here to get the token length, and the clearest thing 
> is to do this completely directly (`Lexer::measureTokenLength` -> 
> `Loc.getLocWithOffset`) rather than obfuscating with tokenbuffer.
> We should have a comment *why* we lex here.
> so this is just running the raw lexer...
> both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
> passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
> (syntax::Token*, SourceMgr, TUPath).

as discussed offline the problem is TokenBuffer won't hold spelled tokens for 
included files. so if you've got a macro definition or declaration coming from 
a header, spelledTokenAt will fail.
making use of `Lexer::MeasureTokenLength` instead.



Comment at: clang-tools-extra/clangd/XRefs.cpp:155
   const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = 
SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());

kadircet wrote:
> sammccall wrote:
> > sammccall wrote:
> > > sammccall wrote:
> > > > so this is just running the raw lexer...
> > > > 
> > > > both callers have a ParsedAST, can we call spelledTokenAt()? Either 
> > > > here, passing in (TokenBuffer, Loc, TUPath) or in the caller, passing 
> > > > in (syntax::Token*, SourceMgr, TUPath).
> > > It *seems* to always be the case that TokLoc is a spelled token, but this 
> > > seems slightly subtle and the previous code defended against marco 
> > > locations. Worth a comment
> > > can we call spelledTokenAt
> > 
> > as you pointed out offline, we only have spelled tokens for the main file.
> > I think we have to lex here to get the token length, and the clearest thing 
> > is to do this completely directly (`Lexer::measureTokenLength` -> 
> > `Loc.getLocWithOffset`) rather than obfuscating with tokenbuffer.
> > We should have a comment *why* we lex here.
> > so this is just running the raw lexer...
> > both callers have a ParsedAST, can we call spelledTokenAt()? Either here, 
> > passing in (TokenBuffer, Loc, TUPath) or in the caller, passing in 
> > (syntax::Token*, SourceMgr, TUPath).
> 
> as discussed offline the problem is TokenBuffer won't hold spelled tokens for 
> included files. so if you've got a macro definition or declaration coming 
> from a header, spelledTokenAt will fail.
> making use of `Lexer::MeasureTokenLength` instead.
as discussed offline, in case of macro locations we'll fail at getting the file 
path and stop there and that logic is the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474



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


[PATCH] D75467: [instcombine] remove fsub to fneg hacks; only emit fneg

2020-03-03 Thread Simon Moll via Phabricator via cfe-commits
simoll updated this revision to Diff 247850.
simoll added a comment.

NFC

- rebased
- formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75467

Files:
  clang/test/CodeGen/fma-builtins-constrained.c
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
  llvm/test/Transforms/InstCombine/cos-1.ll
  llvm/test/Transforms/InstCombine/fadd.ll
  llvm/test/Transforms/InstCombine/fast-math.ll
  llvm/test/Transforms/InstCombine/fdiv.ll
  llvm/test/Transforms/InstCombine/fmul.ll
  llvm/test/Transforms/InstCombine/fneg.ll
  llvm/test/Transforms/InstCombine/fpextend.ll
  llvm/test/Transforms/InstCombine/fsub.ll
  llvm/test/Transforms/InstCombine/maximum.ll
  llvm/test/Transforms/InstCombine/maxnum.ll
  llvm/test/Transforms/InstCombine/minimum.ll
  llvm/test/Transforms/InstCombine/minnum.ll
  llvm/test/Transforms/InstCombine/operand-complexity.ll
  llvm/test/Transforms/InstCombine/vec_shuffle.ll

Index: llvm/test/Transforms/InstCombine/vec_shuffle.ll
===
--- llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -1263,7 +1263,7 @@
 
 define <2 x float> @fneg(<2 x float> %x) {
 ; CHECK-LABEL: @fneg(
-; CHECK-NEXT:[[TMP1:%.*]] = fsub <2 x float> , [[X:%.*]]
+; CHECK-NEXT:[[TMP1:%.*]] = fneg <2 x float> [[X:%.*]]
 ; CHECK-NEXT:[[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> undef, <2 x i32> zeroinitializer
 ; CHECK-NEXT:ret <2 x float> [[R]]
 ;
Index: llvm/test/Transforms/InstCombine/operand-complexity.ll
===
--- llvm/test/Transforms/InstCombine/operand-complexity.ll
+++ llvm/test/Transforms/InstCombine/operand-complexity.ll
@@ -92,7 +92,7 @@
 define float @fneg(float %x) {
 ; CHECK-LABEL: @fneg(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv float [[X:%.*]], 4.20e+01
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub float -0.00e+00, [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg float [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul float [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use(float [[FNEGX]])
 ; CHECK-NEXT:ret float [[R]]
@@ -122,7 +122,7 @@
 define <2 x float> @fneg_vec(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_vec(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv <2 x float> [[X:%.*]], 
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub <2 x float> , [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg <2 x float> [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use_vec(<2 x float> [[FNEGX]])
 ; CHECK-NEXT:ret <2 x float> [[R]]
@@ -137,7 +137,7 @@
 define <2 x float> @fneg_vec_undef(<2 x float> %x) {
 ; CHECK-LABEL: @fneg_vec_undef(
 ; CHECK-NEXT:[[BO:%.*]] = fdiv <2 x float> [[X:%.*]], 
-; CHECK-NEXT:[[FNEGX:%.*]] = fsub <2 x float> , [[X]]
+; CHECK-NEXT:[[FNEGX:%.*]] = fneg <2 x float> [[X]]
 ; CHECK-NEXT:[[R:%.*]] = fmul <2 x float> [[BO]], [[FNEGX]]
 ; CHECK-NEXT:call void @use_vec(<2 x float> [[FNEGX]])
 ; CHECK-NEXT:ret <2 x float> [[R]]
Index: llvm/test/Transforms/InstCombine/minnum.ll
===
--- llvm/test/Transforms/InstCombine/minnum.ll
+++ llvm/test/Transforms/InstCombine/minnum.ll
@@ -301,7 +301,7 @@
 declare void @use(double)
 define double @neg_neg_extra_use_x(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x(
-; CHECK-NEXT:[[NEGX:%.*]] = fsub double -0.00e+00, [[X:%.*]]
+; CHECK-NEXT:[[NEGX:%.*]] = fneg double [[X:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.maxnum.f64(double [[X]], double [[Y:%.*]])
 ; CHECK-NEXT:[[R:%.*]] = fneg double [[TMP1]]
 ; CHECK-NEXT:call void @use(double [[NEGX]])
@@ -331,7 +331,7 @@
 
 define double @neg_neg_extra_use_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_y(
-; CHECK-NEXT:[[NEGY:%.*]] = fsub double -0.00e+00, [[Y:%.*]]
+; CHECK-NEXT:[[NEGY:%.*]] = fneg double [[Y:%.*]]
 ; CHECK-NEXT:[[TMP1:%.*]] = call double @llvm.maxnum.f64(double [[X:%.*]], double [[Y]])
 ; CHECK-NEXT:[[R:%.*]] = fneg double [[TMP1]]
 ; CHECK-NEXT:call void @use(double [[NEGY]])
@@ -361,8 +361,8 @@
 
 define double @neg_neg_extra_use_x_and_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
-; CHECK-NEXT:[[NEGX:%.*]] = fsub double -0.00e+00, [[X:%.*]]
-; CHECK-NEXT:[[NEGY:%.*]] = fsub double -0.00e+00, [[Y:%.*]]
+; CHECK-NEXT:[[NEGX:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:[[NEGY:%.*]] = fneg double [[Y:%.*]]
 ; CHECK-NEXT:[[R:%.*]] = call double @llvm.minnum.f64(double [[NEGX]], double [[NEGY]])
 ; CHECK-NEXT:call void 

[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 247847.
balazske marked an inline comment as done.
balazske added a comment.

Comment changes, updated `lookupFn`, other small change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -108,19 +108,56 @@
 
 void f_double_close(void) {
   FILE *p = fopen("foo", "r");
-  fclose(p); 
-  fclose(p); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  if (!p)
+return;
+  fclose(p);
+  fclose(p); // expected-warning {{Stream might be already closed}}
 }
 
 void f_double_close_alias(void) {
   FILE *p1 = fopen("foo", "r");
+  if (!p1)
+return;
   FILE *p2 = p1;
   fclose(p1);
-  fclose(p2); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  fclose(p2); // expected-warning {{Stream might be already closed}}
+}
+
+void f_use_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  clearerr(p); // expected-warning {{Stream might be already closed}}
+}
+
+void f_open_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+}
+
+void f_reopen_after_close(void) {
+  FILE *p = fopen("foo", "r");
+  if (!p)
+return;
+  fclose(p);
+  // Allow reopen after close.
+  p = freopen("foo", "w", p);
+  if (!p)
+return;
+  fclose(p);
 }
 
 void f_leak(int c) {
   FILE *p = fopen("foo.c", "r");
+  if (!p)
+return;
   if(c)
 return; // expected-warning {{Opened File never closed. Potential Resource leak}}
   fclose(p);
@@ -155,13 +192,13 @@
 if (f2) {
   // Check if f1 and f2 point to the same stream.
   fclose(f1);
-  fclose(f2); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
+  fclose(f2); // expected-warning {{Stream might be already closed.}}
 } else {
   // Reopen failed.
-  // f1 points now to a possibly invalid stream but this condition is currently not checked.
-  // f2 is NULL.
-  rewind(f1);
-  rewind(f2); // expected-warning {{Stream pointer might be NULL}}
+  // f1 is non-NULL but points to a possibly invalid stream.
+  rewind(f1); // expected-warning {{Stream might be invalid}}
+  // f2 is NULL but the previous error stops the checker.
+  rewind(f2);
 }
   }
 }
@@ -170,9 +207,9 @@
   FILE *f1 = fopen("foo.c", "r");
   if (f1) {
 // Unchecked result of freopen.
-// The f1 may be invalid after this call (not checked by the checker).
+// The f1 may be invalid after this call.
 freopen(0, "w", f1);
-rewind(f1);
+rewind(f1); // expected-warning {{Stream might be invalid}}
 fclose(f1);
   }
 }
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -34,8 +34,8 @@
 
   bool isOpened() const { return K == Opened; }
   bool isClosed() const { return K == Closed; }
-  //bool isOpenFailed() const { return K == OpenFailed; }
-  //bool isEscaped() const { return K == Escaped; }
+  bool isOpenFailed() const { return K == OpenFailed; }
+  // bool isEscaped() const { return K == Escaped; }
 
   bool operator==(const StreamState &X) const { return K == X.K; }
 
@@ -44,104 +44,180 @@
   static StreamState getOpenFailed() { return StreamState(OpenFailed); }
   static StreamState getEscaped() { return StreamState(Escaped); }
 
-  void Profile(llvm::FoldingSetNodeID &ID) const {
-ID.AddInteger(K);
-  }
+  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
 };
 
 class StreamChecker;
+struct FnDescription;
+using FnCheck = std::function;
 
-using FnCheck = std::function;
+using ArgNoTy = unsigned int;
+static const ArgNoTy ArgNone = std::numeric_limits::max();
 
 struct FnDescription {
+  FnCheck PreFn;
   FnCheck EvalFn;
+  ArgNoTy StreamArgNo;
 };
 
-class StreamChecker : public Checker {
+/// Get the value of the stream argument out of the passed call event.
+/// The call should contain a function that is described by Desc.
+SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
+  assert(Desc && Desc->StreamArgNo != ArgNone &&
+ "Try to get a non-existing stream argument.");
+  return Call.getArgSVal(Desc->StreamArgNo);
+}
+
+class StreamChecker
+: public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
-  BT_doubleclose, BT_ResourceLeak;
+  BT_UseAfterClose, BT_UseAfterOpenFailed, BT_ResourceLeak;
 
 publ

[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-03-03 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 247856.
baloghadamsoftware added a comment.

Back to the version where we do not check for interestingness.


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

https://reviews.llvm.org/D73720

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorRangeChecker.cpp
  clang/test/Analysis/container-modeling.cpp
  clang/test/Analysis/iterator-range.cpp

Index: clang/test/Analysis/iterator-range.cpp
===
--- clang/test/Analysis/iterator-range.cpp
+++ clang/test/Analysis/iterator-range.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify
-// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false -analyzer-output=text %s -verify
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 -analyzer-output=text %s -verify
 
 #include "Inputs/system-header-simulator-cxx.h"
 
@@ -32,6 +32,7 @@
 void deref_end(const std::vector &V) {
   auto i = V.end();
   *i; // expected-warning{{Past-the-end iterator dereferenced}}
+  // expected-note@-1{{Past-the-end iterator dereferenced}}
 }
 
 // Prefix increment - operator++()
@@ -59,6 +60,7 @@
 void incr_end(const std::vector &V) {
   auto i = V.end();
   ++i; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+   // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 // Postfix increment - operator++(int)
@@ -86,6 +88,7 @@
 void end_incr(const std::vector &V) {
   auto i = V.end();
   i++; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+   // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 // Prefix decrement - operator--()
@@ -93,6 +96,7 @@
 void decr_begin(const std::vector &V) {
   auto i = V.begin();
   --i; // expected-warning{{Iterator decremented ahead of its valid range}}
+   // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
 void decr_behind_begin(const std::vector &V) {
@@ -120,6 +124,7 @@
 void begin_decr(const std::vector &V) {
   auto i = V.begin();
   i--; // expected-warning{{Iterator decremented ahead of its valid range}}
+   // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
 void behind_begin_decr(const std::vector &V) {
@@ -168,11 +173,13 @@
 void incr_by_2_ahead_of_end(const std::vector &V) {
   auto i = --V.end();
   i += 2; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+  // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 void incr_by_2_end(const std::vector &V) {
   auto i = V.end();
   i += 2; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+  // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 // Addition - operator+(int)
@@ -201,11 +208,13 @@
 void incr_by_2_copy_ahead_of_end(const std::vector &V) {
   auto i = --V.end();
   auto j = i + 2; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+  // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 void incr_by_2_copy_end(const std::vector &V) {
   auto i = V.end();
   auto j = i + 2; // expected-warning{{Iterator incremented behind the past-the-end iterator}}
+  // expected-note@-1{{Iterator incremented behind the past-the-end iterator}}
 }
 
 // Subtraction assignment - operator-=(int)
@@ -213,11 +222,13 @@
 void decr_by_2_begin(const std::vector &V) {
   auto i = V.begin();
   i -= 2; // expected-warning{{Iterator decremented ahead of its valid range}}
+  // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
 void decr_by_2_behind_begin(const std::vector &V) {
   auto i = ++V.begin();
   i -= 2; // expected-warning{{Iterator decremented ahead of its valid range}}
+  // expected-note@-1{{Iterator decremented ahead of its valid range}}
 }
 
 void decr_by_2_behind_begin_by_2(const std::vector &V) {
@@ -246,11 +257,13 @@
 void decr_by_2_copy_begin(const std::vector &V) {
   auto i = V.begin();
   auto j = i - 2; // expected-warning{{Iterator decremented ahead 

[PATCH] D75285: Mark restrict pointer or reference to const as invariant

2020-03-03 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D75285#1896610 , @rjmccall wrote:

> Are you sure `restrict` alone isn't good enough?  It doesn't directly tell 
> you that the memory is invariant, but it's usually simple to prove that the 
> memory isn't modified within the `restrict` scope, which might be sufficient.


Do you mean to prove in analysis passes? Should we emit some sort of hints from 
the frontend to indicate what to look for?


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

https://reviews.llvm.org/D75285



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


[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:731
+  }
+  return C.getNoteTag([Text, Name](BugReport &BR) -> std::string {
+  SmallString<256> Msg;

baloghadamsoftware wrote:
> Szelethus wrote:
> > baloghadamsoftware wrote:
> > > NoQ wrote:
> > > > Szelethus wrote:
> > > > > NoQ wrote:
> > > > > > baloghadamsoftware wrote:
> > > > > > > NoQ wrote:
> > > > > > > > You'll need to check whether the container is actually of 
> > > > > > > > interest to the bug report. We don't want notes to be added 
> > > > > > > > about changes to irrelevant containers.
> > > > > > > > 
> > > > > > > > You can use a combination of "Report `BR` was emitted by one of 
> > > > > > > > the iterator checkers" and "The memory region of the container 
> > > > > > > > is marked as interesting" (while also actually marking it as 
> > > > > > > > interesting in the checker).
> > > > > > > > 
> > > > > > > > Ideally we should instead make a new generic storage inside the 
> > > > > > > > `BugReport` object, in order to pass down the interesting 
> > > > > > > > information from the call site of `emitReport` ("Hi, i'm an 
> > > > > > > > iterator checker who emitted this report and i'm interested in 
> > > > > > > > changes made to the size of this container").
> > > > > > > Are you sure in this? I already wondered how it works so I added 
> > > > > > > a test that checks one container and changes another one and 
> > > > > > > there were no note tags displayed for the one we did not check 
> > > > > > > but change. See the last test.
> > > > > > That's because you didn't do
> > > > > > ```lang=c++
> > > > > >   V2.cbegin();
> > > > > >   V2.cend();
> > > > > > ```
> > > > > > in the beginning.
> > > > > A similar conversation sparked up recently in between @boga95, 
> > > > > @steakhal and me regarding reporting taintedness. Bug reports are 
> > > > > fine up to the point where (in reverse) the first propagation 
> > > > > happens, but finding out which value tainted the one that caused the 
> > > > > report isn't handled at the moment. One idea was to mark the initial 
> > > > > (again, in reverse) value as interesting, create a `NoteTag` at the 
> > > > > point of propagation, where we should know which value was the cause 
> > > > > of the spread, mark that interesting as well, etc.
> > > > > 
> > > > > If `NoteTag`s only emit a message when the concerning value is 
> > > > > interesting, this should theoretically solve that problem. I guess 
> > > > > you could say that we're propagating interestingness in reverse.
> > > > > 
> > > > > I'm not immediately sure if this idea was ever mentioned or 
> > > > > implemented here.
> > > > Yes, that's the intended solution to such problems. 
> > > > `trackExpressionValue` works similarly, just with assignments instead 
> > > > of taint propagations. And in both cases note tags are a much more 
> > > > straightforward solution to the problem.
> > > Yes, you are right. My problem now is that how to mark interesting when 
> > > debugging? I I filter for interesting containers only, I lose my ability 
> > > to debug. Should I create a debug function just for marking a container 
> > > as interesting. Or is there such function already?
> > I'm not immediately sure how interetingness ties into debugging, what 
> > specific scenario are you thinking about?
> In the test of the modeling checker we use debug checkers. They should be 
> able to mark the container interesting to be able to test the not tags. I 
> managed to solve problem, even in a somewhat unorthodox way.
The core issue with NoteTag it does not know about interestingness and nor 
about MemRegion. I believe everything based on MemRegions already and when you 
emit the report you know exactly which MemRegion raised an error. So I think 
first we need to solve that the NoteTags only report on given MemRegions and 
those regions of course mega-interesting: we do not need to keep around the 
interestingness then.


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

https://reviews.llvm.org/D73720



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


[PATCH] D75514: [Analyzer] Only add container note tags to the operations of te affected container

2020-03-03 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, Szelethus.
baloghadamsoftware added a project: clang.
Herald added subscribers: martong, steakhal, Charusso, gamesh411, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, whisperity.
baloghadamsoftware added a parent revision: D73720: [Analyzer] Use note tags to 
track container begin and and changes.

If an error happens which is related to a container the Container Modeling 
checker adds note tags to all the container operations along the bug path. This 
may be disturbing if there are other containers beside the one which is 
affected by the bug. This patch restricts the note tags to only the affected 
container and adjust the debug checkers to be able to test this change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75514

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
  clang/test/Analysis/container-modeling.cpp


Index: clang/test/Analysis/container-modeling.cpp
===
--- clang/test/Analysis/container-modeling.cpp
+++ clang/test/Analysis/container-modeling.cpp
@@ -208,7 +208,7 @@
 
   clang_analyzer_denote(clang_analyzer_container_begin(V1), "$V1.begin()");
 
-  V2.push_back(n); // expected-note{{Container 'V2' extended to the right by 1 
position}} FIXME: This note should not appear since `V2` is not affected in the 
"bug"
+  V2.push_back(n); // no note expected
 
   clang_analyzer_express(clang_analyzer_container_begin(V1)); // 
expected-warning{{$V1.begin()}}
  // 
expected-note@-1{{$V1.begin()}}
@@ -223,8 +223,7 @@
   clang_analyzer_denote(clang_analyzer_container_begin(V1), "$V1.begin()");
   clang_analyzer_denote(clang_analyzer_container_begin(V2), "$V2.begin()");
 
-  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 
position}}
-   // expected-note@-1{{Container 'V1' extended to the right 
by 1 position}} FIXME: This should appear only once since there is only one 
"bug" where `V1` is affected
+  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 
position}} -- Only once!
 
   clang_analyzer_express(clang_analyzer_container_begin(V1)); // 
expected-warning{{$V1.begin()}}
  // 
expected-note@-1{{$V1.begin()}}
Index: clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
@@ -52,6 +52,9 @@
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
 };
 
+bool contains(const SourceManager &SM, const SourceRange Outer,
+  SourceRange Inner);
+
 } //namespace
 
 DebugContainerModeling::DebugContainerModeling() {
@@ -92,7 +95,17 @@
   if (Field) {
 State = State->BindExpr(CE, C.getLocationContext(),
 nonloc::SymbolVal(Field));
-C.addTransition(State);
+const auto &SM = C.getSourceManager();
+const NoteTag *InterestingTag =
+  C.getNoteTag([Cont, CE, &SM](BugReport &BR) -> std::string {
+  auto *PSBR = dyn_cast(&BR);
+  if (PSBR && contains(SM, PSBR->getRanges()[0],
+   CE->getSourceRange())) {
+PSBR->markInteresting(Cont);
+  }
+  return "";
+});
+C.addTransition(State, InterestingTag);
 return;
   }
 }
@@ -129,6 +142,18 @@
   return N;
 }
 
+namespace {
+
+bool contains(const SourceManager &SM, const SourceRange Outer,
+  SourceRange Inner) {
+  SourceLocation OB = Outer.getBegin(), OE = Outer.getEnd(),
+ IB = Inner.getBegin(), IE = Inner.getEnd();
+  return (OB == IB || SM.isBeforeInTranslationUnit(OB, IB)) &&
+ (IE == OE || SM.isBeforeInTranslationUnit(IE, OE));
+}
+
+} // namespace
+
 void ento::registerDebugContainerModeling(CheckerManager &mgr) {
   mgr.registerChecker();
 }
Index: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
@@ -715,6 +715,13 @@
   }
 
   return C.getNoteTag([Text, Name, ContReg](BugReport &BR) -> std::string {
+  const auto *PSBR = dyn_cast(&BR);
+  if (!PSBR)
+return "";
+
+  if (!PSBR->isInteresting(ContReg))
+return "";
+
   SmallString<256> Msg;
   llvm::raw_svector_ostream Out(Msg);
   Out << "Container " << (!Name.empty() ? ("'" + Name.str() + "' ") : "" )


Index: clang/test/Analysis/container-modeling.cpp
===

[PATCH] D75514: [Analyzer] Only add container note tags to the operations of te affected container

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

I believe our path and context sensitive engine is more extensible and precise 
than checking the source file. Are you sure it scales? I would prefer to tie 
this information for MemRegions, rather than arbitrary places in the source 
code. My knowledge is very weak in this checker but I have changed from the 
Tidy world to the Analyzer to enjoy its benefits. Please enjoy these benefits 
in your work as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75514



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

If we were to refactor this check I wonder if it would make sense to port 
`evalCall` to `postCall`, so the analyzer engine will conjure the symbol for us.
I wonder what @NoQ thinks about the pros and cons of the approaches.

As far as I understand the con of evalCall is that there is only one check that 
can "win" to do the modelling. Also, it is error prone as everything including 
binding the return values and invalidating some state needs to be done by hand. 
If all we need to do is to record some state for the returned symbol, 
`postCall` should be sufficient. But this can be problematic when we see the 
body of the function and hence we might not see a returned symbol (but a 
constant or something else).

The name of the patch implies refactoring but some functional changes were also 
done. Is it possible to separate the functional changes into a separate patch? 
If it is not a big effort I would prefer that way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D75517: [clang-format] Do not format C# array subscript operators as attributes

2020-03-03 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix misidentification of C# array subscript operators.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75517

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -619,5 +619,13 @@
Style); // An array of a nullable type.
 }
 
+TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,6 +369,17 @@
 if (!Style.isCSharp())
   return false;
 
+// `identifier[i]` is not an attribute.
+if (Tok.Previous && Tok.Previous->is(tok::identifier))
+  return false;
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
+  auto *MatchingParen = Tok.Previous->MatchingParen;
+  if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
+return false;
+}
+
 const FormatToken *AttrTok = Tok.Next;
 if (!AttrTok)
   return false;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -619,5 +619,13 @@
Style); // An array of a nullable type.
 }
 
+TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,6 +369,17 @@
 if (!Style.isCSharp())
   return false;
 
+// `identifier[i]` is not an attribute.
+if (Tok.Previous && Tok.Previous->is(tok::identifier))
+  return false;
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
+  auto *MatchingParen = Tok.Previous->MatchingParen;
+  if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
+return false;
+}
+
 const FormatToken *AttrTok = Tok.Next;
 if (!AttrTok)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75455: [clang-format] Allow nested [] in C# attributes

2020-03-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

That's a bit of a hack (we probably need to hook up full-fledged argument list 
parsing for complete handling), but this seems like a good trade-off between 
heuristics and results right now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75455



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

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



Comment at: clang-tools-extra/clangd/XRefs.cpp:170
+  // outside the main file.
+  L.range = halfOpenToRange(
+  SM, CharSourceRange::getCharRange(

(nit: consider extracting a variable for end loc or token length just for 
readability)



Comment at: clang-tools-extra/clangd/XRefs.cpp:449
+DocumentHighlight DH;
+DH.range = halfOpenToRange(SM, Ref.SpelledTok.range(SM).toCharRange(SM));
+if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Write))

Ref.range(SM)



Comment at: clang-tools-extra/clangd/XRefs.cpp:525
+  Location Result;
+  Result.range =
+  halfOpenToRange(SM, Ref.SpelledTok.range(SM).toCharRange(SM));

Ref.range(SM)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474



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


[PATCH] D75432: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Some nits inline.




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:995
 
-void MallocChecker::checkBasicAlloc(CheckerContext &C, const CallExpr *CE,
-ProgramStateRef State) const {
-  State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State, AF_Malloc);
-  State = ProcessZeroAllocCheck(C, CE, 0, State);
+void MallocChecker::checkBasicAlloc(const CallEvent &Call,
+CheckerContext &C) const {

What is the main reason of getting rid of the state parameter? I think this 
could make using these functions more error prone overall as it would be easier 
to introduce splits in the exploded graph this way (if we somehow wanted to 
model a function as successive calls of some other functions).



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1241
 Arg = CE->getArg(IndexOfSizeArg);
-  }
-  else if (const CXXNewExpr *NE = dyn_cast(E)) {
-if (NE->isArray())
+  } else if (const CXXNewExpr *NE =
+ dyn_cast(Call.getOriginExpr())) {

Use `auto` here to avoid repeating the type.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1641
 ProgramStateRef MallocChecker::FreeMemAux(
-CheckerContext &C, const Expr *ArgExpr, const Expr *ParentExpr,
 ProgramStateRef State, bool Hold, bool &IsKnownToBeAllocated,

In functions where we only use `ArgExpr` to retrieve the corresponding `SVal` 
we could pass the `SVal` in the first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75432



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


[PATCH] D75285: Mark restrict pointer or reference to const as invariant

2020-03-03 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
jeroen.dobbelaere added a comment.

In D75285#1902788 , @Anastasia wrote:

> In D75285#1896610 , @rjmccall wrote:
>
> > Are you sure `restrict` alone isn't good enough?  It doesn't directly tell 
> > you that the memory is invariant, but it's usually simple to prove that the 
> > memory isn't modified within the `restrict` scope, which might be 
> > sufficient.
>
>
> Do you mean to prove in analysis passes? Should we emit some sort of hints 
> from the frontend to indicate what to look for?


Not sure what you mean with 'hints from the frontend', but D68484 
 (and later) contain a significant improvement 
to clang's handling of restrict. That could make the restrict path feasible (if 
that would support the actual use case).


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

https://reviews.llvm.org/D75285



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


[PATCH] D75431: [analyzer][NFC] Merge checkNewAllocator's paramaters into CXXAllocatorCall

2020-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Other than a nit looks good to me but wait for @NoQ before committing.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:208
 
+  SValBuilder &getSValBuilder() const {
+return State->getStateManager().getSValBuilder();

Since `SValBuilder` has relatively little to do with call events I am kind of 
surprised seeing this here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75431



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


[PATCH] D75430: [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker

2020-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

This might be a silly question but is `CXXDeleteExpr` the only way to invoke a 
deallocator? What would happen if the user would call it by hand? Should we 
expect `ExprEngine` to trigger a callback in that case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75430



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


[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247861.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -29,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/IndexDataConsumer.h"
@@ -149,25 +150,27 @@
   return Result;
 }
 
-llvm::Optional makeLocation(ASTContext &AST, SourceLocation TokLoc,
+// Expects Loc to be a SpellingLocation, will bail out otherwise as it can't
+// figure out a filename.
+llvm::Optional makeLocation(const ASTContext &AST, SourceLocation Loc,
   llvm::StringRef TUPath) {
-  const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  const auto &SM = AST.getSourceManager();
+  const FileEntry *F = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!F)
 return None;
-  auto FilePath = getCanonicalPath(F, SourceMgr);
+  auto FilePath = getCanonicalPath(F, SM);
   if (!FilePath) {
 log("failed to get path!");
 return None;
   }
-  if (auto Range =
-  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
-Location L;
-L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-L.range = *Range;
-return L;
-  }
-  return None;
+  Location L;
+  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+  // We call MeasureTokenLength here as TokenBuffer doesn't store spelled tokens
+  // outside the main file.
+  auto TokLen = Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts());
+  L.range = halfOpenToRange(
+  SM, CharSourceRange::getCharRange(Loc, Loc.getLocWithOffset(TokLen)));
+  return L;
 }
 
 } // namespace
@@ -351,11 +354,15 @@
 class ReferenceFinder : public index::IndexDataConsumer {
 public:
   struct Reference {
-SourceLocation Loc;
+syntax::Token SpelledTok;
 index::SymbolRoleSet Role;
+
+Range range(const SourceManager &SM) const {
+  return halfOpenToRange(SM, SpelledTok.range(SM).toCharRange(SM));
+}
   };
 
-  ReferenceFinder(ASTContext &AST, Preprocessor &PP,
+  ReferenceFinder(const ParsedAST &AST,
   const std::vector &TargetDecls)
   : AST(AST) {
 for (const NamedDecl *D : TargetDecls)
@@ -364,13 +371,17 @@
 
   std::vector take() && {
 llvm::sort(References, [](const Reference &L, const Reference &R) {
-  return std::tie(L.Loc, L.Role) < std::tie(R.Loc, R.Role);
+  auto LTok = L.SpelledTok.location();
+  auto RTok = R.SpelledTok.location();
+  return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
 });
 // We sometimes see duplicates when parts of the AST get traversed twice.
 References.erase(std::unique(References.begin(), References.end(),
  [](const Reference &L, const Reference &R) {
-   return std::tie(L.Loc, L.Role) ==
-  std::tie(R.Loc, R.Role);
+   auto LTok = L.SpelledTok.location();
+   auto RTok = R.SpelledTok.location();
+   return std::tie(LTok, L.Role) ==
+  std::tie(RTok, R.Role);
  }),
  References.end());
 return std::move(References);
@@ -382,22 +393,27 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
+if (!CanonicalTargets.count(D))
+  return true;
+const auto &TB = AST.getTokens();
 const SourceManager &SM = AST.getSourceManager();
 Loc = SM.getFileLoc(Loc);
-if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
-  References.push_back({Loc, Roles});
+// We are only traversing decls *inside* the main file, so this should hold.
+assert(isInsideMainFile(Loc, SM));
+if (const auto *Tok = TB.spelledTokenAt(Loc))
+  References.push_back({*Tok, Roles});
 return true;
   }
 
 private:
   llvm::SmallSet C

[clang] cd9b2e1 - [clang][Syntax] Add spelledTokenAt helper to TokenBuffer

2020-03-03 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-03-03T14:30:41+01:00
New Revision: cd9b2e18bd69503e8d624d427caa3a0157b34e52

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

LOG: [clang][Syntax] Add spelledTokenAt helper to TokenBuffer

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tokens.h 
b/clang/include/clang/Tooling/Syntax/Tokens.h
index 19d120ebbc9f..2ee840074810 100644
--- a/clang/include/clang/Tooling/Syntax/Tokens.h
+++ b/clang/include/clang/Tooling/Syntax/Tokens.h
@@ -245,6 +245,10 @@ class TokenBuffer {
   /// "DECL", "(", "a", ")", ";"}
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  /// Returns the spelled Token starting at Loc, if there are no such tokens
+  /// returns nullptr.
+  const syntax::Token *spelledTokenAt(SourceLocation Loc) const;
+
   /// Get all tokens that expand a macro in \p FID. For the following input
   /// #define FOO B
   /// #define FOO2(X) int X

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index ae5bc687553b..9e12d8b603bf 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,6 +183,16 @@ llvm::ArrayRef 
TokenBuffer::spelledTokens(FileID FID) const {
   return It->second.SpelledTokens;
 }
 
+const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
+  assert(Loc.isFileID());
+  const auto *Tok = llvm::partition_point(
+  spelledTokens(SourceMgr->getFileID(Loc)),
+  [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  if (!Tok || Tok->location() != Loc)
+return nullptr;
+  return Tok;
+}
+
 std::string TokenBuffer::Mapping::str() const {
   return std::string(
   llvm::formatv("spelled tokens: [{0},{1}), expanded tokens: [{2},{3})",

diff  --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp 
b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index ad0293bc3e07..d4b015393286 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -59,6 +59,7 @@ using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::Matcher;
 using ::testing::Not;
+using ::testing::Pointee;
 using ::testing::StartsWith;
 
 namespace {
@@ -363,6 +364,12 @@ TEST_F(TokenCollectorTest, Locations) {
   AllOf(Kind(tok::equal), RangeIs(Code.range("r3"))),
   AllOf(Kind(tok::string_literal), RangeIs(Code.range("r4"))),
   AllOf(Kind(tok::semi), RangeIs(Code.range("r5");
+
+  auto StartLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+  for (auto &R : Code.ranges()) {
+EXPECT_THAT(Buffer.spelledTokenAt(StartLoc.getLocWithOffset(R.Begin)),
+Pointee(RangeIs(R)));
+  }
 }
 
 TEST_F(TokenCollectorTest, MacroDirectives) {



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


[PATCH] D75340: [clang-tidy] Change checks to use new isLanguageVersionSupported restriction

2020-03-03 Thread Nathan James via Phabricator via cfe-commits
njames93 requested review of this revision.
njames93 added a comment.

Support for the previous point didnt go too well so will stick with the current 
implementation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75340



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


[clang-tools-extra] 3302af8 - [clangd] Make use of token buffers in semantic highlighting

2020-03-03 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-03-03T14:30:41+01:00
New Revision: 3302af83ef79a8721f047f4b51b84dee8d823a0f

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

LOG: [clangd] Make use of token buffers in semantic highlighting

Reviewers: hokein, sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index e7b1618fd2d4..d5c51ebff5e1 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,39 @@ llvm::Optional kindForReference(const 
ReferenceLoc &R) {
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager &SM) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansion(L))
+return {};
+  // Tokens expanded from macro args are potentially highlightable.
+  return getHighlightableSpellingToken(SM.getImmediateSpellingLoc(L), SM);
+}
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(const ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
+Loc = getHighlightableSpellingToken(Loc, SourceMgr);
 if (Loc.isInvalid())
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
-  return;
+const auto *Tok = TB.spelledTokenAt(Loc);
+assert(Tok);
 
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+auto Range = halfOpenToRange(SourceMgr,
+ Tok->range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST &AST) && {
@@ -211,6 +211,7 @@ class HighlightingsBuilder {
   }
 
 private:
+  const syntax::TokenBuffer &TB;
   const SourceManager &SourceMgr;
   const LangOptions &LangOpts;
   std::vector Tokens;
@@ -311,7 +312,7 @@ takeLine(ArrayRef AllTokens,
 std::vector getSemanticHighlightings(ParsedAST &AST) {
   auto &C = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.



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


[clang-tools-extra] 3755039 - [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-03-03T14:30:42+01:00
New Revision: 3755039c99d85f93168cb7a36501c9586c19d3db

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

LOG: [clangd] Get rid of getTokenRange helper

Summary:

Reviewers: sammccall

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

Tags: #clang

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

Added: 
clang-tools-extra/clangd/CollectMacros.cpp

Modified: 
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/CollectMacros.h
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/XRefs.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index fc5a07e69e9d..5db345ecc63f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangDaemon
   ClangdServer.cpp
   CodeComplete.cpp
   CodeCompletionStrings.cpp
+  CollectMacros.cpp
   CompileCommands.cpp
   Compiler.cpp
   Context.cpp

diff  --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
new file mode 100644
index ..ea7dd18ee130
--- /dev/null
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -0,0 +1,34 @@
+//===--- CollectMacros.cpp ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CollectMacros.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+
+namespace clang {
+namespace clangd {
+
+void CollectMainFileMacros::add(const Token &MacroNameTok,
+const MacroInfo *MI) {
+  if (!InMainFile)
+return;
+  auto Loc = MacroNameTok.getLocation();
+  if (Loc.isInvalid() || Loc.isMacroID())
+return;
+
+  auto Name = MacroNameTok.getIdentifierInfo()->getName();
+  Out.Names.insert(Name);
+  auto Range = halfOpenToRange(
+  SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
+  if (auto SID = getSymbolID(Name, MI, SM))
+Out.MacroRefs[*SID].push_back(Range);
+  else
+Out.UnknownMacros.push_back(Range);
+}
+} // namespace clangd
+} // namespace clang

diff  --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index 5c3fca10ad4a..eecea0455be2 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -40,10 +40,8 @@ struct MainFileMacros {
 ///  - collect macros after the preamble of the main file (in ParsedAST.cpp)
 class CollectMainFileMacros : public PPCallbacks {
 public:
-  explicit CollectMainFileMacros(const SourceManager &SM,
- const LangOptions &LangOpts,
- MainFileMacros &Out)
-  : SM(SM), LangOpts(LangOpts), Out(Out) {}
+  explicit CollectMainFileMacros(const SourceManager &SM, MainFileMacros &Out)
+  : SM(SM), Out(Out) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason,
SrcMgr::CharacteristicKind, FileID) override {
@@ -89,24 +87,8 @@ class CollectMainFileMacros : public PPCallbacks {
   }
 
 private:
-  void add(const Token &MacroNameTok, const MacroInfo *MI) {
-if (!InMainFile)
-  return;
-auto Loc = MacroNameTok.getLocation();
-if (Loc.isMacroID())
-  return;
-
-if (auto Range = getTokenRange(SM, LangOpts, Loc)) {
-  auto Name = MacroNameTok.getIdentifierInfo()->getName();
-  Out.Names.insert(Name);
-  if (auto SID = getSymbolID(Name, MI, SM))
-Out.MacroRefs[*SID].push_back(*Range);
-  else
-Out.UnknownMacros.push_back(*Range);
-}
-  }
+  void add(const Token &MacroNameTok, const MacroInfo *MI);
   const SourceManager &SM;
-  const LangOptions &LangOpts;
   bool InMainFile = true;
   MainFileMacros &Out;
 };

diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 5796657a5800..5c1288c14b58 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Index/IndexSymbol.h"
@@ -530,32 +531,33 

[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3755039c99d8: [clangd] Get rid of getTokenRange helper 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75474

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -29,6 +29,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/IndexDataConsumer.h"
@@ -149,25 +150,27 @@
   return Result;
 }
 
-llvm::Optional makeLocation(ASTContext &AST, SourceLocation TokLoc,
+// Expects Loc to be a SpellingLocation, will bail out otherwise as it can't
+// figure out a filename.
+llvm::Optional makeLocation(const ASTContext &AST, SourceLocation Loc,
   llvm::StringRef TUPath) {
-  const SourceManager &SourceMgr = AST.getSourceManager();
-  const FileEntry *F = SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  const auto &SM = AST.getSourceManager();
+  const FileEntry *F = SM.getFileEntryForID(SM.getFileID(Loc));
   if (!F)
 return None;
-  auto FilePath = getCanonicalPath(F, SourceMgr);
+  auto FilePath = getCanonicalPath(F, SM);
   if (!FilePath) {
 log("failed to get path!");
 return None;
   }
-  if (auto Range =
-  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
-Location L;
-L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-L.range = *Range;
-return L;
-  }
-  return None;
+  Location L;
+  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+  // We call MeasureTokenLength here as TokenBuffer doesn't store spelled tokens
+  // outside the main file.
+  auto TokLen = Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts());
+  L.range = halfOpenToRange(
+  SM, CharSourceRange::getCharRange(Loc, Loc.getLocWithOffset(TokLen)));
+  return L;
 }
 
 } // namespace
@@ -373,11 +376,15 @@
 class ReferenceFinder : public index::IndexDataConsumer {
 public:
   struct Reference {
-SourceLocation Loc;
+syntax::Token SpelledTok;
 index::SymbolRoleSet Role;
+
+Range range(const SourceManager &SM) const {
+  return halfOpenToRange(SM, SpelledTok.range(SM).toCharRange(SM));
+}
   };
 
-  ReferenceFinder(ASTContext &AST, Preprocessor &PP,
+  ReferenceFinder(const ParsedAST &AST,
   const std::vector &TargetDecls)
   : AST(AST) {
 for (const NamedDecl *D : TargetDecls)
@@ -386,13 +393,17 @@
 
   std::vector take() && {
 llvm::sort(References, [](const Reference &L, const Reference &R) {
-  return std::tie(L.Loc, L.Role) < std::tie(R.Loc, R.Role);
+  auto LTok = L.SpelledTok.location();
+  auto RTok = R.SpelledTok.location();
+  return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
 });
 // We sometimes see duplicates when parts of the AST get traversed twice.
 References.erase(std::unique(References.begin(), References.end(),
  [](const Reference &L, const Reference &R) {
-   return std::tie(L.Loc, L.Role) ==
-  std::tie(R.Loc, R.Role);
+   auto LTok = L.SpelledTok.location();
+   auto RTok = R.SpelledTok.location();
+   return std::tie(LTok, L.Role) ==
+  std::tie(RTok, R.Role);
  }),
  References.end());
 return std::move(References);
@@ -404,22 +415,27 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
+if (!CanonicalTargets.count(D))
+  return true;
+const auto &TB = AST.getTokens();
 const SourceManager &SM = AST.getSourceManager();
 Loc = SM.getFileLoc(Loc);
-if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
-  References.push_back({Loc, Roles});
+// We are only traversing decls *inside* the main file, so this should hold.
+assert(isInsideMainFile(Loc, SM));
+if (const auto *Tok = TB.spelledTokenAt(Loc))
+  References.push_back({*Tok, Roles});
 return true;

[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3302af83ef79: [clangd] Make use of token buffers in semantic 
highlighting (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447

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


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,39 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager &SM) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansion(L))
+return {};
+  // Tokens expanded from macro args are potentially highlightable.
+  return getHighlightableSpellingToken(SM.getImmediateSpellingLoc(L), SM);
+}
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(const ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
+Loc = getHighlightableSpellingToken(Loc, SourceMgr);
 if (Loc.isInvalid())
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
-  return;
+const auto *Tok = TB.spelledTokenAt(Loc);
+assert(Tok);
 
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+auto Range = halfOpenToRange(SourceMgr,
+ Tok->range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST &AST) && {
@@ -211,6 +211,7 @@
   }
 
 private:
+  const syntax::TokenBuffer &TB;
   const SourceManager &SourceMgr;
   const LangOptions &LangOpts;
   std::vector Tokens;
@@ -311,7 +312,7 @@
 std::vector getSemanticHighlightings(ParsedAST &AST) {
   auto &C = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,39 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager &SM) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansio

[PATCH] D75503: [clang][Syntax] Add spelledTokenAt helper to TokenBuffer

2020-03-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd9b2e18bd69: [clang][Syntax] Add spelledTokenAt helper to 
TokenBuffer (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75503

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -59,6 +59,7 @@
 using ::testing::Field;
 using ::testing::Matcher;
 using ::testing::Not;
+using ::testing::Pointee;
 using ::testing::StartsWith;
 
 namespace {
@@ -363,6 +364,12 @@
   AllOf(Kind(tok::equal), RangeIs(Code.range("r3"))),
   AllOf(Kind(tok::string_literal), RangeIs(Code.range("r4"))),
   AllOf(Kind(tok::semi), RangeIs(Code.range("r5");
+
+  auto StartLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+  for (auto &R : Code.ranges()) {
+EXPECT_THAT(Buffer.spelledTokenAt(StartLoc.getLocWithOffset(R.Begin)),
+Pointee(RangeIs(R)));
+  }
 }
 
 TEST_F(TokenCollectorTest, MacroDirectives) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,6 +183,16 @@
   return It->second.SpelledTokens;
 }
 
+const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
+  assert(Loc.isFileID());
+  const auto *Tok = llvm::partition_point(
+  spelledTokens(SourceMgr->getFileID(Loc)),
+  [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  if (!Tok || Tok->location() != Loc)
+return nullptr;
+  return Tok;
+}
+
 std::string TokenBuffer::Mapping::str() const {
   return std::string(
   llvm::formatv("spelled tokens: [{0},{1}), expanded tokens: [{2},{3})",
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -245,6 +245,10 @@
   /// "DECL", "(", "a", ")", ";"}
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  /// Returns the spelled Token starting at Loc, if there are no such tokens
+  /// returns nullptr.
+  const syntax::Token *spelledTokenAt(SourceLocation Loc) const;
+
   /// Get all tokens that expand a macro in \p FID. For the following input
   /// #define FOO B
   /// #define FOO2(X) int X


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -59,6 +59,7 @@
 using ::testing::Field;
 using ::testing::Matcher;
 using ::testing::Not;
+using ::testing::Pointee;
 using ::testing::StartsWith;
 
 namespace {
@@ -363,6 +364,12 @@
   AllOf(Kind(tok::equal), RangeIs(Code.range("r3"))),
   AllOf(Kind(tok::string_literal), RangeIs(Code.range("r4"))),
   AllOf(Kind(tok::semi), RangeIs(Code.range("r5");
+
+  auto StartLoc = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
+  for (auto &R : Code.ranges()) {
+EXPECT_THAT(Buffer.spelledTokenAt(StartLoc.getLocWithOffset(R.Begin)),
+Pointee(RangeIs(R)));
+  }
 }
 
 TEST_F(TokenCollectorTest, MacroDirectives) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,6 +183,16 @@
   return It->second.SpelledTokens;
 }
 
+const syntax::Token *TokenBuffer::spelledTokenAt(SourceLocation Loc) const {
+  assert(Loc.isFileID());
+  const auto *Tok = llvm::partition_point(
+  spelledTokens(SourceMgr->getFileID(Loc)),
+  [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  if (!Tok || Tok->location() != Loc)
+return nullptr;
+  return Tok;
+}
+
 std::string TokenBuffer::Mapping::str() const {
   return std::string(
   llvm::formatv("spelled tokens: [{0},{1}), expanded tokens: [{2},{3})",
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -245,6 +245,10 @@
   /// "DECL", "(", "a", ")", ";"}
   llvm::ArrayRef spelledTokens(FileID FID) const;
 
+  /// Returns the spelled Token starting at Loc, if there are no such tokens
+  /// returns nullptr.
+  const syntax::Token *spelledTokenAt(SourceLocation Loc) const;
+
   /// Get all tokens that expand a macro in \p FID. 

[PATCH] D75432: [analyzer][NFC][MallocChecker] Convert many parameters into CallEvent

2020-03-03 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 2 inline comments as done.
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:995
 
-void MallocChecker::checkBasicAlloc(CheckerContext &C, const CallExpr *CE,
-ProgramStateRef State) const {
-  State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State, AF_Malloc);
-  State = ProcessZeroAllocCheck(C, CE, 0, State);
+void MallocChecker::checkBasicAlloc(const CallEvent &Call,
+CheckerContext &C) const {

xazax.hun wrote:
> What is the main reason of getting rid of the state parameter? I think this 
> could make using these functions more error prone overall as it would be 
> easier to introduce splits in the exploded graph this way (if we somehow 
> wanted to model a function as successive calls of some other functions).
Refer to @NoQ's 
[[https://reviews.llvm.org/D68165?id=57#inline-612842|earlier inline]].

> I think this could make using these functions more error prone overall as it 
> would be easier to introduce splits in the exploded graph this way (if we 
> somehow wanted to model a function as successive calls of some other 
> functions).

Why would the removal of a `ProgramStateRef` parameter cause that?



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1641
 ProgramStateRef MallocChecker::FreeMemAux(
-CheckerContext &C, const Expr *ArgExpr, const Expr *ParentExpr,
 ProgramStateRef State, bool Hold, bool &IsKnownToBeAllocated,

xazax.hun wrote:
> In functions where we only use `ArgExpr` to retrieve the corresponding `SVal` 
> we could pass the `SVal` in the first place.
Long term, I plan to find a better value type for the `CallDescriptionMap` 
where information such as this could be retrieved easier, which is why I 
focused on nothing but the task at hand.

While I would like to see `MallocChecker` in a healthier state, at times I find 
the development effort I'm putting into it questionable, so I'll probably stop 
at the point where I can comfortably split it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75432



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


[clang] 859bcf4 - [analyzer][taint] Add isTainted debug expression inspection check

2020-03-03 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2020-03-03T14:40:23+01:00
New Revision: 859bcf4e3bb991a161821129d19d50ba00f9c56a

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

LOG: [analyzer][taint] Add isTainted debug expression inspection check

Summary:
This patch introduces the `clang_analyzer_isTainted` expression inspection
check for checking taint.

Using this we could query the analyzer whether the expression used as the
argument is tainted or not. This would be useful in tests, where we don't want
to issue warning for all tainted expressions in a given file
(like the `debug.TaintTest` would do) but only for certain expressions.

Example usage:

```lang=c++
int read_integer() {
  int n;
  clang_analyzer_isTainted(n); // expected-warning{{NO}}
  scanf("%d", &n);
  clang_analyzer_isTainted(n); // expected-warning{{YES}}
  clang_analyzer_isTainted(n + 2); // expected-warning{{YES}}
  clang_analyzer_isTainted(n > 0); // expected-warning{{YES}}
  int next_tainted_value = n; // no-warning
  return n;
}
```

Reviewers: NoQ, Szelethus, baloghadamsoftware, xazax.hun, boga95

Reviewed By: Szelethus

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

Tags: #clang

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

Added: 
clang/test/Analysis/debug-exprinspection-istainted.c

Modified: 
clang/docs/analyzer/developer-docs/DebugChecks.rst
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

Removed: 




diff  --git a/clang/docs/analyzer/developer-docs/DebugChecks.rst 
b/clang/docs/analyzer/developer-docs/DebugChecks.rst
index 3f9bed78604f..05b3e2480d3b 100644
--- a/clang/docs/analyzer/developer-docs/DebugChecks.rst
+++ b/clang/docs/analyzer/developer-docs/DebugChecks.rst
@@ -275,6 +275,28 @@ ExprInspection checks
 
   See clang_analyzer_denote().
 
+- ``void clang_analyzer_isTainted(a single argument of any type);``
+
+  Queries the analyzer whether the expression used as argument is tainted or 
not.
+  This is useful in tests, where we don't want to issue warning for all tainted
+  expressions but only check for certain expressions.
+  This would help to reduce the *noise* that the `TaintTest` debug checker 
would
+  introduce and let you focus on the `expected-warning`s that you really care
+  about.
+
+  Example usage::
+
+int read_integer() {
+  int n;
+  clang_analyzer_isTainted(n); // expected-warning{{NO}}
+  scanf("%d", &n);
+  clang_analyzer_isTainted(n); // expected-warning{{YES}}
+  clang_analyzer_isTainted(n + 2); // expected-warning{{YES}}
+  clang_analyzer_isTainted(n > 0); // expected-warning{{YES}}
+  int next_tainted_value = n; // no-warning
+  return n;
+}
+
 Statistics
 ==
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 54b364f38f81..10b27831d89f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 
+#include "Taint.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Checkers/SValExplainer.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
@@ -46,6 +47,7 @@ class ExprInspectionChecker : public Checker(C.getCalleeName(CE))
-.Case("clang_analyzer_eval", &ExprInspectionChecker::analyzerEval)
-.Case("clang_analyzer_checkInlined",
-  &ExprInspectionChecker::analyzerCheckInlined)
-.Case("clang_analyzer_crash", &ExprInspectionChecker::analyzerCrash)
-.Case("clang_analyzer_warnIfReached",
-  &ExprInspectionChecker::analyzerWarnIfReached)
-.Case("clang_analyzer_warnOnDeadSymbol",
-  &ExprInspectionChecker::analyzerWarnOnDeadSymbol)
-.StartsWith("clang_analyzer_explain", 
&ExprInspectionChecker::analyzerExplain)
-.StartsWith("clang_analyzer_dump", &ExprInspectionChecker::analyzerDump)
-.Case("clang_analyzer_getExtent", 
&ExprInspectionChecker::analyzerGetExtent)
-.Case("clang_analyzer_printState",
-  &ExprInspectionChecker::analyzerPrintState)
-.Case("clang_analyzer_numTimesReached",
-  &ExprInspectionChecker::analyzerNumTimesReached)
-.Case("clang_analyzer_hashDump", &ExprInspectionChecker::analyzerHashDump)
-.Case("clang_analyzer_denote", &ExprInspectionChecker::analyzerDenote)
-.Case("clang_analyzer_express", &ExprInspectionChecker::analyzerExpress)
-.Default(nullptr);
+  FnCheck Handler =
+  llvm::StringSwitch(C.getCalleeName(CE))
+

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

2020-03-03 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
steakhal marked an inline comment as done.
Closed by commit rG859bcf4e3bb9: [analyzer][taint] Add isTainted debug 
expression inspection check (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74131

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

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

[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

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



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:333-335
+  // Ignore the call if the stream is is not tracked.
+  if (!State->get(StreamSym))
+return;

Szelethus wrote:
> If we check in `preCall` whether the stream is opened why don't we 
> conservatively assume it to be open?
If we do that we get a resource leak error for example in the test function 
`pr8081` (there is only a call to `fseek`). We can assume that if the function 
gets the file pointer as argument it does not "own" it so the close is not 
needed. Otherwise the false positive resource leaks come always in functions 
that take a file argument and use file operations. Or this case (the file 
pointer is passed as input argument, the file is not opened by the function 
that is analyzed) can be handled specially, we can assume that there is no 
error initially and closing the file is not needed.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:351-354
+  // Set state to any error.
+  // Assume that EOF and other error is possible after the call.
+  StateFailed =
+  StateFailed->set(StreamSym, 
StreamState::getOpenedWithError());

Szelethus wrote:
> But why? The standard suggests that the error state isn't changed upon 
> failure. I think we should leave it as-is.
The fseek can fail and set the error flag, see the example code here:
https://en.cppreference.com/w/c/io/fseek
Probably it can not set the **EOF** flag, according to that page it is possible 
to seek after the end of the file. So the function can succeed or fail with 
`OtherError`.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:438-439
   const StreamState *SS = State->get(Sym);
   if (!SS)
 return State;
 

Szelethus wrote:
> Right here, should we just assume a stream to be opened when we can't prove 
> otherwise? `ensureStreamOpened` is only called when we are about to evaluate 
> a function that assumes the stream to be opened anyways, so I don't expect 
> many false positive lack of `fclose` reports.
The warning is created only if we know that the stream is not opened. This 
function makes no difference if the stream is "tracked" (found in StreamMap) or 
not. In the not-tracked case it is the same as if it were opened. Probably the 
function can be changed to take a `StreamState` instead of `StreamVal` and the 
not-tracked case can be handled separately. Or this function can add the new 
`StreamState` in (opened state).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


[clang-tools-extra] c0b27c4 - [clangd] Remove unused getDocument() API

2020-03-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-03T14:53:59+01:00
New Revision: c0b27c489104f6c3c055a3ac1573d05393fe32eb

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

LOG: [clangd] Remove unused getDocument() API

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index f1a88902c8c0..5dd00322a5ab 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -194,10 +194,6 @@ void ClangdServer::addDocument(PathRef File, 
llvm::StringRef Contents,
 
 void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }
 
-llvm::StringRef ClangdServer::getDocument(PathRef File) const {
-  return WorkScheduler.getContents(File);
-}
-
 void ClangdServer::codeComplete(PathRef File, Position Pos,
 const clangd::CodeCompleteOptions &Opts,
 Callback CB) {

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index e9f2c30b1749..d098f6242f72 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -175,9 +175,6 @@ class ClangdServer {
WantDiagnostics WD = WantDiagnostics::Auto,
bool ForceRebuild = false);
 
-  /// Get the contents of \p File, which should have been added.
-  llvm::StringRef getDocument(PathRef File) const;
-
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it. Pending diagnostics for closed files may 
not
   /// be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index f59c19e8031e..3f3162a33c30 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -921,15 +921,6 @@ void TUScheduler::remove(PathRef File) {
  File);
 }
 
-llvm::StringRef TUScheduler::getContents(PathRef File) const {
-  auto It = Files.find(File);
-  if (It == Files.end()) {
-elog("getContents() for untracked file: {0}", File);
-return "";
-  }
-  return It->second->Contents;
-}
-
 llvm::StringMap TUScheduler::getAllFileContents() const {
   llvm::StringMap Results;
   for (auto &It : Files)

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index 5082612b0ccc..948fde7ed109 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -213,10 +213,6 @@ class TUScheduler {
   /// if requested with WantDiags::Auto or WantDiags::Yes.
   void remove(PathRef File);
 
-  /// Returns the current contents of the buffer for File, per last update().
-  /// The returned StringRef may be invalidated by any write to TUScheduler.
-  llvm::StringRef getContents(PathRef File) const;
-
   /// Returns a snapshot of all file buffer contents, per last update().
   llvm::StringMap getAllFileContents() const;
 

diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index 214099767990..9e5952fe2cb5 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -138,9 +138,7 @@ TEST_F(TUSchedulerTests, MissingFiles) {
   auto Missing = testPath("missing.cpp");
   Files[Missing] = "";
 
-  EXPECT_EQ(S.getContents(Added), "");
   S.update(Added, getInputs(Added, "x"), WantDiagnostics::No);
-  EXPECT_EQ(S.getContents(Added), "x");
 
   // Assert each operation for missing file is an error (even if it's
   // available in VFS).
@@ -159,9 +157,7 @@ TEST_F(TUSchedulerTests, MissingFiles) {
 [&](Expected Preamble) {
   EXPECT_TRUE(bool(Preamble));
 });
-  EXPECT_EQ(S.getContents(Added), "x");
   S.remove(Added);
-  EXPECT_EQ(S.getContents(Added), "");
 
   // Assert that all operations fail after removing the file.
   S.runWithAST("", Added,



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


[PATCH] D31343: Add an attribute plugin example

2020-03-03 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

I've been looking into attribute merging, and as far as I can tell there's two 
things going on:

- In SemaDeclAttr.cpp, the various handleXyzAttr functions may call 
mergeXyzAttr to handle clashes with other attributes within the same 
declaration.
- In SemaDecl.cpp, several functions call mergeDeclAttributes, which calls 
mergeXyzAttr, to handle clashes with attributes in a previous declaration of 
the same thing.

For the first kind, the handleDeclAttribute function defined for a plugin 
attribute can check for and handle clashes with other attributes. For the 
second kind, at that point we're using subclasses of Attr which means we're 
beyond the scope of plugin attributes which just work in the realm of 
ParsedAttrs.

So I think things are OK, though I guess it depends on what exactly your plugin 
is doing - our use-case is that the plugin-defined attribute is just used to 
set an AnnotateAttr, which is used to tell a plugin-defined LLVM pass that it 
needs to do something in that function, so we don't need anything special to 
happen with regards to attribute merging.


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

https://reviews.llvm.org/D31343



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

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

In D75163#1902816 , @xazax.hun wrote:

> If we were to refactor this check I wonder if it would make sense to port 
> `evalCall` to `postCall`, so the analyzer engine will conjure the symbol for 
> us.
>  I wonder what @NoQ thinks about the pros and cons of the approaches.


Once I wanted to remove `evalCall` but it was no success:
https://reviews.llvm.org/D69662


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

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

Split the patch into two is really start it from "scratch" again, copy the 
code, decide what to go into the first or second part (and what order) (really 
what?), make some mess with git commands and branches and rebase, probably 
rebuild whole llvm, if review changes are to be done again comes the "git mess" 
problem (change code in a commit that belongs logically before another). It can 
be more work to make changes in the "old way" that are done in the second part 
in a new way. Or somebody could say "this thing makes no sense, I want to see 
the next diff how about it is used", and commit can happen really only if the 
next change is accepted too. So I do not prefer to split it, the change is not 
a very complicated one and the modifications belong somewhat together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/AST/TemplateName.cpp:193
+  } else {
+assert(!getAsOverloadedTemplate() &&
+   "overloaded templates shouldn't survive to here");

sammccall wrote:
> As far as I can tell, an overloaded template will always return null for 
> getAsTemplateDecl(). So this assert can be hoisted to the top, which I think 
> would be clearer.
I didn't get your point here, did you mean moving the assert to the `switch 
(getKind())` like 

```
switch (getKind()) {
  case OverloadedTemplate:
assert(!GetAsTemplateDecl());
}
```
?



Comment at: clang/lib/AST/TemplateName.cpp:205
+  // Dependent template name is always instantiation dependent.
+  if (Dependency & TemplateNameDependence::Dependent)
+Dependency |= TemplateNameDependence::DependentInstantiation;

sammccall wrote:
> why not just add DependentInstantiation above in the first place?
> Tracking incorrect bits and then fixing them at the end seems a bit confusing.
oops, I was confused by the `DependentInstantiation` and `Dependent` bits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75163: [analyzer][StreamChecker] Adding precall and refactoring.

2020-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D75163#1902921 , @balazske wrote:

> In D75163#1902816 , @xazax.hun wrote:
>
> > If we were to refactor this check I wonder if it would make sense to port 
> > `evalCall` to `postCall`, so the analyzer engine will conjure the symbol 
> > for us.
> >  I wonder what @NoQ thinks about the pros and cons of the approaches.
>
>
> Once I wanted to remove `evalCall` but it was no success:
>  https://reviews.llvm.org/D69662


Sounds fair.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75163



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


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 247881.
hokein marked 4 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920

Files:
  clang/include/clang/AST/DependencyFlags.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/AST/NestedNameSpecifier.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp

Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -11,7 +11,6 @@
 //
 //===--===//
 
-#include "clang/Serialization/ASTRecordReader.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/AttrIterator.h"
@@ -22,6 +21,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -49,6 +49,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Serialization/ASTRecordReader.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -511,10 +512,23 @@
 void ASTStmtReader::VisitExpr(Expr *E) {
   VisitStmt(E);
   E->setType(Record.readType());
-  E->setTypeDependent(Record.readInt());
-  E->setValueDependent(Record.readInt());
-  E->setInstantiationDependent(Record.readInt());
-  E->ExprBits.ContainsUnexpandedParameterPack = Record.readInt();
+
+  // FIXME: write and read all DependentFlags with a single call.
+  bool TypeDependent = Record.readInt();
+  bool ValueDependent = Record.readInt();
+  bool InstantiationDependent = Record.readInt();
+  bool ContainsUnexpandedTemplateParameters = Record.readInt();
+  auto Deps = ExprDependence::None;
+  if (TypeDependent)
+Deps |= ExprDependence::Type;
+  if (ValueDependent)
+Deps |= ExprDependence::Value;
+  if (InstantiationDependent)
+Deps |= ExprDependence::Instantiation;
+  if (ContainsUnexpandedTemplateParameters)
+Deps |= ExprDependence::UnexpandedPack;
+  E->setDependence(Deps);
+
   E->setValueKind(static_cast(Record.readInt()));
   E->setObjectKind(static_cast(Record.readInt()));
   assert(Record.getIdx() == NumExprFields &&
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10,10 +10,10 @@
 //
 //===--===//
 
-#include "clang/Sema/Overload.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -25,6 +25,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/Overload.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateDeduction.h"
@@ -12719,9 +12720,7 @@
   // base classes.
   CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy,
   VK_RValue, RParenLoc);
-  CE->setTypeDependent(true);
-  CE->setValueDependent(true);
-  CE->setInstantiationDependent(true);
+  CE->addDependence(ExprDependence::TypeValueInstantiation);
   *Result = CE;
   return true;
 }
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -11,8 +11,10 @@
 //===--===//
 
 #include "clang/AST/TemplateName.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
@@ -168,52 +170,55 @@
   return TemplateName(Decl);
 }
 
-bool TemplateName::isDependent() const {
+TemplateNameDependence TemplateName::getDepend

[clang] d481e59 - [hexagon] Add default paths to support musl target

2020-03-03 Thread Sid Manning via cfe-commits

Author: Sid Manning
Date: 2020-03-03T08:43:10-06:00
New Revision: d481e59863ac0eaca813a972f0dc79b763012d30

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

LOG: [hexagon] Add default paths to support musl target

Pickup the default crt and libs when the target is musl.
Resubmitting after updating the testcase.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-elf.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 88523cd4bb1c..1e2e7c84b006 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,39 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
 UseG0 = G.getValue() == 0;
   }
 
-  
//
-  //
-  
//
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
+ options::OPT_nostdlib))
+  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
+else if (Args.hasArg(options::OPT_shared) &&
+ !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
+  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
+
+CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + D.SysRoot + 
"/lib"));
+Args.AddAllArgs(CmdArgs,
+{options::OPT_T_Group, options::OPT_e, options::OPT_s,
+ options::OPT_t, options::OPT_u_Group});
+AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+
+if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
+  CmdArgs.push_back("-lc");
+}
+
+return;
+  }
+
   
//
   // moslib
   
//
   std::vector OsLibs;
   bool HasStandalone = false;
-
   for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
 A->claim();
 OsLibs.emplace_back(A->getValue());

diff  --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index 0a6c86424955..93c9da2250f5 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,70 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// 
-
+// Passing --musl
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// 
-
+// Passing --musl --shared
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// 
-
+// Passing --musl -nostdlib
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix

[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

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

thanks, that looks better to me




Comment at: clang/lib/AST/TemplateName.cpp:193
+  } else {
+assert(!getAsOverloadedTemplate() &&
+   "overloaded templates shouldn't survive to here");

hokein wrote:
> sammccall wrote:
> > As far as I can tell, an overloaded template will always return null for 
> > getAsTemplateDecl(). So this assert can be hoisted to the top, which I 
> > think would be clearer.
> I didn't get your point here, did you mean moving the assert to the `switch 
> (getKind())` like 
> 
> ```
> switch (getKind()) {
>   case OverloadedTemplate:
> assert(!GetAsTemplateDecl());
> }
> ```
> ?
ITYM `assert(getAsTemplateDecl())`

Yes, but also if this is an `OverloadedTemplate`, then getAsTemplateDecl is 
always false. So this can just be `assert(false && "some message")` in that 
case statement



Comment at: clang/lib/AST/TemplateName.cpp:208
  "overloaded templates shouldn't survive to here");
+  D |= TemplateNameDependence::DependentInstantiation;
+  return D;

what's this line about?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75056: [Driver] Default to -fno-common for all targets

2020-03-03 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Reverted in: https://reviews.llvm.org/rG4e363563fa14

Put up for review some fixes for compiler-rt tests in: 
https://reviews.llvm.org/D75520

Now checking what these test-suite failures are about:

  FAIL: MultiSource/Applications/JM/ldecod/ldecod.compile_time (1 of 2630)
  FAIL: MultiSource/Applications/JM/lencod/lencod.compile_time (2 of 2630)
  FAIL: MultiSource/Benchmarks/ASC_Sequoia/IRSmk/IRSmk.compile_time (3 of 2630)
  FAIL: MultiSource/Benchmarks/DOE-ProxyApps-C/miniAMR/miniAMR.compile_time (4 
of 2630)
  FAIL: MultiSource/Benchmarks/Olden/bh/bh.compile_time (5 of 2630)
  FAIL: 
MultiSource/Benchmarks/Prolangs-C/TimberWolfMC/timberwolfmc.compile_time (6 of 
2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/compiler/compiler.compile_time (7 of 
2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/loader/loader.compile_time (8 of 2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/simulator/simulator.compile_time (9 
of 2630)
  FAIL: MultiSource/Applications/JM/ldecod/ldecod.execution_time (527 of 2630)
  FAIL: MultiSource/Applications/JM/lencod/lencod.execution_time (528 of 2630)
  FAIL: MultiSource/Benchmarks/ASC_Sequoia/IRSmk/IRSmk.execution_time (529 of 
2630)
  FAIL: MultiSource/Benchmarks/DOE-ProxyApps-C/miniAMR/miniAMR.execution_time 
(530 of 2630)
  FAIL: MultiSource/Benchmarks/Olden/bh/bh.execution_time (531 of 2630)
  FAIL: 
MultiSource/Benchmarks/Prolangs-C/TimberWolfMC/timberwolfmc.execution_time (532 
of 2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/compiler/compiler.execution_time (533 
of 2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/loader/loader.execution_time (534 of 
2630)
  FAIL: MultiSource/Benchmarks/Prolangs-C/simulator/simulator.execution_time 
(535 of 2630)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75056



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


[PATCH] D75139: [hexagon] Pickup the default crt and libs when the musl target is selected

2020-03-03 Thread Sid Manning via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd481e59863ac: [hexagon] Add default paths to support musl 
target (authored by sidneym).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75139

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-elf.c

Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,70 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK088 %s
+// CHECK088:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK088:   "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK089 %s
+// CHECK089:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK089:   "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,39 @@
 UseG0 = G.getValue() == 0;
   }
 
-  //
-  //
-  //
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+

[clang-tools-extra] caf5a4d - [clangd] Propagate versions into DraftStore, assigning where missing. NFC

2020-03-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-03-03T16:20:13+01:00
New Revision: caf5a4d57fe0ac0ca8c8d45fd31e5dbbc6bb6bec

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

LOG: [clangd] Propagate versions into DraftStore, assigning where missing. NFC

This prepares for propagating versions through the server so diagnostics
etc can be versioned.

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/DraftStore.cpp
clang-tools-extra/clangd/DraftStore.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/unittests/DraftStoreTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 9d93b8592fdc..44288eb7274d 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -117,7 +117,7 @@ llvm::Error validateEdits(const DraftStore &DraftMgr, const 
FileEdits &FE) {
   // If the file is open in user's editor, make sure the version we
   // saw and current version are compatible as this is the text that
   // will be replaced by editors.
-  if (!It.second.canApplyTo(*Draft)) {
+  if (!It.second.canApplyTo(Draft->Contents)) {
 ++InvalidFileCount;
 LastInvalidFile = It.first();
   }
@@ -630,7 +630,7 @@ void ClangdLSPServer::onDocumentDidOpen(
 
   const std::string &Contents = Params.textDocument.text;
 
-  DraftMgr.addDraft(File, Contents);
+  DraftMgr.addDraft(File, Params.textDocument.version, Contents);
   Server->addDocument(File, Contents, WantDiagnostics::Yes);
 }
 
@@ -642,19 +642,19 @@ void ClangdLSPServer::onDocumentDidChange(
   : WantDiagnostics::No;
 
   PathRef File = Params.textDocument.uri.file();
-  llvm::Expected Contents =
-  DraftMgr.updateDraft(File, Params.contentChanges);
-  if (!Contents) {
+  llvm::Expected Draft = DraftMgr.updateDraft(
+  File, Params.textDocument.version, Params.contentChanges);
+  if (!Draft) {
 // If this fails, we are most likely going to be not in sync anymore with
 // the client.  It is better to remove the draft and let further operations
 // fail rather than giving wrong results.
 DraftMgr.removeDraft(File);
 Server->removeDocument(File);
-elog("Failed to update {0}: {1}", File, Contents.takeError());
+elog("Failed to update {0}: {1}", File, Draft.takeError());
 return;
   }
 
-  Server->addDocument(File, *Contents, WantDiags, Params.forceRebuild);
+  Server->addDocument(File, Draft->Contents, WantDiags, Params.forceRebuild);
 }
 
 void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
@@ -773,8 +773,7 @@ void ClangdLSPServer::onPrepareRename(const 
TextDocumentPositionParams &Params,
 void ClangdLSPServer::onRename(const RenameParams &Params,
Callback Reply) {
   Path File = std::string(Params.textDocument.uri.file());
-  llvm::Optional Code = DraftMgr.getDraft(File);
-  if (!Code)
+  if (!DraftMgr.getDraft(File))
 return Reply(llvm::make_error(
 "onRename called for non-added file", ErrorCode::InvalidParams));
   Server->rename(
@@ -829,7 +828,7 @@ void ClangdLSPServer::onDocumentOnTypeFormatting(
 "onDocumentOnTypeFormatting called for non-added file",
 ErrorCode::InvalidParams));
 
-  Reply(Server->formatOnType(*Code, File, Params.position, Params.ch));
+  Reply(Server->formatOnType(Code->Contents, File, Params.position, 
Params.ch));
 }
 
 void ClangdLSPServer::onDocumentRangeFormatting(
@@ -842,9 +841,10 @@ void ClangdLSPServer::onDocumentRangeFormatting(
 "onDocumentRangeFormatting called for non-added file",
 ErrorCode::InvalidParams));
 
-  auto ReplacementsOrError = Server->formatRange(*Code, File, Params.range);
+  auto ReplacementsOrError =
+  Server->formatRange(Code->Contents, File, Params.range);
   if (ReplacementsOrError)
-Reply(replacementsToEdits(*Code, ReplacementsOrError.get()));
+Reply(replacementsToEdits(Code->Contents, ReplacementsOrError.get()));
   else
 Reply(ReplacementsOrError.takeError());
 }
@@ -859,9 +859,9 @@ void ClangdLSPServer::onDocumentFormatting(
 "onDocumentFormatting called for non-added file",
 ErrorCode::InvalidParams));
 
-  auto ReplacementsOrError = Server->formatFile(*Code, File);
+  auto ReplacementsOrError = Server->formatFile(Code->Contents, File);
   if (ReplacementsOrError)
-Reply(replacementsToEdits(*Code, ReplacementsOrError.get()));
+Reply(replacementsToEdits(Code->Contents, ReplacementsOrError.get()));
   else
 Reply(ReplacementsOrError.takeError());
 }
@@ -1328,7 +1328,7 @@ bool ClangdLSPServer::should

[PATCH] D75523: [www] cxx_status: Update title to mention C++20

2020-03-03 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: rsmith, aaron.ballman.
Herald added a project: clang.

The document covers the Clang implementation status of the "upcoming C++20 
standard". Update the title to match.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75523

Files:
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -2,7 +2,7 @@
 
 
   
-  Clang - C++17, C++14, C++11 and C++98 Status
+  Clang - C++20, C++17, C++14, C++11 and C++98 Status
   
   
   

[PATCH] D75524: [www] cxx_status: Update Reflection TS to Cologne draft

2020-03-03 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: rsmith, aaron.ballman.
Herald added a project: clang.

As of the 2019 Cologne meeting, according to its minutes (N4826), N4818 is the 
draft of the Reflection TS.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75524

Files:
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1321,7 +1321,7 @@
 
 
   [DRAFT TS] Reflection
-  https://wg21.link/n4746";>N4746
+  https://wg21.link/n4818";>N4818
   
   No
 


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1321,7 +1321,7 @@
 
 
   [DRAFT TS] Reflection
-  https://wg21.link/n4746";>N4746
+  https://wg21.link/n4818";>N4818
   
   No
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 247905.
hokein marked an inline comment as done.
hokein added a comment.

move the assert to overloadedTemplate switch case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920

Files:
  clang/include/clang/AST/DependencyFlags.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/AST/NestedNameSpecifier.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/lib/AST/ExprObjC.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp

Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -11,7 +11,6 @@
 //
 //===--===//
 
-#include "clang/Serialization/ASTRecordReader.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/AttrIterator.h"
@@ -22,6 +21,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -49,6 +49,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "clang/Lex/Token.h"
 #include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Serialization/ASTRecordReader.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -511,10 +512,23 @@
 void ASTStmtReader::VisitExpr(Expr *E) {
   VisitStmt(E);
   E->setType(Record.readType());
-  E->setTypeDependent(Record.readInt());
-  E->setValueDependent(Record.readInt());
-  E->setInstantiationDependent(Record.readInt());
-  E->ExprBits.ContainsUnexpandedParameterPack = Record.readInt();
+
+  // FIXME: write and read all DependentFlags with a single call.
+  bool TypeDependent = Record.readInt();
+  bool ValueDependent = Record.readInt();
+  bool InstantiationDependent = Record.readInt();
+  bool ContainsUnexpandedTemplateParameters = Record.readInt();
+  auto Deps = ExprDependence::None;
+  if (TypeDependent)
+Deps |= ExprDependence::Type;
+  if (ValueDependent)
+Deps |= ExprDependence::Value;
+  if (InstantiationDependent)
+Deps |= ExprDependence::Instantiation;
+  if (ContainsUnexpandedTemplateParameters)
+Deps |= ExprDependence::UnexpandedPack;
+  E->setDependence(Deps);
+
   E->setValueKind(static_cast(Record.readInt()));
   E->setObjectKind(static_cast(Record.readInt()));
   assert(Record.getIdx() == NumExprFields &&
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10,10 +10,10 @@
 //
 //===--===//
 
-#include "clang/Sema/Overload.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
@@ -25,6 +25,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/Overload.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateDeduction.h"
@@ -12719,9 +12720,7 @@
   // base classes.
   CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy,
   VK_RValue, RParenLoc);
-  CE->setTypeDependent(true);
-  CE->setValueDependent(true);
-  CE->setInstantiationDependent(true);
+  CE->addDependence(ExprDependence::TypeValueInstantiation);
   *Result = CE;
   return true;
 }
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -11,8 +11,10 @@
 //===--===//
 
 #include "clang/AST/TemplateName.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/DependencyFlags.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
@@ -168,52 +170,54 @@
   return TemplateName(Decl);
 }
 
-bool TemplateName::isDependent() const {
+TemplateNameD

[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

2020-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/AST/TemplateName.cpp:208
  "overloaded templates shouldn't survive to here");
+  D |= TemplateNameDependence::DependentInstantiation;
+  return D;

sammccall wrote:
> what's this line about?
this indicates that the template name is dependent if it doesn't refer to any 
known template declarations (getAsTemplateDecl() returns null). removing it 
will cause a test failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75529: [analyzer] Limit UCharMax to min of max uchar or max int

2020-03-03 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, Szelethus, NoQ.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, kristof.beyls, xazax.hun.
Herald added a project: clang.

This change is a follow up to commit 536456a7e93d73b9ff4e92f3e51d1aa1c72628fe 

and limits UCharMax to the min of the maximum values for the
architecture's maximum unsigned char or maximum int values. This is
required for architectures where these values are different than the
most commonly supported architectures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75529

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -510,8 +510,13 @@
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
   const RangeInt LongLongMax = BVF.getMaxValue(LongLongTy).getLimitedValue();
 
-  const RangeInt UCharMax =
-  BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue();
+  // Set UCharMax to min of int or uchar maximum value.
+  // The C standard states that functions like isalpha must be representable
+  // as an unsigned char. Their type is 'int', so the max value of the
+  // argument should be min(UCharMax, IntMax). This just happen to be true
+  // for commonly used and well tested ISAs, but not for others. 
+  const RangeInt UCharMax = std::min(
+  BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
   // The platform dependent value of EOF.
   // Try our best to parse this from the Preprocessor, otherwise fallback to 
-1.


Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -510,8 +510,13 @@
   const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
   const RangeInt LongLongMax = BVF.getMaxValue(LongLongTy).getLimitedValue();
 
-  const RangeInt UCharMax =
-  BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue();
+  // Set UCharMax to min of int or uchar maximum value.
+  // The C standard states that functions like isalpha must be representable
+  // as an unsigned char. Their type is 'int', so the max value of the
+  // argument should be min(UCharMax, IntMax). This just happen to be true
+  // for commonly used and well tested ISAs, but not for others. 
+  const RangeInt UCharMax = std::min(
+  BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
 
   // The platform dependent value of EOF.
   // Try our best to parse this from the Preprocessor, otherwise fallback to -1.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75340: [clang-tidy] Change checks to use new isLanguageVersionSupported restriction

2020-03-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h:30
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus17;
+  }

njames93 wrote:
> gribozavr2 wrote:
> > I think CPlusPlus17 implies CPlusPlus.
> This is saying it needs c++ but not c++17, so c++98->c++14 are Ok but not 17 
> or 20. Besides this is the current behaviour in the cpp file
Sorry, I misread and didn't notice the exclamation mark. Your edit makes sense 
to me.

I commented because I was comparing with the .cpp file which was not checking 
`CPlusPlus`:

```
void DefaultOperatorNewAlignmentCheck::registerMatchers(MatchFinder *Finder) {
  // Check not applicable in C++17 (or newer).
  if (getLangOpts().CPlusPlus17)
return;
```

So there is a tiny change here: previously, this check was being registered in 
non-C++ language modes, now it is not. I think your change to only enable in 
C++ modes is good, but again I think it would be best done in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75340



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


[PATCH] D75514: [Analyzer] Only add container note tags to the operations of te affected container

2020-03-03 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 247910.
baloghadamsoftware added a comment.

Alternative approach for debugging (instead of checking the source range): 
`clang_analyzer_express()` from `ExprInspection` marks its argument as 
interesting in the bug report. `DebugContainerModeling` propagates the 
interestingness from the symbol (begin or end symbol of the container) to the 
container itself.


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

https://reviews.llvm.org/D75514

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/test/Analysis/container-modeling.cpp

Index: clang/test/Analysis/container-modeling.cpp
===
--- clang/test/Analysis/container-modeling.cpp
+++ clang/test/Analysis/container-modeling.cpp
@@ -208,7 +208,7 @@
 
   clang_analyzer_denote(clang_analyzer_container_begin(V1), "$V1.begin()");
 
-  V2.push_back(n); // expected-note{{Container 'V2' extended to the right by 1 position}} FIXME: This note should not appear since `V2` is not affected in the "bug"
+  V2.push_back(n); // no note expected
 
   clang_analyzer_express(clang_analyzer_container_begin(V1)); // expected-warning{{$V1.begin()}}
  // expected-note@-1{{$V1.begin()}}
@@ -223,8 +223,7 @@
   clang_analyzer_denote(clang_analyzer_container_begin(V1), "$V1.begin()");
   clang_analyzer_denote(clang_analyzer_container_begin(V2), "$V2.begin()");
 
-  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 position}}
-   // expected-note@-1{{Container 'V1' extended to the right by 1 position}} FIXME: This should appear only once since there is only one "bug" where `V1` is affected
+  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 position}} -- Only once!
 
   clang_analyzer_express(clang_analyzer_container_begin(V1)); // expected-warning{{$V1.begin()}}
  // expected-note@-1{{$V1.begin()}}
Index: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -50,9 +50,11 @@
   typedef void (ExprInspectionChecker::*FnCheck)(const CallExpr *,
  CheckerContext &C) const;
 
-  ExplodedNode *reportBug(llvm::StringRef Msg, CheckerContext &C) const;
+  ExplodedNode *reportBug(llvm::StringRef Msg, CheckerContext &C,
+  SVal ExprVal = UndefinedVal()) const;
   ExplodedNode *reportBug(llvm::StringRef Msg, BugReporter &BR,
-  ExplodedNode *N) const;
+  ExplodedNode *N,
+  SVal ExprVal = UndefinedVal()) const;
 
 public:
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
@@ -134,22 +136,28 @@
 }
 
 ExplodedNode *ExprInspectionChecker::reportBug(llvm::StringRef Msg,
-   CheckerContext &C) const {
+   CheckerContext &C,
+   SVal ExprVal) const {
   ExplodedNode *N = C.generateNonFatalErrorNode();
-  reportBug(Msg, C.getBugReporter(), N);
+  reportBug(Msg, C.getBugReporter(), N, ExprVal);
   return N;
 }
 
 ExplodedNode *ExprInspectionChecker::reportBug(llvm::StringRef Msg,
BugReporter &BR,
-   ExplodedNode *N) const {
+   ExplodedNode *N,
+   SVal ExprVal) const {
   if (!N)
 return nullptr;
 
   if (!BT)
 BT.reset(new BugType(this, "Checking analyzer assumptions", "debug"));
 
-  BR.emitReport(std::make_unique(*BT, Msg, N));
+  auto R = std::make_unique(*BT, Msg, N);
+  if (!ExprVal.isUndef()) {
+R->markInteresting(ExprVal);
+  }
+  BR.emitReport(std::move(R));
   return N;
 }
 
@@ -396,7 +404,8 @@
 return;
   }
 
-  SymbolRef Sym = C.getSVal(CE->getArg(0)).getAsSymbol();
+  SVal ArgVal = C.getSVal(CE->getArg(0));
+  SymbolRef Sym = ArgVal.getAsSymbol();
   if (!Sym) {
 reportBug("Not a symbol", C);
 return;
@@ -409,7 +418,7 @@
 return;
   }
 
-  reportBug(*Str, C);
+  reportBug(*Str, C, ArgVal);
 }
 
 void ento::registerExprInspectionChecker(CheckerManager &Mgr) {
Index: clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
@@ -92,7 +92,17 @@
 

[PATCH] D71920: [AST] Refactor propagation of dependency bits. NFC

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



Comment at: clang/lib/AST/TemplateName.cpp:208
  "overloaded templates shouldn't survive to here");
+  D |= TemplateNameDependence::DependentInstantiation;
+  return D;

hokein wrote:
> sammccall wrote:
> > what's this line about?
> this indicates that the template name is dependent if it doesn't refer to any 
> known template declarations (getAsTemplateDecl() returns null). removing it 
> will cause a test failure.
oh, I missed the early return in the other case.
nit: I'd suggest a single return and put this in an else { ... }, which I think 
makes it slightly clearer that the two "parts" of this function are simply 
composed together. Up to you though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71920



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-03 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno 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/D75395/new/

https://reviews.llvm.org/D75395



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


[PATCH] D75514: [Analyzer] Only add container note tags to the operations of te affected container

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso added a comment.
This revision is now accepted and ready to land.

Cool, that one a lucky one! I think the SymbolRef based world also working, 
just at some point it could not scale because other systems are region based... 
For now, it is a much better solution, and this pattern to overload the 
callback with all the interestingness seems like the standard way of using 
NoteTags. Thanks!


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

https://reviews.llvm.org/D75514



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


[PATCH] D75445: [ARM,MVE] Add the `vshlcq` intrinsics.

2020-03-03 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki accepted this revision.
miyuki 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/D75445/new/

https://reviews.llvm.org/D75445



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


[PATCH] D75285: Mark restrict pointer or reference to const as invariant

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

In D75285#1902835 , @jeroen.dobbelaere 
wrote:

> In D75285#1902788 , @Anastasia wrote:
>
> > In D75285#1896610 , @rjmccall 
> > wrote:
> >
> > > Are you sure `restrict` alone isn't good enough?  It doesn't directly 
> > > tell you that the memory is invariant, but it's usually simple to prove 
> > > that the memory isn't modified within the `restrict` scope, which might 
> > > be sufficient.
> >
> >
> > Do you mean to prove in analysis passes? Should we emit some sort of hints 
> > from the frontend to indicate what to look for?
>
>
> Not sure what you mean with 'hints from the frontend', but D68484 
>  (and later) contain a significant 
> improvement to clang's handling of restrict. That could make the restrict 
> path feasible (if that would support the actual use case).


I think there are cases that noalias is not sufficient to prove invariance. For 
example, a global variable, even if we mark it as restrict and we do not modify 
it in a function, the compiler is still not sure it is invariant in that 
function, since it may be modified by another thread. In this case, if a user 
knows that it is invariant in that function, he would just want to mark it as 
`__invariant__` or `__immutable__`.


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

https://reviews.llvm.org/D75285



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


[PATCH] D64464: [CodeGen] Emit destructor calls to destruct compound literals

2020-03-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 247919.
ahatanak marked 5 inline comments as done.
ahatanak retitled this revision from "[CodeGen] Emit destructor calls for 
non-trivial C structs" to "[CodeGen] Emit destructor calls to destruct compound 
literals".
ahatanak edited the summary of this revision.
ahatanak added a comment.
Herald added a subscriber: ributzka.

Address review comments:

- Destruct compound literals of ObjC array types too.
- Use `pushLifetimeExtendedDestroy` to extend the lifetime of compound literals 
to the end of the surrounding block. This simplifies the changes made in IRGen, 
but I was wondering whether we should do what we do to extend lifetime of block 
captures instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64464

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/JumpDiagnostics.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-objc-arc-json.m
  clang/test/AST/ast-dump-stmt.m
  clang/test/CodeGenObjC/arc-ternary-op.m
  clang/test/CodeGenObjC/arc.m
  clang/test/CodeGenObjC/strong-in-c-struct.m
  clang/test/Import/objc-arc/Inputs/cleanup-objects.m
  clang/test/Import/objc-arc/test-cleanup-object.m
  clang/test/PCH/non-trivial-c-compound-literal.m
  clang/test/SemaObjC/strong-in-c-struct.m
  clang/tools/clang-import-test/clang-import-test.cpp

Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -64,6 +64,10 @@
   llvm::cl::desc("The language to parse (default: c++)"),
   llvm::cl::init("c++"));
 
+static llvm::cl::opt
+ObjCARC("objc-arc", llvm::cl::init(false),
+llvm::cl::desc("Emable ObjC ARC"));
+
 static llvm::cl::opt DumpAST("dump-ast", llvm::cl::init(false),
llvm::cl::desc("Dump combined AST"));
 
@@ -183,6 +187,8 @@
   Inv->getLangOpts()->ObjC = 1;
 }
   }
+  Inv->getLangOpts()->ObjCAutoRefCount = ObjCARC;
+
   Inv->getLangOpts()->Bool = true;
   Inv->getLangOpts()->WChar = true;
   Inv->getLangOpts()->Blocks = true;
Index: clang/test/SemaObjC/strong-in-c-struct.m
===
--- clang/test/SemaObjC/strong-in-c-struct.m
+++ clang/test/SemaObjC/strong-in-c-struct.m
@@ -54,3 +54,21 @@
   func(^{ func2(x); });
   goto *ips; // expected-error {{cannot jump}}
 }
+
+void test_compound_literal0(int cond, id x) {
+  switch (cond) {
+  case 0:
+(void)(Strong){ .a = x }; // expected-note {{jump enters lifetime of a compound literal that is non-trivial to destruct}}
+break;
+  default: // expected-error {{cannot jump from switch statement to this case label}}
+break;
+  }
+}
+
+void test_compound_literal1(id x) {
+  static void *ips[] = { &&L0 };
+L0:  // expected-note {{possible target of indirect goto}}
+  ;
+  (void)(Strong){ .a = x }; // expected-note {{jump exits lifetime of a compound literal that is non-trivial to destruct}}
+  goto *ips; // expected-error {{cannot jump}}
+}
Index: clang/test/PCH/non-trivial-c-compound-literal.m
===
--- /dev/null
+++ clang/test/PCH/non-trivial-c-compound-literal.m
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c -fobjc-arc -emit-pch -o %t %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c -fobjc-arc -include-pch %t -emit-llvm -o - %s | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+
+typedef struct {
+  id f;
+} S;
+
+static inline id getObj(id a) {
+  S *p = &(S){ .f = a };
+  return p->f;
+}
+
+#else
+
+// CHECK: %[[STRUCT_S:.*]] = type { i8* }
+
+// CHECK: define internal i8* @getObj(
+// CHECK: %[[_COMPOUNDLITERAL:.*]] = alloca %[[STRUCT_S]],
+// CHECK: %[[V5:.*]] = bitcast %[[STRUCT_S]]* %[[_COMPOUNDLITERAL]] to i8**
+// CHECK: call void @__destructor_8_s0(i8** %[[V5]])
+
+id test(id a) {
+  return getObj(a);
+}
+
+#endif
Index: clang/test/Import/objc-arc/test-cleanup-object.m
===
--- /dev/null
+++ clang/test/Import/objc-arc/test-cleanup-object.m
@@ -0,0 +1,10 @@
+// RUN: clang-import-test -x objective-c -objc-arc -import %S/Inputs/cleanup-objects.m -dump-ast -expression %s | FileCheck %s
+
+// CHECK: FunctionDecl {{.*}} getObj 

[PATCH] D75529: [analyzer] Limit UCharMax to min of max uchar or max int

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Could you add a test please? We really need tests for every patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75529



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


[PATCH] D64464: [CodeGen] Emit destructor calls to destruct compound literals

2020-03-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: test/Import/objc-arc/Inputs/cleanup-objects.m:6
+id getObj(int c, id a) {
+  // Commenting out the following line because AST importer crashes when trying
+  // to import a BlockExpr.

martong wrote:
> Perhaps then this patch depends on another patch which implements the import 
> of a BlockExpr?
> Or maybe the branch `if (auto *BD = From.dyn_cast())` should be 
> left out from the ASTImporter code, and this way BlockExpr and BlockDecl 
> would be implemented later in another patch.
Yes, I removed it from `ASTImporter::Import` and left a FIXME comment there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64464



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


[PATCH] D75529: [analyzer] Limit UCharMax to min of max uchar or max int

2020-03-03 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Looks good to me! Thanks!




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:514
+  // Set UCharMax to min of int or uchar maximum value.
+  // The C standard states that functions like isalpha must be representable
+  // as an unsigned char. Their type is 'int', so the max value of the

Perhaps it would be more precise to refer to the argument of these functions. 
So `The C standard states that the arguments of functions like isalpha must be 
representable ...`



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:517
+  // argument should be min(UCharMax, IntMax). This just happen to be true
+  // for commonly used and well tested ISAs, but not for others. 
+  const RangeInt UCharMax = std::min(

Could you please spell out `ISA`? Maybe it is just me but I don't know what 
that stands for.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75529



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


[PATCH] D64464: [CodeGen] Emit destructor calls to destruct compound literals

2020-03-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:4100
+  if (E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
+pushDestroy(QualType::DK_nontrivial_c_struct, DeclPtr, E->getType());
+

rjmccall wrote:
> rjmccall wrote:
> > Unfortunately, the lifetime of compound literals in C is not this simple; 
> > they're like blocks in that they're destroyed at the end of the enclosing 
> > scope rather than at the end of the current statement. (The cleanup here 
> > will be popped at the end of the full-expression if we've entered an 
> > `ExprWithCleanups`.) And the l-value case is exactly the case where this 
> > matters.
> > 
> > I think you need to do something like what we do with blocks, where we 
> > record all the blocks in the full-expression on the `ExprWithCleanups` so 
> > that we can push an inactive cleanup for them and then activate it when we 
> > emit the block.
> Can we make the check here something like (1) this is a block-scope compound 
> literal and (2) it has a non-trivially-destructed type (of any kind)?  That 
> way we're not conflating two potentially unrelated elements, the lifetime of 
> the object and the kinds of types that can be constructed by the literal.
> 
> Oh, actually, there's a concrete reason to do this: C99 compound literals are 
> not required to have struct type; they can have any object type, including 
> arrays but also scalars.  So we could, even without non-trivial C structs, 
> have a block-scope compound of type `__strong id[]`; I guess we've always 
> just gotten this wrong.  Please add tests for this case. :)
There is a check `E->isFileScope()` above this. Is that sufficient to check for 
block-scoped compound literals?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64464



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


[PATCH] D75514: [Analyzer] Only add container note tags to the operations of te affected container

2020-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I don't have any technical comments on this patch since I haven't used 
`NoteTags` yet, only a couple of readability ones.




Comment at: clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp:97-103
+  auto *PSBR = dyn_cast(&BR);
+  if (PSBR) {
+if (PSBR->isInteresting(Field)) {
+  PSBR->markInteresting(Cont);
+}
+  }
+  return "";

Probably a flattened version would be more readable.
```lang=c++
auto *PSBR = dyn_cast(&BR);
if (PSBR && PSBR->isInteresting(Field))
  PSBR->markInteresting(Cont);
return "";
```



Comment at: clang/test/Analysis/container-modeling.cpp:211
 
-  V2.push_back(n); // expected-note{{Container 'V2' extended to the right by 1 
position}} FIXME: This note should not appear since `V2` is not affected in the 
"bug"
+  V2.push_back(n); // no note expected
 

I'm not sure about the convention about using //dashes//, but I've seen 
multiple time comments like this:
`no-warning` etc. Probably a simple `no-note` or something would be more 
conventional?



Comment at: clang/test/Analysis/container-modeling.cpp:226
 
-  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 
position}}
-   // expected-note@-1{{Container 'V1' extended to the right 
by 1 position}} FIXME: This should appear only once since there is only one 
"bug" where `V1` is affected
+  V1.push_back(n); // expected-note{{Container 'V1' extended to the right by 1 
position}} -- Only once!
 

This line looks quite crowded, can't we use `expected-note@-1` here just like 
it was used previously?
The `only once` comment could be in a separate line as well, just to fit nicely.


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

https://reviews.llvm.org/D75514



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


  1   2   3   >