[PATCH] D104491: [Docs][Clang][Attr] mark no_stack_protector+no_sanitize GCC compatible

2021-06-18 Thread Marco Elver via Phabricator via cfe-commits
melver accepted this revision.
melver added a comment.
This revision is now accepted and ready to land.

There might be subtle inconsistencies between values accepted by our 
no_sanitize and GCC's no_sanitize, because of internal naming differences, but 
I couldn't say what those are right now (I think `no_sanitize("coverage")` only 
works with Clang, and GCC wants `no_sanitize_coverage` which we don't have due 
to not allowing new `no_sanitize_*`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104491

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


[PATCH] D102273: [analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

2021-06-18 Thread Abbas Sabra via Phabricator via cfe-commits
AbbasSabra added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102273

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


[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

Any input on the change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D104299: Handle interactions between reserved identifier and user-defined suffixes

2021-06-18 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 352938.
serge-sans-paille added a comment.

Reviews taken into account, I'm just not 100% sure of the fixit part. The out 
is the following:

  a.cpp:4:16: warning: identifier '_Bye' is reserved because it starts with '_' 
followed by a capital letter [-Wreserved-identifier]
  int operator"" _Bye(const char* s) {
  ~~~^~~~
  operator""_Bye
  1 warning generated.

Does that look good to you?


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

https://reviews.llvm.org/D104299

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/reserved-identifier.cpp

Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -76,7 +76,12 @@
 int _barbatruc; // no-warning
 }
 
-long double operator"" _BarbeBleue(long double) // expected-warning {{identifier 'operator""_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+long double operator"" _BarbeBleue(long double) // expected-warning {{identifier '_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+{
+  return 0.;
+}
+
+long double operator""_SacreBleue(long double) // no-warning
 {
   return 0.;
 }
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -484,8 +484,25 @@
 }
 
 bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
-  const UnqualifiedId &Name) {
+  const UnqualifiedId &Name, bool isUDSuffix) {
   assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId);
+  if (!isUDSuffix) {
+// [over.literal] p8
+// double operator""_Bq(long double);  // OK: does not use
+// the reserved identifier _­Bq ([lex.name]) double operator"" _Bq(long
+// double); // ill-formed, no diagnostic required:
+IdentifierInfo *II = Name.Identifier;
+auto Status = II->isReserved(PP.getLangOpts());
+auto Loc = Name.getEndLoc();
+if (Status != ReservedIdentifierStatus::NotReserved &&
+!PP.getSourceManager().isInSystemHeader(Loc)) {
+  Diag(Loc, diag::warn_reserved_extern_symbol)
+  << II << static_cast(Status)
+  << FixItHint::CreateReplacement(
+ Name.getSourceRange(),
+ (StringRef("operator\"\"") + II->getName()).str());
+}
+  }
 
   if (!SS.isValid())
 return false;
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -9,7 +9,6 @@
 // This file implements the Expression parsing implementation for C++.
 //
 //===--===//
-#include "clang/Parse/Parser.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
@@ -17,6 +16,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
@@ -2636,9 +2636,10 @@
 
 // Grab the literal operator's suffix, which will be either the next token
 // or a ud-suffix from the string literal.
+const bool isUDSuffix = !Literal.getUDSuffix().empty();
 IdentifierInfo *II = nullptr;
 SourceLocation SuffixLoc;
-if (!Literal.getUDSuffix().empty()) {
+if (isUDSuffix) {
   II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
   SuffixLoc =
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
@@ -2675,7 +2676,7 @@
 
 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
 
-return Actions.checkLiteralOperatorId(SS, Result);
+return Actions.checkLiteralOperatorId(SS, Result, isUDSuffix);
   }
 
   // Parse a conversion-function-id.
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1081,10 +1081,9 @@
 ReservedIdentifierStatus
 NamedDecl::isReserved(const LangOptions &LangOpts) const {
   const IdentifierInfo *II = getIdentifier();
-  if (!II)
-if (const auto *FD = dyn_cast(this))
-  II = FD->getLiteralIdentifier();
 
+  // This triggers at least for CXXLiteralIdentifiers, which we already checked
+  // at lexing time.
   if (!II)
 return ReservedIdentifierStatus::NotReserved;
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Se

[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

Looks good to me!
Sorry it took forever!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

Would it be possible to merge it for me, as I do not have a commit right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D103855: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 352957.
mizvekov added a comment.

rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103855

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Index: clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
@@ -159,7 +159,7 @@
 namespace PR48856 {
   struct A {
 auto operator<=>(const A &) const = default; // expected-warning {{implicitly deleted}}
-void (*x)(); // expected-note {{because there is no viable three-way comparison function for member 'x'}}
+void (*x)(); // expected-note {{does not support relational comparisons}}
   };
 
   struct B {
@@ -191,4 +191,13 @@
 a2 f;
   };
   std::partial_ordering cmp_b2 = b2() <=> b2();
+
+  struct a3 {
+using fp = void (*)();
+operator fp() const;
+  };
+  struct b3 {
+auto operator<=>(b3 const &) const = default; // expected-warning {{implicitly deleted}}
+a3 f; // expected-note {{would compare member 'f' as 'void (*)()', which does not support relational comparisons}}
+  };
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7749,16 +7749,11 @@
 
 if (Args[0]->getType()->isOverloadableType())
   S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
-else if (OO == OO_EqualEqual ||
- !Args[0]->getType()->isFunctionPointerType()) {
+else
   // FIXME: We determine whether this is a valid expression by checking to
   // see if there's a viable builtin operator candidate for it. That isn't
   // really what the rules ask us to do, but should give the right results.
-  //
-  // Note that the builtin operator for relational comparisons on function
-  // pointers is the only known case which cannot be used.
   S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, CandidateSet);
-}
 
 Result R;
 
@@ -7802,11 +7797,14 @@
   return Result::deleted();
   }
 
-  // C++2a [class.compare.default]p3 [P2002R0]:
-  //   A defaulted comparison function is constexpr-compatible if [...]
-  //   no overlod resolution performed [...] results in a non-constexpr
-  //   function.
+  bool NeedsDeducing =
+  OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType();
+
   if (FunctionDecl *BestFD = Best->Function) {
+// C++2a [class.compare.default]p3 [P2002R0]:
+//   A defaulted comparison function is constexpr-compatible if
+//   [...] no overlod resolution performed [...] results in a
+//   non-constexpr function.
 assert(!BestFD->isDeleted() && "wrong overload resolution result");
 // If it's not constexpr, explain why not.
 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
@@ -7819,10 +7817,8 @@
   return Result::deleted();
 }
 R.Constexpr &= BestFD->isConstexpr();
-  }
 
-  if (OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType()) {
-if (auto *BestFD = Best->Function) {
+if (NeedsDeducing) {
   // If any callee has an undeduced return type, deduce it now.
   // FIXME: It's not clear how a failure here should be handled. For
   // now, we produce an eager diagnostic, because that is forward
@@ -7848,10 +7844,9 @@
 }
 return Result::deleted();
   }
-  if (auto *Info = S.Context.CompCategories.lookupInfoForType(
-  BestFD->getCallResultType())) {
-R.Category = Info->Kind;
-  } else {
+  auto *Info = S.Context.CompCategories.lookupInfoForType(
+  BestFD->getCallResultType());
+  if (!Info) {
 if (Diagnose == ExplainDeleted) {
   S.Diag(Subobj.Loc, diag::note_defaulted_comparison_cannot_deduce)
   << Subobj.Kind << Subobj.Decl
@@ -7862,12 +7857,25 @@
 }
 return Result::deleted();
   }
-} else {
-  QualType T = Best->BuiltinParamTypes[0];
-  assert(T == Best->BuiltinParamTypes[1] &&
- "builtin comparison for different types?");
-  assert(Best->BuiltinParamTypes[2].isNull() &&
- "invalid builtin comparison");
+  R.Category = Info->Kind;
+}
+  } else {
+QualType T = Best->BuiltinParamTypes[0];
+assert(T == Best->BuiltinParamTypes[1] &&
+   "builtin comparison for different types?");
+assert(Best

[PATCH] D104491: [Docs][Clang][Attr] mark no_stack_protector+no_sanitize GCC compatible

2021-06-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

This change breaks code by removing the `[[clang::no_sanitize]]` spelling (and 
the fact that zero tests broke show we're missing test coverage here). We don't 
currently have a spelling to represent an attribute known to both Clang and 
GCC, nor do we currently have any attributes that use both the `Clang` and 
`GCC` spellings (which both include a `GNU` spelling that would be duplicated). 
I think you should keep the `Clang` spelling, add a `GCC` spelling, make sure 
that ClangAttrEmitter.cpp does not generate two `GNU` spellings for it, and add 
some basic test coverage for the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104491

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This is missing all of the usual semantic tests (attribute accepts no args, 
applies only to functions, etc).




Comment at: clang/include/clang/Basic/Attr.td:1975
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];

Should this also be supported on ObjC methods?



Comment at: clang/include/clang/Basic/AttrDocs.td:2566
+Use the ``no_profile`` attribute on a function declaration to denote that the
+compiler should not instrument the function with profile related
+instrumentation, such as via the




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D103855: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ddd15cd5dea: [clang] Exclude function pointers on 
DefaultedComparisonAnalyzer (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103855

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Index: clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
@@ -159,7 +159,7 @@
 namespace PR48856 {
   struct A {
 auto operator<=>(const A &) const = default; // expected-warning {{implicitly deleted}}
-void (*x)(); // expected-note {{because there is no viable three-way comparison function for member 'x'}}
+void (*x)(); // expected-note {{does not support relational comparisons}}
   };
 
   struct B {
@@ -191,4 +191,13 @@
 a2 f;
   };
   std::partial_ordering cmp_b2 = b2() <=> b2();
+
+  struct a3 {
+using fp = void (*)();
+operator fp() const;
+  };
+  struct b3 {
+auto operator<=>(b3 const &) const = default; // expected-warning {{implicitly deleted}}
+a3 f; // expected-note {{would compare member 'f' as 'void (*)()', which does not support relational comparisons}}
+  };
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7749,16 +7749,11 @@
 
 if (Args[0]->getType()->isOverloadableType())
   S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
-else if (OO == OO_EqualEqual ||
- !Args[0]->getType()->isFunctionPointerType()) {
+else
   // FIXME: We determine whether this is a valid expression by checking to
   // see if there's a viable builtin operator candidate for it. That isn't
   // really what the rules ask us to do, but should give the right results.
-  //
-  // Note that the builtin operator for relational comparisons on function
-  // pointers is the only known case which cannot be used.
   S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, CandidateSet);
-}
 
 Result R;
 
@@ -7802,11 +7797,14 @@
   return Result::deleted();
   }
 
-  // C++2a [class.compare.default]p3 [P2002R0]:
-  //   A defaulted comparison function is constexpr-compatible if [...]
-  //   no overlod resolution performed [...] results in a non-constexpr
-  //   function.
+  bool NeedsDeducing =
+  OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType();
+
   if (FunctionDecl *BestFD = Best->Function) {
+// C++2a [class.compare.default]p3 [P2002R0]:
+//   A defaulted comparison function is constexpr-compatible if
+//   [...] no overlod resolution performed [...] results in a
+//   non-constexpr function.
 assert(!BestFD->isDeleted() && "wrong overload resolution result");
 // If it's not constexpr, explain why not.
 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
@@ -7819,10 +7817,8 @@
   return Result::deleted();
 }
 R.Constexpr &= BestFD->isConstexpr();
-  }
 
-  if (OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType()) {
-if (auto *BestFD = Best->Function) {
+if (NeedsDeducing) {
   // If any callee has an undeduced return type, deduce it now.
   // FIXME: It's not clear how a failure here should be handled. For
   // now, we produce an eager diagnostic, because that is forward
@@ -7848,10 +7844,9 @@
 }
 return Result::deleted();
   }
-  if (auto *Info = S.Context.CompCategories.lookupInfoForType(
-  BestFD->getCallResultType())) {
-R.Category = Info->Kind;
-  } else {
+  auto *Info = S.Context.CompCategories.lookupInfoForType(
+  BestFD->getCallResultType());
+  if (!Info) {
 if (Diagnose == ExplainDeleted) {
   S.Diag(Subobj.Loc, diag::note_defaulted_comparison_cannot_deduce)
   << Subobj.Kind << Subobj.Decl
@@ -7862,12 +7857,25 @@
 }
 return Result::deleted();
   }
-} else {
-  QualType T = Best->BuiltinParamTypes[0];
-  assert(T == Best->BuiltinParamTypes[1] &&
- "builtin comparison for different types?");
-  assert(Best->BuiltinParamTypes[2].isNull() &&
- "invalid builtin comparison");
+  R.Category = Info->Kind;
+}
+  } else {
+Qu

[clang] 7ddd15c - [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-18 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-18T13:07:47+02:00
New Revision: 7ddd15cd5dea76a19a9c5315e2a9903d74a49be8

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

LOG: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

This implements a more comprehensive fix than was done at D95409.
Instead of excluding just function pointer subobjects, we also
exclude any user-defined function pointer conversion operators.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c07e6f9d7421a..33aa5d0483e9c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9143,6 +9143,9 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
+def note_defaulted_comparison_selected_invalid : Note<
+  "would compare %select{|member|base class}0 %1 "
+  "as %2, which does not support relational comparisons">;
 def err_incorrect_defaulted_comparison_constexpr : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
   "three-way comparison operator}0 "

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d39837d277045..5109f1e877a26 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7749,16 +7749,11 @@ class DefaultedComparisonAnalyzer
 
 if (Args[0]->getType()->isOverloadableType())
   S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
-else if (OO == OO_EqualEqual ||
- !Args[0]->getType()->isFunctionPointerType()) {
+else
   // FIXME: We determine whether this is a valid expression by checking to
   // see if there's a viable builtin operator candidate for it. That isn't
   // really what the rules ask us to do, but should give the right results.
-  //
-  // Note that the builtin operator for relational comparisons on function
-  // pointers is the only known case which cannot be used.
   S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, 
CandidateSet);
-}
 
 Result R;
 
@@ -7802,11 +7797,14 @@ class DefaultedComparisonAnalyzer
   return Result::deleted();
   }
 
-  // C++2a [class.compare.default]p3 [P2002R0]:
-  //   A defaulted comparison function is constexpr-compatible if [...]
-  //   no overlod resolution performed [...] results in a non-constexpr
-  //   function.
+  bool NeedsDeducing =
+  OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType();
+
   if (FunctionDecl *BestFD = Best->Function) {
+// C++2a [class.compare.default]p3 [P2002R0]:
+//   A defaulted comparison function is constexpr-compatible if
+//   [...] no overlod resolution performed [...] results in a
+//   non-constexpr function.
 assert(!BestFD->isDeleted() && "wrong overload resolution result");
 // If it's not constexpr, explain why not.
 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
@@ -7819,10 +7817,8 @@ class DefaultedComparisonAnalyzer
   return Result::deleted();
 }
 R.Constexpr &= BestFD->isConstexpr();
-  }
 
-  if (OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType()) {
-if (auto *BestFD = Best->Function) {
+if (NeedsDeducing) {
   // If any callee has an undeduced return type, deduce it now.
   // FIXME: It's not clear how a failure here should be handled. For
   // now, we produce an eager diagnostic, because that is forward
@@ -7848,10 +7844,9 @@ class DefaultedComparisonAnalyzer
 }
 return Result::deleted();
   }
-  if (auto *Info = S.Context.CompCategories.lookupInfoForType(
-  BestFD->getCallResultType())) {
-R.Category = Info->Kind;
-  } else {
+  auto *Info = S.Context.CompCategories.lookupInfoForType(
+  BestFD->getCallResultType());
+  if (!Info) {
 if (Diagnose == ExplainDeleted) {
   S.Diag(Subobj.Loc, diag::note_defaulted_comparison_cannot_deduce)
   << Subobj.Kind << Subobj.Decl
@@ -7862,12 +7857,25 @@ class DefaultedComparisonAnalyzer
 }
   

[PATCH] D104442: [libclang] Fix error handler in translateSourceLocation.

2021-06-18 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.

This change is pretty obvious. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104442

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


[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D103025#2826482 , 
@tomasz-kaminski-sonarsource wrote:

> Would it be possible to merge it for me, as I do not have a commit right?

Sure thing!
Which email should I set for commit author?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D103702: [AArch64][SVE] Wire up vscale_range attribute to SVE min/max vector queries

2021-06-18 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm accepted this revision.
paulwalker-arm added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64Subtarget.cpp:350-352
 unsigned AArch64Subtarget::getMaxSVEVectorSizeInBits() const {
   assert(HasSVE && "Tried to get SVE vector length without SVE support!");
+  return MaxSVEVectorSizeInBits;

Up to you but now these are simple accessors, is it worth having the 
implementations inlined into the header?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103702

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


[PATCH] D97204: [RFC] Clang 64-bit source locations

2021-06-18 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

Thanks to @miyuki for repeating the previous benchmark with this version of the 
patch (and on the same machine as before, which was better than I could have 
done).

The revised results now have the memory usage increase (compared to 32-bit 
SourceLocation) in the region of 5.5% to 7.5% instead of 8% to 9%. In detail:

- average memory usage during a clang build increased by 6.858 ± 0.260 %
- peak memory usage during a clang build increased by 5.529 ± 1.641 %
- memory usage during parsing of TraMP3d source file increased by 7.32 %

The change in speed between the previous version of the patch and this one is 
negligible (both values are within the uncertainty interval of the other one).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97204

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


[clang] fd569a1 - [libclang] Fix error handler in translateSourceLocation.

2021-06-18 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2021-06-18T13:43:14+01:00
New Revision: fd569a11b585d13cdceac2d890c2beda0fa5f0eb

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

LOG: [libclang] Fix error handler in translateSourceLocation.

Given an invalid SourceLocation, translateSourceLocation will call
clang_getNullLocation, and then do nothing with the result. But
clang_getNullLocation has no side effects: it just constructs and
returns a null CXSourceLocation value.

Surely the intention was to //return// that null CXSourceLocation to
the caller, instead of throwing it away and pressing on anyway.

Reviewed By: miyuki

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

Added: 


Modified: 
clang/tools/libclang/CXSourceLocation.h

Removed: 




diff  --git a/clang/tools/libclang/CXSourceLocation.h 
b/clang/tools/libclang/CXSourceLocation.h
index ce3d09e1c9eb8..c86f6850375bb 100644
--- a/clang/tools/libclang/CXSourceLocation.h
+++ b/clang/tools/libclang/CXSourceLocation.h
@@ -29,7 +29,7 @@ static inline CXSourceLocation
 translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
 SourceLocation Loc) {
   if (Loc.isInvalid())
-clang_getNullLocation();
+return clang_getNullLocation();
 
   CXSourceLocation Result = { { &SM, &LangOpts, },
   Loc.getRawEncoding() };



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


[PATCH] D104442: [libclang] Fix error handler in translateSourceLocation.

2021-06-18 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd569a11b585: [libclang] Fix error handler in 
translateSourceLocation. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104442

Files:
  clang/tools/libclang/CXSourceLocation.h


Index: clang/tools/libclang/CXSourceLocation.h
===
--- clang/tools/libclang/CXSourceLocation.h
+++ clang/tools/libclang/CXSourceLocation.h
@@ -29,7 +29,7 @@
 translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
 SourceLocation Loc) {
   if (Loc.isInvalid())
-clang_getNullLocation();
+return clang_getNullLocation();
 
   CXSourceLocation Result = { { &SM, &LangOpts, },
   Loc.getRawEncoding() };


Index: clang/tools/libclang/CXSourceLocation.h
===
--- clang/tools/libclang/CXSourceLocation.h
+++ clang/tools/libclang/CXSourceLocation.h
@@ -29,7 +29,7 @@
 translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
 SourceLocation Loc) {
   if (Loc.isInvalid())
-clang_getNullLocation();
+return clang_getNullLocation();
 
   CXSourceLocation Result = { { &SM, &LangOpts, },
   Loc.getRawEncoding() };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99005: [clang] Implement P2266 Simpler implicit move

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 352985.
mizvekov added a comment.

fix ctidy warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
  clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp
  clang/test/SemaCXX/return-stack-addr.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1278,6 +1278,11 @@
   https://wg21.link/p1102r2";>P1102R2
   Clang 13
 
+
+  Simpler implicit move
+  https://wg21.link/p2266r1";>P2266R1
+  Clang 13
+
 
 
 
Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx20%s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx98_11 %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_20,cxx98_11 %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -8,17 +9,17 @@
 }
 
 struct CopyOnly {
-  CopyOnly();
-  CopyOnly(CopyOnly &);
+  CopyOnly();   // cxx2b-note {{not viable}}
+  CopyOnly(CopyOnly &); // cxx2b-note {{not viable}}
 };
-TEST(CopyOnly);
+TEST(CopyOnly); // cxx2b-error {{no matching constructor}}
 
 struct CopyNoMove {
   CopyNoMove();
   CopyNoMove(CopyNoMove &);
-  CopyNoMove(CopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+  CopyNoMove(CopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(CopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+TEST(CopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct MoveOnly {
   MoveOnly();
@@ -30,9 +31,9 @@
 struct NoCopyNoMove {
   NoCopyNoMove();
   NoCopyNoMove(NoCopyNoMove &) = delete;
-  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(NoCopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+TEST(NoCopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct ConvertingRVRef {
   ConvertingRVRef();
@@ -50,11 +51,11 @@
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20-note {{marked deleted here}}
+  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only 

[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

For the author information use:
Tomasz Kamiński
tomasz.kamin...@sonarsource.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

2021-06-18 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added inline comments.



Comment at: clang/include/clang/AST/Expr.h:4961
+  /// - `nullptr` for invalid index (`i < 0` or `i >= array_size`).
+  const Expr *getExprForConstArrayByRawIndex(int64_t Idx) const;
+

I think in most (all?) other methods in this class, array indices are unsigned 
in the API.  If the array index itself comes from an expression that is 
negative (i.e., a literal negative integer, or an constant expression that 
evaluates to a negative number), that has to be handled correctly, but I'm not 
sure this is the right place to do it.  As this code stands, if an integer 
literal used used, which is greater than LONG_MAX, but less than ULONG_MAX, it 
will be end up being treated as invalid in this method, won't it?



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1671
   if (auto CI = R->getIndex().getAs()) {
 int64_t i = CI->getValue().getSExtValue();
+const Expr *E = InitList->getExprForConstArrayByRawIndex(i);

I see where you got the int64_t from -- that's what getSExtValue() returns.  
So, if the literal const index value in the expr is greater than LONG_MAX (but 
less than ULONG_MAX, of course), this would assert.  That seems undesirable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104285

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


[clang] cc2ef19 - [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Valeriy Savchenko via cfe-commits

Author: Tomasz Kamiński
Date: 2021-06-18T16:32:19+03:00
New Revision: cc2ef195560999d0690a8d8805ea811270e38f26

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

LOG: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

This fixes a crash in MallocChecker for the situation when operator new 
(delete) is invoked via NTTP  and makes the behavior of 
CallContext.getCalleeDecl(Expr) identical to CallEvent.getDecl().

Reviewed By: vsavchenko

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
clang/test/Analysis/NewDelete-checker-test.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp 
b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
index 3d44d2cbc069d..3d64ce453479f 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -19,6 +19,10 @@ using namespace clang;
 using namespace ento;
 
 const FunctionDecl *CheckerContext::getCalleeDecl(const CallExpr *CE) const {
+  const FunctionDecl *D = CE->getDirectCallee();
+  if (D)
+return D;
+
   const Expr *Callee = CE->getCallee();
   SVal L = Pred->getSVal(Callee);
   return L.getAsFunctionDecl();

diff  --git a/clang/test/Analysis/NewDelete-checker-test.cpp 
b/clang/test/Analysis/NewDelete-checker-test.cpp
index 5a8711fa8a7ad..86df9d01dfb01 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -421,3 +421,36 @@ void shouldNotReportLeak() {
   Derived *p = (Derived *)allocate();
   delete p;
 }
+
+template
+void* allocate_via_nttp(size_t n) {
+  return allocate_fn(n);
+}
+
+template
+void deallocate_via_nttp(void* ptr) {
+  deallocate_fn(ptr);
+}
+
+void testNTTPNewNTTPDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  deallocate_via_nttp<::operator delete>(p);
+} // no warn
+
+void testNTTPNewDirectDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  ::operator delete(p);
+} // no warn
+
+void testDirectNewNTTPDelete() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp<::operator delete>(p);
+}
+
+void not_free(void*) {
+}
+
+void testLeakBecauseNTTPIsNotDeallocation() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp(p);
+}  // leak-warning{{Potential leak of memory pointed to by 'p'}}



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


[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc2ef1955609: [analyzer] Handle NTTP invocation in 
CallContext.getCalleeDecl() (authored by tomasz-kaminski-sonarsource, committed 
by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

Files:
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/test/Analysis/NewDelete-checker-test.cpp


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -421,3 +421,36 @@
   Derived *p = (Derived *)allocate();
   delete p;
 }
+
+template
+void* allocate_via_nttp(size_t n) {
+  return allocate_fn(n);
+}
+
+template
+void deallocate_via_nttp(void* ptr) {
+  deallocate_fn(ptr);
+}
+
+void testNTTPNewNTTPDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  deallocate_via_nttp<::operator delete>(p);
+} // no warn
+
+void testNTTPNewDirectDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  ::operator delete(p);
+} // no warn
+
+void testDirectNewNTTPDelete() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp<::operator delete>(p);
+}
+
+void not_free(void*) {
+}
+
+void testLeakBecauseNTTPIsNotDeallocation() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp(p);
+}  // leak-warning{{Potential leak of memory pointed to by 'p'}}
Index: clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -19,6 +19,10 @@
 using namespace ento;
 
 const FunctionDecl *CheckerContext::getCalleeDecl(const CallExpr *CE) const {
+  const FunctionDecl *D = CE->getDirectCallee();
+  if (D)
+return D;
+
   const Expr *Callee = CE->getCallee();
   SVal L = Pred->getSVal(Callee);
   return L.getAsFunctionDecl();


Index: clang/test/Analysis/NewDelete-checker-test.cpp
===
--- clang/test/Analysis/NewDelete-checker-test.cpp
+++ clang/test/Analysis/NewDelete-checker-test.cpp
@@ -421,3 +421,36 @@
   Derived *p = (Derived *)allocate();
   delete p;
 }
+
+template
+void* allocate_via_nttp(size_t n) {
+  return allocate_fn(n);
+}
+
+template
+void deallocate_via_nttp(void* ptr) {
+  deallocate_fn(ptr);
+}
+
+void testNTTPNewNTTPDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  deallocate_via_nttp<::operator delete>(p);
+} // no warn
+
+void testNTTPNewDirectDelete() {
+  void* p = allocate_via_nttp<::operator new>(10);
+  ::operator delete(p);
+} // no warn
+
+void testDirectNewNTTPDelete() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp<::operator delete>(p);
+}
+
+void not_free(void*) {
+}
+
+void testLeakBecauseNTTPIsNotDeallocation() {
+  void* p = ::operator new(10);
+  deallocate_via_nttp(p);
+}  // leak-warning{{Potential leak of memory pointed to by 'p'}}
Index: clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -19,6 +19,10 @@
 using namespace ento;
 
 const FunctionDecl *CheckerContext::getCalleeDecl(const CallExpr *CE) const {
+  const FunctionDecl *D = CE->getDirectCallee();
+  if (D)
+return D;
+
   const Expr *Callee = CE->getCallee();
   SVal L = Pred->getSVal(Callee);
   return L.getAsFunctionDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103025: [analyzer] Handle NTTP invocation in CallContext.getCalleeDecl()

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103025

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


[PATCH] D103849: Fix undeduced type when instanciating template member

2021-06-18 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@rsmith : any opinion on that one?


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

https://reviews.llvm.org/D103849

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


[PATCH] D104536: WIP: [clang][deps] Avoid minimizing PCH input files

2021-06-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch avoid minimizing input files that contributed to a PCH or its 
modules. This prevents the implicit modular build to fail on unexpected file 
size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104536

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -6,7 +6,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
 // RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_pch.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
@@ -127,9 +127,8 @@
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu.json
-// FIXME: Make this work with '-mode preprocess-minimized-sources'.
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
 //
 // CHECK-TU:  -[[PREFIX:.*]]
@@ -193,7 +192,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu_with_common.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU-WITH-COMMON
 //
 // CHECK-TU-WITH-COMMON:  -[[PREFIX:.*]]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -46,25 +46,72 @@
   DependencyConsumer &C;
 };
 
-/// A listener that collects the names and paths to imported modules.
-class ImportCollectingListener : public ASTReaderListener {
-  using PrebuiltModuleFilesT =
-  decltype(HeaderSearchOptions::PrebuiltModuleFiles);
-
+/// A listener that collects the imported modules and optionally input files of
+/// prebuilt module files.
+class PrebuiltModuleListener : public ASTReaderListener {
 public:
-  ImportCollectingListener(PrebuiltModuleFilesT &PrebuiltModuleFiles)
-  : PrebuiltModuleFiles(PrebuiltModuleFiles) {}
+  PrebuiltModuleListener(llvm::StringMap &PrebuiltModuleFiles,
+ llvm::StringSet<> &InputFiles, bool VisitInputFiles)
+  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
+VisitInputFiles(VisitInputFiles) {}
 
   bool needsImportVisitation() const override { return true; }
+  bool needsInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
-PrebuiltModuleFiles[std::string(ModuleName)] = std::string(Filename);
+PrebuiltModuleFiles.insert({ModuleName, Filename.str()});
+  }
+
+  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
+  bool isExplicitModule) override {
+InputFiles.insert(Filename);
+return true;
   }
 
 private:
-  PrebuiltModuleFilesT &PrebuiltModuleFiles;
+  llvm::StringMap &PrebuiltModuleFiles;
+  llvm::StringSet<> &InputFiles;
+  bool VisitInputFiles;
 };
 
+using PrebuiltModuleFilesT = decltype(HeaderSearchOptions::PrebuiltModuleFiles);
+
+/// Iteratively collect all prebuilt modules that are part of the PCH and
+/// the contributing input files.
+static void visitPrebuiltModules(CompilerInstance &Compiler,
+ PrebuiltModuleFilesT &ModuleFiles,
+ llvm::StringSet<> &InputFiles,
+ bool VisitInputFiles) {
+  if (Compiler.getPreprocessorOpts().ImplicitPCHInclude.empty())
+return;
+
+  // Maps module name to the PCM path.
+  llvm::StringMap ModuleFilesWorklist;
+
+  PrebuiltModuleListener Listener(ModuleFi

[PATCH] D104539: [Sema][SVE] Properly match builtin ID when using aux target

2021-06-18 Thread Bradley Smith via Phabricator via cfe-commits
bsmith created this revision.
bsmith added reviewers: paulwalker-arm, peterwaller-arm, joechrisellis, 
sdesmalen.
Herald added subscribers: psnobl, tschuett.
Herald added a reviewer: efriedma.
Herald added a reviewer: aaron.ballman.
bsmith requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104539

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/aarch64-sve-alias-attribute.c


Index: clang/test/Sema/aarch64-sve-alias-attribute.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-alias-attribute.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -aux-triple 
aarch64-none-unknown-eabi -target-feature +sve -fopenmp-is-device -fopenmp 
-verify -fsyntax-only %s
+
+static __inline__ 
__attribute__((__clang_arm_builtin_alias(__builtin_sve_svabd_n_f64_m))) // 
expected-no-diagnostics
+void nop(void);
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5163,7 +5163,9 @@
   return ArmBuiltinAliasValid(BuiltinID, AliasName, Map, IntrinNames);
 }
 
-static bool ArmSveAliasValid(unsigned BuiltinID, StringRef AliasName) {
+static bool ArmSveAliasValid(ASTContext &Context, unsigned BuiltinID, 
StringRef AliasName) {
+  if (Context.BuiltinInfo.isAuxBuiltinID(BuiltinID))
+BuiltinID = Context.BuiltinInfo.getAuxBuiltinID(BuiltinID);
   return BuiltinID >= AArch64::FirstSVEBuiltin &&
  BuiltinID <= AArch64::LastSVEBuiltin;
 }
@@ -5180,7 +5182,7 @@
   StringRef AliasName = cast(D)->getIdentifier()->getName();
 
   bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
-  if ((IsAArch64 && !ArmSveAliasValid(BuiltinID, AliasName)) ||
+  if ((IsAArch64 && !ArmSveAliasValid(S.Context, BuiltinID, AliasName)) ||
   (!IsAArch64 && !ArmMveAliasValid(BuiltinID, AliasName) &&
!ArmCdeAliasValid(BuiltinID, AliasName))) {
 S.Diag(AL.getLoc(), diag::err_attribute_arm_builtin_alias);
@@ -5210,7 +5212,7 @@
   bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
   bool IsARM = S.Context.getTargetInfo().getTriple().isARM();
   bool IsRISCV = S.Context.getTargetInfo().getTriple().isRISCV();
-  if ((IsAArch64 && !ArmSveAliasValid(BuiltinID, AliasName)) ||
+  if ((IsAArch64 && !ArmSveAliasValid(S.Context, BuiltinID, AliasName)) ||
   (IsARM && !ArmMveAliasValid(BuiltinID, AliasName) &&
!ArmCdeAliasValid(BuiltinID, AliasName)) ||
   (IsRISCV && !RISCVAliasValid(BuiltinID, AliasName)) ||


Index: clang/test/Sema/aarch64-sve-alias-attribute.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-alias-attribute.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -aux-triple aarch64-none-unknown-eabi -target-feature +sve -fopenmp-is-device -fopenmp -verify -fsyntax-only %s
+
+static __inline__ __attribute__((__clang_arm_builtin_alias(__builtin_sve_svabd_n_f64_m))) // expected-no-diagnostics
+void nop(void);
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5163,7 +5163,9 @@
   return ArmBuiltinAliasValid(BuiltinID, AliasName, Map, IntrinNames);
 }
 
-static bool ArmSveAliasValid(unsigned BuiltinID, StringRef AliasName) {
+static bool ArmSveAliasValid(ASTContext &Context, unsigned BuiltinID, StringRef AliasName) {
+  if (Context.BuiltinInfo.isAuxBuiltinID(BuiltinID))
+BuiltinID = Context.BuiltinInfo.getAuxBuiltinID(BuiltinID);
   return BuiltinID >= AArch64::FirstSVEBuiltin &&
  BuiltinID <= AArch64::LastSVEBuiltin;
 }
@@ -5180,7 +5182,7 @@
   StringRef AliasName = cast(D)->getIdentifier()->getName();
 
   bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
-  if ((IsAArch64 && !ArmSveAliasValid(BuiltinID, AliasName)) ||
+  if ((IsAArch64 && !ArmSveAliasValid(S.Context, BuiltinID, AliasName)) ||
   (!IsAArch64 && !ArmMveAliasValid(BuiltinID, AliasName) &&
!ArmCdeAliasValid(BuiltinID, AliasName))) {
 S.Diag(AL.getLoc(), diag::err_attribute_arm_builtin_alias);
@@ -5210,7 +5212,7 @@
   bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
   bool IsARM = S.Context.getTargetInfo().getTriple().isARM();
   bool IsRISCV = S.Context.getTargetInfo().getTriple().isRISCV();
-  if ((IsAArch64 && !ArmSveAliasValid(BuiltinID, AliasName)) ||
+  if ((IsAArch64 && !ArmSveAliasValid(S.Context, BuiltinID, AliasName)) ||
   (IsARM && !ArmMveAliasValid(BuiltinID, AliasName) &&
!ArmCdeAliasValid(BuiltinID, AliasName)) ||
   (IsRISCV && !RISCVAliasValid(BuiltinID, AliasName)) ||
___
cfe-commits 

[PATCH] D104465: [clang][deps] Prevent PCH validation failures by padding minimized files

2021-06-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for sharing your ideas! I've left my initial thoughts below, but I want 
to revisit this and think about it some more.

In D104465#2825343 , @dexonsmith 
wrote:

> I'm not sure this is the right approach.
>
> - Don't PCHs sometimes validate based on hashes of inputs instead of size? At 
> least, that has been discussed, and this patch would block making the change.

The hash-based validation only kicks in when modification times don't match. 
The size of input files is always* validated 
.

> - Can PCHs embed inputs, like modules can? How would that work (or not) 
> minimized sources generally?

I think PCHs can embed inputs the same way modules can. When reading an AST 
file, the embedded input files get registered in the current compilation along 
with their buffers via `SourceManager::createFileID`.
But it doesn't seem to be propagated to the `FileManager` level, which the 
input file size check uses. I might need to experiment with this a bit to fully 
understand how this works in practice.

> - What happens if the PCH has a delayed diagnostic, triggered when parsing 
> the next thing? Will the fix-it point in the wrong place? (Are there other 
> things that depend on reading the original sources when reading a PCH?)

Can you point me to the code that handles delayed diagnostics? I can't find 
anything related in `ASTWriter`.

> A few other ideas:
>
> 1. Disable PCH validation when minimizing. (Is that less robust than your 
> current workaround? If so, can you explain why?)

I think PCH validation (and detection of out-of-date input files) is still 
useful for the dependency scanner as it might help debugging build failures 
(e.g. if the input files changed between explicit PCH build and TU dependency 
scan).
Compared to disabling PCH validation, padding of minimized files is fairly 
local change that isn't susceptible to concurrency bugs and integrates with the 
rest of the implicit build infrastructure fairly well IMO.

> 2. Use the original PCH header in the scanning `-cc1`s (translate 
> `-include-pch` to `-include`) and switch back in the generated `-cc1`s (back 
> to `-include-pch`).

The two separate dependency scans (one for PCH, one for TU) could end up using 
different context hashes and we don't have an easy way to detect this.
If they both use a common module A, the explicitly-built PCH would contains 
version 1 of A, while the TU would attempt to build with version 2. This is 
currently not supported in explicit builds AFAIK.
The current implementation works around this by always choosing the module 
present in the explicitly-built module. How could we make this situation work 
here?

> 3. Embed instructions in the PCH for how to build it, and make a "minimized" 
> version of the PCH.

That could work. This makes me think if we could emit a minimized PCH during 
the PCH scan and just reuse it in the TU scan (similarly how we're currently 
reusing the explicitly-built PCH, but with the file size issues gone). Though 
passing state from one dependency scan to another through the filesystem might 
be unreliable.

In D104465#2825786 , @dexonsmith 
wrote:

> Two more options to consider:
>
> 4. If a compilation uses a PCH, use the original files for any input file 
> transitively referenced by the PCH. Can be done by using a filesystem overlay 
> that skips over the minimization layer for those files, or could tell the 
> minimization layer not to minimize those files. You can figure out the files 
> by adding a free function that preloads the PCH and extracts out all the 
> input files.

I tend to prefer this option, since it integrates fairly well with the current 
way we build PCHs in XCBuild.
I have a WIP patch that implements this: D104536 
. I plan to run some benchmarks to see the 
performance impact compared to minification + padding.

> 5. Add support for building/using a PCH, and only support PCHes that are 
> built this way. E.g., add a `-include-pch-auto` option or something. Scanner 
> would use `-include`, spit out a command for building a PCH using explicit 
> modules, and the generated `-cc1`s would use `-include-pch` to refer to it. 
> This way all the modules are generated "in house".

This would be the ideal solution IMO, but needs build system support.



BTW: I noticed the file size stored in AST also plays role when deciding 
whether to import or include header. `HeaderSearch::findModuleForHeader` calls 
`HeaderSearch::getExistingFileInfo` which pulls information (such as the file 
size) from `ExternalSource` (a.k.a. `ASTReader`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104465

__

[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2021-06-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D103930#2825181 , @dexonsmith 
wrote:

> In D103930#2820725 , @bruno wrote:
>
>> Thanks for working on this, comments inline. @vsapsai @jansvoboda11 
>> @dexonsmith any headermap related concerns on your side?
>
> @jansvoboda11, I think it'd be prudent for us to test this patch out 
> internally before it's landed, since I don't really trust that the existing 
> unit tests cover all the interactions between header maps and modules. Might 
> you be able to coordinate something with @arphaman?

I'm OOO until July 7. @arphaman, can you take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103930

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


[PATCH] D104539: [Sema][SVE] Properly match builtin ID when using aux target

2021-06-18 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen 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/D104539/new/

https://reviews.llvm.org/D104539

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


[clang] ced6b20 - [clang] Implement P2266 Simpler implicit move

2021-06-18 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-18T17:08:59+02:00
New Revision: ced6b204d18e6eed611f8ebf27122ec19147ea7a

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

LOG: [clang] Implement P2266 Simpler implicit move

This Implements 
[[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html|P2266 
Simpler implicit move]].

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp
clang/test/SemaObjCXX/block-capture.mm
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7ec89a33e00c..db389922ae3a1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4763,7 +4763,7 @@ class Sema final {
 bool isMoveEligible() const { return S != None; };
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
-  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index b87e2c2bea80d..b450216dcc8b7 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1965,9 +1965,17 @@ static void checkEscapingByref(VarDecl *VD, Sema &S) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
-  ExprResult Result = S.PerformMoveOrCopyInitialization(
-  InitializedEntity::InitializeBlock(Loc, T, false),
-  Sema::NamedReturnInfo{VD, Sema::NamedReturnInfo::MoveEligible}, VarRef);
+  ExprResult Result;
+  auto IE = InitializedEntity::InitializeBlock(Loc, T, false);
+  if (S.getLangOpts().CPlusPlus2b) {
+auto *E = ImplicitCastExpr::Create(S.Context, T, CK_NoOp, VarRef, nullptr,
+   VK_XValue, FPOptionsOverride());
+Result = S.PerformCopyInitialization(IE, SourceLocation(), E);
+  } else {
+Result = S.PerformMoveOrCopyInitialization(
+IE, Sema::NamedReturnInfo{VD, Sema::NamedReturnInfo::MoveEligible},
+VarRef);
+  }
 
   if (!Result.isInvalid()) {
 Result = S.MaybeCreateExprWithCleanups(Result);

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 187e7a0516d10..cec80436d575e 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -994,22 +994,10 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, 
Expr *E,
 E = R.get();
   }
 
-  // Move the return value if we can
-  NamedReturnInfo NRInfo = getNamedReturnInfo(E, /*ForceCXX20=*/true);
-  if (NRInfo.isMoveEligible()) {
-InitializedEntity Entity = InitializedEntity::InitializeResult(
-Loc, E->getType(), NRInfo.Candidate);
-ExprResult MoveResult = PerformMoveOrCopyInitialization(Entity, NRInfo, E);
-if (MoveResult.get())
-  E = MoveResult.get();
-  }
-
-  // FIXME: If the operand is a reference to a variable that's about to go out
-  // of scope, we should treat the operand as an xvalue for this overload
-  // resolution.
   VarDecl *Promise = FSI->CoroutinePromise;
   ExprResult PC;
   if (E && (isa(E) || !E->getType()->isVoidType())) {
+getNamedReturnInfo(E, /*ForceCXX2b=*/true);
 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
   } else {
 E = MakeFullDiscardedValueExpr(E).get();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9d554b5b3a909..a57c5ad198e1b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -854,10 +854,6 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 Diag(OpLoc, diag::err_omp_simd_region_ca

[PATCH] D99005: [clang] Implement P2266 Simpler implicit move

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGced6b204d18e: [clang] Implement P2266 Simpler implicit move 
(authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
  clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp
  clang/test/SemaCXX/return-stack-addr.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1278,6 +1278,11 @@
   https://wg21.link/p1102r2";>P1102R2
   Clang 13
 
+
+  Simpler implicit move
+  https://wg21.link/p2266r1";>P2266R1
+  Clang 13
+
 
 
 
Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx20%s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx98_11 %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_20,cxx98_11 %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -8,17 +9,17 @@
 }
 
 struct CopyOnly {
-  CopyOnly();
-  CopyOnly(CopyOnly &);
+  CopyOnly();   // cxx2b-note {{not viable}}
+  CopyOnly(CopyOnly &); // cxx2b-note {{not viable}}
 };
-TEST(CopyOnly);
+TEST(CopyOnly); // cxx2b-error {{no matching constructor}}
 
 struct CopyNoMove {
   CopyNoMove();
   CopyNoMove(CopyNoMove &);
-  CopyNoMove(CopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+  CopyNoMove(CopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(CopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+TEST(CopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct MoveOnly {
   MoveOnly();
@@ -30,9 +31,9 @@
 struct NoCopyNoMove {
   NoCopyNoMove();
   NoCopyNoMove(NoCopyNoMove &) = delete;
-  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(NoCopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+TEST(NoCopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct ConvertingRVRef {
   ConvertingRVRef();
@@ -50,11 +51,11 @@
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20-note {{marked deleted here}}
+  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s
-// R

[PATCH] D104500: DRAFT: [clang] Apply P1825 as DR for all modes below C++20.

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 353009.
mizvekov added a comment.

rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b   %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -37,31 +37,31 @@
 
 struct ConvertingRVRef {
   ConvertingRVRef();
-  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+  ConvertingRVRef(ConvertingRVRef &) = delete;
 
   struct X {};
   ConvertingRVRef(X &&);
   operator X() const & = delete;
   operator X() &&;
 };
-TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+TEST(ConvertingRVRef);
 
 struct ConvertingCLVRef {
   ConvertingCLVRef();
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx98_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
+  operator X() && = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx98_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
   SubMove();
-  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+  SubMove(SubMove &) = delete;
 
   SubMove(SubSubMove &&);
 };
-TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
+TEST(SubMove);
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ /dev/null
@@ -1,351 +0,0 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b,cxx2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-
-// definitions for std::move
-namespace std {
-inline namespace foo {
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-
-template  typename remove_reference::type &&move(T &&t);
-} // namespace foo
-} // namespace std
-
-struct Instrument {
-Instrument() {}
-Instrument(Instrument&&) { /* MOVE */ }
-Instrument(const Instrument&) { /* COPY */ }
-};
-struct ConvertFromBase { Instrument i; };
-struct ConvertFromDerived { Instrument i; };
-struct Base {
-Instrument i;
-operator ConvertFromBase() const& { return ConvertFromBase{i}; }
-operator ConvertFromBase() && { return ConvertFromBase{std::move(i)}; }
-};
-struc

[PATCH] D104540: [clangd] Dont index ObjCCategoryDecls for completion

2021-06-18 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: dgoldman.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

They are already provided by Sema, deserializing from preamble if need
be. Moreover category names are meaningless outside interface/implementation
context, hence they were only causing noise.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104540

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -552,8 +552,9 @@
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(
   QName("Person"), QName("Person::someMethodName:lastName:"),
-  QName("MyCategory"), QName("Person::someMethodName2:"),
-  QName("MyProtocol"), QName("MyProtocol::someMethodName3:")));
+  AllOf(QName("MyCategory"), ForCodeCompletion(false)),
+  QName("Person::someMethodName2:"), QName("MyProtocol"),
+  QName("MyProtocol::someMethodName3:")));
 }
 
 TEST_F(SymbolCollectorTest, ObjCPropertyImpl) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3221,6 +3221,45 @@
   UnorderedElementsAre(Labeled("ECHO(X)"), Labeled("ECHO2(X)")));
 }
 
+TEST(CompletionTest, ObjCCategoryDecls) {
+  TestTU TU;
+  TU.ExtraArgs.push_back("-xobjective-c");
+  TU.HeaderCode = R"objc(
+  @interface Foo
+  @end
+
+  @interface Foo (FooExt1)
+  @end
+
+  @interface Foo (FooExt2)
+  @end
+
+  @interface Bar
+  @end
+
+  @interface Bar (BarExt)
+  @end)objc";
+
+  {
+Annotations Test(R"objc(
+  @implementation Foo (^)
+  @end
+  )objc");
+TU.Code = Test.code().str();
+auto Results = completions(TU, Test.point());
+EXPECT_THAT(Results.Completions,
+UnorderedElementsAre(Labeled("FooExt1"), Labeled("FooExt2")));
+  }
+  {
+Annotations Test(R"objc(
+  @interface Foo (^)
+  @end
+  )objc");
+TU.Code = Test.code().str();
+auto Results = completions(TU, Test.point());
+EXPECT_THAT(Results.Completions, UnorderedElementsAre(Labeled("BarExt")));
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -62,6 +62,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
@@ -1910,6 +1911,13 @@
   if (isExplicitTemplateSpecialization(&ND))
 return false;
 
+  // Category decls are not useful on their own outside the interface or
+  // implementation blocks. Moreover, sema already provides completion for
+  // these, even if it requires preamble deserialization. So by excluding them
+  // from the index, we reduce the noise in all the other completion scopes.
+  if (llvm::isa(&ND))
+return false;
+
   if (InTopLevelScope(ND))
 return true;
 


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -552,8 +552,9 @@
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(
   QName("Person"), QName("Person::someMethodName:lastName:"),
-  QName("MyCategory"), QName("Person::someMethodName2:"),
-  QName("MyProtocol"), QName("MyProtocol::someMethodName3:")));
+  AllOf(QName("MyCategory"), ForCodeCompletion(false)),
+  QName("Person::someMethodName2:"), QName("MyProtocol"),
+  QName("MyProtocol::someMethodName3:")));
 }
 
 TEST_F(SymbolCollectorTest, ObjCPropertyImpl) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3221,6 +3221,45 @@
   UnorderedElementsAre(Labeled("ECHO(X)"), Labeled("ECHO2(X)")));
 }
 
+TEST(CompletionTest,

[PATCH] D104540: [clangd] Dont index ObjCCategoryDecls for completion

2021-06-18 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1918
+  // from the index, we reduce the noise in all the other completion scopes.
+  if (llvm::isa(&ND))
+return false;

Seems like we should also ignore ObjCCategoryImplDecl, I think those would have 
the same issue (although only from other .m files in the project, not from SDK 
headers)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104540

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


[PATCH] D103426: Clang: Extend format string checking to wprintf/wscanf

2021-06-18 Thread Marcus Johnson via Phabricator via cfe-commits
MarcusJohnson91 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103426

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


[PATCH] D88666: DirectoryWatcher: add an implementation for Windows

2021-06-18 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova added a comment.

I wasn't able to reproduce this locally by running *just* the DirectoryWatcher 
tests. I'm not running all of the clang tests repeatedly to see if I can get a 
repro that way.

The online tests appear to always hang either in the InitialScanAsync or 
InvalidatedWatcherAsync based on the log from the failures. We are using a 
non-OS drive for the tests, but it is not a network drive. The hang is also 
very consistent in our online testing - every couple of runs, sometimes more 
often. I suspect one of the reasons I cannot reproduce it locally with ease is 
that the test machines are able to run more tests in parallel and faster.

  [==] Running 1 test from 1 test suite.
  
  [--] Global test environment set-up.
  
  [--] 1 test from DirectoryWatcherTest
  
  [ RUN  ] DirectoryWatcherTest.InvalidatedWatcherAsync
  
  
  
  Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Terminate batch 
job (Y/N)? 
interrupted by user, skipping remaining tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88666

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


[PATCH] D103612: [flang][driver] Add `-fno-unparse-typed-exprs`

2021-06-18 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 353032.
awarzynski added a comment.

Refine the semantics after some discussion offline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/unparse-typed-exprs.f95
  flang/tools/f18/f18.cpp
  flang/tools/f18/flang

Index: flang/tools/f18/flang
===
--- flang/tools/f18/flang
+++ flang/tools/f18/flang
@@ -8,7 +8,7 @@
 #======#
 
 wd=$(cd $(dirname "$0")/.. && pwd)
-opts="-module-suffix .f18.mod "
+opts="-fno-unparse-typed-exprs -module-suffix .f18.mod "
 if ! $wd/bin/f18 $opts "$@"
 then status=$?
  echo flang: in $PWD, f18 failed with exit status $status: $wd/bin/f18 $opts "$@" >&2
Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -105,7 +105,7 @@
   bool debugModuleWriter{false};
   bool defaultReal8{false};
   bool measureTree{false};
-  bool unparseTypedExprsToF18_FC{false};
+  bool unparseTypedExprsAsFortran{false};
   std::vector F18_FCArgs;
   const char *prefix{nullptr};
   bool getDefinition{false};
@@ -322,7 +322,8 @@
 Unparse(llvm::outs(), parseTree, driver.encoding, true /*capitalize*/,
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
-nullptr /* action before each statement */, &asFortran);
+nullptr /* action before each statement */,
+driver.unparseTypedExprsAsFortran ? nullptr : &asFortran);
 return {};
   }
   if (driver.dumpPreFirTree) {
@@ -353,7 +354,7 @@
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
 nullptr /* action before each statement */,
-driver.unparseTypedExprsToF18_FC ? &asFortran : nullptr);
+driver.unparseTypedExprsAsFortran ? nullptr : &asFortran);
   }
 
   RunOtherCompiler(driver, tmpSourcePath.data(), relo.data());
@@ -578,8 +579,8 @@
 } else if (arg == "-funparse-with-symbols" ||
 arg == "-fdebug-unparse-with-symbols") {
   driver.dumpUnparseWithSymbols = true;
-} else if (arg == "-funparse-typed-exprs-to-f18-fc") {
-  driver.unparseTypedExprsToF18_FC = true;
+} else if (arg == "-funparse-typed-exprs-as-fortran") {
+  driver.unparseTypedExprsAsFortran = true;
 } else if (arg == "-fparse-only" || arg == "-fsyntax-only") {
   driver.syntaxOnly = true;
 } else if (arg == "-c") {
Index: flang/test/Driver/unparse-typed-exprs.f95
===
--- /dev/null
+++ flang/test/Driver/unparse-typed-exprs.f95
@@ -0,0 +1,34 @@
+! Tests `-funparse-typed-exprs-as-fortran` frontend option
+
+!--
+! RUN lines
+!--
+! RUN: %flang_fc1 -fdebug-unparse  %s | FileCheck %s --check-prefix=DEFAULT
+! RUN: %flang_fc1 -fdebug-unparse -funparse-typed-exprs-as-fortran %s | FileCheck %s --check-prefix=AS_FORTRAN
+
+!--
+! EXPECTED OUTPUT: default
+!--
+! DEFAULT: PROGRAM test_allocated
+! DEFAULT-NEXT:  INTEGER :: i = 13_4
+! DEFAULT-NEXT:  REAL(KIND=2_4), ALLOCATABLE :: x(:)
+! DEFAULT-NEXT:  IF (.NOT.allocated(x)) ALLOCATE(x(i))
+! DEFAULT-NEXT: END PROGRAM test_allocated
+
+!-
+! EXPECTED OUTPUT: unparsed as Fortran
+!--
+! AS_FORTRAN: PROGRAM test_allocated
+! AS_FORTRAN-NEXT:  INTEGER :: i = 13
+! AS_FORTRAN-NEXT:  REAL(KIND=2), ALLOCATABLE :: x(:)
+! AS_FORTRAN-NEXT:  IF (.NOT.allocated(x)) ALLOCATE(x(i))
+! AS_FORTRAN-NEXT: END PROGRAM test_allocated
+
+!--
+! INPUT
+!--
+program test_allocated
+  integer :: i = 13
+  real(2), allocatable :: x(:)
+  if (.not. allocated(x)) allocate(x(i))
+end program test_allocated
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -101,8 +101,12 @@
 ! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
+! HELP-FC1-NEXT: -fno-unparse-typed-exprs
+! HELP-FC1-NEXT:Don't unparse typed expressions
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenm

[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

2021-06-18 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan updated this revision to Diff 353035.
scchan added a comment.

Adding test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104392

Files:
  clang/lib/Headers/__clang_hip_runtime_wrapper.h
  clang/test/Headers/hip-header.hip


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -14,6 +14,30 @@
 
 // expected-no-diagnostics
 
+// Check support for pure and deleted virtual functions
+struct base {
+  __host__
+  __device__
+  virtual void pv() = 0;
+  __host__
+  __device__
+  virtual void dv() = delete;
+};
+struct derived:base {
+  __host__
+  __device__
+  virtual void pv() override {};
+};
+__device__ void foo(derived* b) {
+derived d;
+}
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 
x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* 
@_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x 
i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* 
@__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
+
+// CHECK: define{{.*}}void @__cxa_pure_virtual()
+// CHECK: define{{.*}}void @__cxa_deleted_virtual()
+
+
 struct Number {
   __device__ Number(float _x) : x(_x) {}
   float x;
@@ -61,3 +85,4 @@
 __device__ float test_max() {
   return max(5, 6.0);
 }
+
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -14,6 +14,30 @@
 
 // expected-no-diagnostics
 
+// Check support for pure and deleted virtual functions
+struct base {
+  __host__
+  __device__
+  virtual void pv() = 0;
+  __host__
+  __device__
+  virtual void dv() = delete;
+};
+struct derived:base {
+  __host__
+  __device__
+  virtual void pv() override {};
+};
+__device__ void foo(derived* b) {
+derived d;
+}
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* @_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+
+// CHECK: define{{.*}}void @__cxa_pure_virtual()
+// CHECK: define{{.*}}void @__cxa_deleted_virtual()
+
+
 struct Number {
   __device__ Number(float _x) : x(_x) {}
   float x;
@@ -61,3 +85,4 @@
 __device__ float test_max() {
   return max(5, 6.0);
 }
+
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, xazax.hun, martong, steakhal, Szelethus, 
ASDenysPetrov, manas, RedDocMD.
Herald added subscribers: dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, 
rnkovacs, szepet, baloghadamsoftware, mgorny.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This commit adds a function to the top-class of SVal hierarchy to
provide type information about the value.  That can be extremely
useful when this is the only piece of information that the user is
actually caring about.

Additionally, this commit introduces a testing framework for writing
unit-tests for symbolic values.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104550

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -0,0 +1,303 @@
+//===- unittests/StaticAnalyzer/SvalTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+// getType() tests include whole bunch of type comparisons,
+// so when something is wrong, it's good to have gtest telling us
+// what are those types.
+LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
+   const QualType &T) {
+  return OS << T.getAsString();
+}
+
+namespace ento {
+namespace {
+
+//===--===//
+//   Testing framework implementation
+//===--===//
+
+/// A simple map from variable names to symbolic values used to init them.
+using SVals = llvm::StringMap;
+
+/// SValCollector is the barebone of all tests.
+///
+/// It is implemented as a checker and reacts to binds, so we find
+/// symbolic values of interest, and to end analysis, where we actually
+/// can test whatever we gathered.
+class SValCollector : public Checker {
+public:
+  void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+// Skip instantly if we finished testing.
+// Also, we care only for binds happening in variable initializations.
+if (Tested || !isa(S))
+  return;
+
+if (const auto *VR = llvm::dyn_cast_or_null(Loc.getAsRegion())) {
+  CollectedSVals[VR->getDescriptiveName(false)] = Val;
+}
+  }
+
+  void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,
+ExprEngine &Engine) const {
+if (!Tested) {
+  test(Engine);
+  Tested = true;
+  CollectedSVals.clear();
+}
+  }
+
+  /// Helper function for tests to access bound symbolic values.
+  SVal getByName(StringRef Name) const { return CollectedSVals[Name]; }
+
+private:
+  /// Entry point for tests.
+  virtual void test(ExprEngine &Engine) const = 0;
+
+  mutable bool Tested = false;
+  mutable SVals CollectedSVals;
+};
+
+// SVAL_TEST is a combined way of providing a short code snippet and
+// to test some programmatic predicates on symbolic values produced by the
+// engine for the actual code.
+//
+// Each test has a NAME.  One can think of it as a name for normal gtests.
+//
+// Each test should provide a CODE snippet.  Code snippets might contain any
+// valid C/C++, but have ONLY ONE defined function.  There are no requirements
+// about function's name or parameters.  It can even be a class method.  The
+// body of the function must contain a set of variable declarations.  Each
+// variable declaration gets bound to a symbolic value, so for the following

[PATCH] D103612: [flang][driver] Add `-funparse-typed-exprs-as-fortran`

2021-06-18 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

> The default behaviour is to always decorate unparsed typed expression with 
> e.g. their KIND. The new flag can be used to turn this off, so that the 
> generated output uses valid Fortran syntax and can be fed to another Fortran 
> compiler.

The output of Expr::AsFortran() should be valid Fortran, and it's a bug if 
it's not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

2021-06-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks! pls remove the extra line when committing.




Comment at: clang/test/Headers/hip-header.hip:88
 }
+

extrac line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104392

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


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-18 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Hey folks!

I was thinking that this method can be quite handy.
I think it would be great to have another pair of eyes (but more would be 
better) to look into this and:

- Suggest other test cases to add
- See if I missed any "typed" values from the hierarchy
- See if `getType` for supported types does make sense

In particular, it would be great to hear your thoughts on `SymolicRegion` 
because it's not that obvious that we should return that type or not.  On one 
hand, this is the best we've got, on the other hand, it can be misleading.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D103612: [flang][driver] Add `-funparse-typed-exprs-as-fortran`

2021-06-18 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D103612#2827444 , @klausler wrote:

>> The default behaviour is to always decorate unparsed typed expression with 
>> e.g. their KIND. The new flag can be used to turn this off, so that the 
>> generated output uses valid Fortran syntax and can be fed to another Fortran 
>> compiler.
>
> The output of Expr::AsFortran() should be valid Fortran, and it's a bug if 
> it's not.

This is the output that I get from the unparser (input file: 
flang/test/Driver/unparse-typed-exprs.f95):

  PROGRAM test_allocated
   INTEGER :: i = 13_4
   REAL(KIND=2_4), ALLOCATABLE :: x(:)
   IF (.NOT.allocated(x)) ALLOCATE(x(i))
  END PROGRAM test_allocated

This is not valid, is it? Or am I missing something?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D103612: [flang][driver] Add `-funparse-typed-exprs-as-fortran`

2021-06-18 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

In D103612#2827458 , @awarzynski 
wrote:

> In D103612#2827444 , @klausler 
> wrote:
>
>>> The default behaviour is to always decorate unparsed typed expression with 
>>> e.g. their KIND. The new flag can be used to turn this off, so that the 
>>> generated output uses valid Fortran syntax and can be fed to another 
>>> Fortran compiler.
>>
>> The output of Expr::AsFortran() should be valid Fortran, and it's a bug 
>> if it's not.
>
> This is the output that I get from the unparser (input file: 
> flang/test/Driver/unparse-typed-exprs.f95):
>
>   PROGRAM test_allocated
>INTEGER :: i = 13_4
>REAL(KIND=2_4), ALLOCATABLE :: x(:)
>IF (.NOT.allocated(x)) ALLOCATE(x(i))
>   END PROGRAM test_allocated
>
> This is not valid, is it? Or am I missing something?

Kind suffixes are described in subclause 7.4.3 of Fortran 2018, e.g. R708 on p. 
58.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

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


[PATCH] D104124: [IR] Simplify createReplacementInstr

2021-06-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104124

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


[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

2021-06-18 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan updated this revision to Diff 353041.
scchan added a comment.

Minor clean up in the hip-header.hip test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104392

Files:
  clang/lib/Headers/__clang_hip_runtime_wrapper.h
  clang/test/Headers/hip-header.hip


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -14,6 +14,29 @@
 
 // expected-no-diagnostics
 
+// Check support for pure and deleted virtual functions
+struct base {
+  __host__
+  __device__
+  virtual void pv() = 0;
+  __host__
+  __device__
+  virtual void dv() = delete;
+};
+struct derived:base {
+  __host__
+  __device__
+  virtual void pv() override {};
+};
+__device__ void test_vf() {
+derived d;
+}
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 
x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* 
@_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x 
i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* 
@__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
+
+// CHECK: define{{.*}}void @__cxa_pure_virtual()
+// CHECK: define{{.*}}void @__cxa_deleted_virtual()
+
 struct Number {
   __device__ Number(float _x) : x(_x) {}
   float x;
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -14,6 +14,29 @@
 
 // expected-no-diagnostics
 
+// Check support for pure and deleted virtual functions
+struct base {
+  __host__
+  __device__
+  virtual void pv() = 0;
+  __host__
+  __device__
+  virtual void dv() = delete;
+};
+struct derived:base {
+  __host__
+  __device__
+  virtual void pv() override {};
+};
+__device__ void test_vf() {
+derived d;
+}
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* @_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*)] }, comdat, align 8
+
+// CHECK: define{{.*}}void @__cxa_pure_virtual()
+// CHECK: define{{.*}}void @__cxa_deleted_virtual()
+
 struct Number {
   __device__ Number(float _x) : x(_x) {}
   float x;
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added inline comments.



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:3
+// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:  -analyzer-config 
cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
+// RUN:  -analyzer-output=text -std=c++20 %s -verify=expected

NoQ wrote:
> RedDocMD wrote:
> > NoQ wrote:
> > > Could you double-check that this flag correctly disables all the newly 
> > > introduced modeling so that it wasn't accidentally enabled for all users 
> > > before it's ready?
> > Yup. There are 133 notes and warnings (just search for "// expected-" and 
> > see the count). And on setting the flag to `false`, there are 133 errors.
> > So it works.
> I mean, specifically the modeling added by this patch? I see you wrote an 
> entire checker callback that doesn't seem to have an analyzer-config option 
> check anywhere in it. Simply having different results isn't sufficient to 
> verify this.
Oh I see.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D104248: [compiler-rt][hwasan] Refactor Thread::Init

2021-06-18 Thread Leonard Chan via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG88d93923e665: [compiler-rt][hwasan] Move Thread::Init into 
hwasan_linux.cpp (authored by leonardchan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104248

Files:
  compiler-rt/lib/hwasan/hwasan_linux.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp
  compiler-rt/lib/hwasan/hwasan_thread.h


Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,8 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);  // Must be 
called from the thread itself.
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
   void InitRandomState();
+  void InitStackAndTls();
+
+  // Must be called from the thread itself.
+  void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size);
+
   void Destroy();
 
   uptr stack_top() { return stack_top_; }
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -44,6 +44,12 @@
   if (auto sz = flags()->heap_history_size)
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
+  InitStackAndTls();
+  InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
+}
+
+void Thread::InitStackRingBuffer(uptr stack_buffer_start,
+ uptr stack_buffer_size) {
   HwasanTSDThreadInit();  // Only needed with interceptors.
   uptr *ThreadLong = GetCurrentThreadLongPtr();
   // The following implicitly sets (this) as the current thread.
@@ -55,13 +61,6 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
-  uptr tls_size;
-  uptr stack_size;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, 
&tls_begin_,
-   &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
   if (stack_bottom_) {
 int local;
 CHECK(AddrIsInStack((uptr)&local));
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -427,6 +427,14 @@
   HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr);
 }
 
+void Thread::InitStackAndTls() {
+  uptr tls_size;
+  uptr stack_size;
+  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, 
&tls_begin_,
+   &tls_size);
+  stack_top_ = stack_bottom_ + stack_size;
+  tls_end_ = tls_begin_ + tls_size;
+}
 
 } // namespace __hwasan
 


Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,8 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);  // Must be called from the thread itself.
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
   void InitRandomState();
+  void InitStackAndTls();
+
+  // Must be called from the thread itself.
+  void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size);
+
   void Destroy();
 
   uptr stack_top() { return stack_top_; }
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -44,6 +44,12 @@
   if (auto sz = flags()->heap_history_size)
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
+  InitStackAndTls();
+  InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
+}
+
+void Thread::InitStackRingBuffer(uptr stack_buffer_start,
+ uptr stack_buffer_size) {
   HwasanTSDThreadInit();  // Only needed with interceptors.
   uptr *ThreadLong = GetCurrentThreadLongPtr();
   // The following implicitly sets (this) as the current thread.
@@ -55,13 +61,6 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
-  uptr tls_size;
-  uptr stack_size;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
-   &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
   if (stack_bottom_) {
 int local;
 CHECK(AddrIsInStack((uptr)&local));
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_li

[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

In D103750#2825342 , @NoQ wrote:

> In D103750#2823741 , @RedDocMD 
> wrote:
>
>> I would suppose that constructor calls are properly handled. (ie, member 
>> constructors are called properly).
>
> Do the above tests pass when your new `evalCall` modeling is enabled?

The analyzer doesn't seem to be able to make up its mind.

  member-constructor.cpp:15:5: warning: FALSE [debug.ExprInspection]
  clang_analyzer_eval(*P->p == 0);
  ^~~
  member-constructor.cpp:15:25: note: Assuming the condition is false
  clang_analyzer_eval(*P->p == 0);
  ^~
  member-constructor.cpp:15:5: note: FALSE
  clang_analyzer_eval(*P->p == 0);
  ^~~
  member-constructor.cpp:15:5: warning: TRUE [debug.ExprInspection]
  clang_analyzer_eval(*P->p == 0);
  ^~~
  member-constructor.cpp:15:25: note: Assuming the condition is true
  clang_analyzer_eval(*P->p == 0);
  ^~
  member-constructor.cpp:15:5: note: TRUE
  clang_analyzer_eval(*P->p == 0);
  ^~~
  2 warnings generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 353048.
RedDocMD added a comment.

Little changes, a failing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -1,10 +1,17 @@
 // RUN: %clang_analyze_cc1\
-// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
+// RUN:  -analyzer-output=text -std=c++20 %s -verify=expected
+
+// RUN: %clang_analyze_cc1\
+// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr,debug.ExprInspection\
 // RUN:  -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
 // RUN:  -analyzer-output=text -std=c++11 %s -verify=expected
 
 #include "Inputs/system-header-simulator-cxx.h"
 
+void clang_analyzer_eval(bool);
+
 class A {
 public:
   A(){};
@@ -313,3 +320,54 @@
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void makeUniqueReturnsNonNullUniquePtr() {
+  auto P = std::make_unique();
+  if (!P) {   // expected-note {{Taking false branch}}
+P->foo(); // should have no warning here, path is impossible
+  }
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  // Now P is null
+  if (!P) {
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+#if __cplusplus >= 202002L
+
+void makeUniqueForOverwriteReturnsNullUniquePtr() {
+  auto P = std::make_unique_for_overwrite();
+  if (!P) {   // expected-note {{Taking false branch}}
+P->foo(); // should have no warning here, path is impossible
+  }
+  P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
+  // Now P is null
+  if (!P) {
+// expected-note@-1 {{Taking true branch}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+#endif
+
+struct G {
+  int *p;
+  G(int *p): p(p) {}
+  ~G() { *p = 0; }
+};
+
+void foo() {
+  int x = 1;
+  {
+auto P = std::make_unique(&x);
+clang_analyzer_eval(*P->p == 1); // expected-warning {{TRUE [debug.ExprInspection]}}
+// expected-note@-1 {{TRUE}}
+// expected-note@-2 {{Assuming condition is true}}
+  }
+  clang_analyzer_eval(x == 0); // expected-warning {{TRUE [debug.ExprInspection]}}
+  // expected-note@-1 {{TRUE}}
+  // expected-note@-2 {{Assuming condition is true}}
+}
\ No newline at end of file
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -978,6 +978,17 @@
 void swap(unique_ptr &x, unique_ptr &y) noexcept {
   x.swap(y);
 }
+
+template 
+unique_ptr make_unique(Args &&...args);
+
+#if __cplusplus >= 202002L
+
+template 
+unique_ptr make_unique_for_overwrite();
+
+#endif
+
 } // namespace std
 #endif
 
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -192,12 +192,19 @@
   const LocationContext *LCtx,
   unsigned VisitCount) {
   QualType T = E->getType();
-  assert(Loc::isLocType(T));
-  assert(SymbolManager::canSymbolicate(T));
-  if (T->isNullPtrType())
-return makeZeroVal(T);
+  return getConjuredHeapSymbolVal(E, LCtx, T, VisitCount);
+}
+
+DefinedOrUnknownSVal
+SValBuilder::getConjuredHeapSymbolVal(const Expr *E,
+  const LocationContext *LCtx,
+  QualType type, unsigned VisitCount) {
+  assert(Loc::isLocType(type));
+  assert(SymbolManager::canSymbolicate(type));
+  if (type->isNullPtrType())
+return makeZeroVal(type);
 
-  SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, T, VisitCount);
+  SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, type, VisitCount);
   return loc::MemRegionVal(MemMgr.getSymbolicHeapRegion(sym));
 }
 
Index: clang/lib/StaticAna

[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

In D103750#2825823 , @xazax.hun wrote:

> I believe there are a couple of comments that are done but not marked 
> accordingly. 
> I agree with Artem, if we could craft code that fails due to not calling 
> ctors, we should probably include them in the tests, even if they don't 
> reflect the desired behavior they are a great source of documentation what is 
> missing.

Do you want the new failing test to be marked //expected to fail//?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-18 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D103750#2827566 , @RedDocMD wrote:

> Do you want the new failing test to be marked //expected to fail//?

I usually just add the wrong expectation to make the test pass and add a TODO 
comment that explains why is this wrong and we should fix it in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D104500: DRAFT: [clang] Apply P1825 as DR for all modes below C++20.

2021-06-18 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:58-60
 A1 test1(A1 &&a) {
-  return a; // cxx11_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
+  return a;
 }

Personally, I don't think the world will accept applying P0527 unconditionally 
in pre-C++20 modes. But I guess we'll find out. :P


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

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


[PATCH] D104553: [compiler-rt][hwasan] Add InitState options to thread initialization

2021-06-18 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, vitalybuka, eugenis.
leonardchan added a project: Sanitizers.
Herald added a subscriber: dberris.
leonardchan requested review of this revision.
Herald added a subscriber: Sanitizers.

Similar to `InitOptions` in asan, we can use this optional struct for 
initializing some members thread objects before they are created. On linux, 
this is unused and can remain undefined. On fuchsia, this will just be the 
stack bounds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104553

Files:
  compiler-rt/lib/hwasan/hwasan_linux.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp
  compiler-rt/lib/hwasan/hwasan_thread.h
  compiler-rt/lib/hwasan/hwasan_thread_list.h


Index: compiler-rt/lib/hwasan/hwasan_thread_list.h
===
--- compiler-rt/lib/hwasan/hwasan_thread_list.h
+++ compiler-rt/lib/hwasan/hwasan_thread_list.h
@@ -85,7 +85,7 @@
 RoundUpTo(ring_buffer_size_ + sizeof(Thread), ring_buffer_size_ * 2);
   }
 
-  Thread *CreateCurrentThread() {
+  Thread *CreateCurrentThread(const Thread::InitState *state = nullptr) {
 Thread *t = nullptr;
 {
   SpinMutexLock l(&free_list_mutex_);
@@ -104,7 +104,7 @@
   SpinMutexLock l(&live_list_mutex_);
   live_list_.push_back(t);
 }
-t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_);
+t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_, state);
 AddThreadStats(t);
 return t;
   }
Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,9 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
+  // These are optional parameters that can be passed to Init.
+  struct InitState;
+
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size,
+const InitState *state = nullptr);
   void InitRandomState();
-  void InitStackAndTls();
+  void InitStackAndTls(const InitState *state = nullptr);
 
   // Must be called from the thread itself.
   void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size);
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -34,7 +34,8 @@
 stack_allocations_->push(0);
 }
 
-void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size) {
+void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
+  const InitState *state) {
   CHECK_EQ(0, unique_id_);  // try to catch bad stack reuse
   CHECK_EQ(0, stack_top_);
   CHECK_EQ(0, stack_bottom_);
@@ -44,7 +45,7 @@
   if (auto sz = flags()->heap_history_size)
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
-  InitStackAndTls();
+  InitStackAndTls(state);
   InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -427,7 +427,7 @@
   HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr);
 }
 
-void Thread::InitStackAndTls() {
+void Thread::InitStackAndTls(const InitState *state) {
   uptr tls_size;
   uptr stack_size;
   GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, 
&tls_begin_,


Index: compiler-rt/lib/hwasan/hwasan_thread_list.h
===
--- compiler-rt/lib/hwasan/hwasan_thread_list.h
+++ compiler-rt/lib/hwasan/hwasan_thread_list.h
@@ -85,7 +85,7 @@
 RoundUpTo(ring_buffer_size_ + sizeof(Thread), ring_buffer_size_ * 2);
   }
 
-  Thread *CreateCurrentThread() {
+  Thread *CreateCurrentThread(const Thread::InitState *state = nullptr) {
 Thread *t = nullptr;
 {
   SpinMutexLock l(&free_list_mutex_);
@@ -104,7 +104,7 @@
   SpinMutexLock l(&live_list_mutex_);
   live_list_.push_back(t);
 }
-t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_);
+t->Init((uptr)t - ring_buffer_size_, ring_buffer_size_, state);
 AddThreadStats(t);
 return t;
   }
Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,9 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
+  // These are optional parameters that can be passed to Init.
+  struct InitState;
+
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size,
+const InitState *state = nullptr);
   void InitRandomState();
-  void InitStackAndTls();
+  void InitStackAndTls(const InitState *stat

[PATCH] D101775: Fix for Bug 50033 - -fno-temp-file is not respected when creating a pch in clang 12

2021-06-18 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith closed this revision.
dexonsmith added a comment.

I pushed this as 05d0f1a8ea012a6b7b8ea65893ec4121106444b5 
 last 
night, but I just realized I forgot to include the link to the review :(. 
Closing manually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101775

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


[PATCH] D104500: DRAFT: [clang] Apply P1825 as DR for all modes below C++20.

2021-06-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Patch is missing description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

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


[PATCH] D104494: [dfsan] Replace dfs$ prefix with .dfsan suffix

2021-06-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

https://lab.llvm.org/buildbot/#/builders/37/builds/4620 looks broken by this 
patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104494

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


[PATCH] D104494: [dfsan] Replace dfs$ prefix with .dfsan suffix

2021-06-18 Thread George Balatsouras via Phabricator via cfe-commits
gbalats added a comment.

In D104494#2827639 , @vitalybuka 
wrote:

> https://lab.llvm.org/buildbot/#/builders/37/builds/4620 looks broken by this 
> patch

Looking into this. I missed (due to the "\\" in the expression) updating this:
https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/fuzzer/dataflow/DataFlow.cpp#L93-L94

I will try to get `ninja check-fuzzer` working again and either do a small fix 
forward or revert (if it turns out to be more complicated than just updating 
this expression).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104494

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 353061.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- add hyphen to docs, add boilerplate test to check Subjects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/fprofile.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/no_profile-attribute.c

Index: clang/test/Sema/no_profile-attribute.c
===
--- /dev/null
+++ clang/test/Sema/no_profile-attribute.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+__attribute__((no_profile))
+void no_profile0(void);
+void no_profile1(__attribute__((no_profile)) int param); // expected-warning {{'no_profile' attribute only applies to functions}}
+__attribute__((no_profile(""))) // expected-error {{'no_profile' attribute takes no arguments}}
+void no_profile2(void);
+void no_profile3(void) {
+  __attribute__((no_profile)); // expected-error {{'no_profile' attribute cannot be applied to a statement}}
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -99,6 +99,7 @@
 // CHECK-NEXT: NoMerge (SubjectMatchRule_function)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoMips16 (SubjectMatchRule_function)
+// CHECK-NEXT: NoProfileFunction (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/test/CodeGen/fprofile.c
===
--- /dev/null
+++ clang/test/CodeGen/fprofile.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-arcs -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+void __attribute__((no_profile)) no_instr() {
+// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]]
+}
+
+void instr(void) {
+// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]]
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: noprofile
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2559,6 +2559,17 @@
   }];
 }
 
+def NoProfileDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``no_profile`` attribute on a function declaration to denote that the
+compiler should not instrument the function with profile-related
+instrumentation, such as via the
+``-fprofile-generate`` / ``-fprofile-instr-generate`` /
+``-fcs-profile-generate`` / ``-fprofile-arcs`` flags.
+}];
+}
+
 def NoSanitizeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1970,6 +1970,13 @@
   let SimpleHandler = 1;
 }
 
+def NoProfileFunction : InheritableAttr {
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];
+  let SimpleHandler = 1;
+}
+
 def NotTailCalled : InheritableAttr {
   let Spellings = [Clang<"not_tail_called">];
   let Subjects = SubjectList<[Function]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo

[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1975
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];

aaron.ballman wrote:
> Should this also be supported on ObjC methods?
Wouldn't that be the case for many surrounding attributes defined near by?  I 
don't see why not, but I also know literally nothing about ObjC.  Would you 
like me to extend this attribute to ObjC methods?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D104491: [Docs][Clang][Attr] mark no_stack_protector+no_sanitize GCC compatible

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers abandoned this revision.
nickdesaulniers added a comment.

ah, ok, then if this isn't a quick cleanup, I don't really care about this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104491

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


[PATCH] D103021: [clang-tidy] performance-unnecessary-copy-initialization: Search whole function body for variable initializations.

2021-06-18 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 353064.
flx marked 2 inline comments as done.
flx added a comment.

Renamed initializer matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103021

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,9 +1,19 @@
 // RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
 
+template 
+struct Iterator {
+  void operator++();
+  const T &operator*() const;
+  bool operator!=(const Iterator &) const;
+  typedef const T &const_reference;
+};
+
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
   virtual ~ExpensiveToCopyType();
   const ExpensiveToCopyType &reference() const;
+  Iterator begin() const;
+  Iterator end() const;
   void nonConstMethod();
   bool constMethod() const;
 };
@@ -508,3 +518,41 @@
   // CHECK-FIXES: const auto& UnnecessaryCopy = Ref.reference();
   Orig.constMethod();
 }
+
+void negativeloopedOverObjectIsModified() {
+  ExpensiveToCopyType Orig;
+  for (const auto &Element : Orig) {
+const auto Copy = Element;
+Orig.nonConstMethod();
+Copy.constMethod();
+  }
+
+  auto Lambda = []() {
+ExpensiveToCopyType Orig;
+for (const auto &Element : Orig) {
+  const auto Copy = Element;
+  Orig.nonConstMethod();
+  Copy.constMethod();
+}
+  };
+}
+
+void negativeReferenceIsInitializedOutsideOfBlock() {
+  ExpensiveToCopyType Orig;
+  const auto &E2 = Orig;
+  if (1 != 2 * 3) {
+const auto C2 = E2;
+Orig.nonConstMethod();
+C2.constMethod();
+  }
+
+  auto Lambda = []() {
+ExpensiveToCopyType Orig;
+const auto &E2 = Orig;
+if (1 != 2 * 3) {
+  const auto C2 = E2;
+  Orig.nonConstMethod();
+  C2.constMethod();
+}
+  };
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/AST/Decl.h"
 
 namespace clang {
 namespace tidy {
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -12,6 +12,7 @@
 #include "../utils/FixItHintUtils.h"
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 
 namespace clang {
@@ -58,14 +59,14 @@
   .bind(InitFunctionCallId);
 }
 
-AST_MATCHER_FUNCTION(StatementMatcher, isInitializedFromReferenceToConst) {
+AST_MATCHER_FUNCTION(StatementMatcher, initializerReturnsReferenceToConst) {
   auto OldVarDeclRef =
   declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
-  return declStmt(has(varDecl(hasInitializer(
+  return expr(
   anyOf(isConstRefReturningFunctionCall(), isConstRefReturningMethodCall(),
 ignoringImpCasts(OldVarDeclRef),
-ignoringImpCasts(unaryOperator(
-hasOperatorName("&"), hasUnaryOperand(OldVarDeclRef;
+ignoringImpCasts(unaryOperator(hasOperatorName("&"),
+   hasUnaryOperand(OldVarDeclRef);
 }
 
 // This checks that the variable itself is only used as const, and also makes
@@ -92,18 +93,14 @@
   if (!isa(T))
 return true;
 
-  auto Matches =
-  match(findAll(declStmt(has(varDecl(equalsNode(&InitializingVar
-.bind("declStmt")),
-BlockStmt, Context);
-  // The reference or pointer is not initialized in the BlockStmt. We assume
-  // its pointee is not modified then.
-  if (Matches.empty())
+  // The reference or pointer is not declared and hence not initialized anywhere
+  // in the function. We assume its pointee is not modified then.
+  if (!InitializingVar.isLocalVarDecl() || !InitializingVar.hasInit()) {
 return true;
+  }
 
-  const auto *Initialization = selectFirst("declStmt", Matches);
-  Matches =
-  match(isInitializedFromReferenceToConst(), *Initialization, Context);
+  

[PATCH] D104561: [NFC][compiler-rt][hwasan] Move hwasanThreadList().CreateCurrentThread() into InitThreads

2021-06-18 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, vitalybuka, eugenis.
leonardchan added a project: Sanitizers.
Herald added a subscriber: dberris.
leonardchan requested review of this revision.
Herald added a subscriber: Sanitizers.

Once D104553  lands, `CreateCurrentThread` 
will be able to accept optional parameters for initializing the hwasan thread 
object. On fuchsia, we can get stack info in the platform-specific 
`InitThreads` and pass it through `CreateCurrentThread`. On linux, this is a 
no-op.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104561

Files:
  compiler-rt/lib/hwasan/hwasan.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp


Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -250,6 +250,7 @@
   ProtectGap(thread_space_end,
  __hwasan_shadow_memory_dynamic_address - thread_space_end);
   InitThreadList(thread_space_start, thread_space_end - thread_space_start);
+  hwasanThreadList().CreateCurrentThread();
 }
 
 bool MemIsApp(uptr p) {
Index: compiler-rt/lib/hwasan/hwasan.cpp
===
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -276,7 +276,6 @@
   }
 
   InitThreads();
-  hwasanThreadList().CreateCurrentThread();
 
   hwasan_instrumentation_inited = 1;
 }


Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -250,6 +250,7 @@
   ProtectGap(thread_space_end,
  __hwasan_shadow_memory_dynamic_address - thread_space_end);
   InitThreadList(thread_space_start, thread_space_end - thread_space_start);
+  hwasanThreadList().CreateCurrentThread();
 }
 
 bool MemIsApp(uptr p) {
Index: compiler-rt/lib/hwasan/hwasan.cpp
===
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -276,7 +276,6 @@
   }
 
   InitThreads();
-  hwasanThreadList().CreateCurrentThread();
 
   hwasan_instrumentation_inited = 1;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104500: DRAFT: [clang] Apply P1825 as DR for all modes below C++20.

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D104500#2827629 , @lebedev.ri 
wrote:

> Patch is missing description

Yes sorry for the noise, I do that sometimes just to let the bots test my patch 
before it is fully ready for review.
If you have any tips for me so I can upload a diff and have it tested, without 
having to create the DR for it, would appreciate.




Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:58-60
 A1 test1(A1 &&a) {
-  return a; // cxx11_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
+  return a;
 }

Quuxplusone wrote:
> Personally, I don't think the world will accept applying P0527 
> unconditionally in pre-C++20 modes. But I guess we'll find out. :P
Indeed :)
By the way, I have not found a counter example of strict C++98 code (not using 
extensions) breaking with implicit moves enabled.
So it looks like we can have one mode for everything here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

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

LGTM!




Comment at: clang/include/clang/Basic/Attr.td:1975
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];

nickdesaulniers wrote:
> aaron.ballman wrote:
> > Should this also be supported on ObjC methods?
> Wouldn't that be the case for many surrounding attributes defined near by?  I 
> don't see why not, but I also know literally nothing about ObjC.  Would you 
> like me to extend this attribute to ObjC methods?
It would be, and I think many of them are in the same state for the same reason 
(not knowing about ObjC).

I don't insist on the change. I ask whenever I see `Function` in the subject 
list because it's pretty rare that ObjC methods work differently than a 
function call in ways that matter for attributes. We can always add the 
functionality when a user requests it, later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D104491: [Docs][Clang][Attr] mark no_stack_protector+no_sanitize GCC compatible

2021-06-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D104491#2827730 , @nickdesaulniers 
wrote:

> ah, ok, then if this isn't a quick cleanup, I don't really care about this.

I took a quick look at ClangAttrEmitter.cpp, and it looks like the only change 
that is needed is within the `GetFlattenedSpelling()` function. So not quite 
quick, but shouldn't be too bad (in case someone wants to pick this back up).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104491

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked 5 inline comments as done.
RedDocMD added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:435
 
+  void markNotInteresting(SymbolRef sym);
+

xazax.hun wrote:
> Bikeshedding: I wonder if we prefer `Uninteresting` to `NotInteresting`. Or 
> alternatively, if we want to emphasize this is only the lack of 
> interestingness, we could name it `removeInterestingness`. I do not have 
> strong feelings about any of the options, I was just wondering if any of you 
> has a preference.
I was actually planning to use something like `unmarkInteresting`, but that is 
grammatically incorrect. `removeInterestingness` is fair enough, but a mouthful 
I think. As for `Uninteresting`, I think we are better off avoiding clever uses 
of English and stick with simple, programmer jargon.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:191
+// Check the first arg, if it is of std::unique_ptr type.
+assert(Call.getNumArgs() == 2 && "std::swap should have two arguments");
+const Expr *FirstArg = Call.getArgExpr(0);

xazax.hun wrote:
> I wonder about the value of this assertion. Shouldn`t 
> `Call.isCalled(StdSwapCall)` already validate the number of arguments?
About as valuable as any assertion is ;)
My reasoning is that since we are calling `Call.getArgSval(0)` and 
`Call.getArgSVal(1)`, we had better assert that there are two args.
As a side-note, I had a bug in my `CallDescriptor`, which was caught by this 
assertion



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:196-202
+const MemRegion *FirstArgThisRegion = Call.getArgSVal(0).getAsRegion();
+if (!FirstArgThisRegion)
+  return false;
+const MemRegion *SecondArgThisRegion = Call.getArgSVal(1).getAsRegion();
+if (!SecondArgThisRegion)
+  return false;
+

vsavchenko wrote:
> I guess `handleSwap` can take `SVal`s instead of `MemRegion` and we can 
> mostly cut on this boilerplate as well.
> ```
>return handleSwap(State, Call.getArgSVal(0), Call.getArgSVal(1), C);
> ```
> and
> ```
>   return handleSwap(State, IC->getCXXThisVal(), Call.getArgSVal(0), C);
> ```
Yup, okay.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:458-467
+if (BR.isInteresting(FirstThisRegion) &&
+!BR.isInteresting(SecondThisRegion)) {
+  BR.markInteresting(SecondThisRegion);
+  BR.markNotInteresting(FirstThisRegion);
+}
+if (BR.isInteresting(SecondThisRegion) &&
+!BR.isInteresting(FirstThisRegion)) {

xazax.hun wrote:
> vsavchenko wrote:
> > nit: these two pieces of code are very much the same
> I guess we could make `markInteresting` take an optional bool and swap the 
> interestingness unconditionally. 
Then we would need to rename it to something like `setInterestingness`.
And renaming such a widely used function would be a real pain.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:458-467
+if (BR.isInteresting(FirstThisRegion) &&
+!BR.isInteresting(SecondThisRegion)) {
+  BR.markInteresting(SecondThisRegion);
+  BR.markNotInteresting(FirstThisRegion);
+}
+if (BR.isInteresting(SecondThisRegion) &&
+!BR.isInteresting(FirstThisRegion)) {

RedDocMD wrote:
> xazax.hun wrote:
> > vsavchenko wrote:
> > > nit: these two pieces of code are very much the same
> > I guess we could make `markInteresting` take an optional bool and swap the 
> > interestingness unconditionally. 
> Then we would need to rename it to something like `setInterestingness`.
> And renaming such a widely used function would be a real pain.
Yes, but I don't think refactoring them into a lambda (within a lambda) would 
be that nice either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 353068.
RedDocMD added a comment.

Some more refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -69,20 +69,17 @@
 
 void derefOnSwappedNullPtr() {
   std::unique_ptr P(new A()); // expected-note {{Smart pointer 'P' is constructed}}
-  std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  P.swap(PNull); // expected-note {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
+  std::unique_ptr PNull;
+  P.swap(PNull);
   PNull->foo(); // No warning.
   (*P).foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
 
-// FIXME: Fix this test when "std::swap" is modeled seperately.
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
-  std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:979 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
-  // expected-note@-1 {{Calling 'swap'}}
-  // expected-note@-2 {{Returning from 'swap'}}
+  std::unique_ptr PNull;
+  std::swap(P, PNull);
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   // expected-note@-1{{Dereference of null smart pointer 'P'}}
 }
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2261,6 +2261,14 @@
 markInteresting(meta->getRegion(), TKind);
 }
 
+void PathSensitiveBugReport::markNotInteresting(SymbolRef sym) {
+  if (!sym)
+return;
+  InterestingSymbols.erase(sym);
+  if (const auto *meta = dyn_cast(sym))
+markNotInteresting(meta->getRegion());
+}
+
 void PathSensitiveBugReport::markInteresting(const MemRegion *R,
  bugreporter::TrackingKind TKind) {
   if (!R)
@@ -2273,6 +2281,17 @@
 markInteresting(SR->getSymbol(), TKind);
 }
 
+void PathSensitiveBugReport::markNotInteresting(const MemRegion *R) {
+  if (!R)
+return;
+
+  R = R->getBaseRegion();
+  InterestingRegions.erase(R);
+
+  if (const auto *SR = dyn_cast(R))
+markNotInteresting(SR->getSymbol());
+}
+
 void PathSensitiveBugReport::markInteresting(SVal V,
  bugreporter::TrackingKind TKind) {
   markInteresting(V.getAsRegion(), TKind);
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -60,7 +60,7 @@
 private:
   void handleReset(const CallEvent &Call, CheckerContext &C) const;
   void handleRelease(const CallEvent &Call, CheckerContext &C) const;
-  void handleSwap(const CallEvent &Call, CheckerContext &C) const;
+  void handleSwapMethod(const CallEvent &Call, CheckerContext &C) const;
   void handleGet(const CallEvent &Call, CheckerContext &C) const;
   bool handleAssignOp(const CallEvent &Call, CheckerContext &C) const;
   bool handleMoveCtr(const CallEvent &Call, CheckerContext &C,
@@ -68,14 +68,17 @@
   bool updateMovedSmartPointers(CheckerContext &C, const MemRegion *ThisRegion,
 const MemRegion *OtherSmartPtrRegion) const;
   void handleBoolConversion(const CallEvent &Call, CheckerContext &C) const;
+  bool handleSwap(ProgramStateRef State, SVal First, SVal Second,
+  CheckerContext &C) const;
 
   using SmartPtrMethodHandlerFn =
   void (SmartPtrModeling::*)(const CallEvent &Call, CheckerContext &) const;
   CallDescriptionMap SmartPtrMethodHandlers{
   {{"reset"}, &SmartPtrModeling::handleReset},
   {{"release"}, &SmartPtrModeling::handleRelease},
-  {{"swap", 1}, &SmartPtrModeling::handleSwap},
+  {{"swap", 1}, &SmartPtrModeling::handleSwapMethod},
   {{"get"}, &SmartPtrModeling::handleGet}};
+  const CallDescription StdSwapCall{{"std", "swap"}, 2};
 };
 } // end of anonymous namespace
 
@@ -91,11 +94,15 @@
 return false;
 
   const auto *RecordDecl = MethodDecl->getParent();
-  if (!RecordDecl ||

[PATCH] D103434: [analyzer] Allow visitors to run callbacks on completion

2021-06-18 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD abandoned this revision.
RedDocMD added a comment.

I am closing this since it has been addressed much better by the patches from 
@vsavchenko.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103434

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


[PATCH] D104342: [IR] convert warn-stack-size from module attr to fn attr

2021-06-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds OK to me.

Another thing you might want to check is linkonce_odr functions - I guess 
you'll get an arbitrary choice between two linkonce_odr functions under LTO 
where they have different warn-stack-size? Maybe there's a way/place to merge 
and always pick the lower or upper value if there's one you think would be more 
right?




Comment at: llvm/test/Transforms/Inline/warn-stack-size.ll:1
+; RUN: opt -passes=inline -S %s | FileCheck %s
+

Nice to see the test - though I probably wouldn't bother adding this test if 
this behavior already falls out of more general support in the inliner and the 
way it already handles attributes - the general behavior is likely already 
tested elsewhere? (though it'd be good to confirm that either in tests and/or 
the inliner code itself)

my original question was to confirm that the inliner already had accounted for 
this situation in a way that was desirable & it looks like/sounds like it is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D104475#2825841 , @nickdesaulniers 
wrote:

> In D104475#2825795 , @MaskRay wrote:
>
>> In D104475#2825772 , 
>> @nickdesaulniers wrote:
>>
>>> In D104475#2825711 , @MaskRay 
>>> wrote:
>>>
 So if we don't want to offer guarantee for IR/C/C++ attributes, we can 
 document that users may need to additionally specify 
 `__attribute__((noinline))` to suppress inlining.
>>>
>>> I don't generally like that approach:
>>
>> If a guarantee would cause inferior optimization or we cannot think of all 
>> the complication/fallout initially, I'd prefer that we keep the initial 
>> semantics narrow.
>
> The guarantee is more important than the optimization.
>
>> If we cannot make a promise, don't provide a promise.
>> No-suppressing inlining makes the attribute freely composable with other 
>> attributes (https://lists.llvm.org/pipermail/llvm-dev/2021-April/150062.html 
>> )
>
> IIUC, isn't @jdoerfert arguing that `optnone` and `noinline` being composable 
> is _bad_?

No, the opposite. @jdoerfert is arguing that attributes should be composable.
I agree and I think the `optnone` design has some orthogonality problems.

>>> 1. it's not easy for developers to validate their call call chains to 
>>> ensure that a caller with a restrictive function attribute doesn't have 
>>> unrestricted callers inlined into the restricted caller.
>>> 2. that behavior opposes the principle of least surprise.
>>
>> Disagree. If the user wants a function not to be inlined, let them add 
>> `__attribute__((noinline))`.
>>
>>> 3. We don't have a statement attribute for call sites to say "please don't 
>>> inline this call" which would be fine grain. noinline is a course-grain 
>>> hammer; what if we want to inline a callee into most callers but not this 
>>> one caller that has such a restricted function attribute?
>>
>>
>>
>>> See also D91816  where I took the 
>>> conservative approach for `no_stack_protector` and simply chose not to 
>>> perform such inline substitution on caller and callee function attribute 
>>> mismatch.  I find this behavior to be the least surprising, and the 
>>> developer is provided with introspection as to why the compile did not 
>>> perform such inlining via `-Rpass=inline` flag.
>>
>> I think D91816  was an unfortunate case. 
>> That would require the inliner to understand every possible attribute.
>
> Hyperbole. Only a few such function attributes would need such restrictions.
>
>> That was the practical approach back then because it is not easy for the 
>> kernel to cope.
>> For new things we should strive for making the kernel do the right thing.
>>
>> For example, if a kernel function can sometimes be inlinable, sometimes not: 
>> add a alias and add `__attribute__((noinline))` to that alias.
>
> Interesting idea, but `noinline` is straight up broken in LLVM: 
> https://godbolt.org/z/MoE1a7c3v. The Linux kernel relies on `noinline` 
> meaning don't perform inline substitution.  That violates the principal of 
> least surprise.  When a developer uses `noinline`, `no_stack_protector`, or 
> `no_profile`, they mean DO NOT inline, insert a stack protector, or insert 
> profiling/coverage instrumentation EVER.
>
> Also debugging to find out that inlining was the cause of such violated 
> expectations sucks.

It is not broken. That is constant propagation in early-cse. A function call 
can be optimized out if it has no side effect and its value can be determined. 
The behavior may look like inlining. That is the `nointeropt` IR attribute 
proposal intends to address.
I guess for most(all?) non-trivial noinline usage in the Linux kernel, we can 
assume `noinline` is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a subscriber: marxin.
MaskRay added a comment.

LG.

@marxin FYI the GNU-style function attribute `no_profile`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D104475: [Clang][Codegen] emit noprofile IR Fn Attr for new Fn Attr no_profile

2021-06-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGen/fprofile.c:1
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s

no_profile may be a better test name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-18 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

Reply to @joerg proposing new wording for the option description




Comment at: clang/docs/UsersManual.rst:1484
+   Where unsafe floating point optimizations are enabled, this option
+   determines whether the optimizer honors parentheses when floating-point
+   expressions are evaluated.  If unsafe floating point optimizations are

joerg wrote:
> aaron.ballman wrote:
> > mibintc wrote:
> > > aaron.ballman wrote:
> > > > We may need to expound on what "honor parentheses" means. The summary 
> > > > for the patch mentions `(a + b) + c`, but does this also mean `(x + y) 
> > > > * z`  could be interpreted as `x + (y * z)`? What about for 
> > > > non-arithmetic expressions involving parentheses, like `(float1 == 
> > > > float2 && float1 == float3) || blah()`?
> > > Thanks for your review. Just a quick first response, What do you mean "(x 
> > > + y) * z could be reinterpreted as x + (y * z)" -- not following you 
> > > here? 
> > "whether the optimizer honors the parentheses" reads to me like `(x + y) * 
> > z` could either honor or not honor the parentheses, so that could either 
> > evaluate as `(x + y) * z` or `x + (y * z)` depending on whether the parens 
> > are honored or not.
> I would prefer to start with a description of the intended behavior from 
> first principles. The logic here should not be tied to fast-mode as it also 
> overlaps a lot with the formulation of fused multiply-add expressions and 
> certainly should have specified behavior on the interaction. I'm also not 
> sure about what you mean with value-safe FP modes, IIRC the C/C++ standard 
> explicitly leave it open in which order floating point expressions of the 
> same operand priority are evaluated.
> 
> I'm also a bit puzzled why __arithmethic_fence should not be considered a 
> constant expression?
> I would prefer to start with a description of the intended behavior from 
> first principles. The logic here should not be tied to fast-mode as it also 
> overlaps a lot with the formulation of fused multiply-add expressions and 
> certainly should have specified behavior on the interaction. I'm also not 
> sure about what you mean with value-safe FP modes, IIRC the C/C++ standard 
> explicitly leave it open in which order floating point expressions of the 
> same operand priority are evaluated.

@joerg  Thank you.  What do you think about this modified description of the 
option:
option:: -f[no-]protect-parens:

This option pertains to floating-point types, complex types with floating-point 
components, and vectors of these types. Some arithmetic expression 
transformations that are mathematically correct and permissible according to 
the C and C++ language standards may be incorrect when dealing with 
floating-point types, such as reassociation and distribution. Further, the 
optimizer may ignore parentheses when computing arithmetic expressions in 
circumstances where the parenthesized and unparenthesized expression express 
the same mathematical value. For example (a+b)+c is the same mathematical value 
as a+(b+c), but the optimizer is free to evaluate the additions in any order 
regardless of the parentheses. When enabled, this option forces the optimizer 
to honor the order of operations with respect to parentheses in all 
circumstances.

Note that floating-point contraction (option `-ffp-contract=`) is disabled when 
`-fprotect-parens` is enabled.  Also note that in safe floating-point modes, 
such as `-ffp-model=precise` or `-ffp-model=strict`, this option has no effect 
because the optimizer is prohibited from making unsafe transformations.

> 
> I'm also a bit puzzled why __arithmethic_fence should not be considered a 
> constant expression?
I can see your point about that. I was leery of steering into constant folding 
waters but I will make that change.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

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


[PATCH] D104475: [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to noprofile

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 353074.
nickdesaulniers added a comment.

- rename test, add __has_attribute unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/no_profile.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/no_profile-attribute.c

Index: clang/test/Sema/no_profile-attribute.c
===
--- /dev/null
+++ clang/test/Sema/no_profile-attribute.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+__attribute__((no_profile))
+void no_profile0(void);
+#if !__has_attribute(no_profile)
+#error "Where did the no_profile function attribute go?"
+#endif
+
+void no_profile1(__attribute__((no_profile)) int param); // expected-warning {{'no_profile' attribute only applies to functions}}
+__attribute__((no_profile(""))) // expected-error {{'no_profile' attribute takes no arguments}}
+void no_profile2(void);
+void no_profile3(void) {
+  __attribute__((no_profile)); // expected-error {{'no_profile' attribute cannot be applied to a statement}}
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -99,6 +99,7 @@
 // CHECK-NEXT: NoMerge (SubjectMatchRule_function)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoMips16 (SubjectMatchRule_function)
+// CHECK-NEXT: NoProfileFunction (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/test/CodeGen/no_profile.c
===
--- /dev/null
+++ clang/test/CodeGen/no_profile.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-arcs -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+void __attribute__((no_profile)) no_instr() {
+// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]]
+}
+
+void instr(void) {
+// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]]
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: noprofile
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2559,6 +2559,17 @@
   }];
 }
 
+def NoProfileDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``no_profile`` attribute on a function declaration to denote that the
+compiler should not instrument the function with profile-related
+instrumentation, such as via the
+``-fprofile-generate`` / ``-fprofile-instr-generate`` /
+``-fcs-profile-generate`` / ``-fprofile-arcs`` flags.
+}];
+}
+
 def NoSanitizeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1970,6 +1970,13 @@
   let SimpleHandler = 1;
 }
 
+def NoProfileFunction : InheritableAttr {
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];
+  let SimpleHandler = 1;
+}
+
 def NotTailCalled : InheritableAttr {
   let Spellings = [Clang<"not_tail_called">];
   let Subjects = SubjectList<[Function]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https

[clang-tools-extra] bdd5da9 - [clang-tidy] performance-unnecessary-copy-initialization: Directly examine the initializing var's initializer.

2021-06-18 Thread Felix Berger via cfe-commits

Author: Felix Berger
Date: 2021-06-18T15:25:17-04:00
New Revision: bdd5da9dec61072f693726d9ed2a94c78e431ba2

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

LOG: [clang-tidy] performance-unnecessary-copy-initialization: Directly examine 
the initializing var's initializer.

This fixes false positive cases where a reference is initialized outside of a
block statement and then its initializing variable is modified. Another case is
when the looped over container is modified.

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

Reviewed-by: ymandel

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 27ce36e49a073..f75a3a901ecd5 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -12,6 +12,7 @@
 #include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 
 namespace clang {
@@ -72,14 +73,14 @@ AST_MATCHER_FUNCTION(StatementMatcher, 
isConstRefReturningFunctionCall) {
   .bind(InitFunctionCallId);
 }
 
-AST_MATCHER_FUNCTION(StatementMatcher, isInitializedFromReferenceToConst) {
+AST_MATCHER_FUNCTION(StatementMatcher, initializerReturnsReferenceToConst) {
   auto OldVarDeclRef =
   declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
-  return declStmt(has(varDecl(hasInitializer(
+  return expr(
   anyOf(isConstRefReturningFunctionCall(), isConstRefReturningMethodCall(),
 ignoringImpCasts(OldVarDeclRef),
-ignoringImpCasts(unaryOperator(
-hasOperatorName("&"), hasUnaryOperand(OldVarDeclRef;
+ignoringImpCasts(unaryOperator(hasOperatorName("&"),
+   hasUnaryOperand(OldVarDeclRef);
 }
 
 // This checks that the variable itself is only used as const, and also makes
@@ -106,18 +107,14 @@ static bool isInitializingVariableImmutable(const VarDecl 
&InitializingVar,
   if (!isa(T))
 return true;
 
-  auto Matches =
-  match(findAll(declStmt(has(varDecl(equalsNode(&InitializingVar
-.bind("declStmt")),
-BlockStmt, Context);
-  // The reference or pointer is not initialized in the BlockStmt. We assume
-  // its pointee is not modified then.
-  if (Matches.empty())
+  // The reference or pointer is not declared and hence not initialized 
anywhere
+  // in the function. We assume its pointee is not modified then.
+  if (!InitializingVar.isLocalVarDecl() || !InitializingVar.hasInit()) {
 return true;
+  }
 
-  const auto *Initialization = selectFirst("declStmt", Matches);
-  Matches =
-  match(isInitializedFromReferenceToConst(), *Initialization, Context);
+  auto Matches = match(initializerReturnsReferenceToConst(),
+   *InitializingVar.getInit(), Context);
   // The reference is initialized from a free function without arguments
   // returning a const reference. This is a global immutable object.
   if (selectFirst(InitFunctionCallId, Matches) != nullptr)

diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
index 8193672218932..c11be2d8885d6 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
@@ -10,6 +10,7 @@
 #define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/AST/Decl.h"
 
 namespace clang {
 namespace tidy {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
index e894f84f11d8c..c2b3d8f9c7395 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,10 +1,20 @@
 // RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
 
+template 
+struct Iterator {
+  void operator++();
+  const T &operator*() const;
+  bool operator!=(const Iterator &) const

[PATCH] D103021: [clang-tidy] performance-unnecessary-copy-initialization: Search whole function body for variable initializations.

2021-06-18 Thread Felix Berger via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdd5da9dec61: [clang-tidy] 
performance-unnecessary-copy-initialization: Directly examine the… (authored by 
flx).

Changed prior to commit:
  https://reviews.llvm.org/D103021?vs=353064&id=353075#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103021

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,10 +1,20 @@
 // RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
 
+template 
+struct Iterator {
+  void operator++();
+  const T &operator*() const;
+  bool operator!=(const Iterator &) const;
+  typedef const T &const_reference;
+};
+
 struct ExpensiveToCopyType {
   ExpensiveToCopyType();
   virtual ~ExpensiveToCopyType();
   const ExpensiveToCopyType &reference() const;
   const ExpensiveToCopyType *pointer() const;
+  Iterator begin() const;
+  Iterator end() const;
   void nonConstMethod();
   bool constMethod() const;
 };
@@ -589,3 +599,41 @@
   // CHECK-FIXES-NOT: auto TrailingCommentRemoved = ExpensiveTypeReference(); // Trailing comment.
   // clang-format on
 }
+
+void negativeloopedOverObjectIsModified() {
+  ExpensiveToCopyType Orig;
+  for (const auto &Element : Orig) {
+const auto Copy = Element;
+Orig.nonConstMethod();
+Copy.constMethod();
+  }
+
+  auto Lambda = []() {
+ExpensiveToCopyType Orig;
+for (const auto &Element : Orig) {
+  const auto Copy = Element;
+  Orig.nonConstMethod();
+  Copy.constMethod();
+}
+  };
+}
+
+void negativeReferenceIsInitializedOutsideOfBlock() {
+  ExpensiveToCopyType Orig;
+  const auto &E2 = Orig;
+  if (1 != 2 * 3) {
+const auto C2 = E2;
+Orig.nonConstMethod();
+C2.constMethod();
+  }
+
+  auto Lambda = []() {
+ExpensiveToCopyType Orig;
+const auto &E2 = Orig;
+if (1 != 2 * 3) {
+  const auto C2 = E2;
+  Orig.nonConstMethod();
+  C2.constMethod();
+}
+  };
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/AST/Decl.h"
 
 namespace clang {
 namespace tidy {
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -12,6 +12,7 @@
 #include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 
 namespace clang {
@@ -72,14 +73,14 @@
   .bind(InitFunctionCallId);
 }
 
-AST_MATCHER_FUNCTION(StatementMatcher, isInitializedFromReferenceToConst) {
+AST_MATCHER_FUNCTION(StatementMatcher, initializerReturnsReferenceToConst) {
   auto OldVarDeclRef =
   declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
-  return declStmt(has(varDecl(hasInitializer(
+  return expr(
   anyOf(isConstRefReturningFunctionCall(), isConstRefReturningMethodCall(),
 ignoringImpCasts(OldVarDeclRef),
-ignoringImpCasts(unaryOperator(
-hasOperatorName("&"), hasUnaryOperand(OldVarDeclRef;
+ignoringImpCasts(unaryOperator(hasOperatorName("&"),
+   hasUnaryOperand(OldVarDeclRef);
 }
 
 // This checks that the variable itself is only used as const, and also makes
@@ -106,18 +107,14 @@
   if (!isa(T))
 return true;
 
-  auto Matches =
-  match(findAll(declStmt(has(varDecl(equalsNode(&InitializingVar
-.bind("declStmt")),
-BlockStmt, Context);
-  // The reference or pointer is not initialized in the BlockStmt. We assume
-  // its pointee is not modified then.
-  if (Matches.empty())
+  // The reference or pointer is not declared and hence not initialized anywhere
+  // in the function. We ass

[PATCH] D71734: [Modules] Handle tag types and complain about bad merges in C/Objective-C mode

2021-06-18 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:9585-9587
+assert(getContext().hasSameType(FirstField->getType(),
+SecondField->getType()));
+

rsmith wrote:
> bruno wrote:
> > rsmith wrote:
> > > I don't understand why this assertion would be correct if the above 
> > > branch can ever be taken. It's possible for two different types to have 
> > > the same hash, and it looks like we'll assert here if that happens. 
> > > Should we be branching on `hasSameType` above instead of comparing hashes?
> > This is trying to cover two things. The first one is to handle nested 
> > anonymous unions, which might have the same type, but underlying 
> > mismatching fields:
> > ```
> > #if defined(FIRST)
> > struct AU {
> >   union {
> > int a;
> >   };
> > };
> > #elif defined(SECOND)
> > struct AU {
> >   union {
> > char a;
> >   };
> > };
> > #else
> > struct AU au;
> > ```
> > 
> > The second is to allow for @interfaces (downstream patches at the moment) 
> > to reuse logic to diagnose fields in `ODRDiagField` without having to add 
> > its own check for the underlying types. Does that makes sense?
> I still don't understand.
> 
> Either the types are always the same before the previous `if` and can only 
> differ in type sugar (in which case this change is unnecessary), or the types 
> can be different in more than just sugar (in which case this assert is wrong 
> because there's no guarantee that different types will have different hashes).
> 
> What am I missing?
@vsapsai: just to follow up here a bit. I don't remember the full context 
anymore, but it should be fine to reintroduce this in a later patch with a 
better explanation to @rsmith, or change the approach if it makes sense. Thanks 
for taking this over!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

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


[PATCH] D104155: Add documentation for -fsanitize-address-use-after-return.

2021-06-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/docs/AddressSanitizer.rst:17-19
+* Use-after-return (clang flag 
``-fsanitize-address-use-after-return=(never|runtime|always)`` default: 
``runtime``)
+* Enable ``runtime`` with: ``ASAN_OPTIONS=detect_stack_use_after_return=1``
+* Use-after-scope (clang flag ``-fsanitize-address-use-after-scope``)

I guess just flag name is enough here, the rest in the section below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104155

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


[PATCH] D103958: [WIP] Support MustControl conditional control attribute

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

FWIW, LWN recently published summary of some of the recent discussions on LKML: 
https://lwn.net/SubscriberLink/860037/aca06acfafce7937/.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103958

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


[PATCH] D104155: Add documentation for -fsanitize-address-use-after-return.

2021-06-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/docs/AddressSanitizer.rst:143
+
+AddressSanitizer (``-fsanitize=address``) can optionally detect stack use after
+return problems.

Maybe -fsanitize=address is reduntant here, we are already in the 
-fsanitize=address document. Mentioning the flag in the line 11 seems more 
appropriate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104155

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


[PATCH] D104475: [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to noprofile

2021-06-18 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.

LGTM I'm happy to see that the `noprofile` LLVM attribute is useful in other 
contexts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[PATCH] D104566: [UpdateCCTestChecks] Fix --replace-value-regex across RUN lines

2021-06-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: arichardson, ggeorgakoudis, jdoerfert, MaskRay, 
mtrofin, greened.
jdenny requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added projects: clang, LLVM.

Without this patch, llvm/utils/update_cc_test_checks.py fails to
perform `--replace-value-regex` replacements when two RUN lines
produce the same output and use the same single FileCheck prefix.  The 
problem is that replacements in a RUN line's output are not performed
until after comparing against previous RUN lines' output, where
replacements have already been performed.  This patch fixes that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104566

Files:
  
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c
  
clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
  clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -350,27 +350,6 @@
 for l in scrubbed_body.splitlines():
   print('  ' + l, file=sys.stderr)
   for prefix in prefixes:
-if func in self._func_dict[prefix]:
-  if (self._func_dict[prefix][func] is None or
-  str(self._func_dict[prefix][func]) != scrubbed_body or
-  self._func_dict[prefix][func].args_and_sig != args_and_sig or
-  self._func_dict[prefix][func].attrs != attrs):
-if (self._func_dict[prefix][func] is not None and
-self._func_dict[prefix][func].is_same_except_arg_names(
-scrubbed_extra,
-args_and_sig,
-attrs)):
-  self._func_dict[prefix][func].scrub = scrubbed_extra
-  self._func_dict[prefix][func].args_and_sig = args_and_sig
-  continue
-else:
-  # This means a previous RUN line produced a body for this function
-  # that is different from the one produced by this current RUN line,
-  # so the body can't be common accross RUN lines. We use None to
-  # indicate that.
-  self._func_dict[prefix][func] = None
-  continue
-
 # Replace function names matching the regex.
 for regex in self._replace_value_regex:
   # Pattern that matches capture groups in the regex in leftmost order.
@@ -393,7 +372,29 @@
 func_repl = group_regex.sub(re.escape(g), func_repl, count=1)
 # Substitute function call names that match the regex with the same
 # capture groups set.
-scrubbed_body = re.sub(func_repl, '{{' + func_repl + '}}', scrubbed_body)
+scrubbed_body = re.sub(func_repl, '{{' + func_repl + '}}',
+   scrubbed_body)
+
+if func in self._func_dict[prefix]:
+  if (self._func_dict[prefix][func] is None or
+  str(self._func_dict[prefix][func]) != scrubbed_body or
+  self._func_dict[prefix][func].args_and_sig != args_and_sig or
+  self._func_dict[prefix][func].attrs != attrs):
+if (self._func_dict[prefix][func] is not None and
+self._func_dict[prefix][func].is_same_except_arg_names(
+scrubbed_extra,
+args_and_sig,
+attrs)):
+  self._func_dict[prefix][func].scrub = scrubbed_extra
+  self._func_dict[prefix][func].args_and_sig = args_and_sig
+  continue
+else:
+  # This means a previous RUN line produced a body for this function
+  # that is different from the one produced by this current RUN line,
+  # so the body can't be common accross RUN lines. We use None to
+  # indicate that.
+  self._func_dict[prefix][func] = None
+  continue
 
 self._func_dict[prefix][func] = function_body(
 scrubbed_body, scrubbed_extra, args_and_sig, attrs)
Index: clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/replace-value-regex-across-runs.test
@@ -0,0 +1,7 @@
+# Test that --replace-value-regex is applied correctly when multiple RUN lines
+# use the same FileCheck prefix and have the same output.
+
+RUN: cp %S/Inputs/replace-value-regex-across-runs.c %t.c
+RUN: %update_cc_test_checks %t.c \
+RUN: --replace-value-regex '__omp_offloading_[0-9a-z]+_[0-9a-z]+'
+RUN: diff -u %S/Inputs/replace-value-regex-across-runs.c.expected %t.c
Index: clang/test/utils/update_cc_test_checks/Inputs/replace-value-regex-across-runs.c.expected
==

[PATCH] D71734: [Modules] Handle tag types and complain about bad merges in C/Objective-C mode

2021-06-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 353081.
vsapsai marked an inline comment as done.
vsapsai added a comment.

Rebase on top of "main" and address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/odr_hash-record.c

Index: clang/test/Modules/odr_hash-record.c
===
--- /dev/null
+++ clang/test/Modules/odr_hash-record.c
@@ -0,0 +1,391 @@
+// Clear and create directories
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/cache
+// RUN: mkdir %t/Inputs
+
+// Build first header file
+// RUN: echo "#define FIRST" >> %t/Inputs/first.h
+// RUN: cat %s   >> %t/Inputs/first.h
+
+// Build second header file
+// RUN: echo "#define SECOND" >> %t/Inputs/second.h
+// RUN: cat %s>> %t/Inputs/second.h
+
+// Test that each header can compile
+// RUN: %clang_cc1 -fsyntax-only -x c %t/Inputs/first.h
+// RUN: %clang_cc1 -fsyntax-only -x c %t/Inputs/second.h
+
+// Build module map file
+// RUN: echo "module FirstModule {" >> %t/Inputs/module.map
+// RUN: echo "header \"first.h\""   >> %t/Inputs/module.map
+// RUN: echo "}">> %t/Inputs/module.map
+// RUN: echo "module SecondModule {">> %t/Inputs/module.map
+// RUN: echo "header \"second.h\""  >> %t/Inputs/module.map
+// RUN: echo "}">> %t/Inputs/module.map
+
+// Run test
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c \
+// RUN:   -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN:   -I%t/Inputs -verify %s
+
+#if !defined(FIRST) && !defined(SECOND)
+#include "first.h"
+#include "second.h"
+#endif
+
+#if defined(FIRST)
+struct S1 {};
+struct S1 s1a;
+#elif defined(SECOND)
+struct S1 {};
+#else
+struct S1 s1;
+#endif
+
+#if defined(FIRST)
+struct S2 {
+  int x;
+  int y;
+};
+#elif defined(SECOND)
+struct S2 {
+  int y;
+  int x;
+};
+#else
+struct S2 s2;
+// expected-error@first.h:* {{'S2' has different definitions in different modules; first difference is definition in module 'FirstModule' found field 'x'}}
+// expected-note@second.h:* {{but in 'SecondModule' found field 'y'}}
+#endif
+
+#if defined(FIRST)
+struct S3 {
+  double x;
+};
+#elif defined(SECOND)
+struct S3 {
+  int x;
+};
+#else
+struct S3 s3;
+// expected-error@second.h:* {{'S3::x' from module 'SecondModule' is not present in definition of 'struct S3' in module 'FirstModule'}}
+// expected-note@first.h:* {{declaration of 'x' does not match}}
+#endif
+
+#if defined(FIRST)
+typedef int A;
+struct S4 {
+  A x;
+};
+
+struct S5 {
+  A x;
+};
+#elif defined(SECOND)
+typedef int B;
+struct S4 {
+  B x;
+};
+
+struct S5 {
+  int x;
+};
+#else
+struct S4 s4;
+// expected-error@first.h:* {{'S4' has different definitions in different modules; first difference is definition in module 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
+// expected-note@second.h:* {{but in 'SecondModule' found field 'x' with type 'B' (aka 'int')}}
+
+struct S5 s5;
+// expected-error@first.h:* {{'S5' has different definitions in different modules; first difference is definition in module 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
+// expected-note@second.h:* {{but in 'SecondModule' found field 'x' with type 'int'}}
+#endif
+
+#if defined(FIRST)
+struct S6 {
+  unsigned x;
+};
+#elif defined(SECOND)
+struct S6 {
+  unsigned x : 1;
+};
+#else
+struct S6 s6;
+// expected-error@first.h:* {{'S6' has different definitions in different modules; first difference is definition in module 'FirstModule' found non-bitfield 'x'}}
+// expected-note@second.h:* {{but in 'SecondModule' found bitfield 'x'}}
+#endif
+
+#if defined(FIRST)
+struct S7 {
+  unsigned x : 2;
+};
+#elif defined(SECOND)
+struct S7 {
+  unsigned x : 1;
+};
+#else
+struct S7 s7;
+// expected-error@first.h:* {{'S7' has different definitions in different modules; first difference is definition in module 'FirstModule' found bitfield 'x' with one width expression}}
+// expected-note@second.h:* {{but in 'SecondModule' found bitfield 'x' with different width expression}}
+#endif
+
+#if defined(FIRST)
+struct S8 {
+  unsigned x : 2;
+};
+#elif defined(SECOND)
+struct S8 {
+  unsigned x : 1 + 1;
+};
+#else
+struct S8 s8;
+// expected-error@first.h:* {{'S8' has different definitions in different modules; first difference is definition in module 'FirstModule' found bitfield 'x' with one width expression}}
+// expected-note@second.h:* {{but in 'SecondModule' found bitfield 'x' with different width expression}}
+#endif
+
+#if defined(FIRS

[PATCH] D71734: [Modules] Handle tag types and complain about bad merges in C/Objective-C mode

2021-06-18 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/AST/DeclCXX.cpp:487
   // Only calculate hash on first call of getODRHash per record.
-  ODRHash Hash;
+  class ODRHash Hash;
   Hash.AddCXXRecordDecl(getDefinition());

rsmith wrote:
> I think this change is no longer necessary.
Reverted the change.



Comment at: clang/lib/Serialization/ASTReader.cpp:9585-9587
+assert(getContext().hasSameType(FirstField->getType(),
+SecondField->getType()));
+

bruno wrote:
> rsmith wrote:
> > bruno wrote:
> > > rsmith wrote:
> > > > I don't understand why this assertion would be correct if the above 
> > > > branch can ever be taken. It's possible for two different types to have 
> > > > the same hash, and it looks like we'll assert here if that happens. 
> > > > Should we be branching on `hasSameType` above instead of comparing 
> > > > hashes?
> > > This is trying to cover two things. The first one is to handle nested 
> > > anonymous unions, which might have the same type, but underlying 
> > > mismatching fields:
> > > ```
> > > #if defined(FIRST)
> > > struct AU {
> > >   union {
> > > int a;
> > >   };
> > > };
> > > #elif defined(SECOND)
> > > struct AU {
> > >   union {
> > > char a;
> > >   };
> > > };
> > > #else
> > > struct AU au;
> > > ```
> > > 
> > > The second is to allow for @interfaces (downstream patches at the moment) 
> > > to reuse logic to diagnose fields in `ODRDiagField` without having to add 
> > > its own check for the underlying types. Does that makes sense?
> > I still don't understand.
> > 
> > Either the types are always the same before the previous `if` and can only 
> > differ in type sugar (in which case this change is unnecessary), or the 
> > types can be different in more than just sugar (in which case this assert 
> > is wrong because there's no guarantee that different types will have 
> > different hashes).
> > 
> > What am I missing?
> @vsapsai: just to follow up here a bit. I don't remember the full context 
> anymore, but it should be fine to reintroduce this in a later patch with a 
> better explanation to @rsmith, or change the approach if it makes sense. 
> Thanks for taking this over!
I think it makes the most sense to remove the assertion. Based on the local 
code, it doesn't make much sense, as equality of field names doesn't imply the 
equality of field types. On the higher level, we were checking field types in a 
different place, specifically we populated `PendingOdrMergeChecks` in 
`ASTDeclReader::findExisting` and diagnosed it earlier in this mega-method 
`ASTReader::diagnoseOdrViolations` (error constant 
`err_module_odr_violation_missing_decl`). Also you can notice that the 
diagnostic for

```lang=c++
struct S { int x; };

struct S { float x; };
```
is different, it is
> 'S::x' from module 'SecondModule' is not present in definition of 'S' in 
> module 'FirstModule'

compared to
> 'S' has different definitions in different modules; first difference is 
> definition in module 'FirstModule' found field 'x' with type 'int'

that we emit in ODRDiagField.

It is possible to try to make unions behave the same way as structs (and keep 
the assertion) but I'm not sure it is worth it. Looks like the major difference 
is that not all tag types are true Redeclerable and I don't know if it is 
something we should change.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:489
+  // of CXXRecordDecl.
+  Record.push_back(Writer.getLangOpts().CPlusPlus ? 0UL : D->getODRHash());
 

rsmith wrote:
> It would be better to avoid writing this at all for a CXXRecordDecl, to avoid 
> adding 6 unused bits per class to the bitcode. (Please also look at 
> isa(D) not at the LangOpts here.)
Changed to write ODR hash for everything except CXXRecordDecl (right now 
everything is RecordDecl). Also updated ASTReaderDecl.cpp. Not 100% sure I 
understand your comment correctly, so if my change is way off, please let me 
know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

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


[PATCH] D104561: [NFC][compiler-rt][hwasan] Move hwasanThreadList().CreateCurrentThread() into InitThreads

2021-06-18 Thread Leonard Chan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7999e73caef: [NFC][compiler-rt][hwasan] Move 
hwasanThreadList().CreateCurrentThread() into… (authored by leonardchan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104561

Files:
  compiler-rt/lib/hwasan/hwasan.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp


Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -250,6 +250,7 @@
   ProtectGap(thread_space_end,
  __hwasan_shadow_memory_dynamic_address - thread_space_end);
   InitThreadList(thread_space_start, thread_space_end - thread_space_start);
+  hwasanThreadList().CreateCurrentThread();
 }
 
 bool MemIsApp(uptr p) {
Index: compiler-rt/lib/hwasan/hwasan.cpp
===
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -276,7 +276,6 @@
   }
 
   InitThreads();
-  hwasanThreadList().CreateCurrentThread();
 
   hwasan_instrumentation_inited = 1;
 }


Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -250,6 +250,7 @@
   ProtectGap(thread_space_end,
  __hwasan_shadow_memory_dynamic_address - thread_space_end);
   InitThreadList(thread_space_start, thread_space_end - thread_space_start);
+  hwasanThreadList().CreateCurrentThread();
 }
 
 bool MemIsApp(uptr p) {
Index: compiler-rt/lib/hwasan/hwasan.cpp
===
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -276,7 +276,6 @@
   }
 
   InitThreads();
-  hwasanThreadList().CreateCurrentThread();
 
   hwasan_instrumentation_inited = 1;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 193e41c - [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to noprofile

2021-06-18 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2021-06-18T13:42:32-07:00
New Revision: 193e41c987127aad86d0380df83e67a85266f1f1

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

LOG: [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to 
noprofile

noprofile IR attribute already exists to prevent profiling with PGO;
emit that when a function uses the newly added no_profile function
attribute.

The Linux kernel would like to avoid compiler generated code in
functions annotated with such attribute. We already respect this for
libcalls to fentry() and mcount().

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80223
Link: 
https://lore.kernel.org/lkml/cakwvodmpti93n2l0_yqkrzldmpxzror7zggszonyaw2pgsh...@mail.gmail.com/

Reviewed By: MaskRay, void, phosek, aaron.ballman

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

Added: 
clang/test/CodeGen/no_profile.c
clang/test/Sema/no_profile-attribute.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 714621087cb77..8829b4b6d560b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1970,6 +1970,13 @@ def NoInstrumentFunction : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def NoProfileFunction : InheritableAttr {
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];
+  let SimpleHandler = 1;
+}
+
 def NotTailCalled : InheritableAttr {
   let Spellings = [Clang<"not_tail_called">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6594e77d0beef..6173c8cd90af0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2559,6 +2559,17 @@ This attribute accepts a single parameter that must be 
one of the following:
   }];
 }
 
+def NoProfileDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``no_profile`` attribute on a function declaration to denote that the
+compiler should not instrument the function with profile-related
+instrumentation, such as via the
+``-fprofile-generate`` / ``-fprofile-instr-generate`` /
+``-fcs-profile-generate`` / ``-fprofile-arcs`` flags.
+}];
+}
+
 def NoSanitizeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 518305e1113cd..97288d01686e1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))

diff  --git a/clang/test/CodeGen/no_profile.c b/clang/test/CodeGen/no_profile.c
new file mode 100644
index 0..5ac116b19c7a0
--- /dev/null
+++ b/clang/test/CodeGen/no_profile.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-arcs -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+void __attribute__((no_profile)) no_instr() {
+// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]]
+}
+
+void instr(void) {
+// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]]
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: noprofile
+// CHECK: }

diff  --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index 8256f12a07684..290306bfb6a23 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -99,6 +99,7 @@
 // CHECK-NEXT: NoMerge (SubjectMatchRule_function)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoMips16 (SubjectMatchRule_function)
+// CHECK-NEXT: NoProfileFunction (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (S

[PATCH] D104475: [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to noprofile

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG193e41c98712: [Clang][Codegen] Add GNU function attribute 
'no_profile' and lower it to… (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/no_profile.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/no_profile-attribute.c

Index: clang/test/Sema/no_profile-attribute.c
===
--- /dev/null
+++ clang/test/Sema/no_profile-attribute.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+__attribute__((no_profile))
+void no_profile0(void);
+#if !__has_attribute(no_profile)
+#error "Where did the no_profile function attribute go?"
+#endif
+
+void no_profile1(__attribute__((no_profile)) int param); // expected-warning {{'no_profile' attribute only applies to functions}}
+__attribute__((no_profile(""))) // expected-error {{'no_profile' attribute takes no arguments}}
+void no_profile2(void);
+void no_profile3(void) {
+  __attribute__((no_profile)); // expected-error {{'no_profile' attribute cannot be applied to a statement}}
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -99,6 +99,7 @@
 // CHECK-NEXT: NoMerge (SubjectMatchRule_function)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: NoMips16 (SubjectMatchRule_function)
+// CHECK-NEXT: NoProfileFunction (SubjectMatchRule_function)
 // CHECK-NEXT: NoSanitize (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSanitizeSpecific (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: NoSpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/test/CodeGen/no_profile.c
===
--- /dev/null
+++ clang/test/CodeGen/no_profile.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-arcs -disable-llvm-passes \
+// RUN:   -emit-llvm -o - %s | FileCheck %s
+int g(int);
+
+void __attribute__((no_profile)) no_instr() {
+// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]]
+}
+
+void instr(void) {
+// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]]
+}
+// CHECK: attributes [[ATTR]] = {{.*}} noprofile
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: noprofile
+// CHECK: }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -893,6 +893,9 @@
   if (D && D->hasAttr())
 Fn->addFnAttr("cfi-canonical-jump-table");
 
+  if (D && D->hasAttr())
+Fn->addFnAttr(llvm::Attribute::NoProfile);
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2559,6 +2559,17 @@
   }];
 }
 
+def NoProfileDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the ``no_profile`` attribute on a function declaration to denote that the
+compiler should not instrument the function with profile-related
+instrumentation, such as via the
+``-fprofile-generate`` / ``-fprofile-instr-generate`` /
+``-fcs-profile-generate`` / ``-fprofile-arcs`` flags.
+}];
+}
+
 def NoSanitizeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1970,6 +1970,13 @@
   let SimpleHandler = 1;
 }
 
+def NoProfileFunction : InheritableAttr {
+  let Spellings = [Clang<"no_profile">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoProfileDocs];
+  let SimpleHandler = 1;
+}
+
 def NotTailCalled : InheritableAttr {
   let Spellings = [Clang<"not_tail_called">];
   let Subjec

[PATCH] D104342: [IR] convert warn-stack-size from module attr to fn attr

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 353102.
nickdesaulniers added a comment.

- fix lint, add linker test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Frontend/fwarn-stack-size.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Module.h
  llvm/lib/CodeGen/PrologEpilogInserter.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/CodeGen/ARM/warn-stack.ll
  llvm/test/CodeGen/X86/warn-stack.ll
  llvm/test/Linker/warn-stack-frame.ll
  llvm/test/Transforms/Inline/warn-stack-size.ll
  llvm/test/Verifier/invalid-warn-stack-size.ll

Index: llvm/test/Verifier/invalid-warn-stack-size.ll
===
--- /dev/null
+++ llvm/test/Verifier/invalid-warn-stack-size.ll
@@ -0,0 +1,10 @@
+; RUN: not opt -passes=verify %s -disable-output 2>&1 | FileCheck %s
+define void @foo() "warn-stack-size"="42" { ret void }
+define void @bar() "warn-stack-size"="-1" { ret void }
+define void @baz() "warn-stack-size"="9" { ret void }
+define void @qux() "warn-stack-size"="a lot lol" { ret void }
+
+; CHECK-NOT: "warn-stack-size" takes an unsigned integer: 42
+; CHECK: "warn-stack-size" takes an unsigned integer: -1
+; CHECK: "warn-stack-size" takes an unsigned integer: 9
+; CHECK: "warn-stack-size" takes an unsigned integer: a lot lol
Index: llvm/test/Transforms/Inline/warn-stack-size.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/warn-stack-size.ll
@@ -0,0 +1,24 @@
+; RUN: opt -passes=inline -S %s | FileCheck %s
+
+; The caller should NOT inherit the callee's "warn-stack-size" value.
+define void @foo() "warn-stack-size"="42" { ret void }
+; CHECK: @foo(
+; CHECK-NEXT:ret void
+;
+define void @bar() "warn-stack-size"="7" {
+; CHECK: @bar() [[ATTR0:#[0-9]+]] {
+; CHECK-NEXT:ret void
+;
+  call void @foo()
+  ret void
+}
+define void @baz() "warn-stack-size"="99" {
+; CHECK: @baz() [[ATTR1:#[0-9]+]] {
+; CHECK-NEXT:ret void
+;
+  call void @bar()
+  ret void
+}
+
+; CHECK: attributes [[ATTR0]] = {{.*}} "warn-stack-size"="7"
+; CHECK: attributes [[ATTR1]] = {{.*}} "warn-stack-size"="99"
Index: llvm/test/Linker/warn-stack-frame.ll
===
--- llvm/test/Linker/warn-stack-frame.ll
+++ /dev/null
@@ -1,16 +0,0 @@
-; RUN: split-file %s %t
-; RUN: llvm-link %t/main.ll %t/match.ll
-; RUN: not llvm-link %t/main.ll %t/mismatch.ll 2>&1 | \
-; RUN:   FileCheck --check-prefix=CHECK-MISMATCH %s
-
-; CHECK-MISMATCH: error: linking module flags 'warn-stack-size': IDs have conflicting values
-
-;--- main.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
-;--- match.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
-;--- mismatch.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 81}
Index: llvm/test/CodeGen/X86/warn-stack.ll
===
--- llvm/test/CodeGen/X86/warn-stack.ll
+++ llvm/test/CodeGen/X86/warn-stack.ll
@@ -4,7 +4,7 @@
 ; 
 
 ; CHECK-NOT: nowarn
-define void @nowarn() nounwind ssp {
+define void @nowarn() nounwind ssp "warn-stack-size"="80" {
 entry:
   %buffer = alloca [12 x i8], align 1
   %arraydecay = getelementptr inbounds [12 x i8], [12 x i8]* %buffer, i64 0, i64 0
@@ -13,7 +13,7 @@
 }
 
 ; CHECK: warning: stack size limit exceeded (88) in warn
-define void @warn() nounwind ssp {
+define void @warn() nounwind ssp "warn-stack-size"="80" {
 entry:
   %buffer = alloca [80 x i8], align 1
   %arraydecay = getelementptr inbounds [80 x i8], [80 x i8]* %buffer, i64 0, i64 0
@@ -22,6 +22,3 @@
 }
 
 declare void @doit(i8*)
-
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
Index: llvm/test/CodeGen/ARM/warn-stack.ll
===
--- llvm/test/CodeGen/ARM/warn-stack.ll
+++ llvm/test/CodeGen/ARM/warn-stack.ll
@@ -4,7 +4,7 @@
 ; 
 
 ; CHECK-NOT: nowarn
-define void @nowarn() nounwind ssp "frame-pointer"="all" {
+define void @nowarn() nounwind ssp "frame-pointer"="all" "warn-stack-size"="80" {
 entry:
   %buffer = alloca [12 x i8], align 1
   %arraydecay = getelementptr inbounds [12 x i8], [12 x i8]* %buffer, i64 0, i64 0
@@ -13,7 +13,7 @@
 }
 
 ; CHECK: warning: stack size limit exceeded (92) in warn
-define void @warn() nounwind ssp "frame-pointer"="all" {
+define void @warn() nounwind ssp "frame-pointer"="all" "warn-stack-size"="80" {
 entry:
   %buffer = alloca [80 x i8], align 1
   %arraydecay = getelementptr inbounds [80 x i8], [80 x i8]* %buffer, i64 0, i64 0
@@ -22,6 +22,3 @@
 }
 
 declare void @doit(i8*)
-
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
Index: llvm/lib/IR/Verifier

[PATCH] D104494: [dfsan] Replace dfs$ prefix with .dfsan suffix

2021-06-18 Thread George Balatsouras via Phabricator via cfe-commits
gbalats added a comment.

In D104494#2827708 , @gbalats wrote:

> In D104494#2827639 , @vitalybuka 
> wrote:
>
>> https://lab.llvm.org/buildbot/#/builders/37/builds/4620 looks broken by this 
>> patch
>
> Looking into this. I missed (due to the "\\" in the expression) updating this:
> https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/fuzzer/dataflow/DataFlow.cpp#L93-L94
>
> I will try to get `ninja check-fuzzer` working again and either do a small 
> fix forward or revert (if it turns out to be more complicated than just 
> updating this expression).

https://reviews.llvm.org/D104568


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104494

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


[PATCH] D104342: [IR] convert warn-stack-size from module attr to fn attr

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D104342#2827847 , @dblaikie wrote:

> Another thing you might want to check is linkonce_odr functions - I guess 
> you'll get an arbitrary choice between two linkonce_odr functions under LTO 
> where they have different warn-stack-size? Maybe there's a way/place to merge 
> and always pick the lower or upper value if there's one you think would be 
> more right?

I've added an `llvm-link` test for this. I'm not sure it adds any signal though 
here; I think the answer to such a question is "don't do that."




Comment at: llvm/test/Transforms/Inline/warn-stack-size.ll:1
+; RUN: opt -passes=inline -S %s | FileCheck %s
+

dblaikie wrote:
> Nice to see the test - though I probably wouldn't bother adding this test if 
> this behavior already falls out of more general support in the inliner and 
> the way it already handles attributes - the general behavior is likely 
> already tested elsewhere? (though it'd be good to confirm that either in 
> tests and/or the inliner code itself)
> 
> my original question was to confirm that the inliner already had accounted 
> for this situation in a way that was desirable & it looks like/sounds like it 
> is.
`AttributeFuncs::areInlineCompatible` seems to define the disallow-list for 
mismatched function attributes.

`AttributeFuncs::mergeAttributesForInlining()` seems to be the merging strategy 
for certain function attributes.

I agree that this test just confirms that the implicit default merge strategy 
is used.  I guess it would fail if someone unintentionally changed that, but I 
don't mind removing this test either.  WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

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


[PATCH] D104342: [IR] convert warn-stack-size from module attr to fn attr

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 353110.
nickdesaulniers added a comment.

- git add the Linker test!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Frontend/fwarn-stack-size.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Module.h
  llvm/lib/CodeGen/PrologEpilogInserter.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/CodeGen/ARM/warn-stack.ll
  llvm/test/CodeGen/X86/warn-stack.ll
  llvm/test/Linker/warn-stack-frame.ll
  llvm/test/Linker/warn-stack-size.ll
  llvm/test/Transforms/Inline/warn-stack-size.ll
  llvm/test/Verifier/invalid-warn-stack-size.ll

Index: llvm/test/Verifier/invalid-warn-stack-size.ll
===
--- /dev/null
+++ llvm/test/Verifier/invalid-warn-stack-size.ll
@@ -0,0 +1,10 @@
+; RUN: not opt -passes=verify %s -disable-output 2>&1 | FileCheck %s
+define void @foo() "warn-stack-size"="42" { ret void }
+define void @bar() "warn-stack-size"="-1" { ret void }
+define void @baz() "warn-stack-size"="9" { ret void }
+define void @qux() "warn-stack-size"="a lot lol" { ret void }
+
+; CHECK-NOT: "warn-stack-size" takes an unsigned integer: 42
+; CHECK: "warn-stack-size" takes an unsigned integer: -1
+; CHECK: "warn-stack-size" takes an unsigned integer: 9
+; CHECK: "warn-stack-size" takes an unsigned integer: a lot lol
Index: llvm/test/Transforms/Inline/warn-stack-size.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/warn-stack-size.ll
@@ -0,0 +1,24 @@
+; RUN: opt -passes=inline -S %s | FileCheck %s
+
+; The caller should NOT inherit the callee's "warn-stack-size" value.
+define void @foo() "warn-stack-size"="42" { ret void }
+; CHECK: @foo(
+; CHECK-NEXT:ret void
+;
+define void @bar() "warn-stack-size"="7" {
+; CHECK: @bar() [[ATTR0:#[0-9]+]] {
+; CHECK-NEXT:ret void
+;
+  call void @foo()
+  ret void
+}
+define void @baz() "warn-stack-size"="99" {
+; CHECK: @baz() [[ATTR1:#[0-9]+]] {
+; CHECK-NEXT:ret void
+;
+  call void @bar()
+  ret void
+}
+
+; CHECK: attributes [[ATTR0]] = {{.*}} "warn-stack-size"="7"
+; CHECK: attributes [[ATTR1]] = {{.*}} "warn-stack-size"="99"
Index: llvm/test/Linker/warn-stack-size.ll
===
--- /dev/null
+++ llvm/test/Linker/warn-stack-size.ll
@@ -0,0 +1,22 @@
+; RUN: split-file %s %t
+; RUN: llvm-link %t/first.ll %t/second.ll -o %t/linked.bc
+; RUN: llvm-dis %t/linked.bc -o - | FileCheck %s
+
+; CHECK: define weak_odr void @bar() [[ATTR0:#[0-9]+]]
+; CHECK: define linkonce_odr void @foo() [[ATTR1:#[0-9]+]]
+; CHECK: define linkonce void @baz() [[ATTR2:#[0-9]+]]
+
+; CHECK: attributes [[ATTR0]] = { "warn-stack-size"="43" }
+; CHECK: attributes [[ATTR1]] = { "warn-stack-size"="42" }
+; CHECK: attributes [[ATTR2]] = { "warn-stack-size"="44" }
+
+;--- first.ll
+define linkonce_odr void @foo() "warn-stack-size"="42" { ret void }
+define weak_odr void @bar() "warn-stack-size"="43" { ret void }
+define linkonce void @baz() "warn-stack-size"="44" { ret void }
+@llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void ()* @bar to i8*), i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @baz to i8*)], section "llvm.metadata"
+;--- second.ll
+define linkonce_odr void @foo() "warn-stack-size"="9001" { ret void }
+define weak_odr void @bar() "warn-stack-size"="9002" { ret void }
+define linkonce void @baz() "warn-stack-size"="9003" { ret void }
+@llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void ()* @bar to i8*), i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @baz to i8*)], section "llvm.metadata"
Index: llvm/test/Linker/warn-stack-frame.ll
===
--- llvm/test/Linker/warn-stack-frame.ll
+++ /dev/null
@@ -1,16 +0,0 @@
-; RUN: split-file %s %t
-; RUN: llvm-link %t/main.ll %t/match.ll
-; RUN: not llvm-link %t/main.ll %t/mismatch.ll 2>&1 | \
-; RUN:   FileCheck --check-prefix=CHECK-MISMATCH %s
-
-; CHECK-MISMATCH: error: linking module flags 'warn-stack-size': IDs have conflicting values
-
-;--- main.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
-;--- match.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 80}
-;--- mismatch.ll
-!llvm.module.flags = !{!0}
-!0 = !{i32 1, !"warn-stack-size", i32 81}
Index: llvm/test/CodeGen/X86/warn-stack.ll
===
--- llvm/test/CodeGen/X86/warn-stack.ll
+++ llvm/test/CodeGen/X86/warn-stack.ll
@@ -4,7 +4,7 @@
 ; 
 
 ; CHECK-NOT: nowarn
-define void @nowarn() nounwind ssp {
+define void @nowarn() nounwind ssp "warn-stack-size"="80" {
 entry:
   %buffer = alloca [12 x i8

[clang] 8172183 - Whitespace fixes for

2021-06-18 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2021-06-18T15:09:18-07:00
New Revision: 817218336aa3e3c0ca422ae00f8d8ca41b8fbd6d

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

LOG: Whitespace fixes for
193e41c987127aad86d0380df83e67a85266f1f1
which reportedly fails on the mac builds.

Added: 


Modified: 
clang/test/CodeGen/no_profile.c

Removed: 




diff  --git a/clang/test/CodeGen/no_profile.c b/clang/test/CodeGen/no_profile.c
index 5ac116b19c7a..50ca71f4fa0e 100644
--- a/clang/test/CodeGen/no_profile.c
+++ b/clang/test/CodeGen/no_profile.c
@@ -9,11 +9,11 @@
 int g(int);
 
 void __attribute__((no_profile)) no_instr() {
-// CHECK: define {{.*}} void @no_instr() [[ATTR:#[0-9]+]]
+// CHECK: define {{.*}}void @no_instr() [[ATTR:#[0-9]+]]
 }
 
 void instr(void) {
-// CHECK: define {{.*}} void @instr() [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}}void @instr() [[ATTR2:#[0-9]+]]
 }
 // CHECK: attributes [[ATTR]] = {{.*}} noprofile
 // CHECK: attributes [[ATTR2]] = {



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


[PATCH] D104475: [Clang][Codegen] Add GNU function attribute 'no_profile' and lower it to noprofile

2021-06-18 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

rG817218336aa3e3c0ca422ae00f8d8ca41b8fbd6d 
 follow up 
based on reports of test failure on mac.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104475

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


[clang] fb32de9 - Re-Revert "DirectoryWatcher: add an implementation for Windows"

2021-06-18 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-06-18T18:51:41-04:00
New Revision: fb32de9e97af0921242a021e30020ffacf7aa6e2

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

LOG: Re-Revert "DirectoryWatcher: add an implementation for Windows"

This reverts commit 76f1baa7875acd88bdd4b431eed6e2d2decfc0fe.

Also reverts 2 follow-ups:

1. Revert "DirectoryWatcher: also wait for the notifier thread"
   This reverts commit 527a1821e6f8e115db3335a3341c7ac491725a0d.

2. Revert "DirectoryWatcher: close a possible window of race on Windows"
   This reverts commit a6948da86ad7e78d66b26263c2681ef6385cc234.

Makes tests hang, see comments on https://reviews.llvm.org/D88666

Added: 


Modified: 
clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
clang/unittests/DirectoryWatcher/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp 
b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
index 8a4f5a87d967c..25cbcf536388a 100644
--- a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
+++ b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
@@ -6,12 +6,19 @@
 //
 
//===--===//
 
+// TODO: This is not yet an implementation, but it will make it so Windows
+//   builds don't fail.
+
 #include "DirectoryScanner.h"
 #include "clang/DirectoryWatcher/DirectoryWatcher.h"
+
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/ConvertUTF.h"
+#include "llvm/ADT/ScopeExit.h"
+#include "llvm/Support/AlignOf.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/Windows/WindowsSupport.h"
+#include 
 #include 
 #include 
 #include 
@@ -21,283 +28,23 @@
 
 namespace {
 
-using DirectoryWatcherCallback =
-std::function, bool)>;
-
 using namespace llvm;
 using namespace clang;
 
 class DirectoryWatcherWindows : public clang::DirectoryWatcher {
-  OVERLAPPED Overlapped;
-
-  std::vector Notifications;
-
-  std::thread WatcherThread;
-  std::thread HandlerThread;
-  std::function, bool)> Callback;
-  SmallString Path;
-  HANDLE Terminate;
-
-  std::mutex Mutex;
-  bool WatcherActive = false;
-  bool NotifierActive = false;
-  std::condition_variable Ready;
-
-  class EventQueue {
-std::mutex M;
-std::queue Q;
-std::condition_variable CV;
-
-  public:
-void emplace(DirectoryWatcher::Event::EventKind Kind, StringRef Path) {
-  {
-std::unique_lock L(M);
-Q.emplace(Kind, Path);
-  }
-  CV.notify_one();
-}
-
-DirectoryWatcher::Event pop_front() {
-  std::unique_lock L(M);
-  while (true) {
-if (!Q.empty()) {
-  DirectoryWatcher::Event E = Q.front();
-  Q.pop();
-  return E;
-}
-CV.wait(L, [this]() { return !Q.empty(); });
-  }
-}
-  } Q;
-
 public:
-  DirectoryWatcherWindows(HANDLE DirectoryHandle, bool WaitForInitialSync,
-  DirectoryWatcherCallback Receiver);
-
-  ~DirectoryWatcherWindows() override;
-
-  void InitialScan();
-  void WatcherThreadProc(HANDLE DirectoryHandle);
-  void NotifierThreadProc(bool WaitForInitialSync);
+  ~DirectoryWatcherWindows() override { }
+  void InitialScan() { }
+  void EventReceivingLoop() { }
+  void StopWork() { }
 };
-
-DirectoryWatcherWindows::DirectoryWatcherWindows(
-HANDLE DirectoryHandle, bool WaitForInitialSync,
-DirectoryWatcherCallback Receiver)
-: Callback(Receiver), Terminate(INVALID_HANDLE_VALUE) {
-  // Pre-compute the real location as we will be handing over the directory
-  // handle to the watcher and performing synchronous operations.
-  {
-DWORD Size = GetFinalPathNameByHandleW(DirectoryHandle, NULL, 0, 0);
-std::unique_ptr Buffer{new WCHAR[Size]};
-Size = GetFinalPathNameByHandleW(DirectoryHandle, Buffer.get(), Size, 0);
-Buffer[Size] = L'\0';
-llvm::sys::windows::UTF16ToUTF8(Buffer.get(), Size, Path);
-  }
-
-  size_t EntrySize = sizeof(FILE_NOTIFY_INFORMATION) + MAX_PATH * 
sizeof(WCHAR);
-  Notifications.resize((4 * EntrySize) / sizeof(DWORD));
-
-  memset(&Overlapped, 0, sizeof(Overlapped));
-  Overlapped.hEvent =
-  CreateEventW(NULL, /*bManualReset=*/FALSE, /*bInitialState=*/FALSE, 
NULL);
-  assert(Overlapped.hEvent && "unable to create event");
-
-  Terminate =
-  CreateEventW(NULL, /*bManualReset=*/TRUE, /*bInitialState=*/FALSE, NULL);
-
-  WatcherThread = std::thread([this, DirectoryHandle]() {
-this->WatcherThreadProc(DirectoryHandle);
-  });
-
-  if (WaitForInitialSync)
-InitialScan();
-
-  HandlerThread = std::thread([this, WaitForInitialSync]() {
-this->NotifierThreadProc(WaitForInitialSync);
-  });
-
-  std::unique_lock lo

[PATCH] D88666: DirectoryWatcher: add an implementation for Windows

2021-06-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

We also see check-all timeout recently (fairly consistently), see 
https://bugs.chromium.org/p/chromium/issues/detail?id=1221702

Since Stella reported problems with this too, I speculatively reverted it (and 
follow-ups) in fb32de9e97af0921242a021e30020ffacf7aa6e2 
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88666

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


[PATCH] D88666: DirectoryWatcher: add an implementation for Windows

2021-06-18 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova added a comment.

In D88666#2828306 , @thakis wrote:

> We also see check-all timeout recently (fairly consistently), see 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1221702
>
> Since Stella reported problems with this too, I speculatively reverted it 
> (and follow-ups) in fb32de9e97af0921242a021e30020ffacf7aa6e2 
>  for now.

Thanks!

I'm still trying to reproduce locally by running bigger and bigger sets of 
tests. check-clang doesn't appear to reproduce the issue for me, all of our 
online tests run check-all, so I am trying that next.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88666

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


[PATCH] D103615: [Clang] Add option for vector compare compatibility.

2021-06-18 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp updated this revision to Diff 353126.
stefanp added a comment.

Moved if statement out of switch and added the Default=Mixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/vector-compat-pixel-bool-ternary.c
  clang/test/CodeGen/vector-compat-pixel-bool.c
  clang/test/CodeGen/vector-compat-ternary.c
  clang/test/CodeGen/vector-compat.c

Index: clang/test/CodeGen/vector-compat.c
===
--- /dev/null
+++ clang/test/CodeGen/vector-compat.c
@@ -0,0 +1,162 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -vector-compare-compat=mixed -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -vector-compare-compat=gcc -triple powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -vector-compare-compat=xl -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang -mcpu=pwr8 -vector-compare-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -mcpu=pwr9 -vector-compare-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @ui8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned char ui8(vector unsigned char a, vector unsigned char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed char si8(vector signed char a, vector signed char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @ui16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned short ui16(vector unsigned short a, vector unsigned short b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+/

[PATCH] D104500: DRAFT: [clang] Apply P1825 as DR for all modes below C++20.

2021-06-18 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 353127.
mizvekov added a comment.

rip out warn_return_std_move completely.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b   %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -37,31 +37,31 @@
 
 struct ConvertingRVRef {
   ConvertingRVRef();
-  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+  ConvertingRVRef(ConvertingRVRef &) = delete;
 
   struct X {};
   ConvertingRVRef(X &&);
   operator X() const & = delete;
   operator X() &&;
 };
-TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+TEST(ConvertingRVRef);
 
 struct ConvertingCLVRef {
   ConvertingCLVRef();
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx98_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
+  operator X() && = delete; // cxx98_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx98_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
   SubMove();
-  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+  SubMove(SubMove &) = delete;
 
   SubMove(SubSubMove &&);
 };
-TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
+TEST(SubMove);
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ /dev/null
@@ -1,351 +0,0 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b,cxx2b -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=cxx11_17   -fcxx-exceptions -Wreturn-std-move %s
-
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
-
-// definitions for std::move
-namespace std {
-inline namespace foo {
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-
-template  typename remove_reference::type &&move(T &&t);
-} // namespace foo
-} // namespace std
-
-struct Instrument {
-Instrument() {}
-Instrument(Instrument&&) { /* MOVE */ }
-Instrument(const Instrument&) { /* COPY */ }
-};
-struct ConvertFromBase { Instrument i; };
-struct ConvertFromDerived { Instrument i; };
-struct Base {
-Instrument i;
-operator ConvertFromBase() const& { return ConvertFromBase{i}; }
-  

[PATCH] D104342: [IR] convert warn-stack-size from module attr to fn attr

2021-06-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D104342#2828193 , @nickdesaulniers 
wrote:

> In D104342#2827847 , @dblaikie 
> wrote:
>
>> Another thing you might want to check is linkonce_odr functions - I guess 
>> you'll get an arbitrary choice between two linkonce_odr functions under LTO 
>> where they have different warn-stack-size? Maybe there's a way/place to 
>> merge and always pick the lower or upper value if there's one you think 
>> would be more right?
>
> I've added an `llvm-link` test for this. I'm not sure it adds any signal 
> though here; I think the answer to such a question is "don't do that."

I don't think it's as easy as "don't do that". Unless someone passes exactly 
the same flags to every compilation (which they won't, that's why this is being 
implemented as a function attribute) then it'll be really easy for an inline 
function in a header (say, `std::vector::size` - something easy for two 
unrelated translation units to use) in two different translation units each 
with a different warn-stack-size flag and so to get somewhat arbitrary behavior 
about how that function is warned on.

For instance: maybe the function doesn't get a warning because a copy with a 
higher warn-stack-size value is picked, until the translation unit using that 
higher value is refactored and starts using std::list instead of std::vector... 
and now some other TU's std::vector is picked, with a lower warn-stack-size 
value and breaks the build (assuming -Werror)...




Comment at: llvm/test/Transforms/Inline/warn-stack-size.ll:1
+; RUN: opt -passes=inline -S %s | FileCheck %s
+

nickdesaulniers wrote:
> dblaikie wrote:
> > Nice to see the test - though I probably wouldn't bother adding this test 
> > if this behavior already falls out of more general support in the inliner 
> > and the way it already handles attributes - the general behavior is likely 
> > already tested elsewhere? (though it'd be good to confirm that either in 
> > tests and/or the inliner code itself)
> > 
> > my original question was to confirm that the inliner already had accounted 
> > for this situation in a way that was desirable & it looks like/sounds like 
> > it is.
> `AttributeFuncs::areInlineCompatible` seems to define the disallow-list for 
> mismatched function attributes.
> 
> `AttributeFuncs::mergeAttributesForInlining()` seems to be the merging 
> strategy for certain function attributes.
> 
> I agree that this test just confirms that the implicit default merge strategy 
> is used.  I guess it would fail if someone unintentionally changed that, but 
> I don't mind removing this test either.  WDYT?
generally I wouldn't add a test like this, or the LTO one - I'd just confirm 
that their features are separately tested and the behavior that's desired for 
how I want to use the feature (eg: I wouldn't test that the add instruction 
lowers to some machine code in my optimization - I'd confirm the add 
instruction has the desired semantics for whatever transformation I want to 
perform)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104342

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


  1   2   >