[PATCH] D55262: [OpenCL] Fix for TBAA information of pointer after addresspacecast

2018-12-11 Thread Romanov Vlad via Phabricator via cfe-commits
romanovvlad added a comment.

@Anastasia Could you, please, merge the patch if it's OK with you?


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

https://reviews.llvm.org/D55262



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


r348834 - Reland r348741 "[Sema] Further improvements to to static_assert diagnostics."

2018-12-11 Thread Clement Courbet via cfe-commits
Author: courbet
Date: Tue Dec 11 00:39:11 2018
New Revision: 348834

URL: http://llvm.org/viewvc/llvm-project?rev=348834&view=rev
Log:
Reland r348741 "[Sema] Further improvements to to static_assert diagnostics."

Fix a dangling reference to temporary, never return nullptr.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/PCH/cxx-static_assert.cpp
cfe/trunk/test/Sema/static-assert.c
cfe/trunk/test/SemaCXX/static-assert-cxx17.cpp
cfe/trunk/test/SemaCXX/static-assert.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=348834&r1=348833&r2=348834&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Dec 11 00:39:11 2018
@@ -2861,11 +2861,7 @@ public:
 
   /// Find the failed Boolean condition within a given Boolean
   /// constant expression, and describe it with a string.
-  ///
-  /// \param AllowTopLevelCond Whether to allow the result to be the
-  /// complete top-level condition.
-  std::pair
-  findFailedBooleanCondition(Expr *Cond, bool AllowTopLevelCond);
+  std::pair findFailedBooleanCondition(Expr *Cond);
 
   /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
   /// non-ArgDependent DiagnoseIfAttrs.

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=348834&r1=348833&r2=348834&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Dec 11 00:39:11 2018
@@ -13913,9 +13913,9 @@ Decl *Sema::BuildStaticAssertDeclaration
   Expr *InnerCond = nullptr;
   std::string InnerCondDescription;
   std::tie(InnerCond, InnerCondDescription) =
-findFailedBooleanCondition(Converted.get(),
-   /*AllowTopLevelCond=*/false);
-  if (InnerCond) {
+findFailedBooleanCondition(Converted.get());
+  if (InnerCond && !isa(InnerCond)
+&& !isa(InnerCond)) {
 Diag(StaticAssertLoc, diag::err_static_assert_requirement_failed)
   << InnerCondDescription << !AssertMessage
   << Msg.str() << InnerCond->getSourceRange();

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=348834&r1=348833&r2=348834&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Dec 11 00:39:11 2018
@@ -3052,30 +3052,42 @@ static Expr *lookThroughRangesV3Conditio
   return Cond;
 }
 
-// Print a diagnostic for the failing static_assert expression. Defaults to
-// pretty-printing the expression.
-static void prettyPrintFailedBooleanCondition(llvm::raw_string_ostream &OS,
-  const Expr *FailedCond,
-  const PrintingPolicy &Policy) {
-  const auto *DR = dyn_cast(FailedCond);
-  if (DR && DR->getQualifier()) {
-// If this is a qualified name, expand the template arguments in nested
-// qualifiers.
-DR->getQualifier()->print(OS, Policy, true);
-// Then print the decl itself.
-const ValueDecl *VD = DR->getDecl();
-OS << VD->getName();
-if (const auto *IV = dyn_cast(VD)) {
-  // This is a template variable, print the expanded template arguments.
-  printTemplateArgumentList(OS, IV->getTemplateArgs().asArray(), Policy);
+namespace {
+
+// A PrinterHelper that prints more helpful diagnostics for some 
sub-expressions
+// within failing boolean expression, such as substituting template parameters
+// for actual types.
+class FailedBooleanConditionPrinterHelper : public PrinterHelper {
+public:
+  explicit FailedBooleanConditionPrinterHelper(const PrintingPolicy &P)
+  : Policy(P) {}
+
+  bool handledStmt(Stmt *E, raw_ostream &OS) override {
+const auto *DR = dyn_cast(E);
+if (DR && DR->getQualifier()) {
+  // If this is a qualified name, expand the template arguments in nested
+  // qualifiers.
+  DR->getQualifier()->print(OS, Policy, true);
+  // Then print the decl itself.
+  const ValueDecl *VD = DR->getDecl();
+  OS << VD->getName();
+  if (const auto *IV = dyn_cast(VD)) {
+// This is a template variable, print the expanded template arguments.
+printTemplateArgumentList(OS, IV->getTemplateArgs().asArray(), Policy);
+  }
+  return true;
 }
-return;
+return false;
   }
-  FailedCond->printPretty(OS, nullptr, Policy);
-}
+
+private:
+  const PrintingPolicy Policy;
+};
+
+} // end anonymous namespace
 
 std::pair
-Sema::fin

[PATCH] D55428: [Docs] Expand -fstack-protector and -fstack-protector-all info

2018-12-11 Thread Carey Williams via Phabricator via cfe-commits
carwil updated this revision to Diff 177668.
carwil added a comment.

Make thopre's suggested changes.


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

https://reviews.llvm.org/D55428

Files:
  include/clang/Driver/Options.td


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1635,9 +1635,16 @@
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Force the usage of stack protectors for all functions">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,
-  HelpText<"Use a strong heuristic to apply stack protectors to functions">;
+  HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "
+   "Compared to -fstack-protector, this uses a stronger heuristic "
+   "that includes functions containing arrays of any size (and any 
type), "
+   "as well as any calls to alloca or the taking of an address from a 
local variable">;
 def fstack_protector : Flag<["-"], "fstack-protector">, Group,
-  HelpText<"Enable stack protectors for functions potentially vulnerable to 
stack smashing">;
+  HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "
+   "This uses a loose heuristic, which considers functions vulnerable "
+   "if they contain a char (or 8bit integer) array or constant sized 
calls to "
+   "alloca, which are of greater size than ssp-buffer-size (default: 8 
bytes). "
+   "All variable sized calls to alloca are considered vulnerable">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
 def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, 
Group, Flags<[CoreOption]>,


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1635,9 +1635,16 @@
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Force the usage of stack protectors for all functions">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, Group,
-  HelpText<"Use a strong heuristic to apply stack protectors to functions">;
+  HelpText<"Enable stack protectors for some functions vulnerable to stack smashing. "
+   "Compared to -fstack-protector, this uses a stronger heuristic "
+   "that includes functions containing arrays of any size (and any type), "
+   "as well as any calls to alloca or the taking of an address from a local variable">;
 def fstack_protector : Flag<["-"], "fstack-protector">, Group,
-  HelpText<"Enable stack protectors for functions potentially vulnerable to stack smashing">;
+  HelpText<"Enable stack protectors for some functions vulnerable to stack smashing. "
+   "This uses a loose heuristic, which considers functions vulnerable "
+   "if they contain a char (or 8bit integer) array or constant sized calls to "
+   "alloca, which are of greater size than ssp-buffer-size (default: 8 bytes). "
+   "All variable sized calls to alloca are considered vulnerable">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
 def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, Group, Flags<[CoreOption]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-11 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

A few more ideas for enhancements.




Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:41
+  //bool foo(A*)
+  // then they may not care about the return value,  because of passing data
+  // via the arguments however functions with no arguments will fall through

Double space after comma. Please check all comments.



Comment at: docs/clang-tidy/checks/modernize-use-nodiscard.rst:9
+
+Member functions which return non void types, and take in only pass by value or
+non constant references, and non pointer arguments, and of which the member

`non-void`, `pass-by-value`, `non-const`, `non-pointer` with hyphens.
You may simplify `, and of which ...` (if you have an idea how to do it) as 
it's a bit hard to read.

The phrase starting with `Unless` is actually not a full phrase.

I'd suggest something along the lines:

```
Adds ``[[nodiscard]]`` attributes (introduced in C++17) to member functions in 
order to
highlight at compile time which return values should not be ignored.
Member functions need to satisfy the following conditions to be considered by 
this check:
  - no ``[[nodiscard]]``, ``[[noreturn]]``, 
``__attribute__((warn_unused_result))``, ``[[clang::warn_unused_result]]`` nor 
`[[gcc::warn_unused_result]]``  attribute,
  - non-void return type,
  - no non-const reference parameters,
  - no non-const pointer parameters,
...
```



Comment at: test/clang-tidy/modernize-use-nodiscard-cxx11.cpp:24
+
+};
+

I think that it would be cool to test that the check doesn't warn on 
`[[clang::warn_unused_result]]` nor `[[gcc::warn_unused_result]]`.



Comment at: test/clang-tidy/modernize-use-nodiscard.cpp:126
+template
+class Bar
+{

JonasToth wrote:
> I think the template tests should be improved.
> What happens for `T empty()`, `typename T::value_type empty()` and so on. THe 
> same for the parameters for functions/methods (including function templates).
> 
> Thinking of it, it might be a good idea to ignore functions where the 
> heuristic depends on the template-paramters.
It might be a good idea to add a note in the documentation about handling of 
function templates and functions in class templates.


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

https://reviews.llvm.org/D55433



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


[PATCH] D55337: NFC: Move dumpDeclRef to NodeDumper

2018-12-11 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 177670.
steveire added a comment.

Rebase


Repository:
  rC Clang

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

https://reviews.llvm.org/D55337

Files:
  include/clang/AST/TextNodeDumper.h
  lib/AST/ASTDumper.cpp
  lib/AST/TextNodeDumper.cpp

Index: lib/AST/TextNodeDumper.cpp
===
--- lib/AST/TextNodeDumper.cpp
+++ lib/AST/TextNodeDumper.cpp
@@ -15,12 +15,13 @@
 
 using namespace clang;
 
-TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors,
+TextNodeDumper::TextNodeDumper(TextTreeStructure &TreeStructure,
+   raw_ostream &OS, bool ShowColors,
const SourceManager *SM,
const PrintingPolicy &PrintPolicy,
const comments::CommandTraits *Traits)
-: OS(OS), ShowColors(ShowColors), SM(SM), PrintPolicy(PrintPolicy),
-  Traits(Traits) {}
+: TreeStructure(TreeStructure), OS(OS), ShowColors(ShowColors), SM(SM),
+  PrintPolicy(PrintPolicy), Traits(Traits) {}
 
 void TextNodeDumper::Visit(const comments::Comment *C,
const comments::FullComment *FC) {
@@ -161,6 +162,17 @@
   OS << ")";
 }
 
+void TextNodeDumper::dumpDeclRef(const Decl *D, const char *Label) {
+  if (!D)
+return;
+
+  TreeStructure.addChild([=] {
+if (Label)
+  OS << Label << ' ';
+dumpBareDeclRef(D);
+  });
+}
+
 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
   if (Traits)
 return Traits->getCommandInfo(CommandID)->Name;
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -80,8 +80,8 @@
   const SourceManager *SM, bool ShowColors,
   const PrintingPolicy &PrintPolicy)
 : TreeStructure(OS, ShowColors),
-  NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
-  PrintPolicy(PrintPolicy), ShowColors(ShowColors) {}
+  NodeDumper(TreeStructure, OS, ShowColors, SM, PrintPolicy, Traits),
+  OS(OS), PrintPolicy(PrintPolicy), ShowColors(ShowColors) {}
 
 void setDeserialize(bool D) { Deserialize = D; }
 
@@ -92,7 +92,6 @@
 void dumpType(QualType T) { NodeDumper.dumpType(T); }
 void dumpTypeAsChild(QualType T);
 void dumpTypeAsChild(const Type *T);
-void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
 void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); }
 void dumpDeclContext(const DeclContext *DC);
 void dumpLookups(const DeclContext *DC, bool DumpDecls);
@@ -220,10 +219,10 @@
 dumpChild([=] { OS << "..."; });
 }
 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitTypedefType(const TypedefType *T) {
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitTypeOfExprType(const TypeOfExprType *T) {
   dumpStmt(T->getUnderlyingExpr());
@@ -240,7 +239,7 @@
   dumpTypeAsChild(T->getBaseType());
 }
 void VisitTagType(const TagType *T) {
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitAttributedType(const AttributedType *T) {
   // FIXME: AttrKind
@@ -249,7 +248,7 @@
 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
   OS << " depth " << T->getDepth() << " index " << T->getIndex();
   if (T->isParameterPack()) OS << " pack";
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
   dumpTypeAsChild(T->getReplacedParameter());
@@ -273,10 +272,10 @@
 dumpTypeAsChild(T->getAliasedType());
 }
 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
-  dumpDeclRef(T->getDecl());
+  NodeDumper.dumpDeclRef(T->getDecl());
 }
 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
   dumpTypeAsChild(T->getPointeeType());
@@ -510,17 +509,6 @@
   });
 }
 
-void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
-  if (!D)
-return;
-
-  dumpChild([=]{
-if (Label)
-  OS << Label << ' ';
-dumpBareDeclRef(D);
-  });
-}
-
 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
   if (!DC)
 return;
@@ -699,7 +687,7 @@
   NodeDumper.dumpSourceRange(R);
 
 if (From)
-  dumpDeclRef(From, Label);
+  NodeDumper.dumpDeclRef(From, Label);
 
 switch (A.getKind()) {
 case TemplateArgument::Null:
@@ -711,7 +699,7 @@
   break;
 case TemplateArgument::Declaration:
   OS << " decl";

[libunwind] r348836 - [SEH] Zero-initialize EXCEPTION_RECORD and UNWIND_HISTORY_TABLE before calling RtlUnwindEx

2018-12-11 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Tue Dec 11 01:53:11 2018
New Revision: 348836

URL: http://llvm.org/viewvc/llvm-project?rev=348836&view=rev
Log:
[SEH] Zero-initialize EXCEPTION_RECORD and UNWIND_HISTORY_TABLE before calling 
RtlUnwindEx

This fixes PR39935.

Modified:
libunwind/trunk/src/Unwind-seh.cpp

Modified: libunwind/trunk/src/Unwind-seh.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind-seh.cpp?rev=348836&r1=348835&r2=348836&view=diff
==
--- libunwind/trunk/src/Unwind-seh.cpp (original)
+++ libunwind/trunk/src/Unwind-seh.cpp Tue Dec 11 01:53:11 2018
@@ -374,6 +374,8 @@ _Unwind_Resume(_Unwind_Exception *except
 CONTEXT ms_ctx;
 UNWIND_HISTORY_TABLE hist;
 
+memset(&ms_exc, 0, sizeof(ms_exc));
+memset(&hist, 0, sizeof(hist));
 ms_exc.ExceptionCode = STATUS_GCC_THROW;
 ms_exc.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
 ms_exc.NumberParameters = 4;


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


[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-11 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:65
+void UseNodiscardCheck::registerMatchers(MatchFinder *Finder) {
+  // If we are using C++17 attributes we are going to need c++17
+  if (NoDiscardMacro == "[[nodiscard]]") {

I'd suggets: ` // If we use [[nodiscard]] attribute, we require at least C++17.`



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:73
+  // c++17 compilers.
+  if (!getLangOpts().CPlusPlus)
+return;

I'd move this if to the bottom of the function as it's the most general one and 
fix the comment above: e.g. `// Ignore non-C++ code.`.



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:92
+  SourceLocation Loc = MatchedDecl->getLocation();
+  if (!Loc.isValid() || Loc.isMacroID())
+return;

You can simplify `!Loc.isValid()` to `Loc.isInvalid()`.


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

https://reviews.llvm.org/D55433



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


[PATCH] D54862: [OpenCL] Add generic AS to 'this' pointer

2018-12-11 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaType.cpp:3929
+static TypeSourceInfo *
+GetFullTypeForDeclarator(TypeProcessingState &state, QualType declSpecType,
+ TypeSourceInfo *TInfo,

From the `state` you can use `getDeclarator()` that then call a method 
`getContext()`.



Comment at: lib/Sema/SemaType.cpp:5169
+TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
+   const DeclContext *DC) {
   // Determine the type of the declarator. Not all forms of declarator

Rather than passing `DeclContext` you can get it from the `Declarator` using 
`getContext()` method.



Comment at: lib/Sema/TreeTransform.h:4277
   //   cv-qualifiers are ignored.
-  if (T->isFunctionType())
+  // OpenCL: The address space should not be ignored.
+  if (T->isFunctionType()) {

mikael wrote:
> Another place where the address space was removed.
Why OpenCL in the comment, since the code seems to be rather generic.

Also not sure this comments adds anything that can't be understood from the 
code you are adding.



Comment at: test/SemaOpenCLCXX/address-space-templates.cl:7
   T f1(); // expected-error{{function type may not be qualified with an 
address space}}
-  void f2(T); // expected-error{{parameter may not be qualified with an 
address space}}
+  // FIXME: Should only get the error message once.
+  void f2(T); // expected-error{{parameter may not be qualified with an 
address space}} expected-error{{parameter may not be qualified with an address 
space}}

mikael wrote:
> This was the remaining issue that I have not solved yet. It looked like this 
> issue was not so trivial so I think it makes sense to postpone it.
Do you know why it appears twice?


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

https://reviews.llvm.org/D54862



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


[PATCH] D54862: [OpenCL] Add generic AS to 'this' pointer

2018-12-11 Thread Mikael Nilsson via Phabricator via cfe-commits
mikael marked an inline comment as done.
mikael added inline comments.



Comment at: test/SemaOpenCLCXX/address-space-templates.cl:7
   T f1(); // expected-error{{function type may not be qualified with an 
address space}}
-  void f2(T); // expected-error{{parameter may not be qualified with an 
address space}}
+  // FIXME: Should only get the error message once.
+  void f2(T); // expected-error{{parameter may not be qualified with an 
address space}} expected-error{{parameter may not be qualified with an address 
space}}

Anastasia wrote:
> mikael wrote:
> > This was the remaining issue that I have not solved yet. It looked like 
> > this issue was not so trivial so I think it makes sense to postpone it.
> Do you know why it appears twice?
I believe the main issue is that  we have some code that does the following in 
SemaTemplateInstantiateDecl.cpp:

```
OldTL.getAs()
```

But the implementation of getAs returns nullptr if you have local modifiers. So 
since this code will always return nullptr we end up taking a different paths.


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

https://reviews.llvm.org/D54862



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


[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-11 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 177679.
MyDeveloperDay marked 10 inline comments as done.
MyDeveloperDay added a comment.

Resolving some (not all yet) review comments, and looking for help on template 
parameter exclusion

- add additional template argument tests
- add additional clang-warn-unused-result tests
- add additional gcc-warn-unused-result tests
- exclude template parameters
- improve nodiscard wordage in documentation regarding conditions of checker


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

https://reviews.llvm.org/D55433

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNodiscardCheck.cpp
  clang-tidy/modernize/UseNodiscardCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-nodiscard.rst
  test/clang-tidy/modernize-use-nodiscard-clang-unused.cpp
  test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
  test/clang-tidy/modernize-use-nodiscard-gcc-unused.cpp
  test/clang-tidy/modernize-use-nodiscard-no-macro.cpp
  test/clang-tidy/modernize-use-nodiscard.cpp

Index: test/clang-tidy/modernize-use-nodiscard.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-nodiscard.cpp
@@ -0,0 +1,202 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}" \
+// RUN: -- -std=c++17 \
+
+#define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define NO_DISCARD [[nodiscard]]
+#define NO_RETURN [[noreturn]]
+
+#define BOOLEAN_FUNC bool f23() const
+
+typedef unsigned my_unsigned;
+typedef unsigned& my_unsigned_reference;
+typedef const unsigned& my_unsigned_const_reference;
+
+class Foo
+{
+public:
+using size_type = unsigned;
+
+bool f1() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f1() const;
+
+bool f2(int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f2(int) const;
+
+bool f3(const int &) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f3(const int &) const;
+
+bool f4(void) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f4(void) const;
+
+// negative tests
+
+void f5() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: void f5() const;
+
+bool f6();
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f6();
+
+bool f7(int &);
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f7(int &);
+
+bool f8(int &) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f8(int &) const;
+
+bool f9(int *) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f9(int *) const;
+
+bool f10(const int &,int &) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f10(const int &,int &) const;
+
+NO_DISCARD bool f12() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: NO_DISCARD bool f12() const;
+
+MUST_USE_RESULT bool f13() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: MUST_USE_RESULT bool f13() const;
+   
+[[nodiscard]] bool f11() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f11() const;
+
+bool _f20() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function '_f20' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool _f20() const;
+
+NO_RETURN bool f21() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: NO_RETURN bool f21() const;
+
+~Foo();
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: ~Foo();
+
+bool operator +=(int) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool operator +=(int) const;
+   
+// extra keywords (virtual,inline,const) on return type
+
+virtual bool f14() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f14' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD virtual bool f14() const;
+
+const bool f15() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f15' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD const bool f15() const;
+
+inline const bool f16() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f16' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD inline const bool f16() const;
+
+inline v

[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-11 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I wanted to leave a comment regarding running the [[nodiscard]] checker over 
all of clang... as requested by @JonasToth, @lebedev.ri  and @Szelethus

I'm not 100% sure how to present the results, but let me pick out a few 
high/low lights...

My efforts are somewhat thwarted by the fact I build and develop on windows 
(its ok, I use vim and command line tools!), but I run clang-tidy inside visual 
studio

My first problem is that on windows build of clang LLVM_NODISCARD is #defined 
as nothing unless you tell CMAKE to use C++17  (-DCMAKE_CXX_STANDARD="17" )

Then if you try and make llvm with VS2017 with C++17 turned on, you get into 
all sort of trouble,

You also get into trouble because there are many header files that it add 
LLVM_NODISCARD to but they don't include "Compiler.h" where LLVM is defined (so 
you end up with lots of errors)

3>C:\llvm\include\llvm/ADT/iterator_range.h(46): error C3646: 'IteratorT': 
unknown override specifier (compiling source file 
C:\llvm\tools\clang\utils\TableGen\ClangCommentHTMLNamedCharacterReferenceEmitter.cpp)

I'm wondering if there is anything I can add to the checker, to check to see if 
the macro being used for the ReplacementString is defined "in scope"

Of course as I'm not building with C++17 I could have used [[nodiscard]] 
instead of LLVM_NODISCARD, and that would of improved this I guess

I do get 100's of nodiscard warnings

the majority come from Diag() calls e.g.

  Diag(clang::diag::err_drv_expecting_fopenmp_with_fopenmp_targets);
  
  96>C:\llvm\tools\clang\lib\Driver\Driver.cpp(591): warning C4834: discarding 
return value of function with 'nodiscard' attribute
  96>C:\llvm\tools\clang\lib\Driver\Driver.cpp(688): warning C4834: discarding 
return value of function with 'nodiscard' attribute
  96>C:\llvm\tools\clang\lib\Driver\Driver.cpp(749): warning C4834: discarding 
return value of function with 'nodiscard' attribute
  96>C:\llvm\tools\clang\lib\Driver\Driver.cpp(795): warning C4834: discarding 
return value of function with 'nodiscard' attribute

But I do get some other ones which look interesting, (I don't know these areas 
of the code well enough to know if these are real issues!)

90>C:\llvm\tools\clang\lib\Frontend\DiagnosticRenderer.cpp(476): warning C4834: 
discarding return value of function with 'nodiscard' attribute

  static bool checkRangeForMacroArgExpansion(CharSourceRange Range,
 const SourceManager &SM,
 SourceLocation ArgumentLoc) {
SourceLocation BegLoc = Range.getBegin(), EndLoc = Range.getEnd();
while (BegLoc != EndLoc) {
  if (!checkLocForMacroArgExpansion(BegLoc, SM, ArgumentLoc))
return false;
  BegLoc.getLocWithOffset(1);
}
  
return checkLocForMacroArgExpansion(BegLoc, SM, ArgumentLoc);
  }

also a couple like this

90>C:\llvm\tools\clang\lib\Frontend\SerializedDiagnosticReader.cpp(133): 
warning C4834: discarding return value of function with 'nodiscard' attribute
90>C:\llvm\tools\clang\lib\Frontend\SerializedDiagnosticReader.cpp(175): 
warning C4834: discarding return value of function with 'nodiscard' attribute

  unsigned BlockOrCode = 0;
  llvm::ErrorOr Res = skipUntilRecordOrBlock(Stream, BlockOrCode);
  if (!Res)
Res.getError();

I could see that this level of noise might put people off, although this is 
alot higher level of noise than I saw in both protobuf or in opencv which I 
tried.

I wonder if it would be enough to put in some kind of exclusion regex list?

Reruning the build after having removed the LLVM_NODISCARD from Diag(...) to 
see how much it quietens down

I'll continue looking to see if I find anything interesting.




Comment at: test/clang-tidy/modernize-use-nodiscard.cpp:126
+template
+class Bar
+{

curdeius wrote:
> JonasToth wrote:
> > I think the template tests should be improved.
> > What happens for `T empty()`, `typename T::value_type empty()` and so on. 
> > THe same for the parameters for functions/methods (including function 
> > templates).
> > 
> > Thinking of it, it might be a good idea to ignore functions where the 
> > heuristic depends on the template-paramters.
> It might be a good idea to add a note in the documentation about handling of 
> function templates and functions in class templates.
I think I need some help to determine if the parameter is a template parameter 
(specially a const T & or a const_reference)

I'm trying to remove functions which have any type of Template parameter (at 
least for now)

I've modified the hasNonConstReferenceOrPointerArguments matcher to use 
isTemplateTypeParamType()

but this doesn't seem to work though an Alias or even just with a const &

```
  return llvm::any_of(Node.parameters(), [](const ParmVarDecl *Par) {
QualType ParType = Par->getType();

if (ParType->isTemplateTypeParmType())
  return true;

if (ParType->isPointerType() || isNo

[PATCH] D54862: [OpenCL] Add generic AS to 'this' pointer

2018-12-11 Thread Mikael Nilsson via Phabricator via cfe-commits
mikael marked an inline comment as done.
mikael added inline comments.



Comment at: lib/Sema/SemaType.cpp:5169
+TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
+   const DeclContext *DC) {
   // Determine the type of the declarator. Not all forms of declarator

Anastasia wrote:
> Rather than passing `DeclContext` you can get it from the `Declarator` using 
> `getContext()` method.
Declarator::getContext() returns an enumeration DeclaratorContext which is not 
enough in this case.


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

https://reviews.llvm.org/D54862



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


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-11 Thread Clement Courbet via Phabricator via cfe-commits
courbet created this revision.
courbet added reviewers: aaron.ballman, Quuxplusone.
Herald added a subscriber: cfe-commits.

Handles expressions such as:

- `std::is_const()`
- `std::is_const()()`;
- `std::is_same(decltype(U()), V>::value`;


Repository:
  rC Clang

https://reviews.llvm.org/D2

Files:
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/static-assert.cpp

Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -76,6 +76,8 @@
   static const Tp value = v;
   typedef Tp value_type;
   typedef integral_constant type;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
 };
 
 template 
@@ -103,6 +105,7 @@
 } // namespace std
 
 struct ExampleTypes {
+  explicit ExampleTypes(int);
   using T = int;
   using U = float;
 };
@@ -119,6 +122,18 @@
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
 static_assert(!(std::is_const::value == true), "message");
 // expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+static_assert(std::is_const(), "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+static_assert(!(std::is_const()()), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "message"}}
+static_assert(std::is_same()), int>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same, int>::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3059,8 +3059,9 @@
 // for actual types.
 class FailedBooleanConditionPrinterHelper : public PrinterHelper {
 public:
-  explicit FailedBooleanConditionPrinterHelper(const PrintingPolicy &P)
-  : Policy(P) {}
+  FailedBooleanConditionPrinterHelper(const ASTContext &Context,
+  const PrintingPolicy &P)
+  : Context(Context), Policy(P) {}
 
   bool handledStmt(Stmt *E, raw_ostream &OS) override {
 const auto *DR = dyn_cast(E);
@@ -3077,10 +3078,38 @@
   }
   return true;
 }
+if (auto *Node = dyn_cast(E)) {
+  Node->getType().getCanonicalType().print(OS, Policy);
+  if (Node->isStdInitListInitialization())
+/* Nothing to do; braces are part of creating the std::initializer_list.
+ */
+;
+  else if (Node->isListInitialization())
+OS << "{";
+  else
+OS << "(";
+  for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
+ArgEnd = Node->arg_end();
+   Arg != ArgEnd; ++Arg) {
+if ((*Arg)->isDefaultArgument())
+  break;
+if (Arg != Node->arg_begin())
+  OS << ", ";
+(*Arg)->printPretty(OS, this, Policy);
+  }
+  if (Node->isStdInitListInitialization())
+/* See above. */;
+  else if (Node->isListInitialization())
+OS << "}";
+  else
+OS << ")";
+  return true;
+}
 return false;
   }
 
 private:
+  const ASTContext &Context;
   const PrintingPolicy Policy;
 };
 
@@ -3122,7 +3151,7 @@
   std::string Description;
   {
 llvm::raw_string_ostream Out(Description);
-FailedBooleanConditionPrinterHelper Helper(getPrintingPolicy());
+FailedBooleanConditionPrinterHelper Helper(Context, getPrintingPolicy());
 FailedCond->printPretty(Out, &Helper, getPrintingPolicy());
   }
   return { FailedCond, Description };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47196: [Time-report ](2): Recursive timers in Clang

2018-12-11 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

In D47196#1324540 , @Trass3r wrote:

> Is this still in progress?


AFAIK, this is abandoned by author now. I'm working on other implementation 
which is similar but with another angle of view. The implementation projected 
by author measures time of _compiler_ code, whereas _user_ source code 
compilation time looks more useful.
There are also another two differentials related to this one which may require 
revertion: https://reviews.llvm.org/D45619 and https://reviews.llvm.org/D43578.


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

https://reviews.llvm.org/D47196



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


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-11 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 177681.
courbet added a comment.

cosmetics


Repository:
  rC Clang

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

https://reviews.llvm.org/D2

Files:
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/static-assert.cpp

Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -76,6 +76,8 @@
   static const Tp value = v;
   typedef Tp value_type;
   typedef integral_constant type;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
 };
 
 template 
@@ -103,6 +105,7 @@
 } // namespace std
 
 struct ExampleTypes {
+  explicit ExampleTypes(int);
   using T = int;
   using U = float;
 };
@@ -119,6 +122,18 @@
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
 static_assert(!(std::is_const::value == true), "message");
 // expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+static_assert(std::is_const(), "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+static_assert(!(std::is_const()()), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "message"}}
+static_assert(std::is_same()), int>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same, int>::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3059,8 +3059,9 @@
 // for actual types.
 class FailedBooleanConditionPrinterHelper : public PrinterHelper {
 public:
-  explicit FailedBooleanConditionPrinterHelper(const PrintingPolicy &P)
-  : Policy(P) {}
+  FailedBooleanConditionPrinterHelper(const ASTContext &Context,
+  const PrintingPolicy &P)
+  : Context(Context), Policy(P) {}
 
   bool handledStmt(Stmt *E, raw_ostream &OS) override {
 const auto *DR = dyn_cast(E);
@@ -3077,10 +3078,37 @@
   }
   return true;
 }
+if (auto *Node = dyn_cast(E)) {
+  Node->getType().getCanonicalType().print(OS, Policy);
+  if (Node->isStdInitListInitialization())
+// Nothing to do; braces are part of creating the std::initializer_list.
+;
+  else if (Node->isListInitialization())
+OS << "{";
+  else
+OS << "(";
+  for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
+ArgEnd = Node->arg_end();
+   Arg != ArgEnd; ++Arg) {
+if ((*Arg)->isDefaultArgument())
+  break;
+if (Arg != Node->arg_begin())
+  OS << ", ";
+(*Arg)->printPretty(OS, this, Policy);
+  }
+  if (Node->isStdInitListInitialization())
+/* See above. */;
+  else if (Node->isListInitialization())
+OS << "}";
+  else
+OS << ")";
+  return true;
+}
 return false;
   }
 
 private:
+  const ASTContext &Context;
   const PrintingPolicy Policy;
 };
 
@@ -3122,7 +3150,7 @@
   std::string Description;
   {
 llvm::raw_string_ostream Out(Description);
-FailedBooleanConditionPrinterHelper Helper(getPrintingPolicy());
+FailedBooleanConditionPrinterHelper Helper(Context, getPrintingPolicy());
 FailedCond->printPretty(Out, &Helper, getPrintingPolicy());
   }
   return { FailedCond, Description };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54309: [AST] Allow limiting the scope of common AST traversals (getParents, RAV).

2018-12-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

See PR39949 as well, as it seems to trigger the same or a similar problem.
@ioeric and @klimek  maybe could give an opinion, too?


Repository:
  rC Clang

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

https://reviews.llvm.org/D54309



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


[clang-tools-extra] r348840 - [clang-tidy] NFC Consolidate test absl::Time implementation

2018-12-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Dec 11 04:42:17 2018
New Revision: 348840

URL: http://llvm.org/viewvc/llvm-project?rev=348840&view=rev
Log:
[clang-tidy] NFC Consolidate test absl::Time implementation

Summary: Several tests re-implement these same prototypes (differently), so we 
can put them in a common location.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/
clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
Modified:
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h?rev=348840&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h Tue Dec 11 
04:42:17 2018
@@ -0,0 +1,72 @@
+// Mimic the implementation of absl::Duration
+namespace absl {
+
+using int64_t = long long int;
+
+class Duration {
+public:
+  Duration &operator*=(int64_t r);
+  Duration &operator*=(float r);
+  Duration &operator*=(double r);
+  template  Duration &operator*=(T r);
+
+  Duration &operator/=(int64_t r);
+  Duration &operator/=(float r);
+  Duration &operator/=(double r);
+  template  Duration &operator/=(T r);
+};
+
+template  Duration operator*(Duration lhs, T rhs);
+template  Duration operator*(T lhs, Duration rhs);
+template  Duration operator/(Duration lhs, T rhs);
+
+class Time{};
+
+constexpr Duration Nanoseconds(long long);
+constexpr Duration Microseconds(long long);
+constexpr Duration Milliseconds(long long);
+constexpr Duration Seconds(long long);
+constexpr Duration Minutes(long long);
+constexpr Duration Hours(long long);
+
+template  struct EnableIfFloatImpl {};
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template <> struct EnableIfFloatImpl { typedef int Type; };
+template  using EnableIfFloat = typename 
EnableIfFloatImpl::Type;
+
+template  = 0> Duration Nanoseconds(T n);
+template  = 0> Duration Microseconds(T n);
+template  = 0> Duration Milliseconds(T n);
+template  = 0> Duration Seconds(T n);
+template  = 0> Duration Minutes(T n);
+template  = 0> Duration Hours(T n);
+
+double ToDoubleHours(Duration d);
+double ToDoubleMinutes(Duration d);
+double ToDoubleSeconds(Duration d);
+double ToDoubleMilliseconds(Duration d);
+double ToDoubleMicroseconds(Duration d);
+double ToDoubleNanoseconds(Duration d);
+int64_t ToInt64Hours(Duration d);
+int64_t ToInt64Minutes(Duration d);
+int64_t ToInt64Seconds(Duration d);
+int64_t ToInt64Milliseconds(Duration d);
+int64_t ToInt64Microseconds(Duration d);
+int64_t ToInt64Nanoseconds(Duration d);
+
+// Relational Operators
+constexpr bool operator<(Duration lhs, Duration rhs);
+constexpr bool operator>(Duration lhs, Duration rhs);
+constexpr bool operator>=(Duration lhs, Duration rhs);
+constexpr bool operator<=(Duration lhs, Duration rhs);
+constexpr bool operator==(Duration lhs, Duration rhs);
+constexpr bool operator!=(Duration lhs, Duration rhs);
+
+// Additive Operators
+inline Time operator+(Time lhs, Duration rhs);
+inline Time operator+(Duration lhs, Time rhs);
+inline Time operator-(Time lhs, Duration rhs);
+inline Duration operator-(Time lhs, Time rhs);
+
+}  // namespace absl

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp?rev=348840&r1=348839&r2=348840&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp Tue 
Dec 11 04:42:17 2018
@@ -1,62 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-comparison %t
+// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
 
-// Mimic the implementation of absl::Duration
-namespace absl {
-
-class Duration {};
-class Time{};
-
-Duration Nanoseconds(long long);
-Duration Microseconds(long long);
-Duration Milliseconds(long long);
-Duration Seconds(long long);
-Duration Minutes(long long);
-Duration Hours(long long);
-
-#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \
-  Duration NAME(float n); \
-  Duration NAME(double n);\
-  template

[clang-tools-extra] r348842 - Use the standard Duration factory matcher

2018-12-11 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Tue Dec 11 04:45:51 2018
New Revision: 348842

URL: http://llvm.org/viewvc/llvm-project?rev=348842&view=rev
Log:
Use the standard Duration factory matcher

Summary: A new check came in over the weekend; it should use our existing 
infrastructure for matching `absl::Duration` factories.

Patch by hwright.

Reviewers: JonasToth

Reviewed By: JonasToth

Subscribers: astrelni

Tags: #clang-tools-extra

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

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp?rev=348842&r1=348841&r2=348842&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
Tue Dec 11 04:45:51 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "UpgradeDurationConversionsCheck.h"
+#include "DurationRewriter.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -102,10 +103,7 @@ void UpgradeDurationConversionsCheck::re
   anyOf(hasCastKind(CK_UserDefinedConversion),
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
-  callee(functionDecl(
-  hasAnyName("::absl::Nanoseconds", "::absl::Microseconds",
- "::absl::Milliseconds", "::absl::Seconds",
- "::absl::Minutes", "::absl::Hours"),
+  callee(functionDecl(DurationFactoryFunction(),
   unless(hasParent(functionTemplateDecl(),
   hasArgument(0, expr().bind("arg"),
   this);


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


[PATCH] D55541: Use the standard Duration factory matcher

2018-12-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D55541#1326868 , @lebedev.ri wrote:

> In D55541#1326867 , @JonasToth wrote:
>
> > Please remember to upload your patches with full context (i can highly 
> > recommend using `arc`, see 
> > https://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch 
> > and https://llvm.org/docs/Phabricator.html for the relevant command).
>
>
> And to add to that, please do set the correct "Repo" field, correct tag if 
> appropriate (clang-tools-extra), and subscribe the appropriate -commits list 
> (in this case, cfe-commits.)


Wups, overlooked that too, but your right.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55541



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


[PATCH] D55428: [Docs] Expand -fstack-protector and -fstack-protector-all info

2018-12-11 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added inline comments.



Comment at: include/clang/Driver/Options.td:1636
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Force the usage of stack protectors for all functions">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,

May I suggest to change it to "Enable stack protectors for all functions" for 
consistency with below entries? Rest LGTM otherwise.


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

https://reviews.llvm.org/D55428



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: include/clang/AST/Expr.h:2425
   CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
-   unsigned NumArgs, EmptyShell Empty);
+   unsigned NumArgs, bool UsesADL, EmptyShell Empty);
 

There is no need to pass this flag to the empty constructor
since it is going to be deserialized in `ASTReaderStmt`.
Only what is strictly needed to create the empty `CallExpr`
is passed here. In fact if you wanted to pass the flag when creating
the empty `CallExpr` you would have to update what is
under `case EXPR_CALL:` in `ASTReader::ReadStmtFromStream`.



Comment at: include/clang/AST/ExprCXX.h:106
   : CallExpr(C, CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs,
- Empty) {}
+ /*UsesADL=*/false, Empty) {}
 

same



Comment at: include/clang/AST/ExprCXX.h:178
+  : CallExpr(C, CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs,
+ /*UsesADL=*/false, Empty) {}
 

same



Comment at: include/clang/AST/ExprCXX.h:224
   : CallExpr(C, CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, 
NumArgs,
- Empty) {}
+ /*UsesADL=*/false, Empty) {}
 

same



Comment at: include/clang/AST/ExprCXX.h:505
   : CallExpr(C, UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs,
- Empty) {}
+ /*UsesADL=*/false, Empty) {}
 

same



Comment at: lib/Serialization/ASTReaderStmt.cpp:741
 E->setArg(I, Record.readSubExpr());
+  E->setUsesADL(UsesADL);
 }

`E->setUsesADL(Record.readInt())` with the
` bool UsesADL = Record.readInt();` removed ?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55534



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


[PATCH] D54309: [AST] Allow limiting the scope of common AST traversals (getParents, RAV).

2018-12-11 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In D54309#1326852 , @JonasToth wrote:

> See PR39949 as well, as it seems to trigger the same or a similar problem.
>  @ioeric and @klimek  maybe could give an opinion, too?


Sounds like we might not correctly set the parent map for CXXConstructorDecl 
then?


Repository:
  rC Clang

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

https://reviews.llvm.org/D54309



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


[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

It would probably be a good idea to have a similar check on properties, as 
property encoding strings contain the type encoding (plus extra stuff).

I wonder if we also want an option in code generation to replace very long type 
encodings (or encodings of specifically annotated ivars?) with `"?"` ('unknown 
type')?




Comment at: lib/Sema/SemaDeclObjC.cpp:3881
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize == 0) return;
+  for (ObjCIvarDecl *ivar = ID->getClassInterface()->all_declared_ivar_begin();

I missed this early exit on the first pass, please can you add some spacing to 
make it more obvious?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544



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


Re: r348276 - [AST][NFC] Make ArrayTypeTraitExpr non polymorphic

2018-12-11 Thread Mikael Holmén via cfe-commits
Hi Bruno,

I've no idea if this is really related to your change, but with this 
commit, the following starts crashing:

clang-tidy -allow-enabling-analyzer-alpha-checkers 
-checks='-*,clang-analyzer-*' ./reduced.c --

It seems like it recurses forever for some reason, and then we run out 
of stack and it crashes:

elxhw7c132-n7[llvm]: build-all-bbigcc/bin/clang-tidy 
-allow-enabling-analyzer-alpha-checkers -checks='-*,clang-analyzer-*' 
./reduced.c --
#0 0x0074fbda llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
(build-all-bbigcc/bin/clang-tidy+0x74fbda)
#1 0x0074e0aa llvm::sys::RunSignalHandlers() 
(build-all-bbigcc/bin/clang-tidy+0x74e0aa)
#2 0x0074e1d7 SignalHandler(int) 
(build-all-bbigcc/bin/clang-tidy+0x74e1d7)
#3 0x7f6cd7f84330 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00f06c63 clang::StmtVisitorBase::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c63)
#5 0x00f0a282 (anonymous 
namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
(build-all-bbigcc/bin/clang-tidy+0xf0a282)
#6 0x00f0527f clang::StmtVisitorBase::Visit(clang::Stmt*) (.part.132) 
(build-all-bbigcc/bin/clang-tidy+0xf0527f)
#7 0x00f06c68 clang::StmtVisitorBase::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
#8 0x00f0a282 (anonymous 
namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
(build-all-bbigcc/bin/clang-tidy+0xf0a282)
#9 0x00f03fcf clang::StmtVisitorBase::Visit(clang::Stmt*) (.part.132) 
(build-all-bbigcc/bin/clang-tidy+0xf03fcf)
#10 0x00f06c68 clang::StmtVisitorBase::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
#11 0x00f0a282 (anonymous 
namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
(build-all-bbigcc/bin/clang-tidy+0xf0a282)
#12 0x00f03fcf clang::StmtVisitorBase::Visit(clang::Stmt*) (.part.132) 
(build-all-bbigcc/bin/clang-tidy+0xf03fcf)
#13 0x00f06c68 clang::StmtVisitorBase::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
#14 0x00f0a282 (anonymous 
namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
(build-all-bbigcc/bin/clang-tidy+0xf0a282)
#15 0x00f03fcf clang::StmtVisitorBase::Visit(clang::Stmt*) (.part.132) 
(build-all-bbigcc/bin/clang-tidy+0xf03fcf)

etc

I've only seen this when I compile clang-tidy with gcc 5.4.0, assertions 
on, with optimizations. Simply turning on debug info when compiling 
clang-tidy makes the crash go away so it's quite fragile.

Regards,
Mikael

On 12/4/18 5:01 PM, Bruno Ricci via cfe-commits wrote:
> Author: brunoricci
> Date: Tue Dec  4 08:01:24 2018
> New Revision: 348276
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=348276&view=rev
> Log:
> [AST][NFC] Make ArrayTypeTraitExpr non polymorphic
> 
> ArrayTypeTraitExpr is the only expression class which is polymorphic.
> As far as I can tell this is completely pointless.
> 
> Differential Revision: https://reviews.llvm.org/D55221
> 
> Reviewed By: aaron.ballman
> 
> 
> Modified:
>  cfe/trunk/include/clang/AST/ExprCXX.h
>  cfe/trunk/lib/AST/ExprCXX.cpp
> 
> Modified: cfe/trunk/include/clang/AST/ExprCXX.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=348276&r1=348275&r2=348276&view=diff
> ==
> --- cfe/trunk/include/clang/AST/ExprCXX.h (original)
> +++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Dec  4 08:01:24 2018
> @@ -2455,8 +2455,6 @@ class ArrayTypeTraitExpr : public Expr {
> /// The type being queried.
> TypeSourceInfo *QueriedType = nullptr;
>   
> -  virtual void anchor();
> -
>   public:
> friend class ASTStmtReader;
>   
> @@ -2474,8 +2472,6 @@ public:
> explicit ArrayTypeTraitExpr(EmptyShell Empty)
> : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
>   
> -  virtual ~ArrayTypeTraitExpr() = default;
> -
> SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
> SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
>   
> 
> Modified: cfe/trunk/lib/AST/ExprCXX.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=348276&r1=348275&r2=348276&view=diff
> ==
> --- cfe/trunk/lib/AST/ExprCXX.cpp (original)
> +++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Dec  4 08:01:24 2018
> @@ -1443,5 +1443,3 @@ TypeTraitExpr *TypeTraitExpr::CreateDese
> void *Mem = C.Allocate(totalSizeToAlloc(NumArgs));
> return new (Mem) TypeTraitExpr(EmptyShell());
>   }
> -
> -void ArrayTypeTraitExpr::anchor() {}
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> 
 const bbiTcbb_mtd_isTcbb_indexOffsetId;
  bbiTcbb_mtd_isTcbb (  ) {
   switch ( bbiTcbb_mtd_isTcbb_indexOffsetId ) case 3235: case 3236:

r348848 - [analyzer] Fix a minor typo.

2018-12-11 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Tue Dec 11 06:40:48 2018
New Revision: 348848

URL: http://llvm.org/viewvc/llvm-project?rev=348848&view=rev
Log:
[analyzer] Fix a minor typo.

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=348848&r1=348847&r2=348848&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Tue 
Dec 11 06:40:48 2018
@@ -1081,7 +1081,7 @@ public:
   void dump() const;
 };
 
-/// ElementRegin is used to represent both array elements and casts.
+/// ElementRegion is used to represent both array elements and casts.
 class ElementRegion : public TypedValueRegion {
   friend class MemRegionManager;
 


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


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-11 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: lib/Sema/SemaTemplate.cpp:3089
+  else
+OS << "(";
+  for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),

It might be more maintainer-proof to write this as

std::pair Braces;
if (Node->isStdInitListInitialization())
  Braces = std::make_pair("", "");
else if (Node->isListInitialization())
  Braces = std::make_pair("{", "}");
else
  Braces = std::make_pair("(", ")");
OS << Braces.first;
for (...) { ... }
OS << Braces.second;
return true;




Comment at: test/SemaCXX/static-assert.cpp:136
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 
'std::is_const::value' "message"}}
 

Conspicuously missing any test for lines 3081–3106 above. IIUC, those lines 
would trigger on things like

```
template struct X { int i=0, j=0; constexpr operator bool() const { 
return false; } };
template void test() {
static_assert(X{});
static_assert(X{1,2});
static_assert(T{0});
static_assert(T(0));
}
template void test();
```

But I guess I don't see why extra code is needed to handle those; shouldn't the 
pretty-printer handle them already? What do the current diagnostics look like 
for my example?


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


[libunwind] r348852 - [cmake] Rename append_if to avoid collision with LLVM

2018-12-11 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Tue Dec 11 07:30:04 2018
New Revision: 348852

URL: http://llvm.org/viewvc/llvm-project?rev=348852&view=rev
Log:
[cmake] Rename append_if to avoid collision with LLVM

Rename the 'append_if' macro used in libunwind to 'unwind_append_if'.
Otherwise, when used in a combined LLVM+libunwind build, it overrides
the *incompatible* 'append_if' function from LLVM and breaks projects
following libunwind, e.g. OpenMP.

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

Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=348852&r1=348851&r2=348852&view=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Tue Dec 11 07:30:04 2018
@@ -204,7 +204,7 @@ set(LIBUNWIND_COMPILE_FLAGS "")
 set(LIBUNWIND_LINK_FLAGS "")
 
 # Get required flags.
-macro(append_if list condition var)
+macro(unwind_append_if list condition var)
   if (${condition})
 list(APPEND ${list} ${var})
   endif()
@@ -242,48 +242,48 @@ endif()
 # Setup Compiler Flags
 
#===
 
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG 
-Werror=return-type)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG 
-Werror=return-type)
 
 # Get warning flags
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_W_FLAG -W)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WALL_FLAG -Wall)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCHAR_SUBSCRIPTS_FLAG 
-Wchar-subscripts)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCONVERSION_FLAG -Wconversion)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISMATCHED_TAGS_FLAG 
-Wmismatched-tags)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISSING_BRACES_FLAG 
-Wmissing-braces)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WNEWLINE_EOF_FLAG 
-Wnewline-eof)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WNO_UNUSED_FUNCTION_FLAG 
-Wno-unused-function)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHADOW_FLAG -Wshadow)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHORTEN_64_TO_32_FLAG 
-Wshorten-64-to-32)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_COMPARE_FLAG 
-Wsign-compare)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_CONVERSION_FLAG 
-Wsign-conversion)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_ALIASING_FLAG 
-Wstrict-aliasing=2)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_OVERFLOW_FLAG 
-Wstrict-overflow=4)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_PARAMETER_FLAG 
-Wunused-parameter)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_VARIABLE_FLAG 
-Wunused-variable)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WWRITE_STRINGS_FLAG 
-Wwrite-strings)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNDEF_FLAG -Wundef)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_W_FLAG -W)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WALL_FLAG -Wall)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCHAR_SUBSCRIPTS_FLAG 
-Wchar-subscripts)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCONVERSION_FLAG 
-Wconversion)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISMATCHED_TAGS_FLAG 
-Wmismatched-tags)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISSING_BRACES_FLAG 
-Wmissing-braces)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WNEWLINE_EOF_FLAG 
-Wnewline-eof)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS 
LIBUNWIND_HAS_WNO_UNUSED_FUNCTION_FLAG -Wno-unused-function)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHADOW_FLAG -Wshadow)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHORTEN_64_TO_32_FLAG 
-Wshorten-64-to-32)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_COMPARE_FLAG 
-Wsign-compare)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_CONVERSION_FLAG 
-Wsign-conversion)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_ALIASING_FLAG 
-Wstrict-aliasing=2)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_OVERFLOW_FLAG 
-Wstrict-overflow=4)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_PARAMETER_FLAG 
-Wunused-parameter)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_VARIABLE_FLAG 
-Wunused-variable)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WWRITE_STRINGS_FLAG 
-Wwrite-strings)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNDEF_FLAG -Wundef)
 
 if (LIBUNWIND_ENABLE_WERROR)
-  append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG -Werror)
-  append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WX_FLAG -WX)
+  unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG -Werror)
+  unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WX_FLAG -WX)
 

[PATCH] D55476: [libunwind] [cmake] Rename append_if to avoid collision with LLVM

2018-12-11 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348852: [cmake] Rename append_if to avoid collision with 
LLVM (authored by mgorny, committed by ).
Herald added subscribers: llvm-commits, christof.

Changed prior to commit:
  https://reviews.llvm.org/D55476?vs=177394&id=177704#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55476

Files:
  libunwind/trunk/CMakeLists.txt
  libunwind/trunk/src/CMakeLists.txt

Index: libunwind/trunk/src/CMakeLists.txt
===
--- libunwind/trunk/src/CMakeLists.txt
+++ libunwind/trunk/src/CMakeLists.txt
@@ -4,7 +4,7 @@
 libunwind.cpp
 Unwind-EHABI.cpp
 Unwind-seh.cpp)
-append_if(LIBUNWIND_CXX_SOURCES APPLE Unwind_AppleExtras.cpp)
+unwind_append_if(LIBUNWIND_CXX_SOURCES APPLE Unwind_AppleExtras.cpp)
 
 set(LIBUNWIND_C_SOURCES
 UnwindLevel1.c
@@ -36,7 +36,7 @@
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
 ${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)
 
-append_if(LIBUNWIND_HEADERS APPLE
+unwind_append_if(LIBUNWIND_HEADERS APPLE
   "${CMAKE_CURRENT_SOURCE_DIR}/../include/mach-o/compact_unwind_encoding.h")
 
 if (MSVC_IDE)
@@ -52,25 +52,25 @@
 
 # Generate library list.
 set(libraries)
-append_if(libraries LIBUNWIND_HAS_C_LIB c)
+unwind_append_if(libraries LIBUNWIND_HAS_C_LIB c)
 if (LIBUNWIND_USE_COMPILER_RT)
   list(APPEND libraries "${LIBUNWIND_BUILTINS_LIBRARY}")
 else()
-  append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
-  append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc)
+  unwind_append_if(libraries LIBUNWIND_HAS_GCC_S_LIB gcc_s)
+  unwind_append_if(libraries LIBUNWIND_HAS_GCC_LIB gcc)
 endif()
-append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
+unwind_append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
 if (LIBUNWIND_ENABLE_THREADS)
-  append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+  unwind_append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
 endif()
 
 # Setup flags.
-append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
+unwind_append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
 
-append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
+unwind_append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
 
 # MINGW_LIBRARIES is defined in config-ix.cmake
-append_if(libraries MINGW "${MINGW_LIBRARIES}")
+unwind_append_if(libraries MINGW "${MINGW_LIBRARIES}")
 
 if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES)
   list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions)
Index: libunwind/trunk/CMakeLists.txt
===
--- libunwind/trunk/CMakeLists.txt
+++ libunwind/trunk/CMakeLists.txt
@@ -204,7 +204,7 @@
 set(LIBUNWIND_LINK_FLAGS "")
 
 # Get required flags.
-macro(append_if list condition var)
+macro(unwind_append_if list condition var)
   if (${condition})
 list(APPEND ${list} ${var})
   endif()
@@ -242,48 +242,48 @@
 # Setup Compiler Flags
 #===
 
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG -Werror=return-type)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG -Werror=return-type)
 
 # Get warning flags
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_W_FLAG -W)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WALL_FLAG -Wall)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCHAR_SUBSCRIPTS_FLAG -Wchar-subscripts)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WCONVERSION_FLAG -Wconversion)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISMATCHED_TAGS_FLAG -Wmismatched-tags)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WMISSING_BRACES_FLAG -Wmissing-braces)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WNEWLINE_EOF_FLAG -Wnewline-eof)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WNO_UNUSED_FUNCTION_FLAG -Wno-unused-function)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHADOW_FLAG -Wshadow)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSHORTEN_64_TO_32_FLAG -Wshorten-64-to-32)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_COMPARE_FLAG -Wsign-compare)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSIGN_CONVERSION_FLAG -Wsign-conversion)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_ALIASING_FLAG -Wstrict-aliasing=2)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WSTRICT_OVERFLOW_FLAG -Wstrict-overflow=4)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_PARAMETER_FLAG -Wunused-parameter)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNUSED_VARIABLE_FLAG -Wunused-variable)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings)
-append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WUNDEF_FLAG -Wundef)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_W_FLAG -W)
+unwind_append_if(LIBUNWIND_COMPILE_FLAGS LIB

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 12 inline comments as done.
EricWF added a comment.

Address more review comments. Update incoming.




Comment at: include/clang/AST/Expr.h:2425
   CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
-   unsigned NumArgs, EmptyShell Empty);
+   unsigned NumArgs, bool UsesADL, EmptyShell Empty);
 

riccibruno wrote:
> There is no need to pass this flag to the empty constructor
> since it is going to be deserialized in `ASTReaderStmt`.
> Only what is strictly needed to create the empty `CallExpr`
> is passed here. In fact if you wanted to pass the flag when creating
> the empty `CallExpr` you would have to update what is
> under `case EXPR_CALL:` in `ASTReader::ReadStmtFromStream`.
Ack. Thanks for the explanation.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55534



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 177705.
EricWF marked an inline comment as done.
EricWF added a comment.

Update with fixes for review comments.


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

https://reviews.llvm.org/D55534

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/AST/ast-dump-expr.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -199,6 +199,32 @@
"-fno-delayed-template-parsing"));
 }
 
+TEST(Matcher, ADLCall) {
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  auto NS_Str = R"cpp(
+  namespace NS {
+struct X {};
+struct Y {};
+void f(X);
+template 
+void g(T);
+  }
+  struct MyX {};
+  void f(...);
+  void g(...);
+)cpp";
+
+  auto MkStr = [&](std::string Body) -> std::string {
+std::string S = NS_Str;
+S += "void test_fn() { " + Body + " }";
+return S;
+  };
+
+  EXPECT_TRUE(matches(MkStr("NS::X x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; f(x);"), ADLMatch));
+}
+
 TEST(Matcher, Call) {
   // FIXME: Do we want to overload Call() to directly take
   // Matcher, too?
Index: test/AST/ast-dump-expr.cpp
===
--- /dev/null
+++ test/AST/ast-dump-expr.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=c++14 -ast-dump %s \
+// RUN:| FileCheck -strict-whitespace %s
+
+namespace NS {
+struct X {};
+void f(X);
+void y(...);
+} // namespace NS
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
+void ADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
+void NonADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  NS::f(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
+void NonADLCall2() {
+  NS::X x;
+  using NS::f;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+namespace test_adl_call_three {
+using namespace NS;
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
+void NonADLCall3() {
+  X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+}
+} // namespace test_adl_call_three
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -651,6 +651,7 @@
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
 Record.AddStmt(*Arg);
+  Record.push_back(E->usesADL());
   Code = serialization::EXPR_CALL;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -737,6 +737,7 @@
   E->setCallee(Record.readSubExpr());
   for (unsigned I = 0; I != NumArgs; ++I)
 E->setArg(I, Record.readSubExpr());
+  E->setUsesADL(Record.readInt());
 }
 
 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -5946,15 +5946,13 @@
 /// \param PartialOverloading true if we are performing "partial" overloading
 /// based on an incomplete set of function arguments. This feature is used by
 /// code completion.
-void
-Sema::AddOverloadCandidate(FunctionDecl *Function,
-   DeclAccessPair FoundDecl,
-   ArrayRef Args,
-   OverloadCandidateSet &CandidateSet,
-   bool SuppressUserConversions,
-   bool PartialOverloading,
-   bool AllowExplicit,
-   ConversionSequenceList EarlyConversions) {
+void Sema::AddOverloadCandidate(FunctionDecl *Function,
+DeclAccessPair FoundDecl, ArrayRef Args,
+OverloadCandidateSet &CandidateSet,
+bool SuppressUserConversions,
+ 

[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

2018-12-11 Thread S. B. Tam via Phabricator via cfe-commits
cpplearner updated this revision to Diff 177708.

Repository:
  rC Clang

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

https://reviews.llvm.org/D55413

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx1y.cpp


Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -340,9 +340,9 @@
 if (a != 9) return false;
 a -= 2;
 if (a != 7) return false;
-a *= 3;
+a *= 3.1;
 if (a != 21) return false;
-if (&(a /= 10) != &a) return false;
+if (&(a /= 7.9) != &a) return false;
 if (a != 2) return false;
 a <<= 3;
 if (a != 16) return false;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3424,13 +3424,21 @@
 if (!checkConst(SubobjType))
   return false;
 
-if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+if (!SubobjType->isIntegerType() || !RHS.isInt() && !RHS.isFloat()) {
   // We don't support compound assignment on integer-cast-to-pointer
   // values.
   Info.FFDiag(E);
   return false;
 }
 
+if (RHS.isFloat()) {
+  APFloat FValue(0.0);
+  return HandleIntToFloatCast(Info, E, SubobjType, Value, PromotedLHSType,
+  FValue) &&
+ handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
+ HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
+  Value);
+}
 APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType,
 SubobjType, Value);
 if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))


Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -340,9 +340,9 @@
 if (a != 9) return false;
 a -= 2;
 if (a != 7) return false;
-a *= 3;
+a *= 3.1;
 if (a != 21) return false;
-if (&(a /= 10) != &a) return false;
+if (&(a /= 7.9) != &a) return false;
 if (a != 2) return false;
 a <<= 3;
 if (a != 16) return false;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3424,13 +3424,21 @@
 if (!checkConst(SubobjType))
   return false;
 
-if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+if (!SubobjType->isIntegerType() || !RHS.isInt() && !RHS.isFloat()) {
   // We don't support compound assignment on integer-cast-to-pointer
   // values.
   Info.FFDiag(E);
   return false;
 }
 
+if (RHS.isFloat()) {
+  APFloat FValue(0.0);
+  return HandleIntToFloatCast(Info, E, SubobjType, Value, PromotedLHSType,
+  FValue) &&
+ handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
+ HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
+  Value);
+}
 APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType,
 SubobjType, Value);
 if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

It do not really matter but there is not point initializing this bit here.


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

https://reviews.llvm.org/D55534



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:1260
 
+/// Matches call expressions which were resolved using ADL.
+///

Don't forget to regenerate the documentation and update Registry.cpp to add 
clang-query support.


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

https://reviews.llvm.org/D55534



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


[PATCH] D42682: [clang-tidy] Add io-functions-misused checker

2018-12-11 Thread Gábor Horváth via Phabricator via cfe-commits
hgabii updated this revision to Diff 177713.

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D42682

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/IoFunctionsCheck.cpp
  clang-tidy/bugprone/IoFunctionsCheck.h
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-io-functions.rst
  docs/clang-tidy/checks/cert-fio34-c.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-io-functions.cpp

Index: test/clang-tidy/bugprone-io-functions.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-io-functions.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s bugprone-io-functions %t
+
+typedef int wint_t;
+typedef void *FILE;
+
+namespace std {
+int getchar();
+int getc(FILE);
+int fgetc(FILE);
+wint_t getwchar();
+wint_t getwc(FILE);
+wint_t fgetwc(FILE);
+class istream {
+public:
+  wint_t get();
+};
+} // namespace std
+
+int char_io_getchar() {
+  char c;
+  c = std::getchar();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getchar' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_getc(FILE *fp) {
+  char c;
+  c = std::getc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_fgetc(FILE *fp) {
+  char c;
+  c = std::fgetc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'fgetc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_getwchar() {
+  char c;
+  c = std::getwchar();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getwchar' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_getwc(FILE *fp) {
+  char c;
+  c = std::getwc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getwc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_fgetwc(FILE *fp) {
+  char c;
+  c = std::fgetwc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'fgetwc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+int char_io_get(std::istream &is) {
+  char c;
+  c = is.get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'get' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+  return c;
+}
+
+void char_type_in_argument(char c) {}
+
+void call_char_type_in_argument_with_getchar(FILE *fp) {
+  char_type_in_argument(std::fgetc(fp));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: consider to cast the return value of 'fgetc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+}
+
+void call_char_type_in_argument_with_getwchar() {
+  char_type_in_argument(std::getwchar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: consider to cast the return value of 'getwchar' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached, EOF and WEOF can be lost [bugprone-io-functions]
+}
+
+// Negatives
+int int_io_getchar() {
+  int x;
+  x = std::getchar();
+  return x;
+}
+
+int int_io_getc(FILE *fp) {
+  int x;
+  x = std::getc(fp);
+  return x;
+}
+
+int int_io_fgetc(FILE *fp) {
+  int x;
+  x = std::fgetc(fp);
+  return x;
+}
+
+int int_io_getwchar() {
+  int x;
+  x = std::getwchar();
+  return x;
+}
+
+int int_io_getwc(FILE *fp) {
+  int x;
+  x = std::getwc(fp);
+  return x;
+}
+
+int int_io_fgetwc(FILE *fp) {
+  int x;
+  x = std::fgetwc(fp);
+  return x;
+}
+
+int int_io_get(std::istream &is) {
+  int x;
+  x = is.get();
+  return x;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/che

r348858 - Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"

2018-12-11 Thread Stefan Pintilie via cfe-commits
Author: stefanp
Date: Tue Dec 11 07:47:57 2018
New Revision: 348858

URL: http://llvm.org/viewvc/llvm-project?rev=348858&view=rev
Log:
Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"

This reverts commit rL348299.

Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/clang-offload-bundler.c
cfe/trunk/test/Driver/ppc-abi.c

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=348858&r1=348857&r2=348858&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Dec 11 07:47:57 2018
@@ -2435,7 +2435,7 @@ bool Generic_GCC::isPICDefault() const {
   case llvm::Triple::x86_64:
 return getTriple().isOSWindows();
   case llvm::Triple::ppc64:
-// Big endian PPC is PIC by default
+  case llvm::Triple::ppc64le:
 return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:

Modified: cfe/trunk/test/Driver/clang-offload-bundler.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=348858&r1=348857&r2=348858&view=diff
==
--- cfe/trunk/test/Driver/clang-offload-bundler.c (original)
+++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Dec 11 07:47:57 2018
@@ -115,7 +115,7 @@
 // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLEEND__ openmp-x86_64-pc-linux-gnu
 
 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
host-powerpc64le-ibm-linux-gnu
-// CK-TEXTLL: @A = dso_local global i32 0
+// CK-TEXTLL: @A = global i32 0
 // CK-TEXTLL: define {{.*}}@test_func()
 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLEEND__ host-powerpc64le-ibm-linux-gnu
 // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
openmp-powerpc64le-ibm-linux-gnu

Modified: cfe/trunk/test/Driver/ppc-abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-abi.c?rev=348858&r1=348857&r2=348858&view=diff
==
--- cfe/trunk/test/Driver/ppc-abi.c (original)
+++ cfe/trunk/test/Driver/ppc-abi.c Tue Dec 11 07:47:57 2018
@@ -13,12 +13,12 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s
+// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
 
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv2 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s
+// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
 // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
 // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
@@ -26,44 +26,8 @@
 
 // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv1: "-target-abi" "elfv1"
-// CHECK-ELFv1-LE: "-mrelocation-model" "static"
-// CHECK-ELFv1-LE: "-target-abi" "elfv1"
 // CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx"
-// CHECK-ELFv2: "-mrelocation-model" "static"
+// CHECK-ELFv2: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv2: "-target-abi" "elfv2"
-// CHECK-ELFv2-BE: "-mrelocation-model" "pic" "-pic-level" "2"
-// CHECK-ELFv2-BE: "-target-abi" "elfv2"
-
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mabi=elfv1-qpx | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mcpu=a2q | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mcpu=a2 -mqpx | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
-// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
-// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-PIC %s
-
-// RUN: %clang -fPIC -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 
2>&1 \
-// RUN:   | FileCheck -che

[PATCH] D42682: [clang-tidy] Add io-functions-misused checker

2018-12-11 Thread Gábor Horváth via Phabricator via cfe-commits
hgabii marked 3 inline comments as done.
hgabii added inline comments.



Comment at: clang-tidy/bugprone/IoFunctionsCheck.cpp:32
+has(cxxMemberCallExpr(
+on(hasType(namedDecl(hasAnyName("istream",
+callee(cxxMethodDecl(hasName("get")).bind("DeclOfGet"),

aaron.ballman wrote:
> `::std::istream`
True. Fixed.



Comment at: clang-tidy/bugprone/IoFunctionsCheck.cpp:47-49
+  "consider to cast the return value of %0 from type integer to type char, 
"
+  "possible loss of precision if an error has occurred or the end "
+  "of file has been reached");

aaron.ballman wrote:
> This diagnostic confuses me, so perhaps you can explain the situation you 
> want to diagnose a bit further.
> 
> FIO34-C is about situations where `sizeof(char) == sizeof(int)` and the call 
> returns EOF/WEOF. In that case, there's no way to distinguish between an 
> EOF/error and a valid character. Suggesting to explicitly cast to a character 
> type doesn't add any safety to the code -- the user needs to insert calls to 
> `feof()` or `ferror()` instead (to make it portable, anyway) and should store 
> the character value in a sufficiently large integer type before doing the 
> comparison against EOF.
> 
> Are you trying to catch a different kind of bug?
Yes, I want to diagnose this problem. Do you think I need to add suggestions 
into the warning message to use `feof()` or `ferror()`?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D42682



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


[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

2018-12-11 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:3427
 
-if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+if (!SubobjType->isIntegerType() || !RHS.isInt() && !RHS.isFloat()) {
   // We don't support compound assignment on integer-cast-to-pointer

Parentheses ? It is always nicer to be able to read this
without having to remember whether `||` has a higher precedence
than `&&`.



Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:343
 if (a != 7) return false;
-a *= 3;
 if (a != 21) return false;

Why remove `a *= 3` instead of just adding `a *= 3.1`.



Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:345
 if (a != 21) return false;
-if (&(a /= 10) != &a) return false;
 if (a != 2) return false;

same


Repository:
  rC Clang

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

https://reviews.llvm.org/D55413



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


Re: r348858 - Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"

2018-12-11 Thread Aaron Ballman via cfe-commits
On Tue, Dec 11, 2018 at 10:50 AM Stefan Pintilie via cfe-commits
 wrote:
>
> Author: stefanp
> Date: Tue Dec 11 07:47:57 2018
> New Revision: 348858
>
> URL: http://llvm.org/viewvc/llvm-project?rev=348858&view=rev
> Log:
> Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"
>
> This reverts commit rL348299.

When reverting a commit, you should explain why the commit was
reverted as part of the commit message (this makes code archaeology
much easier). Why was this reverted 500+ revisions after it landed?

~Aaron

>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> cfe/trunk/test/Driver/clang-offload-bundler.c
> cfe/trunk/test/Driver/ppc-abi.c
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=348858&r1=348857&r2=348858&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Dec 11 07:47:57 2018
> @@ -2435,7 +2435,7 @@ bool Generic_GCC::isPICDefault() const {
>case llvm::Triple::x86_64:
>  return getTriple().isOSWindows();
>case llvm::Triple::ppc64:
> -// Big endian PPC is PIC by default
> +  case llvm::Triple::ppc64le:
>  return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
>case llvm::Triple::mips64:
>case llvm::Triple::mips64el:
>
> Modified: cfe/trunk/test/Driver/clang-offload-bundler.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=348858&r1=348857&r2=348858&view=diff
> ==
> --- cfe/trunk/test/Driver/clang-offload-bundler.c (original)
> +++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Dec 11 07:47:57 2018
> @@ -115,7 +115,7 @@
>  // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLEEND__ openmp-x86_64-pc-linux-gnu
>
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
> host-powerpc64le-ibm-linux-gnu
> -// CK-TEXTLL: @A = dso_local global i32 0
> +// CK-TEXTLL: @A = global i32 0
>  // CK-TEXTLL: define {{.*}}@test_func()
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLEEND__ 
> host-powerpc64le-ibm-linux-gnu
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
> openmp-powerpc64le-ibm-linux-gnu
>
> Modified: cfe/trunk/test/Driver/ppc-abi.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-abi.c?rev=348858&r1=348857&r2=348858&view=diff
> ==
> --- cfe/trunk/test/Driver/ppc-abi.c (original)
> +++ cfe/trunk/test/Driver/ppc-abi.c Tue Dec 11 07:47:57 2018
> @@ -13,12 +13,12 @@
>  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
>  // RUN:   -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s
>  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> -// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s
> +// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
>
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
>  // RUN:   | FileCheck -check-prefix=CHECK-ELFv2 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> -// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s
> +// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
>  // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> @@ -26,44 +26,8 @@
>
>  // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv1: "-target-abi" "elfv1"
> -// CHECK-ELFv1-LE: "-mrelocation-model" "static"
> -// CHECK-ELFv1-LE: "-target-abi" "elfv1"
>  // CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx"
> -// CHECK-ELFv2: "-mrelocation-model" "static"
> +// CHECK-ELFv2: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv2: "-target-abi" "elfv2"
> -// CHECK-ELFv2-BE: "-mrelocation-model" "pic" "-pic-level" "2"
> -// CHECK-ELFv2-BE: "-target-abi" "elfv2"
> -
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
> 2>&1 \
> -// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
> 2>&1 \
> -// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-PIC %s
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
> 2>&1 \
> -// RUN:   -mabi=elfv1-qpx | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
> 2>&1 \
> -// RUN:   -mcpu=a2q | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 
> 2>&1 \
> -// RUN:   -mcp

[PATCH] D53023: Prototype OpenCL BIFs using Tablegen

2018-12-11 Thread Nicola Zaghen via Phabricator via cfe-commits
Nicola added a comment.

This looks quite useful, thanks for taking time to do it! I can help verifying 
some of the tablegen'd builtins with internal tests too, if you decide to 
pursue this further.


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

https://reviews.llvm.org/D53023



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


[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.

2018-12-11 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Thanks!

I don't have commit access, so I would appreciate it if you could commit the 
change.


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

https://reviews.llvm.org/D51211



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 177716.
EricWF added a comment.

More tests.


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

https://reviews.llvm.org/D55534

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/AST/ast-dump-expr.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -199,6 +199,40 @@
"-fno-delayed-template-parsing"));
 }
 
+TEST(Matcher, ADLCall) {
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  StatementMatcher ADLMatchOper = cxxOperatorCallExpr(usesADL());
+  auto NS_Str = R"cpp(
+  namespace NS {
+struct X {};
+void f(X);
+void operator+(X, X);
+  }
+  struct MyX {};
+  void f(...);
+  void operator+(MyX, MyX);
+)cpp";
+
+  auto MkStr = [&](std::string Body) -> std::string {
+std::string S = NS_Str;
+S += "void test_fn() { " + Body + " }";
+return S;
+  };
+
+  EXPECT_TRUE(matches(MkStr("NS::X x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; using NS::f; f(x);"), ADLMatch));
+
+  // Operator call expressions
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatch));
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(matches(MkStr("NS::X x; operator+(x, x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::operator+(x, x);"), ADLMatch));
+}
+
 TEST(Matcher, Call) {
   // FIXME: Do we want to overload Call() to directly take
   // Matcher, too?
Index: test/AST/ast-dump-expr.cpp
===
--- /dev/null
+++ test/AST/ast-dump-expr.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=c++14 -ast-dump %s \
+// RUN:| FileCheck -strict-whitespace %s
+
+namespace NS {
+struct X {};
+void f(X);
+void y(...);
+} // namespace NS
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
+void ADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
+void NonADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  NS::f(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
+void NonADLCall2() {
+  NS::X x;
+  using NS::f;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+namespace test_adl_call_three {
+using namespace NS;
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
+void NonADLCall3() {
+  X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+}
+} // namespace test_adl_call_three
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -651,6 +651,7 @@
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
 Record.AddStmt(*Arg);
+  Record.push_back(E->usesADL());
   Code = serialization::EXPR_CALL;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -737,6 +737,7 @@
   E->setCallee(Record.readSubExpr());
   for (unsigned I = 0; I != NumArgs; ++I)
 E->setArg(I, Record.readSubExpr());
+  E->setUsesADL(Record.readInt());
 }
 
 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -5946,15 +5946,13 @@
 /// \param PartialOverloading true if we are performing "partial" overloading
 /// based on an incomplete set of function arguments. This feature is used by
 /// code completion.
-void
-Sema::AddOverloadCandidate(FunctionDecl *Function,
-   DeclAccessPair FoundDecl,
-   ArrayRef Args,
-   OverloadCandidateSet &CandidateSet,
-   

[PATCH] D54592: [analyzer][CStringChecker] evaluate explicit_bzero

2018-12-11 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

ping just want to put it behind :-) thanks.


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

https://reviews.llvm.org/D54592



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


[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

2018-12-11 Thread S. B. Tam via Phabricator via cfe-commits
cpplearner updated this revision to Diff 177719.
cpplearner added a comment.

Added parentheses. Restored the original tests and add more tests to the end of 
this function.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55413

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx1y.cpp


Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -356,6 +356,14 @@
 if (a != 13) return false;
 a &= 14;
 if (a != 12) return false;
+a += -1.2;
+if (a != 10) return false;
+a -= 3.1;
+if (a != 6) return false;
+a *= 2.2;
+if (a != 13) return false;
+if (&(a /= 1.5) != &a) return false;
+if (a != 8) return false;
 return true;
   }
   static_assert(test_int(), "");
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3424,13 +3424,21 @@
 if (!checkConst(SubobjType))
   return false;
 
-if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+if (!SubobjType->isIntegerType() || (!RHS.isInt() && !RHS.isFloat())) {
   // We don't support compound assignment on integer-cast-to-pointer
   // values.
   Info.FFDiag(E);
   return false;
 }
 
+if (RHS.isFloat()) {
+  APFloat FValue(0.0);
+  return HandleIntToFloatCast(Info, E, SubobjType, Value, PromotedLHSType,
+  FValue) &&
+ handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
+ HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
+  Value);
+}
 APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType,
 SubobjType, Value);
 if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))


Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -356,6 +356,14 @@
 if (a != 13) return false;
 a &= 14;
 if (a != 12) return false;
+a += -1.2;
+if (a != 10) return false;
+a -= 3.1;
+if (a != 6) return false;
+a *= 2.2;
+if (a != 13) return false;
+if (&(a /= 1.5) != &a) return false;
+if (a != 8) return false;
 return true;
   }
   static_assert(test_int(), "");
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3424,13 +3424,21 @@
 if (!checkConst(SubobjType))
   return false;
 
-if (!SubobjType->isIntegerType() || !RHS.isInt()) {
+if (!SubobjType->isIntegerType() || (!RHS.isInt() && !RHS.isFloat())) {
   // We don't support compound assignment on integer-cast-to-pointer
   // values.
   Info.FFDiag(E);
   return false;
 }
 
+if (RHS.isFloat()) {
+  APFloat FValue(0.0);
+  return HandleIntToFloatCast(Info, E, SubobjType, Value, PromotedLHSType,
+  FValue) &&
+ handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
+ HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
+  Value);
+}
 APSInt LHS = HandleIntToIntCast(Info, E, PromotedLHSType,
 SubobjType, Value);
 if (!handleIntIntBinOp(Info, E, LHS, Opcode, RHS.getInt(), LHS))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55413: [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type

2018-12-11 Thread S. B. Tam via Phabricator via cfe-commits
cpplearner marked an inline comment as done.
cpplearner added inline comments.



Comment at: clang/test/SemaCXX/constant-expression-cxx1y.cpp:343
 if (a != 7) return false;
-a *= 3;
 if (a != 21) return false;

riccibruno wrote:
> Why remove `a *= 3` instead of just adding `a *= 3.1`.
Because adding `a *= 3.1` here will change the result of the whole calculation?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55413



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 177720.
EricWF marked 2 inline comments as done.
EricWF added a comment.

Register matcher and regenerate docs.


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

https://reviews.llvm.org/D55534

Files:
  docs/LibASTMatchersReference.html
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/AST/ast-dump-expr.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -199,6 +199,40 @@
"-fno-delayed-template-parsing"));
 }
 
+TEST(Matcher, ADLCall) {
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  StatementMatcher ADLMatchOper = cxxOperatorCallExpr(usesADL());
+  auto NS_Str = R"cpp(
+  namespace NS {
+struct X {};
+void f(X);
+void operator+(X, X);
+  }
+  struct MyX {};
+  void f(...);
+  void operator+(MyX, MyX);
+)cpp";
+
+  auto MkStr = [&](std::string Body) -> std::string {
+std::string S = NS_Str;
+S += "void test_fn() { " + Body + " }";
+return S;
+  };
+
+  EXPECT_TRUE(matches(MkStr("NS::X x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; using NS::f; f(x);"), ADLMatch));
+
+  // Operator call expressions
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatch));
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(matches(MkStr("NS::X x; operator+(x, x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::operator+(x, x);"), ADLMatch));
+}
+
 TEST(Matcher, Call) {
   // FIXME: Do we want to overload Call() to directly take
   // Matcher, too?
Index: test/AST/ast-dump-expr.cpp
===
--- /dev/null
+++ test/AST/ast-dump-expr.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=c++14 -ast-dump %s \
+// RUN:| FileCheck -strict-whitespace %s
+
+namespace NS {
+struct X {};
+void f(X);
+void y(...);
+} // namespace NS
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
+void ADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
+void NonADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  NS::f(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
+void NonADLCall2() {
+  NS::X x;
+  using NS::f;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+namespace test_adl_call_three {
+using namespace NS;
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
+void NonADLCall3() {
+  X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+}
+} // namespace test_adl_call_three
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -651,6 +651,7 @@
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
 Record.AddStmt(*Arg);
+  Record.push_back(E->usesADL());
   Code = serialization::EXPR_CALL;
 }
 
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -737,6 +737,7 @@
   E->setCallee(Record.readSubExpr());
   for (unsigned I = 0; I != NumArgs; ++I)
 E->setArg(I, Record.readSubExpr());
+  E->setUsesADL(Record.readInt());
 }
 
 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -5946,15 +5946,13 @@
 /// \param PartialOverloading true if we are performing "partial" overloading
 /// based on an incomplete set of function arguments. This feature is used by
 /// code completion.
-void
-Sema::AddOverloadCandidate(FunctionDecl *Function,
-  

r348860 - Adding tests for -ast-dump; NFC.

2018-12-11 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Dec 11 08:34:59 2018
New Revision: 348860

URL: http://llvm.org/viewvc/llvm-project?rev=348860&view=rev
Log:
Adding tests for -ast-dump; NFC.

This adds tests for expressions in C++.

Added:
cfe/trunk/test/AST/ast-dump-expr.cpp

Added: cfe/trunk/test/AST/ast-dump-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-expr.cpp?rev=348860&view=auto
==
--- cfe/trunk/test/AST/ast-dump-expr.cpp (added)
+++ cfe/trunk/test/AST/ast-dump-expr.cpp Tue Dec 11 08:34:59 2018
@@ -0,0 +1,510 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-fcxx-exceptions -std=gnu++17 -ast-dump %s | FileCheck -strict-whitespace %s
+
+namespace std {
+using size_t = decltype(sizeof(0));
+
+class type_info {
+public:
+  virtual ~type_info();
+  bool operator==(const type_info& rhs) const noexcept;
+  bool operator!=(const type_info& rhs) const noexcept;
+  type_info(const type_info& rhs) = delete; // cannot be copied
+  type_info& operator=(const type_info& rhs) = delete; // cannot be copied
+};
+
+class bad_typeid {
+public:
+  bad_typeid() noexcept;
+  bad_typeid(const bad_typeid&) noexcept;
+  virtual ~bad_typeid();
+  bad_typeid& operator=(const bad_typeid&) noexcept;
+  const char* what() const noexcept;
+};
+} // namespace std
+void *operator new(std::size_t, void *ptr);
+
+struct S {
+  virtual ~S() = default;
+
+  void func(int);
+  template 
+  Ty foo();
+
+  int i;
+};
+
+struct T : S {};
+
+template 
+struct U {};
+
+void Throw() {
+  throw 12;
+  // CHECK: CXXThrowExpr 0x{{[^ ]*}}  'void'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 12
+
+  throw;
+  // CHECK: CXXThrowExpr 0x{{[^ ]*}}  'void'
+}
+
+void PointerToMember(S obj1, S *obj2, int S::* data, void (S::*call)(int)) {
+  obj1.*data;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' 
lvalue '.*'
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S' lvalue ParmVar 0x{{[^ 
]*}} 'obj1' 'S'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int S::*' lvalue ParmVar 
0x{{[^ ]*}} 'data' 'int S::*'
+
+  obj2->*data;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' 
lvalue '->*'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S *' lvalue ParmVar 0x{{[^ 
]*}} 'obj2' 'S *'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int S::*' lvalue ParmVar 
0x{{[^ ]*}} 'data' 'int S::*'
+
+  (obj1.*call)(12);
+  // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
+  // CHECK-NEXT: ParenExpr 0x{{[^ ]*}}  ''
+  // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}}  '' '.*'
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S' lvalue ParmVar 0x{{[^ 
]*}} 'obj1' 'S'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void (S::*)(int)' lvalue 
ParmVar 0x{{[^ ]*}} 'call' 'void (S::*)(int)'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 12
+
+  (obj2->*call)(12);
+  // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
+  // CHECK-NEXT: ParenExpr 0x{{[^ ]*}}  ''
+  // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}}  '' '->*'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S *' lvalue ParmVar 0x{{[^ 
]*}} 'obj2' 'S *'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'void (S::*)(int)' lvalue 
ParmVar 0x{{[^ ]*}} 'call' 'void (S::*)(int)'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 12
+}
+
+void Casting(const S *s) {
+  // FIXME: The cast expressions contain "struct S" instead of "S".
+
+  const_cast(s);
+  // CHECK: CXXConstCastExpr 0x{{[^ ]*}}  'S *' 
const_cast 
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const S *' 
 part_of_explicit_cast
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'const S *' lvalue ParmVar 
0x{{[^ ]*}} 's' 'const S *'
+
+  static_cast(s);
+  // CHECK: CXXStaticCastExpr 0x{{[^ ]*}}  'const 
T *' static_cast 
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const S *' 
 part_of_explicit_cast
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'const S *' lvalue ParmVar 
0x{{[^ ]*}} 's' 'const S *'
+
+  dynamic_cast(s);
+  // CHECK: CXXDynamicCastExpr 0x{{[^ ]*}}  'const 
T *' dynamic_cast 
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const S *' 
 part_of_explicit_cast
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'const S *' lvalue ParmVar 
0x{{[^ ]*}} 's' 'const S *'
+
+  reinterpret_cast(s);
+  // CHECK: CXXReinterpretCastExpr 0x{{[^ ]*}}  
'const int *' reinterpret_cast 
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const S *' 
 part_of_explicit_cast
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'const S *' lvalue ParmVar 
0x{{[^ ]*}} 's' 'const S *'
+}
+
+template 
+void UnaryExpressions(int *p) {
+  sizeof...(Ts);
+  // CHECK: SizeOfPackExpr 0x{{[^ ]*}}  'unsigned 
long' 0x{{[^ ]*}} Ts
+
+  noexcept(p - p);
+  // CHECK: CXXNoexceptExpr 0x{{[^ ]*}}  'bool'
+  // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}}  'long' '-'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[

[PATCH] D55066: [ASan] Minor documentation fix: clarify static linking limitation.

2018-12-11 Thread Max Moroz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC348863: [ASan] Minor documentation fix: clarify static 
linking limitation. (authored by Dor1s, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55066?vs=176712&id=177724#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55066

Files:
  docs/AddressSanitizer.rst


Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -265,7 +265,7 @@
 * On 64-bit platforms AddressSanitizer maps (but not reserves) 16+ Terabytes of
   virtual address space. This means that tools like ``ulimit`` may not work as
   usually expected.
-* Static linking is not supported.
+* Static linking of executables is not supported.
 
 Supported Platforms
 ===


Index: docs/AddressSanitizer.rst
===
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -265,7 +265,7 @@
 * On 64-bit platforms AddressSanitizer maps (but not reserves) 16+ Terabytes of
   virtual address space. This means that tools like ``ulimit`` may not work as
   usually expected.
-* Static linking is not supported.
+* Static linking of executables is not supported.
 
 Supported Platforms
 ===
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r348276 - [AST][NFC] Make ArrayTypeTraitExpr non polymorphic

2018-12-11 Thread Bruno Ricci via cfe-commits
Hi Mikael,

I can indeed reproduce this with gcc 5.5.0 when doing a Release
build with assertions. I cannot reproduce this with gcc 6.5.0
(also with a Release build with assertions), nor can I reproduce
this with clang 7 (also with a Release build with assertions).

I tried to instrument StringRefCheckerVisitor::VisitChildren but this
just causes the stack overflow to move to CGBuilder.

What is stranger is that the reproducer do not even causes
an ArrayTypeTraitExpr node to be created.

Increasing the maximum stack size with ulimit by a small amount fixes
the problem, so I don't think this is a mis-compilation either.

I think that this change is correct since no one is using the polymorphism
of ArrayTypeTraitExpr. Indeed taking the blunt step of making it final do
not causes any failure.

The only possible explaination I can think of is that for one reason
or another, with this particular compiler + build settings, this change
causes an increase of stack usage which exceeed the default limit ?

Regards,
Bruno

On 11/12/2018 14:13, Mikael Holmén wrote:
> Hi Bruno,
> 
> I've no idea if this is really related to your change, but with this 
> commit, the following starts crashing:
> 
> clang-tidy -allow-enabling-analyzer-alpha-checkers 
> -checks='-*,clang-analyzer-*' ./reduced.c --
> 
> It seems like it recurses forever for some reason, and then we run out 
> of stack and it crashes:
> 
> elxhw7c132-n7[llvm]: build-all-bbigcc/bin/clang-tidy 
> -allow-enabling-analyzer-alpha-checkers -checks='-*,clang-analyzer-*' 
> ./reduced.c --
> #0 0x0074fbda llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
> (build-all-bbigcc/bin/clang-tidy+0x74fbda)
> #1 0x0074e0aa llvm::sys::RunSignalHandlers() 
> (build-all-bbigcc/bin/clang-tidy+0x74e0aa)
> #2 0x0074e1d7 SignalHandler(int) 
> (build-all-bbigcc/bin/clang-tidy+0x74e1d7)
> #3 0x7f6cd7f84330 __restore_rt 
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
> #4 0x00f06c63 clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c63)
> #5 0x00f0a282 (anonymous 
> namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
> (build-all-bbigcc/bin/clang-tidy+0xf0a282)
> #6 0x00f0527f clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (.part.132) 
> (build-all-bbigcc/bin/clang-tidy+0xf0527f)
> #7 0x00f06c68 clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
> #8 0x00f0a282 (anonymous 
> namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
> (build-all-bbigcc/bin/clang-tidy+0xf0a282)
> #9 0x00f03fcf clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (.part.132) 
> (build-all-bbigcc/bin/clang-tidy+0xf03fcf)
> #10 0x00f06c68 clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
> #11 0x00f0a282 (anonymous 
> namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
> (build-all-bbigcc/bin/clang-tidy+0xf0a282)
> #12 0x00f03fcf clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (.part.132) 
> (build-all-bbigcc/bin/clang-tidy+0xf03fcf)
> #13 0x00f06c68 clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (build-all-bbigcc/bin/clang-tidy+0xf06c68)
> #14 0x00f0a282 (anonymous 
> namespace)::StringRefCheckerVisitor::VisitChildren(clang::Stmt*) 
> (build-all-bbigcc/bin/clang-tidy+0xf0a282)
> #15 0x00f03fcf clang::StmtVisitorBase (anonymous namespace)::StringRefCheckerVisitor, 
> void>::Visit(clang::Stmt*) (.part.132) 
> (build-all-bbigcc/bin/clang-tidy+0xf03fcf)
> 
> etc
> 
> I've only seen this when I compile clang-tidy with gcc 5.4.0, assertions 
> on, with optimizations. Simply turning on debug info when compiling 
> clang-tidy makes the crash go away so it's quite fragile.
> 
> Regards,
> Mikael
> 
> On 12/4/18 5:01 PM, Bruno Ricci via cfe-commits wrote:
>> Author: brunoricci
>> Date: Tue Dec  4 08:01:24 2018
>> New Revision: 348276
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=348276&view=rev
>> Log:
>> [AST][NFC] Make ArrayTypeTraitExpr non polymorphic
>>
>> ArrayTypeTraitExpr is the only expression class which is polymorphic.
>> As far as I can tell this is completely pointless.
>>
>> Differential Revision: https://reviews.llvm.org/D55221
>>
>> Reviewed By: aaron.ballman
>>
>>
>> Modified:
>>  cfe/trunk/include/clang/AST/ExprCXX.h
>>  cfe/trunk/lib/AST/ExprCXX.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/ExprCXX.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=348276&r1=348275&r2=348276&view=diff
>> =

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added a comment.

A few more minor nits.




Comment at: docs/LibASTMatchersReference.html:2579-2581
+y(x); Matches
+NS::y(x); Doesn't match
+y(42); Doesn't match.

This is not your bug to fix, but it seems the documentation generator is 
stripping the comment markers. This impacts other matchers as well, such as 
`throughUsingDecl()`.



Comment at: include/clang/Sema/Overload.h:831
+  private:
+// Only the OverloadCandidate set is allowed to construct 
OverloadCandidates.
+friend class OverloadCandidateSet;

OverloadCandidate set -> OverloadCandidateSet  ?  (I'd also be fine with 
removing the comment -- seems somewhat obvious from context.)



Comment at: lib/Sema/SemaExpr.cpp:5672
   CallExpr *TheCall;
-  if (Config)
+  if (Config) {
 TheCall = new (Context)

No need to add the braces here (alternatively, add them to the `else` clause).



Comment at: unittests/ASTMatchers/ASTMatchersNodeTest.cpp:204
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  auto NS_Str = R"DELIM(
+  namespace NS {

EricWF wrote:
> fowles wrote:
> > if you use cc or cpp as your delimiter, I think clang-format will recurse 
> > correctly
> That's super cool. Thanks!
Wow, that is really neat!


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

https://reviews.llvm.org/D55534



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


r348863 - [ASan] Minor documentation fix: clarify static linking limitation.

2018-12-11 Thread Max Moroz via cfe-commits
Author: dor1s
Date: Tue Dec 11 08:47:12 2018
New Revision: 348863

URL: http://llvm.org/viewvc/llvm-project?rev=348863&view=rev
Log:
[ASan] Minor documentation fix: clarify static linking limitation.

Summary:
ASan does not support statically linked binaries, but ASan runtime itself can
be statically linked into a target binary executable.

Reviewers: eugenis, kcc

Reviewed By: eugenis

Subscribers: cfe-commits, llvm-commits

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

Modified:
cfe/trunk/docs/AddressSanitizer.rst

Modified: cfe/trunk/docs/AddressSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AddressSanitizer.rst?rev=348863&r1=348862&r2=348863&view=diff
==
--- cfe/trunk/docs/AddressSanitizer.rst (original)
+++ cfe/trunk/docs/AddressSanitizer.rst Tue Dec 11 08:47:12 2018
@@ -265,7 +265,7 @@ Limitations
 * On 64-bit platforms AddressSanitizer maps (but not reserves) 16+ Terabytes of
   virtual address space. This means that tools like ``ulimit`` may not work as
   usually expected.
-* Static linking is not supported.
+* Static linking of executables is not supported.
 
 Supported Platforms
 ===


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


r348864 - Pass PartialOverloading argument to the correct corresponding parameter

2018-12-11 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Dec 11 08:53:25 2018
New Revision: 348864

URL: http://llvm.org/viewvc/llvm-project?rev=348864&view=rev
Log:
Pass PartialOverloading argument to the correct corresponding parameter

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeCompletion/function-overloads.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=348864&r1=348863&r2=348864&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Dec 11 08:53:25 2018
@@ -8939,12 +8939,14 @@ Sema::AddArgumentDependentLookupCandidat
   if (ExplicitTemplateArgs)
 continue;
 
-  AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet, false,
+  AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet,
+   /*SupressUserConversions=*/false,
PartialOverloading);
-} else
-  AddTemplateOverloadCandidate(cast(*I),
-   FoundDecl, ExplicitTemplateArgs,
-   Args, CandidateSet, PartialOverloading);
+} else {
+ AddTemplateOverloadCandidate(
+  cast(*I), FoundDecl, ExplicitTemplateArgs, 
Args,
+  CandidateSet, /*SupressUserConversions=*/false, PartialOverloading);
+}
   }
 }
 

Modified: cfe/trunk/test/CodeCompletion/function-overloads.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/function-overloads.cpp?rev=348864&r1=348863&r2=348864&view=diff
==
--- cfe/trunk/test/CodeCompletion/function-overloads.cpp (original)
+++ cfe/trunk/test/CodeCompletion/function-overloads.cpp Tue Dec 11 08:53:25 
2018
@@ -10,12 +10,27 @@ void test() {
   A a(f(1, 2, 3, 4), 2, 3);
 }
 
+
+namespace NS {
+  struct X { };
+  struct Y { Y(X); };
+  template 
+  void g(X, Y);
+}
+
+void test_adl() {
+  NS::X x;
+  g(x, x);
+}
+
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:9 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:10 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:17 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:19 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:20 %s -o - | 
FileCheck -check-prefix=CHECK-CC3 %s
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:21 %s -o - | 
FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:7 %s -o - | \
+// RUN:FileCheck -check-prefix=CHECK-CC5 %s
 // CHECK-CC1: OVERLOAD: [#int#]f(<#float x#>, float y)
 // CHECK-CC1: OVERLOAD: [#int#]f(<#int i#>)
 // CHECK-CC1-NOT, CHECK-CC2-NOT: OVERLOAD: A(
@@ -25,3 +40,4 @@ void test() {
 // CHECK-CC3: OVERLOAD: A(<#const A &#>)
 // CHECK-CC3: OVERLOAD: A(<#A &&#>)
 // CHECK-CC4: OVERLOAD: A(int, <#int#>, int)
+// CHECK-CC5: OVERLOAD: [#void#]g(X, <#Y#>)


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


r348865 - Reuse code from CGDebugInfo::getOrCreateFile() when creating the file

2018-12-11 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Dec 11 08:58:43 2018
New Revision: 348865

URL: http://llvm.org/viewvc/llvm-project?rev=348865&view=rev
Log:
Reuse code from CGDebugInfo::getOrCreateFile() when creating the file
for the DICompileUnit.

This addresses post-commit feedback for D55085. Without this patch, a
main source file with an absolute paths may appear in different
DIFiles, once with the absolute path and once with the common prefix
between the absolute path and the current working directory.

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/test/CodeGen/debug-info-compilation-dir.c
cfe/trunk/test/PCH/debug-info-pch-path.c

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=348865&r1=348864&r2=348865&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Dec 11 08:58:43 2018
@@ -429,7 +429,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
   Optional> CSInfo;
   if (CSKind)
 CSInfo.emplace(*CSKind, Checksum);
+  return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
+}
 
+llvm::DIFile *
+CGDebugInfo::createFile(StringRef FileName,
+Optional> CSInfo,
+Optional Source) {
   StringRef Dir;
   StringRef File;
   std::string RemappedFile = remapDIPath(FileName);
@@ -460,16 +466,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
 Dir = CurDir;
 File = RemappedFile;
   }
-  llvm::DIFile *F =
-  DBuilder.createFile(File, Dir, CSInfo,
-  getSource(SM, SM.getFileID(Loc)));
-
+  llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
   DIFileCache[FileName.data()].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
-  return DBuilder.createFile(
+  return createFile(
   remapDIPath(TheCU->getFilename()), remapDIPath(TheCU->getDirectory()),
   TheCU->getFile()->getChecksum(),
   CGM.getCodeGenOpts().EmbedSource ? TheCU->getSource() : None);
@@ -607,9 +610,7 @@ void CGDebugInfo::CreateCompileUnit() {
   auto &CGOpts = CGM.getCodeGenOpts();
   TheCU = DBuilder.createCompileUnit(
   LangTag,
-  DBuilder.createFile(remapDIPath(MainFileName),
-  remapDIPath(getCurrentDirname()), CSInfo,
-  getSource(SM, SM.getMainFileID())),
+  createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID())),
   CGOpts.EmitVersionIdentMetadata ? Producer : "",
   LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
   CGOpts.DwarfDebugFlags, RuntimeVers,

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=348865&r1=348864&r2=348865&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Dec 11 08:58:43 2018
@@ -538,9 +538,16 @@ private:
   /// Get the source of the given file ID.
   Optional getSource(const SourceManager &SM, FileID FID);
 
-  /// Get the file debug info descriptor for the input location.
+  /// Convenience function to get the file debug info descriptor for the input
+  /// location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
+  /// Create a file debug info descriptor for a source file.
+  llvm::DIFile *
+  createFile(StringRef FileName,
+ Optional> CSInfo,
+ Optional Source);
+
   /// Get the file info for main compile unit.
   llvm::DIFile *getOrCreateMainFile();
 

Modified: cfe/trunk/test/CodeGen/debug-info-compilation-dir.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-compilation-dir.c?rev=348865&r1=348864&r2=348865&view=diff
==
--- cfe/trunk/test/CodeGen/debug-info-compilation-dir.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-compilation-dir.c Tue Dec 11 08:58:43 2018
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
+// RUN: mkdir -p %t.dir && cd %t.dir
+// RUN: cp %s rel.c
+// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm 
-debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s
 // CHECK-NONSENSE: nonsense
 
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck 
-check-prefix=CHECK-DIR %s

Modified: cfe/trunk/test/PCH/debug-info-pch-path.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/debug-info-pch-path.c?rev=348865&r1=348864&r2=348865&view=diff
==
--- cfe/trunk

r348866 - Remove CGDebugInfo::getOrCreateFile() and use TheCU->getFile() directly.

2018-12-11 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Dec 11 08:58:46 2018
New Revision: 348866

URL: http://llvm.org/viewvc/llvm-project?rev=348866&view=rev
Log:
Remove CGDebugInfo::getOrCreateFile() and use TheCU->getFile() directly.

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=348866&r1=348865&r2=348866&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Dec 11 08:58:46 2018
@@ -220,7 +220,7 @@ llvm::DIScope *CGDebugInfo::getContextDe
   if (const auto *RDecl = dyn_cast(Context))
 if (!RDecl->isDependentType())
   return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
- getOrCreateMainFile());
+ TheCU->getFile());
   return Default;
 }
 
@@ -404,7 +404,7 @@ Optional CGDebugInfo::getSour
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
-return getOrCreateMainFile();
+return TheCU->getFile();
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
@@ -412,7 +412,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
   StringRef FileName = PLoc.getFilename();
   if (PLoc.isInvalid() || FileName.empty())
 // If the location is not valid then use main input file.
-return getOrCreateMainFile();
+return TheCU->getFile();
 
   // Cache the results.
   auto It = DIFileCache.find(FileName.data());
@@ -471,13 +471,6 @@ CGDebugInfo::createFile(StringRef FileNa
   return F;
 }
 
-llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
-  return createFile(
-  remapDIPath(TheCU->getFilename()), remapDIPath(TheCU->getDirectory()),
-  TheCU->getFile()->getChecksum(),
-  CGM.getCodeGenOpts().EmbedSource ? TheCU->getSource() : None);
-}
-
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
   for (const auto &Entry : DebugPrefixMap)
 if (Path.startswith(Entry.first))
@@ -641,9 +634,9 @@ llvm::DIType *CGDebugInfo::CreateType(co
 return nullptr;
   case BuiltinType::ObjCClass:
 if (!ClassTy)
-  ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
-   "objc_class", TheCU,
-   getOrCreateMainFile(), 0);
+  ClassTy =
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
+ "objc_class", TheCU, TheCU->getFile(), 0);
 return ClassTy;
   case BuiltinType::ObjCId: {
 // typedef struct objc_class *Class;
@@ -655,21 +648,21 @@ llvm::DIType *CGDebugInfo::CreateType(co
   return ObjTy;
 
 if (!ClassTy)
-  ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
-   "objc_class", TheCU,
-   getOrCreateMainFile(), 0);
+  ClassTy =
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
+ "objc_class", TheCU, TheCU->getFile(), 0);
 
 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
 
 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
 
-ObjTy = DBuilder.createStructType(
-TheCU, "objc_object", getOrCreateMainFile(), 0, 0, 0,
-llvm::DINode::FlagZero, nullptr, llvm::DINodeArray());
+ObjTy = DBuilder.createStructType(TheCU, "objc_object", TheCU->getFile(), 
0,
+  0, 0, llvm::DINode::FlagZero, nullptr,
+  llvm::DINodeArray());
 
 DBuilder.replaceArrays(
 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
-   ObjTy, "isa", getOrCreateMainFile(), 0, Size, 0, 0,
+   ObjTy, "isa", TheCU->getFile(), 0, Size, 0, 0,
llvm::DINode::FlagZero, ISATy)));
 return ObjTy;
   }
@@ -677,7 +670,7 @@ llvm::DIType *CGDebugInfo::CreateType(co
 if (!SelTy)
   SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
  "objc_selector", TheCU,
- getOrCreateMainFile(), 0);
+ TheCU->getFile(), 0);
 return SelTy;
   }
 
@@ -998,7 +991,7 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   if (Cache)
 return Cache;
   Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
- TheCU, getOrCreateMainFile(), 0);
+ TheCU, TheCU->getFile(), 0);
   unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
   Cache = DBuilder.createPointerType(C

Re: r348858 - Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"

2018-12-11 Thread Stefan Pintilie via cfe-commits
Hi Aaron, 

Sorry about giving so little info.

The commit was reverted because it broke two test cases on an internal 
buildbot. The reason this was reverted so late was because this failure 
was buried underneath another set of failures on that same buildbot which 
initially hid the problem. I'm looking at the failures now and hopefully 
I'll have the change back in soon.

Stefan



From:   Aaron Ballman 
To: stef...@ca.ibm.com
Cc: cfe-commits 
Date:   2018/12/11 10:56 AM
Subject:Re: r348858 - Revert "[PowerPC] Make no-PIC default to 
match GCC - CLANG"



On Tue, Dec 11, 2018 at 10:50 AM Stefan Pintilie via cfe-commits
 wrote:
>
> Author: stefanp
> Date: Tue Dec 11 07:47:57 2018
> New Revision: 348858
>
> URL: 
http://llvm.org/viewvc/llvm-project?rev=348858&view=rev

> Log:
> Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"
>
> This reverts commit rL348299.

When reverting a commit, you should explain why the commit was
reverted as part of the commit message (this makes code archaeology
much easier). Why was this reverted 500+ revisions after it landed?

~Aaron

>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> cfe/trunk/test/Driver/clang-offload-bundler.c
> cfe/trunk/test/Driver/ppc-abi.c
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=348858&r1=348857&r2=348858&view=diff

> 
==
> --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Dec 11 07:47:57 2018
> @@ -2435,7 +2435,7 @@ bool Generic_GCC::isPICDefault() const {
>case llvm::Triple::x86_64:
>  return getTriple().isOSWindows();
>case llvm::Triple::ppc64:
> -// Big endian PPC is PIC by default
> +  case llvm::Triple::ppc64le:
>  return !getTriple().isOSBinFormatMachO() && 
!getTriple().isMacOSX();
>case llvm::Triple::mips64:
>case llvm::Triple::mips64el:
>
> Modified: cfe/trunk/test/Driver/clang-offload-bundler.c
> URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=348858&r1=348857&r2=348858&view=diff

> 
==
> --- cfe/trunk/test/Driver/clang-offload-bundler.c (original)
> +++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Dec 11 07:47:57 
2018
> @@ -115,7 +115,7 @@
>  // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLEEND__ 
openmp-x86_64-pc-linux-gnu
>
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
host-powerpc64le-ibm-linux-gnu
> -// CK-TEXTLL: @A = dso_local global i32 0
> +// CK-TEXTLL: @A = global i32 0
>  // CK-TEXTLL: define {{.*}}@test_func()
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLEEND__ 
host-powerpc64le-ibm-linux-gnu
>  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
openmp-powerpc64le-ibm-linux-gnu
>
> Modified: cfe/trunk/test/Driver/ppc-abi.c
> URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-abi.c?rev=348858&r1=348857&r2=348858&view=diff

> 
==
> --- cfe/trunk/test/Driver/ppc-abi.c (original)
> +++ cfe/trunk/test/Driver/ppc-abi.c Tue Dec 11 07:47:57 2018
> @@ -13,12 +13,12 @@
>  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 
\
>  // RUN:   -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s
>  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 
\
> -// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s
> +// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
>
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 
2>&1 \
>  // RUN:   | FileCheck -check-prefix=CHECK-ELFv2 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 
2>&1 \
> -// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s
> +// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 
2>&1 \
>  // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
>  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 
2>&1 \
> @@ -26,44 +26,8 @@
>
>  // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv1: "-target-abi" "elfv1"
> -// CHECK-ELFv1-LE: "-mrelocation-model" "static"
> -// CHECK-ELFv1-LE: "-target-abi" "elfv1"
>  // CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx"
> -// CHECK-ELFv2: "-mrelocation-model" "static"
> +// CHECK-ELFv2: "-mrelocation-model" "pic" "-pic-level" "2"
>  // CHECK-ELFv2: "-target-abi" "elfv2"
> -// CHECK-ELFv2-BE: "-mrelocation-model" "pic" "-pic-level" "2"
> -// CHECK-ELFv2-BE: "-target-abi" "elfv2"
> -
> -// RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o 
%t.o 2>&1 \
> -// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-PIC 

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 3 inline comments as done.
EricWF added a comment.

Address more inline comments.




Comment at: docs/LibASTMatchersReference.html:2579-2581
+y(x); Matches
+NS::y(x); Doesn't match
+y(42); Doesn't match.

aaron.ballman wrote:
> This is not your bug to fix, but it seems the documentation generator is 
> stripping the comment markers. This impacts other matchers as well, such as 
> `throughUsingDecl()`.
I wonder if it strips `/**/` comments. I don't want to get blocked on this.




Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

riccibruno wrote:
> It do not really matter but there is not point initializing this bit here.
I'm a but nervous MSAN won't catch an uninitialized read because it's a 
bitfield, so I would rather be safe than sorry?


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

https://reviews.llvm.org/D55534



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: docs/LibASTMatchersReference.html:2579-2581
+y(x); Matches
+NS::y(x); Doesn't match
+y(42); Doesn't match.

EricWF wrote:
> aaron.ballman wrote:
> > This is not your bug to fix, but it seems the documentation generator is 
> > stripping the comment markers. This impacts other matchers as well, such as 
> > `throughUsingDecl()`.
> I wonder if it strips `/**/` comments. I don't want to get blocked on this.
> 
Don't let it block you -- I'm poking at a fix currently, but this is not your 
bug.


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

https://reviews.llvm.org/D55534



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


[PATCH] D55561: Stop stripping comments from AST matcher example code

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: JonasToth, klimek.

The AST matcher documentation dumping script was being a bit over-zealous about 
stripping comment markers, which ended up causing comments in example code to 
stop being comments. This patch fixes that by only stripping comments at the 
start of a line, rather than removing any forward slash (which also impacts 
prose text).

As a drive-by, this fixes a broken doxygen comment marker as well.


https://reviews.llvm.org/D55561

Files:
  docs/LibASTMatchersReference.html
  docs/tools/dump_ast_matchers.py
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3528,7 +3528,7 @@
 ///   } catch (...) {
 /// // ...
 ///   }
-/// /endcode
+/// \endcode
 /// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
 AST_MATCHER(CXXCatchStmt, isCatchAll) {
   return Node.getExceptionDecl() == nullptr;
Index: docs/tools/dump_ast_matchers.py
===
--- docs/tools/dump_ast_matchers.py
+++ docs/tools/dump_ast_matchers.py
@@ -354,7 +354,7 @@
 allowed_types += [m.group(1)]
 continue
   if line.strip() and line.lstrip()[0] == '/':
-comment += re.sub(r'/+\s?', '', line) + '\n'
+comment += re.sub(r'^/+\s?', '', line) + '\n'
   else:
 declaration += ' ' + line
 if ((not line.strip()) or 
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -499,7 +499,7 @@
   int X;
   namespace NS {
   int Y;
-  }  namespace NS
+  }  // namespace NS
 decl(hasDeclContext(translationUnitDecl()))
   matches "int X", but not "int Y".
 
@@ -1152,7 +1152,7 @@
 
 
 MatcherStmt>floatLiteralMatcherFloatingLiteral>...
-Matches float literals of all sizes encodings, e.g.
+Matches float literals of all sizes / encodings, e.g.
 1.0, 1.0f, 1.0L and 1e10.
 
 Does not match implicit conversions such as
@@ -1230,7 +1230,7 @@
 
 
 MatcherStmt>integerLiteralMatcherIntegerLiteral>...
-Matches integer literals of all sizes encodings, e.g.
+Matches integer literals of all sizes / encodings, e.g.
 1, 1L, 0x1 and 1U.
 
 Does not match character-encoded integers such as L'a'.
@@ -1911,8 +1911,8 @@
   template 
   class C { };
 
-  template class C;  A
-  C var;B
+  template class C;  // A
+  C var;// B
 
 templateSpecializationType() matches the type of the explicit
 instantiation in A and the type of the variable declaration in B.
@@ -2091,13 +2091,12 @@
 
 Given
   try {
-...
+// ...
   } catch (int) {
-...
+// ...
   } catch (...) {
-...
+// ...
   }
-endcode
 cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
 
 
@@ -2136,9 +2135,9 @@
 
 Given
   struct S {
-S(); #1
-S(const S &); #2
-S(S &&); #3
+S(); // #1
+S(const S &); // #2
+S(S &&); // #3
   };
 cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
 
@@ -2149,9 +2148,9 @@
 
 Given
   struct S {
-S(); #1
-S(const S &); #2
-S(S &&); #3
+S(); // #1
+S(const S &); // #2
+S(S &&); // #3
   };
 cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
 
@@ -2162,11 +2161,11 @@
 
 Given
   struct S {
-S(); #1
-S(int) {} #2
-S(S &&) : S() {} #3
+S(); // #1
+S(int) {} // #2
+S(S &&) : S() {} // #3
   };
-  S::S() : S(0) {} #4
+  S::S() : S(0) {} // #4
 cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not
 #1 or #2.
 
@@ -2178,10 +2177,10 @@
 
 Given
   struct S {
-S(int); #1
-explicit S(double); #2
-operator int(); #3
-explicit operator bool(); #4
+S(int); // #1
+explicit S(double); // #2
+operator int(); // #3
+explicit operator bool(); // #4
   };
 cxxConstructorDecl(isExplicit()) will match #2, but not #1.
 cxxConversionDecl(isExplicit()) will match #4, but not #3.
@@ -2193,9 +2192,9 @@
 
 Given
   struct S {
-S(); #1
-S(const S &); #2
-S(S &&); #3
+S(); // #1
+S(const S &); // #2
+S(S &&); // #3
   };
 cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
 
@@ -2207,10 +2206,10 @@
 
 Given
   struct S {
-S(int); #1
-explicit S(double); #2
-operator int(); #3
-explicit operator bool(); #4
+S(int); // #1
+explicit S(double); // #2
+operator int(); // #3
+explicit operator bool(); // #4
   };
 cxxConstructorDecl(isExplicit()) w

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 177732.
dmaclach added a comment.

Added some spacing around early exit as requested by theraven.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Sema/Sema.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/objc-large-encoding-warn.m

Index: test/SemaObjC/objc-large-encoding-warn.m
===
--- test/SemaObjC/objc-large-encoding-warn.m
+++ test/SemaObjC/objc-large-encoding-warn.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -Wobjc-encoding-larger-than=10 -Wno-objc-root-class %s
+
+struct MyStruct {
+  int a;
+  int b;
+  struct MyStruct *c;
+};
+
+@interface MyClass {
+  struct MyStruct iVarThatWarns; // expected-warning {{instance variable encoding of size 24 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  struct MyStruct iVarThatDoesntWarn;
+#pragma clang diagnostic pop
+  id idThatDoesntWarn;
+}
+@end
+
+@implementation MyClass
+- (void)methodThatWarns:(struct MyStruct)aStruct {} // expected-warning {{instance method 'methodThatWarns:' encoding of size 33 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+- (void)methodThatDoesntWarn:(struct MyStruct)aStruct {}
+#pragma clang diagnostic pop
+- (void)methodThatAlsoDoesntWarn {}
+@end
+
+void BlockFunc() {
+  void(^aBlockThatWarns)(struct MyStruct) = ^(struct MyStruct a) {}; // expected-warning {{block argument encoding of size 31 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  void(^aBlockThatDoesntWarn)(struct MyStruct) = ^(struct MyStruct a) {};
+#pragma clang diagnostic pop
+  void(^aBlockThatAlsoDoesntWarn)() = ^() {};
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13777,6 +13777,16 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  /// Check for block objective C encoding size
+  if (getLangOpts().ObjC) {
+std::string encoding = Context.getObjCEncodingForBlock(Result);
+unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+if (encodingSize && encoding.length() > encodingSize) {
+  Diag(BD->getLocation(), diag::warn_objc_block_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+
   return Result;
 }
 
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3875,6 +3875,25 @@
   }
 }
 
+// Run through the ivars and see if any of their encodings are larger than
+// ObjCLargeEncodingSize.
+void Sema::DiagnoseLargeIvarEncodings(ObjCImplementationDecl *ID) {
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize == 0) return;
+
+  for (ObjCIvarDecl *ivar = ID->getClassInterface()->all_declared_ivar_begin();
+   ivar; ivar = ivar->getNextIvar()) {
+QualType QT = Context.getBaseElementType(ivar->getType());
+std::string encoding;
+QualType NotEncodedT;
+Context.getObjCEncodingForType(QT, encoding, nullptr, &NotEncodedT);
+if (encoding.length() > encodingSize) {
+  Diag(ivar->getLocation(), diag::warn_objc_ivar_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+}
+
 // Note: For class/category implementations, allMethods is always null.
 Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef allMethods,
ArrayRef allTUVars) {
@@ -4006,6 +4025,7 @@
   if (IDecl->hasDesignatedInitializers())
 DiagnoseMissingDesignatedInitOverrides(IC, IDecl);
   DiagnoseWeakIvars(*this, IC);
+  DiagnoseLargeIvarEncodings(IC);
   DiagnoseRetainableFlexibleArrayMember(*this, IDecl);
 
   bool HasRootClassAttr = IDecl->hasAttr();
@@ -4768,6 +4788,15 @@
 }
   }
 
+  /// Check for method encoding size.
+  std::string encoding = Context.getObjCEncodingForMethodDecl(ObjCMethod);
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize && encoding.length() > encodingSize) {
+Diag(ObjCMethod->getLocation(), diag::warn_objc_method_encoding_too_large)
+  << (ObjCMethod->isInstanceMethod() ? "instance" : "class")
+  << ObjCMethod->getDeclName() << (unsigned)encoding.length()
+  << (unsigned)encodingSize;
+  }
   ActOnDocumentableDecl(ObjCMethod);
 
   return ObjCMethod;
Ind

[PATCH] D55562: Atomics: support min/max orthogonally

2018-12-11 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
t.p.northover added reviewers: delena, yaxunl.
Herald added subscribers: jfb, mcrosier.

We seem to have been gradually growing support for atomic min/max operations 
(exposing longstanding IR atomicrmw instructions). But until now there have 
been gaps in the expected intrinsics. This adds support for the C11-style 
intrinsics (i.e. taking _Atomic, rather than individually blessed by C11 
standard), and the variants that return the new value instead of the original 
one.

That way, people won't be misled by trying one form and it not working, and the 
front-end is more friendly to people using _Atomic types, as we recommend.


Repository:
  rC Clang

https://reviews.llvm.org/D55562

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/atomic-ops-libcall.c
  clang/test/CodeGen/atomic-ops.c
  clang/test/Sema/atomic-ops.c

Index: clang/test/Sema/atomic-ops.c
===
--- clang/test/Sema/atomic-ops.c
+++ clang/test/Sema/atomic-ops.c
@@ -354,6 +354,20 @@
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_acq_rel);
   (void)__c11_atomic_fetch_xor(Ap, val, memory_order_seq_cst);
 
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_relaxed);
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_acquire);
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_consume);
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_release);
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_acq_rel);
+  (void)__c11_atomic_fetch_min(Ap, val, memory_order_seq_cst);
+
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_relaxed);
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_acquire);
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_consume);
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_release);
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_acq_rel);
+  (void)__c11_atomic_fetch_max(Ap, val, memory_order_seq_cst);
+
   (void)__c11_atomic_exchange(Ap, val, memory_order_relaxed);
   (void)__c11_atomic_exchange(Ap, val, memory_order_acquire);
   (void)__c11_atomic_exchange(Ap, val, memory_order_consume);
@@ -501,6 +515,20 @@
   (void)__atomic_nand_fetch(p, val, memory_order_acq_rel);
   (void)__atomic_nand_fetch(p, val, memory_order_seq_cst);
 
+  (void)__atomic_max_fetch(p, val, memory_order_relaxed);
+  (void)__atomic_max_fetch(p, val, memory_order_acquire);
+  (void)__atomic_max_fetch(p, val, memory_order_consume);
+  (void)__atomic_max_fetch(p, val, memory_order_release);
+  (void)__atomic_max_fetch(p, val, memory_order_acq_rel);
+  (void)__atomic_max_fetch(p, val, memory_order_seq_cst);
+
+  (void)__atomic_min_fetch(p, val, memory_order_relaxed);
+  (void)__atomic_min_fetch(p, val, memory_order_acquire);
+  (void)__atomic_min_fetch(p, val, memory_order_consume);
+  (void)__atomic_min_fetch(p, val, memory_order_release);
+  (void)__atomic_min_fetch(p, val, memory_order_acq_rel);
+  (void)__atomic_min_fetch(p, val, memory_order_seq_cst);
+
   (void)__atomic_exchange_n(p, val, memory_order_relaxed);
   (void)__atomic_exchange_n(p, val, memory_order_acquire);
   (void)__atomic_exchange_n(p, val, memory_order_consume);
Index: clang/test/CodeGen/atomic-ops.c
===
--- clang/test/CodeGen/atomic-ops.c
+++ clang/test/CodeGen/atomic-ops.c
@@ -661,4 +661,46 @@
   __atomic_compare_exchange(&aligned_a, &aligned_b, &aligned_c, 1, memory_order_seq_cst, memory_order_seq_cst);
 }
 
+void test_c11_minmax(_Atomic(int) *si, _Atomic(unsigned) *ui) {
+  // CHECK-LABEL: @test_c11_minmax
+
+  // CHECK: atomicrmw max
+  *si = __c11_atomic_fetch_max(si, 42, memory_order_acquire);
+  // CHECK: atomicrmw min
+  *si = __c11_atomic_fetch_min(si, 42, memory_order_acquire);
+  // CHECK: atomicrmw umax
+  *ui = __c11_atomic_fetch_max(ui, 42, memory_order_acquire);
+  // CHECK: atomicrmw umin
+  *ui = __c11_atomic_fetch_min(ui, 42, memory_order_acquire);
+}
+
+void test_minmax_postop(int *si, unsigned *ui) {
+  int val = 42;
+  // CHECK-LABEL: @test_minmax_postop
+
+  // CHECK: [[OLD:%.*]] = atomicrmw max i32* [[PTR:%.*]], i32 [[RHS:%.*]] release
+  // CHECK: [[TST:%.*]] = icmp sgt i32 [[OLD]], [[RHS]]
+  // CHECK: [[NEW:%.*]] = select i1 [[TST]], i32 [[OLD]], i32 [[RHS]]
+  // CHECK: store i32 [[NEW]], i32*
+  *si = __atomic_max_fetch(si, 42, memory_order_release);
+
+  // CHECK: [[OLD:%.*]] = atomicrmw min i32* [[PTR:%.*]], i32 [[RHS:%.*]] release
+  // CHECK: [[TST:%.*]] = icmp slt i32 [[OLD]], [[RHS]]
+  // CHECK: [[NEW:%.*]] = select i1 [[TST]], i32 [[OLD]], i32 [[RHS]]
+  // CHECK: store i32 [[NEW]], i32*
+  *si = __atomic_min_fetch(si, 42, memory_order_release);
+  
+  // CHECK: [[OLD:%.*]] = atomicrmw umax i32* [[PTR:%.*]], i32 [[RHS:%.*]] release
+  // CHECK: [[TST:%.*]] = icmp ugt i32 [[OLD]], [[RHS]]
+  // CHECK

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach added a comment.

In D55544#1326956 , @theraven wrote:

> It would probably be a good idea to have a similar check on properties, as 
> property encoding strings contain the type encoding (plus extra stuff).


Properties are already picked up based on the ivars and methods that they 
generate.

> I wonder if we also want an option in code generation to replace very long 
> type encodings (or encodings of specifically annotated ivars?) with `"?"` 
> ('unknown type')?

Yeah, this is the next step. I'm trying to decide how best to do this. For a 
large cross platform code base I don't necessarily want to have folks having to 
annotate every C++ class they use with a somewhat non-portable annotation. At 
the same time you can't make all structs/classes encode as ? because I think it 
will mess up some existing Objective C patterns such as NSCoding.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

I believe that msan can cope with bit level operations just fine.
What I am afraid is that initializing it here will hide the
fact that it is not initialized during deserialization if the
`E->setUsesADL(Record.readInt());` is removed by mistake.

At least not initializing it here will leave a chance for msan
to catch this.


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

https://reviews.llvm.org/D55534



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


Re: r348858 - Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"

2018-12-11 Thread Aaron Ballman via cfe-commits
On Tue, Dec 11, 2018 at 12:07 PM Stefan Pintilie  wrote:
>
> Hi Aaron,
>
> Sorry about giving so little info.

No worries!

> The commit was reverted because it broke two test cases on an internal 
> buildbot. The reason this was reverted so late was because this failure was 
> buried underneath another set of failures on that same buildbot which 
> initially hid the problem. I'm looking at the failures now and hopefully I'll 
> have the change back in soon.

Ah, thank you for the information.

~Aaron

>
> Stefan
>
>
>
> From:Aaron Ballman 
> To:stef...@ca.ibm.com
> Cc:cfe-commits 
> Date:2018/12/11 10:56 AM
> Subject:Re: r348858 - Revert "[PowerPC] Make no-PIC default to match 
> GCC - CLANG"
> 
>
>
>
> On Tue, Dec 11, 2018 at 10:50 AM Stefan Pintilie via cfe-commits
>  wrote:
> >
> > Author: stefanp
> > Date: Tue Dec 11 07:47:57 2018
> > New Revision: 348858
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=348858&view=rev
> > Log:
> > Revert "[PowerPC] Make no-PIC default to match GCC - CLANG"
> >
> > This reverts commit rL348299.
>
> When reverting a commit, you should explain why the commit was
> reverted as part of the commit message (this makes code archaeology
> much easier). Why was this reverted 500+ revisions after it landed?
>
> ~Aaron
>
> >
> > Modified:
> > cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> > cfe/trunk/test/Driver/clang-offload-bundler.c
> > cfe/trunk/test/Driver/ppc-abi.c
> >
> > Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=348858&r1=348857&r2=348858&view=diff
> > ==
> > --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
> > +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Dec 11 07:47:57 2018
> > @@ -2435,7 +2435,7 @@ bool Generic_GCC::isPICDefault() const {
> >case llvm::Triple::x86_64:
> >  return getTriple().isOSWindows();
> >case llvm::Triple::ppc64:
> > -// Big endian PPC is PIC by default
> > +  case llvm::Triple::ppc64le:
> >  return !getTriple().isOSBinFormatMachO() && !getTriple().isMacOSX();
> >case llvm::Triple::mips64:
> >case llvm::Triple::mips64el:
> >
> > Modified: cfe/trunk/test/Driver/clang-offload-bundler.c
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-offload-bundler.c?rev=348858&r1=348857&r2=348858&view=diff
> > ==
> > --- cfe/trunk/test/Driver/clang-offload-bundler.c (original)
> > +++ cfe/trunk/test/Driver/clang-offload-bundler.c Tue Dec 11 07:47:57 2018
> > @@ -115,7 +115,7 @@
> >  // CK-TEXTI: // __CLANG_OFFLOAD_BUNDLEEND__ openmp-x86_64-pc-linux-gnu
> >
> >  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
> > host-powerpc64le-ibm-linux-gnu
> > -// CK-TEXTLL: @A = dso_local global i32 0
> > +// CK-TEXTLL: @A = global i32 0
> >  // CK-TEXTLL: define {{.*}}@test_func()
> >  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLEEND__ 
> > host-powerpc64le-ibm-linux-gnu
> >  // CK-TEXTLL: ; __CLANG_OFFLOAD_BUNDLESTART__ 
> > openmp-powerpc64le-ibm-linux-gnu
> >
> > Modified: cfe/trunk/test/Driver/ppc-abi.c
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ppc-abi.c?rev=348858&r1=348857&r2=348858&view=diff
> > ==
> > --- cfe/trunk/test/Driver/ppc-abi.c (original)
> > +++ cfe/trunk/test/Driver/ppc-abi.c Tue Dec 11 07:47:57 2018
> > @@ -13,12 +13,12 @@
> >  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> >  // RUN:   -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s
> >  // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> > -// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s
> > +// RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
> >
> >  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> >  // RUN:   | FileCheck -check-prefix=CHECK-ELFv2 %s
> >  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> > -// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s
> > +// RUN:   -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s
> >  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> >  // RUN:   -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s
> >  // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
> > @@ -26,44 +26,8 @@
> >
> >  // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
> >  // CHECK-ELFv1: "-target-abi" "elfv1"
> > -// CHECK-ELFv1-LE: "-mrelocation-model" "static"
> > -// CHECK-ELFv1-LE: "-target-abi" "elfv1"
> >  // CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2"
> >  // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx"
> > -// CHECK-ELFv2: "-mrelocatio

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Sema/Sema.h:2758
 bool AllowExplicit = false,
+bool IsADLCandidate = false,
 ConversionSequenceList EarlyConversions = None);

Long lists of bool arguments make me nervous, especially with default 
arguments. Can you introduce an enum for the new param at least?



Comment at: lib/AST/ASTImporter.cpp:7387
   return new (Importer.getToContext()) CallExpr(
   Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(),
   ToRParenLoc);

Do we need to pass through the usesADL flag here too?



Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

EricWF wrote:
> riccibruno wrote:
> > It do not really matter but there is not point initializing this bit here.
> I'm a but nervous MSAN won't catch an uninitialized read because it's a 
> bitfield, so I would rather be safe than sorry?
IIRC all the ExprBits get initialized by the Expr(EmptyShell) ctor.



Comment at: lib/Sema/SemaExpr.cpp:5673
+  if (Config) {
 TheCall = new (Context)
 CUDAKernelCallExpr(Context, Fn, cast(Config), Args, ResultTy,

If you believe that CUDA kernel calls can't find functions with ADL, please add 
an assert here.


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

https://reviews.llvm.org/D55534



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


[PATCH] D55226: [Fix][StaticAnalyzer] Bug 39792 - False positive on strcpy targeting struct member

2018-12-11 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added a comment.

Hello!

I'm pinging since it's been a week. If someone can commit this patch on my 
behalf, that would be great.

Thank you :)


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

https://reviews.llvm.org/D55226



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

riccibruno wrote:
> I believe that msan can cope with bit level operations just fine.
> What I am afraid is that initializing it here will hide the
> fact that it is not initialized during deserialization if the
> `E->setUsesADL(Record.readInt());` is removed by mistake.
> 
> At least not initializing it here will leave a chance for msan
> to catch this.
I don't think they do.


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

https://reviews.llvm.org/D55534



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


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-12-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Here's the test case that we have https://reviews.llvm.org/P8123   gcc seems to 
accept it at O0


Repository:
  rC Clang

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

https://reviews.llvm.org/D54355



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


[PATCH] D54592: [analyzer][CStringChecker] evaluate explicit_bzero

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!




Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2216
+  // In this case we just return.
+  if (StateZeroSize && !StateNonZeroSize) {
+C.addTransition(StateZeroSize);

`!StateNonZeroSize` implies `StateZeroSize`, you can drop the left-hand side of 
`&&`.



Comment at: test/Analysis/string.c:1405-1406
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  bzero(str + 2, 2);
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{FALSE}}
+}

devnexen wrote:
> NoQ wrote:
> > Let's also add the true statement. I.e., do we know here that the actual 
> > length is 2?
> I think that s the limit of this checker (even with memset that does not 
> work).
I mean, even if it doesn't work, let's add a FIXME test.


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

https://reviews.llvm.org/D54592



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


[PATCH] D54923: [Modules] Remove non-determinism while serializing DECL_CONTEXT_LEXICAL and DECL_RECORD

2018-12-11 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Ping


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

https://reviews.llvm.org/D54923



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


[PATCH] D55482: [clang-tidy] Improve google-objc-function-naming diagnostics 📙

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:113
 
+  const bool IsGlobal = MatchedDecl->getStorageClass() != SC_Static;
   diag(MatchedDecl->getLocation(),

Drop the top-level `const` qualifier, please.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:115
   diag(MatchedDecl->getLocation(),
-   "function name %0 not using function naming conventions described by "
-   "Google Objective-C style guide")
-  << MatchedDecl << generateFixItHint(MatchedDecl);
+   "%select{static|global}1 function name %0 must %select{be in|have an "
+   "appropriate prefix followed by}1 Pascal case as required by Google "

stephanemoore wrote:
> benhamilton wrote:
> > I know "global" is the correct name, but I feel like "non-static" might be 
> > clearer to folks dealing with these error messages.
> > 
> > WDYT?
> > 
> I'm wary of saying "non-static" because namespaced functions in Objective-C++ 
> are not subject to the cited rules. The term "non-static" seems like it could 
> be interpreted to extend to namespaced functions which could potentially 
> mislead someone into adding prefixes to namespaced functions in Objective-C++.
How about "%select{static function|function in global namespace}1 named %0..."


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

https://reviews.llvm.org/D55482



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


[PATCH] D43871: [modules] No longer include stdlib.h from mm_malloc.h.

2018-12-11 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

@joerg Yeah, we saw the commit explaining why the original fwd declaration 
patch was reverted. However, from what I can see, we only have three ways to 
fix the cyclic dependency between glibc and Clang's internal module:

1. We say that we don't support including mm_malloc.h from the module 
containing stdlib.h.
2. We don't include mm_malloc.h (and the internal headers that include 
mm_malloc.h) in Clang's internal module.
3. We add this workaround to allow us to forward declare free/malloc here.

Solution 1 essentially means that we won't support a glibc with modules until 
they work around this issue. And solution 2 means that all affected headers in 
clang's internal module have to be textually copied into modules that include 
them.

So after some offline discussion on how to proceed with this, the plan we came 
up with was to land this patch (which implements solution 3) and then see 
how/if we can work around the problems that users experience because of it 
(otherwise we would revert).

I don't have a strict preference between solution 2 and 3 at this point. So if 
@joerg thinks that this approach is not the right one, then I would just make a 
new patch that removes the affected headers from Clang's internal module.


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

https://reviews.llvm.org/D43871



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


[PATCH] D55562: Atomics: support min/max orthogonally

2018-12-11 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

What does it do with floating-point inputs?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55562



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


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-12-11 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D54355#1327237 , @craig.topper 
wrote:

> Here's the test case that we have https://reviews.llvm.org/P8123   gcc seems 
> to accept it at O0


Smaller test case:

  extern unsigned long long __sdt_unsp;
  
  void foo() {
__asm__ __volatile__(
"" :: "n"( (__builtin_constant_p(__sdt_unsp) || 0) ? 1 : -1));
  }


Repository:
  rC Clang

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

https://reviews.llvm.org/D54355



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


r348884 - [analyzer][CStringChecker] evaluate explicit_bzero

2018-12-11 Thread David Carlier via cfe-commits
Author: devnexen
Date: Tue Dec 11 10:57:07 2018
New Revision: 348884

URL: http://llvm.org/viewvc/llvm-project?rev=348884&view=rev
Log:
[analyzer][CStringChecker] evaluate explicit_bzero


- explicit_bzero has limited scope/usage only for security/crypto purposes but 
is non-optimisable version of memset/0 and bzero.
- explicit_memset has similar signature and semantics as memset but is also a 
non-optimisable version.

Reviewers: NoQ

Reviewed By: NoQ

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


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/trunk/test/Analysis/string.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=348884&r1=348883&r2=348884&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Tue Dec 11 
10:57:07 2018
@@ -124,6 +124,7 @@ public:
   void evalStdCopyBackward(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyCommon(CheckerContext &C, const CallExpr *CE) const;
   void evalMemset(CheckerContext &C, const CallExpr *CE) const;
+  void evalBzero(CheckerContext &C, const CallExpr *CE) const;
 
   // Utility methods
   std::pair
@@ -158,7 +159,7 @@ public:
   static bool SummarizeRegion(raw_ostream &os, ASTContext &Ctx,
   const MemRegion *MR);
 
-  static bool memsetAux(const Expr *DstBuffer, const Expr *CharE,
+  static bool memsetAux(const Expr *DstBuffer, SVal CharE,
 const Expr *Size, CheckerContext &C,
 ProgramStateRef &State);
 
@@ -1005,11 +1006,10 @@ bool CStringChecker::SummarizeRegion(raw
   }
 }
 
-bool CStringChecker::memsetAux(const Expr *DstBuffer, const Expr *CharE,
+bool CStringChecker::memsetAux(const Expr *DstBuffer, SVal CharVal,
const Expr *Size, CheckerContext &C,
ProgramStateRef &State) {
   SVal MemVal = C.getSVal(DstBuffer);
-  SVal CharVal = C.getSVal(CharE);
   SVal SizeVal = C.getSVal(Size);
   const MemRegion *MR = MemVal.getAsRegion();
   if (!MR)
@@ -2184,13 +2184,59 @@ void CStringChecker::evalMemset(CheckerC
   // According to the values of the arguments, bind the value of the second
   // argument to the destination buffer and set string length, or just
   // invalidate the destination buffer.
-  if (!memsetAux(Mem, CharE, Size, C, State))
+  if (!memsetAux(Mem, C.getSVal(CharE), Size, C, State))
 return;
 
   State = State->BindExpr(CE, LCtx, MemVal);
   C.addTransition(State);
 }
 
+void CStringChecker::evalBzero(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() != 2)
+return;
+
+  CurrentFunctionDescription = "memory clearance function";
+
+  const Expr *Mem = CE->getArg(0);
+  const Expr *Size = CE->getArg(1);
+  SVal Zero = C.getSValBuilder().makeZeroVal(C.getASTContext().IntTy);
+
+  ProgramStateRef State = C.getState();
+  
+  // See if the size argument is zero.
+  SVal SizeVal = C.getSVal(Size);
+  QualType SizeTy = Size->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  // If the size is zero, there won't be any actual memory access,
+  // In this case we just return.
+  if (StateZeroSize && !StateNonZeroSize) {
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  // Get the value of the memory area.
+  SVal MemVal = C.getSVal(Mem);
+
+  // Ensure the memory area is not null.
+  // If it is NULL there will be a NULL pointer dereference.
+  State = checkNonNull(C, StateNonZeroSize, Mem, MemVal);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Size, Mem);
+  if (!State)
+return;
+
+  if (!memsetAux(Mem, Zero, Size, C, State))
+return;
+
+  C.addTransition(State);
+}
+
 static bool isCPPStdLibraryFunction(const FunctionDecl *FD, StringRef Name) {
   IdentifierInfo *II = FD->getIdentifier();
   if (!II)
@@ -2224,7 +2270,8 @@ bool CStringChecker::evalCall(const Call
 evalFunction =  &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
 evalFunction =  &CStringChecker::evalMemmove;
-  else if (C.isCLibraryFunction(FDecl, "memset"))
+  else if (C.isCLibraryFunction(FDecl, "memset") || 
+C.isCLibraryFunction(FDecl, "explicit_memset"))
 evalFunction =  &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
 evalFunction =  &CStringChecker::evalStrcpy;
@@ -2262,6 +2309,9 @@ bool CStringChecker::evalCall(const Call
 evalFunction =  &CStringChecker::evalStdCopy;
   else if (isCPPStdLibraryFunction(FDecl, "copy_backward"))
 evalFunction =  &CStringChecker::evalStdCopyBackward;
+  else if (C.isCLibraryFunction(FDecl, "bzero") ||
+

[PATCH] D54592: [analyzer][CStringChecker] evaluate explicit_bzero

2018-12-11 Thread David CARLIER via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348884: [analyzer][CStringChecker] evaluate explicit_bzero 
(authored by devnexen, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54592?vs=177171&id=177739#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D54592

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/test/Analysis/string.c

Index: cfe/trunk/test/Analysis/string.c
===
--- cfe/trunk/test/Analysis/string.c
+++ cfe/trunk/test/Analysis/string.c
@@ -1184,11 +1184,14 @@
 }
 
 //===--===
-// memset()
+// memset() / explicit_bzero() / bzero()
 //===--===
 
 void *memset(void *dest, int ch, size_t count);
 
+void bzero(void *dst, size_t count);
+void explicit_bzero(void *dest, size_t count);
+
 void *malloc(size_t size);
 void free(void *);
 
@@ -1383,6 +1386,57 @@
   clang_analyzer_eval(array[4] == 0); // expected-warning{{TRUE}}
 }
 
+void bzero1_null() {
+  char *a = NULL;
+
+  bzero(a, 10); // expected-warning{{Null pointer argument in call to memory clearance function}}
+}
+
+void bzero2_char_array_null() {
+  char str[] = "abcd";
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  bzero(str, 2);
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{TRUE}}
+}
+
+void bzero3_char_ptr_null() {
+  char *str = "abcd";
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  bzero(str + 2, 2);
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{FALSE}}
+}
+
+void explicit_bzero1_null() {
+  char *a = NULL;
+
+  explicit_bzero(a, 10); // expected-warning{{Null pointer argument in call to memory clearance function}}
+}
+
+void explicit_bzero2_clear_mypassword() {
+  char passwd[7] = "passwd";
+
+  explicit_bzero(passwd, sizeof(passwd)); // no-warning
+
+  clang_analyzer_eval(strlen(passwd) == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(passwd[0] == '\0'); // expected-warning{{TRUE}}
+}
+
+void explicit_bzero3_out_ofbound() {
+  char *privkey = (char *)malloc(7);
+  const char newprivkey[10] = "mysafekey";
+
+  strcpy(privkey, "random");
+  explicit_bzero(privkey, sizeof(newprivkey));
+#ifndef SUPPRESS_OUT_OF_BOUND
+  // expected-warning@-2 {{Memory clearance function accesses out-of-bound array element}}
+#endif
+  clang_analyzer_eval(privkey[0] == '\0');
+#ifdef SUPPRESS_OUT_OF_BOUND
+  // expected-warning@-2 {{UNKNOWN}}
+#endif
+  free(privkey);
+}
+
 //===--===
 // FIXMEs
 //===--===
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -124,6 +124,7 @@
   void evalStdCopyBackward(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyCommon(CheckerContext &C, const CallExpr *CE) const;
   void evalMemset(CheckerContext &C, const CallExpr *CE) const;
+  void evalBzero(CheckerContext &C, const CallExpr *CE) const;
 
   // Utility methods
   std::pair
@@ -158,7 +159,7 @@
   static bool SummarizeRegion(raw_ostream &os, ASTContext &Ctx,
   const MemRegion *MR);
 
-  static bool memsetAux(const Expr *DstBuffer, const Expr *CharE,
+  static bool memsetAux(const Expr *DstBuffer, SVal CharE,
 const Expr *Size, CheckerContext &C,
 ProgramStateRef &State);
 
@@ -1005,11 +1006,10 @@
   }
 }
 
-bool CStringChecker::memsetAux(const Expr *DstBuffer, const Expr *CharE,
+bool CStringChecker::memsetAux(const Expr *DstBuffer, SVal CharVal,
const Expr *Size, CheckerContext &C,
ProgramStateRef &State) {
   SVal MemVal = C.getSVal(DstBuffer);
-  SVal CharVal = C.getSVal(CharE);
   SVal SizeVal = C.getSVal(Size);
   const MemRegion *MR = MemVal.getAsRegion();
   if (!MR)
@@ -2184,13 +2184,59 @@
   // According to the values of the arguments, bind the value of the second
   // argument to the destination buffer and set string length, or just
   // invalidate the destination buffer.
-  if (!memsetAux(Mem, CharE, Size, C, State))
+  if (!memsetAux(Mem, C.getSVal(CharE), Size, C, State))
 return;
 
   State = State->BindExpr(CE, LCtx, MemVal);
   C.addTransition(State);
 }
 
+void CStringChecker::evalBzero(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() != 2)
+return;
+
+  CurrentFunctionDescription = "memory clearance function";
+
+  const Expr *Mem = CE-

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks for working on this! Could you please post a patch with full context 
(git diff -U)?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544



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


[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 177744.
dmaclach marked an inline comment as done.
dmaclach added a comment.

Full Diffs as requested.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Sema/Sema.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/objc-large-encoding-warn.m

Index: test/SemaObjC/objc-large-encoding-warn.m
===
--- test/SemaObjC/objc-large-encoding-warn.m
+++ test/SemaObjC/objc-large-encoding-warn.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -Wobjc-encoding-larger-than=10 -Wno-objc-root-class %s
+
+struct MyStruct {
+  int a;
+  int b;
+  struct MyStruct *c;
+};
+
+@interface MyClass {
+  struct MyStruct iVarThatWarns; // expected-warning {{instance variable encoding of size 24 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  struct MyStruct iVarThatDoesntWarn;
+#pragma clang diagnostic pop
+  id idThatDoesntWarn;
+}
+@end
+
+@implementation MyClass
+- (void)methodThatWarns:(struct MyStruct)aStruct {} // expected-warning {{instance method 'methodThatWarns:' encoding of size 33 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+- (void)methodThatDoesntWarn:(struct MyStruct)aStruct {}
+#pragma clang diagnostic pop
+- (void)methodThatAlsoDoesntWarn {}
+@end
+
+void BlockFunc() {
+  void(^aBlockThatWarns)(struct MyStruct) = ^(struct MyStruct a) {}; // expected-warning {{block argument encoding of size 31 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  void(^aBlockThatDoesntWarn)(struct MyStruct) = ^(struct MyStruct a) {};
+#pragma clang diagnostic pop
+  void(^aBlockThatAlsoDoesntWarn)() = ^() {};
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13777,6 +13777,16 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  /// Check for block objective C encoding size
+  if (getLangOpts().ObjC) {
+std::string encoding = Context.getObjCEncodingForBlock(Result);
+unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+if (encodingSize && encoding.length() > encodingSize) {
+  Diag(BD->getLocation(), diag::warn_objc_block_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+
   return Result;
 }
 
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3875,6 +3875,25 @@
   }
 }
 
+// Run through the ivars and see if any of their encodings are larger than
+// ObjCLargeEncodingSize.
+void Sema::DiagnoseLargeIvarEncodings(ObjCImplementationDecl *ID) {
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize == 0) return;
+
+  for (ObjCIvarDecl *ivar = ID->getClassInterface()->all_declared_ivar_begin();
+   ivar; ivar = ivar->getNextIvar()) {
+QualType QT = Context.getBaseElementType(ivar->getType());
+std::string encoding;
+QualType NotEncodedT;
+Context.getObjCEncodingForType(QT, encoding, nullptr, &NotEncodedT);
+if (encoding.length() > encodingSize) {
+  Diag(ivar->getLocation(), diag::warn_objc_ivar_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+}
+
 // Note: For class/category implementations, allMethods is always null.
 Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef allMethods,
ArrayRef allTUVars) {
@@ -4006,6 +4025,7 @@
   if (IDecl->hasDesignatedInitializers())
 DiagnoseMissingDesignatedInitOverrides(IC, IDecl);
   DiagnoseWeakIvars(*this, IC);
+  DiagnoseLargeIvarEncodings(IC);
   DiagnoseRetainableFlexibleArrayMember(*this, IDecl);
 
   bool HasRootClassAttr = IDecl->hasAttr();
@@ -4768,6 +4788,15 @@
 }
   }
 
+  /// Check for method encoding size.
+  std::string encoding = Context.getObjCEncodingForMethodDecl(ObjCMethod);
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize && encoding.length() > encodingSize) {
+Diag(ObjCMethod->getLocation(), diag::warn_objc_method_encoding_too_large)
+  << (ObjCMethod->isInstanceMethod() ? "instance" : "class")
+  << ObjCMethod->getDeclName() << (unsigned)encoding.length()
+  << (unsigned)encodingSize;
+  }
   ActOnDocumentableDecl(ObjCMethod);
 
   return ObjCMethod

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-11 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 177746.
dmaclach added a comment.

Updated to fix Stephane's good catch of Objective C vs Objective-C


Repository:
  rC Clang

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

https://reviews.llvm.org/D55544

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Sema/Sema.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/objc-large-encoding-warn.m

Index: test/SemaObjC/objc-large-encoding-warn.m
===
--- test/SemaObjC/objc-large-encoding-warn.m
+++ test/SemaObjC/objc-large-encoding-warn.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -Wobjc-encoding-larger-than=10 -Wno-objc-root-class %s
+
+struct MyStruct {
+  int a;
+  int b;
+  struct MyStruct *c;
+};
+
+@interface MyClass {
+  struct MyStruct iVarThatWarns; // expected-warning {{instance variable encoding of size 24 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  struct MyStruct iVarThatDoesntWarn;
+#pragma clang diagnostic pop
+  id idThatDoesntWarn;
+}
+@end
+
+@implementation MyClass
+- (void)methodThatWarns:(struct MyStruct)aStruct {} // expected-warning {{instance method 'methodThatWarns:' encoding of size 33 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+- (void)methodThatDoesntWarn:(struct MyStruct)aStruct {}
+#pragma clang diagnostic pop
+- (void)methodThatAlsoDoesntWarn {}
+@end
+
+void BlockFunc() {
+  void(^aBlockThatWarns)(struct MyStruct) = ^(struct MyStruct a) {}; // expected-warning {{block argument encoding of size 31 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  void(^aBlockThatDoesntWarn)(struct MyStruct) = ^(struct MyStruct a) {};
+#pragma clang diagnostic pop
+  void(^aBlockThatAlsoDoesntWarn)() = ^() {};
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13777,6 +13777,16 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  /// Check for block objective C encoding size
+  if (getLangOpts().ObjC) {
+std::string encoding = Context.getObjCEncodingForBlock(Result);
+unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+if (encodingSize && encoding.length() > encodingSize) {
+  Diag(BD->getLocation(), diag::warn_objc_block_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+
   return Result;
 }
 
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3875,6 +3875,25 @@
   }
 }
 
+// Run through the ivars and see if any of their encodings are larger than
+// ObjCLargeEncodingSize.
+void Sema::DiagnoseLargeIvarEncodings(ObjCImplementationDecl *ID) {
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize == 0) return;
+
+  for (ObjCIvarDecl *ivar = ID->getClassInterface()->all_declared_ivar_begin();
+   ivar; ivar = ivar->getNextIvar()) {
+QualType QT = Context.getBaseElementType(ivar->getType());
+std::string encoding;
+QualType NotEncodedT;
+Context.getObjCEncodingForType(QT, encoding, nullptr, &NotEncodedT);
+if (encoding.length() > encodingSize) {
+  Diag(ivar->getLocation(), diag::warn_objc_ivar_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+}
+
 // Note: For class/category implementations, allMethods is always null.
 Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef allMethods,
ArrayRef allTUVars) {
@@ -4006,6 +4025,7 @@
   if (IDecl->hasDesignatedInitializers())
 DiagnoseMissingDesignatedInitOverrides(IC, IDecl);
   DiagnoseWeakIvars(*this, IC);
+  DiagnoseLargeIvarEncodings(IC);
   DiagnoseRetainableFlexibleArrayMember(*this, IDecl);
 
   bool HasRootClassAttr = IDecl->hasAttr();
@@ -4768,6 +4788,15 @@
 }
   }
 
+  /// Check for method encoding size.
+  std::string encoding = Context.getObjCEncodingForMethodDecl(ObjCMethod);
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize && encoding.length() > encodingSize) {
+Diag(ObjCMethod->getLocation(), diag::warn_objc_method_encoding_too_large)
+  << (ObjCMethod->isInstanceMethod() ? "instance" : "class")
+  << ObjCMethod->getDeclName() << (unsigned)encoding.length()
+  << (unsigned)encodingSize;
+  }
   ActOnDocumentableDecl(ObjCMethod);
 
   return ObjCMethod;

[PATCH] D55561: Stop stripping comments from AST matcher example code

2018-12-11 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth accepted this revision.
JonasToth added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55561



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


[PATCH] D55488: Add utility for dumping a label with child nodes

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/AST/ASTDumper.cpp:89
 void dumpDecl(const Decl *D);
-void dumpStmt(const Stmt *S);
+void dumpStmt(const Stmt *S, const std::string &label = {});
 

steveire wrote:
> aaron.ballman wrote:
> > Label
> > 
> > Rather than using `{}`, how about `""` (same behavior, but looks more 
> > idiomatic).
> > 
> > Why `std::string` instead of `StringRef`? I expect this will be called 
> > mostly with string literals, which saves an allocation. The other labels 
> > are using `const char *`, which would be another reasonable option. 
> > Whatever we go with, it'd be nice to make the label types agree across the 
> > calls.
> The actual print in TextTreeStructure is deferred, so it can't be `const 
> char*` or `StringRef`.
I think I've convinced myself there are not lifetime issues here, but it's 
subtle. In the case where the default argument is used, it creates a temporary 
object that is lifetime extended for the duration of the full expression 
including the call to `dumpStmt()`. The capture of `Label` in the lambda in 
`addChild()` captures the reference by copy and initializes the implicit field 
for the capture to the temporary value while its still within its lifetime. So 
I don't think this introduces UB.

However, if that lambda ever changes the capture list to use capture defaults 
(which we typically prefer when capturing multiple entities) and someone uses 
`&` or `this` as the capture default, they're going to have a very 
hard-to-discover bug on their hands. :-/

Another approach is to use `StringRef` in these calls, but within `addChild()` 
change the lambda to capture a local `std::string` by copy. e.g.,
```
template 
void addChild(StringRef Label, Fn doAddChild) {
  ...
  std::string LabelStr = Label.str();
  auto dumpWithIndent = [this, doAddChild, LabelStr](bool isLastChild) {
...
  };
  ...
```
(And when we upgrade to C++14 we can drop the local and just use an init 
capture instead.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D55488



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


[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit in r348889, thank you for the patch!


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

https://reviews.llvm.org/D51211



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


r348889 - Emit -Wformat properly for bit-field promotions.

2018-12-11 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Dec 11 11:18:01 2018
New Revision: 348889

URL: http://llvm.org/viewvc/llvm-project?rev=348889&view=rev
Log:
Emit -Wformat properly for bit-field promotions.

Only explicitly look through integer and floating-point promotion where the 
result type is actually a promotion, which is not always the case for 
bit-fields in C.

Added:
cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=348889&r1=34&r2=348889&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 11 11:18:01 2018
@@ -7709,6 +7709,24 @@ shouldNotPrintDirectly(const ASTContext
   return std::make_pair(QualType(), StringRef());
 }
 
+/// Return true if \p ICE is an implicit argument promotion of an arithmetic
+/// type. Bit-field 'promotions' from a higher ranked type to a lower ranked
+/// type do not count.
+static bool
+isArithmeticArgumentPromotion(Sema &S, const ImplicitCastExpr *ICE) {
+  QualType From = ICE->getSubExpr()->getType();
+  QualType To = ICE->getType();
+  // It's a floating promotion if the source type is a lower rank.
+  if (ICE->getCastKind() == CK_FloatingCast &&
+  S.Context.getFloatingTypeOrder(From, To) < 0)
+return true;
+  // It's an integer promotion if the destination type is the promoted
+  // source type.
+  return ICE->getCastKind() == CK_IntegralCast &&
+ From->isPromotableIntegerType() &&
+ S.Context.getPromotedIntegerType(From) == To;
+}
+
 bool
 CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
 const char *StartSpecifier,
@@ -7736,11 +7754,11 @@ CheckPrintfHandler::checkFormatExpr(cons
 
   // Look through argument promotions for our error message's reported type.
   // This includes the integral and floating promotions, but excludes array
-  // and function pointer decay; seeing that an argument intended to be a
-  // string has type 'char [6]' is probably more confusing than 'char *'.
+  // and function pointer decay (seeing that an argument intended to be a
+  // string has type 'char [6]' is probably more confusing than 'char *') and
+  // certain bitfield promotions (bitfields can be 'demoted' to a lesser type).
   if (const ImplicitCastExpr *ICE = dyn_cast(E)) {
-if (ICE->getCastKind() == CK_IntegralCast ||
-ICE->getCastKind() == CK_FloatingCast) {
+if (isArithmeticArgumentPromotion(S, ICE)) {
   E = ICE->getSubExpr();
   ExprTy = E->getType();
 

Added: cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.c?rev=348889&view=auto
==
--- cfe/trunk/test/Sema/format-strings-bitfield-promotion.c (added)
+++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.c Tue Dec 11 11:18:01 
2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s
+
+int printf(const char *restrict, ...);
+
+struct bitfields {
+  long a : 2;
+  unsigned long b : 2;
+  long c : 32;  // assumes that int is 32 bits
+  unsigned long d : 32; // assumes that int is 32 bits
+} bf;
+
+void bitfield_promotion() {
+  printf("%ld", bf.a); // expected-warning {{format specifies type 'long' but 
the argument has type 'int'}}
+  printf("%lu", bf.b); // expected-warning {{format specifies type 'unsigned 
long' but the argument has type 'int'}}
+  printf("%ld", bf.c); // expected-warning {{format specifies type 'long' but 
the argument has type 'int'}}
+  printf("%lu", bf.d); // expected-warning {{format specifies type 'unsigned 
long' but the argument has type 'unsigned int'}}
+}

Added: cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx?rev=348889&view=auto
==
--- cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx (added)
+++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx Tue Dec 11 
11:18:01 2018
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s
+
+// In C++, the bitfield promotion from long to int does not occur, unlike C.
+// expected-no-diagnostics
+
+int printf(const char *restrict, ...);
+
+struct bitfields {
+  long a : 2;
+  unsigned long b : 2;
+  long c : 32;  // assumes that int is 32 bits
+  

Re: r348889 - Emit -Wformat properly for bit-field promotions.

2018-12-11 Thread Aaron Ballman via cfe-commits
On Tue, Dec 11, 2018 at 2:21 PM Aaron Ballman via cfe-commits
 wrote:
>
> Author: aaronballman
> Date: Tue Dec 11 11:18:01 2018
> New Revision: 348889
>
> URL: http://llvm.org/viewvc/llvm-project?rev=348889&view=rev
> Log:
> Emit -Wformat properly for bit-field promotions.
>
> Only explicitly look through integer and floating-point promotion where the 
> result type is actually a promotion, which is not always the case for 
> bit-fields in C.

Patch by Bevin Hansson. (Sorry for missing that in the commit message, Bevin!)

~Aaron

>
> Added:
> cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
> cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=348889&r1=34&r2=348889&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 11 11:18:01 2018
> @@ -7709,6 +7709,24 @@ shouldNotPrintDirectly(const ASTContext
>return std::make_pair(QualType(), StringRef());
>  }
>
> +/// Return true if \p ICE is an implicit argument promotion of an arithmetic
> +/// type. Bit-field 'promotions' from a higher ranked type to a lower ranked
> +/// type do not count.
> +static bool
> +isArithmeticArgumentPromotion(Sema &S, const ImplicitCastExpr *ICE) {
> +  QualType From = ICE->getSubExpr()->getType();
> +  QualType To = ICE->getType();
> +  // It's a floating promotion if the source type is a lower rank.
> +  if (ICE->getCastKind() == CK_FloatingCast &&
> +  S.Context.getFloatingTypeOrder(From, To) < 0)
> +return true;
> +  // It's an integer promotion if the destination type is the promoted
> +  // source type.
> +  return ICE->getCastKind() == CK_IntegralCast &&
> + From->isPromotableIntegerType() &&
> + S.Context.getPromotedIntegerType(From) == To;
> +}
> +
>  bool
>  CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier 
> &FS,
>  const char *StartSpecifier,
> @@ -7736,11 +7754,11 @@ CheckPrintfHandler::checkFormatExpr(cons
>
>// Look through argument promotions for our error message's reported type.
>// This includes the integral and floating promotions, but excludes array
> -  // and function pointer decay; seeing that an argument intended to be a
> -  // string has type 'char [6]' is probably more confusing than 'char *'.
> +  // and function pointer decay (seeing that an argument intended to be a
> +  // string has type 'char [6]' is probably more confusing than 'char *') and
> +  // certain bitfield promotions (bitfields can be 'demoted' to a lesser 
> type).
>if (const ImplicitCastExpr *ICE = dyn_cast(E)) {
> -if (ICE->getCastKind() == CK_IntegralCast ||
> -ICE->getCastKind() == CK_FloatingCast) {
> +if (isArithmeticArgumentPromotion(S, ICE)) {
>E = ICE->getSubExpr();
>ExprTy = E->getType();
>
>
> Added: cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.c?rev=348889&view=auto
> ==
> --- cfe/trunk/test/Sema/format-strings-bitfield-promotion.c (added)
> +++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.c Tue Dec 11 
> 11:18:01 2018
> @@ -0,0 +1,18 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
> +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify 
> %s
> +
> +int printf(const char *restrict, ...);
> +
> +struct bitfields {
> +  long a : 2;
> +  unsigned long b : 2;
> +  long c : 32;  // assumes that int is 32 bits
> +  unsigned long d : 32; // assumes that int is 32 bits
> +} bf;
> +
> +void bitfield_promotion() {
> +  printf("%ld", bf.a); // expected-warning {{format specifies type 'long' 
> but the argument has type 'int'}}
> +  printf("%lu", bf.b); // expected-warning {{format specifies type 'unsigned 
> long' but the argument has type 'int'}}
> +  printf("%ld", bf.c); // expected-warning {{format specifies type 'long' 
> but the argument has type 'int'}}
> +  printf("%lu", bf.d); // expected-warning {{format specifies type 'unsigned 
> long' but the argument has type 'unsigned int'}}
> +}
>
> Added: cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx?rev=348889&view=auto
> ==
> --- cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx (added)
> +++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx Tue Dec 11 
> 11:18:01 2018
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsynt

[PATCH] D55245: [clang-tidy] Add the abseil-duration-subtraction check

2018-12-11 Thread Hyrum Wright via Phabricator via cfe-commits
hwright added inline comments.



Comment at: test/clang-tidy/abseil-duration-subtraction.cpp:12
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the 
duration domain [abseil-duration-subtraction]

JonasToth wrote:
> hwright wrote:
> > JonasToth wrote:
> > > From this example starting:
> > > 
> > > - The RHS should be a nested expression with function calls, as the RHS 
> > > is transformed to create the adversary example i mean in the 
> > > transformation function above.
> > > 
> > > ```
> > > absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) 
> > > - absl::ToDoubleSeconds(d1));
> > > ```
> > > I think you need the proper conversion function, as the result of the 
> > > expression is `double` and you need a `Duration`, right?
> > > 
> > > But in principle starting from this idea the transformation might break.
> > I think there may be some confusion here (and that's entirely my fault. :) )
> > 
> > We should never get this expression as input to the check, since it doesn't 
> > compile (as you point out):
> > ```
> > absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) - 
> > absl::ToDoubleSeconds(d1));
> > ```
> > 
> > Since `absl::ToDoubleSeconds` requires that its argument is an 
> > `absl::Duration`, but the expression `absl::ToDoubleSeconds(d) - 
> > absl::ToDoubleSeconds(d1)` results in a `double`, we can't get this as 
> > input.
> > 
> > There may be other expressions which could be input, but in practice they 
> > don't really happen.  I've added a contrived example to the tests, but at 
> > some point the tests get too complex and confuse the fix matching 
> > infrastructure.
> Your last sentence is the thing ;) Murphies Law will hit this check, too. In 
> my opinion wrong transformations are very unfortunate and should be avoided 
> if possible (in this case possible).
> You can simply require that the expression of type double does not contain 
> any duration subtraction calls.
> 
> This is even possible in the matcher-part of the check.
I've written a test (which the testing infrastructure fails to handle well, so 
I haven't included it in the diff), and it produces these results:

```
   //
   //
-  x = absl::ToDoubleSeconds(d) - (absl::ToDoubleSeconds(d1) - 5);
+  x = absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1) - 5));
   //
   //
-  x = absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1) - 5));
+  x = absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1 - 
absl::Seconds(5;
```

Those results are correct.  There is a cosmetic issue of round tripping through 
the `double` conversion in the `absl::Seconds(absl::ToDoubleSeconds(...))` 
phrase, but untangling that is 1) difficult (because of order of operations 
issues) and thus; 2) probably the subject of a separate check.

This is still such a rare case (as in, we've not encountered it in Google's 
codebase), that I'm not really concerned.  But if it's worth it to explicitly 
exclude it from the traversal matcher, I can do that.


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

https://reviews.llvm.org/D55245



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


[PATCH] D55245: [clang-tidy] Add the abseil-duration-subtraction check

2018-12-11 Thread Hyrum Wright via Phabricator via cfe-commits
hwright updated this revision to Diff 177749.
hwright marked 6 inline comments as done.
hwright added a comment.

Rebase


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

https://reviews.llvm.org/D55245

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/DurationComparisonCheck.cpp
  clang-tidy/abseil/DurationRewriter.cpp
  clang-tidy/abseil/DurationRewriter.h
  clang-tidy/abseil/DurationSubtractionCheck.cpp
  clang-tidy/abseil/DurationSubtractionCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-duration-subtraction.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/abseil-duration-subtraction.cpp

Index: test/clang-tidy/abseil-duration-subtraction.cpp
===
--- /dev/null
+++ test/clang-tidy/abseil-duration-subtraction.cpp
@@ -0,0 +1,64 @@
+// RUN: %check_clang_tidy %s abseil-duration-subtraction %t -- -- -I %S/Inputs
+
+#include "absl/time/time.h"
+
+void f() {
+  double x;
+  absl::Duration d, d1, d2;
+
+  x = absl::ToDoubleSeconds(d) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - d1);
+  x = absl::ToDoubleSeconds(d) - 6.5 - 8.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(6.5)) - 8.0;
+  x = absl::ToDoubleHours(d) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleHours(d - absl::Hours(1))
+  x = absl::ToDoubleMinutes(d) - 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMinutes(d - absl::Minutes(1))
+  x = absl::ToDoubleMilliseconds(d) - 9;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMilliseconds(d - absl::Milliseconds(9))
+  x = absl::ToDoubleMicroseconds(d) - 9;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMicroseconds(d - absl::Microseconds(9))
+  x = absl::ToDoubleNanoseconds(d) - 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleNanoseconds(d - absl::Nanoseconds(42))
+
+  // We can rewrite the argument of the duration conversion
+#define THIRTY absl::Seconds(30)
+  x = absl::ToDoubleSeconds(THIRTY) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(THIRTY - absl::Seconds(1))
+#undef THIRTY
+
+  // Some other contexts
+  if (absl::ToDoubleSeconds(d) - 1.0 > 10) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: if (absl::ToDoubleSeconds(d - absl::Seconds(1)) > 10) {}
+
+  // A nested occurance
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(5));
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(5))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(absl::ToDoubleSeconds(d1)));
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1)))
+
+  // These should not match
+  x = 5 - 6;
+  x = 4 - absl::ToDoubleSeconds(d) - 6.5 - 8.0;
+  x = absl::ToDoubleSeconds(d) + 1.0;
+  x = absl::ToDoubleSeconds(d) * 1.0;
+  x = absl::ToDoubleSeconds(d) / 1.0;
+
+#define MINUS_FIVE(z) absl::ToDoubleSeconds(z) - 5
+  x = MINUS_FIVE(d);
+#undef MINUS_FIVE
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -8,6 +8,7 @@
abseil-duration-division
abseil-duration-factory-float
abseil-duration-factory-scale
+   abseil-duration-subtraction
abseil-faster-strsplit-delimiter
abseil-no-internal-dependencies
abseil-no-namespace
Index: docs/clang-tidy/checks/abseil-duration-subtraction.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/abse

r348891 - Stop stripping comments from AST matcher example code.

2018-12-11 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Dec 11 11:30:49 2018
New Revision: 348891

URL: http://llvm.org/viewvc/llvm-project?rev=348891&view=rev
Log:
Stop stripping comments from AST matcher example code.

The AST matcher documentation dumping script was being a bit over-zealous about 
stripping comment markers, which ended up causing comments in example code to 
stop being comments. Fix that by only stripping comments at the start of a 
line, rather than removing any forward slash (which also impacts prose text).

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/docs/tools/dump_ast_matchers.py
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=348891&r1=348890&r2=348891&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Dec 11 11:30:49 2018
@@ -499,7 +499,7 @@ Given
   int X;
   namespace NS {
   int Y;
-  }  namespace NS
+  }  // namespace NS
 decl(hasDeclContext(translationUnitDecl()))
   matches "int X", but not "int Y".
 
@@ -1152,7 +1152,7 @@ Example matches std::string()
 
 
 MatcherStmt>floatLiteralMatcherFloatingLiteral>...
-Matches float literals 
of all sizes encodings, e.g.
+Matches float literals 
of all sizes / encodings, e.g.
 1.0, 1.0f, 1.0L and 1e10.
 
 Does not match implicit conversions such as
@@ -1230,7 +1230,7 @@ initListExpr()
 
 
 MatcherStmt>integerLiteralMatcherIntegerLiteral>...
-Matches integer 
literals of all sizes encodings, e.g.
+Matches integer 
literals of all sizes / encodings, e.g.
 1, 1L, 0x1 and 1U.
 
 Does not match character-encoded integers such as L'a'.
@@ -1911,8 +1911,8 @@ Given
   template 
   class C { };
 
-  template class C;  A
-  C var;B
+  template class C;  // A
+  C var;// B
 
 templateSpecializationType() matches the type of the explicit
 instantiation in A and the type of the variable declaration in B.
@@ -2091,13 +2091,12 @@ Usable as: MatcherDecl>isImplicit
 Matches a declaration 
that has been implicitly added
-by the compiler (eg. implicit defaultcopy constructors).
+by the compiler (eg. implicit default/copy constructors).
 
 
 
@@ -2942,7 +2941,7 @@ Given:
   class A { int operator*(); };
   const A &operator<<(const A &a, const A &b);
   A a;
-  a << a;   <-- This matches
+  a << a;   // <-- This matches
 
 cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
 specified line and
@@ -2995,13 +2994,13 @@ functionDecl(isDefaulted())
 
 Example matches A, va, fa
   class A {};
-  class B;  Doesn't match, as it has no body.
+  class B;  // Doesn't match, as it has no body.
   int va;
-  extern int vb;  Doesn't match, as it doesn't define the variable.
+  extern int vb;  // Doesn't match, as it doesn't define the variable.
   void fa() {}
-  void fb();  Doesn't match, as it has no body.
+  void fb();  // Doesn't match, as it has no body.
   @interface X
-  - (void)ma; Doesn't match, interface is declaration.
+  - (void)ma; // Doesn't match, interface is declaration.
   @end
   @implementation X
   - (void)ma {}
@@ -3104,7 +3103,7 @@ functionDecl(isNoThrow()) and functionPr
 
 
 MatcherFunctionDecl>isStaticStorageClass
-Matches 
variablefunction declarations that have "static" storage
+Matches 
variable/function declarations that have "static" storage
 class specifier ("static" keyword) written in the source.
 
 Given:
@@ -3360,7 +3359,7 @@ Example matches X (regexp is one of "::X
 
 Given
   namespace n {
-  namespace {} #1
+  namespace {} // #1
   }
 namespaceDecl(isAnonymous()) will match #1 but not ::n.
 
@@ -3401,7 +3400,7 @@ message expression in
   CGRect bodyFrame = webView.frame;
   bodyFrame.size.height = self.bodyContentHeight;
   webView.frame = bodyFrame;
-  ^ matches here
+  // ^ matches here
 
 
 
@@ -3473,13 +3472,13 @@ a substring matched by the given RegExp.
 
 Example matches A, va, fa
   class A {};
-  class B;  Doesn't match, as it has no body.
+  class B;  // Doesn't match, as it has no body.
   int va;
-  extern int vb;  Doesn't match, as it doesn't define the variable.
+  extern int vb;  // Doesn't match, as it doesn't define the variable.
   void fa() {}
-  void fb();  Doesn't match, as it has no body.
+  void fb();  // Doesn't match, as it has no body.
   @interface X
-  - (void)ma; Doesn't match, interface is declaration.
+  - (void)ma; // Doesn't match, interface is

[PATCH] D55561: Stop stripping comments from AST matcher example code

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Committed in r348891.


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

https://reviews.llvm.org/D55561



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 13 inline comments as done.
EricWF added inline comments.



Comment at: include/clang/Sema/Sema.h:2758
 bool AllowExplicit = false,
+bool IsADLCandidate = false,
 ConversionSequenceList EarlyConversions = None);

rsmith wrote:
> Long lists of bool arguments make me nervous, especially with default 
> arguments. Can you introduce an enum for the new param at least?
Ack. I was thinking the same thing. 



Comment at: lib/AST/ASTImporter.cpp:7387
   return new (Importer.getToContext()) CallExpr(
   Importer.getToContext(), ToCallee, ToArgs, ToType, E->getValueKind(),
   ToRParenLoc);

rsmith wrote:
> Do we need to pass through the usesADL flag here too?
Seems like it. I'll add tests as well.



Comment at: lib/AST/Expr.cpp:1267
 : Expr(SC, Empty), NumArgs(NumArgs) {
+  CallExprBits.UsesADL = false;
   CallExprBits.NumPreArgs = NumPreArgs;

riccibruno wrote:
> riccibruno wrote:
> > I believe that msan can cope with bit level operations just fine.
> > What I am afraid is that initializing it here will hide the
> > fact that it is not initialized during deserialization if the
> > `E->setUsesADL(Record.readInt());` is removed by mistake.
> > 
> > At least not initializing it here will leave a chance for msan
> > to catch this.
> I don't think they do.
Regardless. I'll remove the initialization.

I think potentially getting a random value will make it easier to spot bugs.


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

https://reviews.llvm.org/D55534



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


[PATCH] D55566: [analyzer] LiveVariables: Fix a zombie expression problem, add testing infrastructure.

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, george.karpenkov, szepet, 
rnkovacs, Szelethus.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, baloghadamsoftware.

For the first time in years, there seems to be a bug in our "live variables" 
analysis, which is an auxiliary data flow analysis that decides which variables 
and expressions are live, so that we could collect dead symbols, clean up the 
program state, and, ultimately, find memory leaks.

The bug shows up on the move-checker, as demonstrated on attached tests (except 
the do-while test, which worked fine, but i added it to make sure it stays that 
way). It was originally hidden by D54372  and 
seems to have been another reason why the hack that was removed in D54372 
 was introduced in the first place.

Consider `checkMoreLoopZombies1()` (other tests are similar). `LiveVariables` 
analysis reports that //expression// `e` that constitutes the true-branch of 
`if` is live throughout almost the whole body of the loop (!), namely, until 
the beginning of `if (true)` "on the next iteration" (quotes because it doesn't 
really make sense for live variables analysis, but kinda makes sense for us to 
think of it this way). There's a brief period when it doesn't live, but it 
quickly becomes live again. The expression, being an lvalue, evaluates to the 
`VarRegion` for variable `e`. This means that at least one of the two - the 
variable `e` itself and the expression that evaluates to the region `e` - is 
always live, and region `e` never becomes dead, and the moved-from state never 
gets cleaned up, which leads to an invalid use-after-move report on the second 
iteration of the loop.

Expressions don't need to be live after the first statement that contains them 
is evaluated. So the liveness analysis was overly conservative in this case, 
and it caused problems for a checker that relies on values being cleaned up 
perfectly.

It was essential that the expression `e` appears directly as a sub-statement of 
`if`, i.e. written without `{`...`}`. Otherwise the compound statement would 
have been marked as live instead, which is kinda fine, even if it doesn't make 
sense.

Because of that, when the `if`-statement is being evaluated as a terminator, 
the generic code that works for pretty much all statements was marking the 
expression as live:

  for (Stmt *Child : S->children()) {
if (Child)
  AddLiveStmt(val.liveStmts, LV.SSetFact, Child);

This caused `e` to be incorrectly marked as live at the end of block that 
terminates at `if (true)`, which is propagated to the beginning of that block 
(similarly to how in `x ? y : z` expressions `y` and `z` need to live at 
operator `x ?`, so that the operator could have been evaluated), which is then 
propagated to the while-loop terminator.

This is fixed by specializing the generic case for these control flow operators 
to avoid the unnecessary propagation of non-compound-statement branch liveness.

-

Because i wanted to add more direct tests for this stuff (as we had none), i 
had to introduce a new debug checker to dump statement liveness: 
`debug.DumpLiveStmts`. Dumps should be human-readable and testable.

These direct tests indicate that the same incorrect behavior does indeed occur 
in the do-while loop case, even if it doesn't have much consequences for the 
move-checker.

-

I'll add more tests if i notice that this change increases the number of leaks 
Static Analyzer finds.


Repository:
  rC Clang

https://reviews.llvm.org/D55566

Files:
  include/clang/Analysis/Analyses/LiveVariables.h
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/Analysis/LiveVariables.cpp
  lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  test/Analysis/live-stmts.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -784,6 +784,45 @@
   }
 }
 
+void checkMoreLoopZombies1(bool flag) {
+  while (flag) {
+Empty e{};
+if (true)
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
+bool coin();
+
+void checkMoreLoopZombies2(bool flag) {
+  while (flag) {
+Empty e{};
+while (coin())
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
+void checkMoreLoopZombies3(bool flag) {
+  while (flag) {
+Empty e{};
+do
+  e; // expected-warning {{expression result unused}}
+while (coin());
+Empty f = std::move(e); // no-warning
+  }
+}
+
+void checkMoreLoopZombies4(bool flag) {
+  while (flag) {
+Empty e{};
+for (; coin();)
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
 struct MoveOnlyWithDest

r348892 - Revert r348889; it fails some tests.

2018-12-11 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Dec 11 11:42:04 2018
New Revision: 348892

URL: http://llvm.org/viewvc/llvm-project?rev=348892&view=rev
Log:
Revert r348889; it fails some tests.

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/40784

Removed:
cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=348892&r1=348891&r2=348892&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 11 11:42:04 2018
@@ -7709,24 +7709,6 @@ shouldNotPrintDirectly(const ASTContext
   return std::make_pair(QualType(), StringRef());
 }
 
-/// Return true if \p ICE is an implicit argument promotion of an arithmetic
-/// type. Bit-field 'promotions' from a higher ranked type to a lower ranked
-/// type do not count.
-static bool
-isArithmeticArgumentPromotion(Sema &S, const ImplicitCastExpr *ICE) {
-  QualType From = ICE->getSubExpr()->getType();
-  QualType To = ICE->getType();
-  // It's a floating promotion if the source type is a lower rank.
-  if (ICE->getCastKind() == CK_FloatingCast &&
-  S.Context.getFloatingTypeOrder(From, To) < 0)
-return true;
-  // It's an integer promotion if the destination type is the promoted
-  // source type.
-  return ICE->getCastKind() == CK_IntegralCast &&
- From->isPromotableIntegerType() &&
- S.Context.getPromotedIntegerType(From) == To;
-}
-
 bool
 CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
 const char *StartSpecifier,
@@ -7754,11 +7736,11 @@ CheckPrintfHandler::checkFormatExpr(cons
 
   // Look through argument promotions for our error message's reported type.
   // This includes the integral and floating promotions, but excludes array
-  // and function pointer decay (seeing that an argument intended to be a
-  // string has type 'char [6]' is probably more confusing than 'char *') and
-  // certain bitfield promotions (bitfields can be 'demoted' to a lesser type).
+  // and function pointer decay; seeing that an argument intended to be a
+  // string has type 'char [6]' is probably more confusing than 'char *'.
   if (const ImplicitCastExpr *ICE = dyn_cast(E)) {
-if (isArithmeticArgumentPromotion(S, ICE)) {
+if (ICE->getCastKind() == CK_IntegralCast ||
+ICE->getCastKind() == CK_FloatingCast) {
   E = ICE->getSubExpr();
   ExprTy = E->getType();
 

Removed: cfe/trunk/test/Sema/format-strings-bitfield-promotion.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.c?rev=348891&view=auto
==
--- cfe/trunk/test/Sema/format-strings-bitfield-promotion.c (original)
+++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.c (removed)
@@ -1,18 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s
-
-int printf(const char *restrict, ...);
-
-struct bitfields {
-  long a : 2;
-  unsigned long b : 2;
-  long c : 32;  // assumes that int is 32 bits
-  unsigned long d : 32; // assumes that int is 32 bits
-} bf;
-
-void bitfield_promotion() {
-  printf("%ld", bf.a); // expected-warning {{format specifies type 'long' but 
the argument has type 'int'}}
-  printf("%lu", bf.b); // expected-warning {{format specifies type 'unsigned 
long' but the argument has type 'int'}}
-  printf("%ld", bf.c); // expected-warning {{format specifies type 'long' but 
the argument has type 'int'}}
-  printf("%lu", bf.d); // expected-warning {{format specifies type 'unsigned 
long' but the argument has type 'unsigned int'}}
-}

Removed: cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx?rev=348891&view=auto
==
--- cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx (original)
+++ cfe/trunk/test/Sema/format-strings-bitfield-promotion.cxx (removed)
@@ -1,21 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only -verify %s
-
-// In C++, the bitfield promotion from long to int does not occur, unlike C.
-// expected-no-diagnostics
-
-int printf(const char *restrict, ...);
-
-struct bitfields {
-  long a : 2;
-  unsigned long b : 2;
-  long c : 32;  // assumes that int is 32 bits
-  unsigned long d : 32; // assumes that int is 32 bits
-} bf;
-
-void bitfield_promotion() {
-  printf("%ld",

[PATCH] D51211: [Sema] Emit -Wformat properly for bitfield promotions.

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman reopened this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

I had to revert the commit as the changes caused some test failures.

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/40784/steps/test/logs/stdio

  FAIL: Clang :: CodeGenOpenCL/printf.cl (8013 of 45545)
   TEST 'Clang :: CodeGenOpenCL/printf.cl' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang
 -cc1 -internal-isystem 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/lib/clang/8.0.0/include
 -nostdsysteminc -cl-std=CL1.2 -cl-ext=-+cl_khr_fp64 -triple 
spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl
 | 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/FileCheck
 -check-prefixes=FP64,ALL 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl
  : 'RUN: at line 2';   
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang
 -cc1 -internal-isystem 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/lib/clang/8.0.0/include
 -nostdsysteminc -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -triple 
spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl
 | 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/FileCheck
 -check-prefixes=NOFP64,ALL 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl
  --
  Exit Code: 2
  
  Command Output (stderr):
  --
  
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl:20:18:
 warning: format specifies type 'double __attribute__((ext_vector_type(2)))' 
but the argument has type 'float2' (vector of 2 'float' values)
printf("%v2f", arg);
   ^~~
%v2f
  clang: 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/lib/AST/ASTContext.cpp:5554:
 FloatingRank getFloatingRank(clang::QualType): Assertion 
`T->getAs() && "getFloatingRank(): not a floating type"' failed.
  Stack dump:
  0.Program arguments: 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang
 -cc1 -internal-isystem 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/lib/clang/8.0.0/include
 -nostdsysteminc -cl-std=CL1.2 -cl-ext=-cl_khr_fp64 -triple 
spir-unknown-unknown -disable-llvm-passes -emit-llvm -o - 
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl
 
  1.
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl:30:21:
 current parser token ')'
  2.
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl:29:42:
 parsing function body 'test_printf_half2'
  3.
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.src/tools/clang/test/CodeGenOpenCL/printf.cl:29:42:
 in compound statement ('{}')
  #0 0x015d9934 PrintStackTraceSignalHandler(void*) 
(/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang+0x15d9934)
  #1 0x015d769e llvm::sys::RunSignalHandlers() 
(/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang+0x15d769e)
  #2 0x015d9af8 SignalHandler(int) 
(/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang+0x15d9af8)
  #3 0x7f95cde44890 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
  #4 0x7f95ccb0ae97 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x3ee97)
  #5 0x7f95ccb0c801 abort (/lib/x86_64-linux-gnu/libc.so.6+0x40801)
  #6 0x7f95ccafc39a (/lib/x86_64-linux-gnu/libc.so.6+0x3039a)
  #7 0x7f95ccafc412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
  #8 0x032f872c getFloatingRank(clang::QualType) 
(/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang+0x32f872c)
  #9 0x032f877e 
clang::ASTContext::getFloatingTypeOrder(clang::QualType, clang::QualType) const 
(/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm.obj/bin/clang+0x32f877e)
  #10 0x02bf9316 (anonymous 
namespace)::CheckPrintfHandler::checkFormatExpr(clang::

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 177752.
EricWF marked 3 inline comments as done.
EricWF added a comment.

Address review comments.


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

https://reviews.llvm.org/D55534

Files:
  docs/LibASTMatchersReference.html
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/AST/ast-dump-expr.cpp
  test/Import/call-expr/Inputs/F.cpp
  test/Import/call-expr/test.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -199,6 +199,40 @@
"-fno-delayed-template-parsing"));
 }
 
+TEST(Matcher, ADLCall) {
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  StatementMatcher ADLMatchOper = cxxOperatorCallExpr(usesADL());
+  auto NS_Str = R"cpp(
+  namespace NS {
+struct X {};
+void f(X);
+void operator+(X, X);
+  }
+  struct MyX {};
+  void f(...);
+  void operator+(MyX, MyX);
+)cpp";
+
+  auto MkStr = [&](std::string Body) -> std::string {
+std::string S = NS_Str;
+S += "void test_fn() { " + Body + " }";
+return S;
+  };
+
+  EXPECT_TRUE(matches(MkStr("NS::X x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; using NS::f; f(x);"), ADLMatch));
+
+  // Operator call expressions
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatch));
+  EXPECT_TRUE(matches(MkStr("NS::X x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; x + x;"), ADLMatchOper));
+  EXPECT_TRUE(matches(MkStr("NS::X x; operator+(x, x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::operator+(x, x);"), ADLMatch));
+}
+
 TEST(Matcher, Call) {
   // FIXME: Do we want to overload Call() to directly take
   // Matcher, too?
Index: test/Import/call-expr/test.cpp
===
--- /dev/null
+++ test/Import/call-expr/test.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s
+void expr() {
+  f();
+}
+
+// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^>]*}}> line:{{.*}}:{{[^ ]*}} used f 'void ()'
+// CHECK: -CallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
+// CHECK: -CXXOperatorCallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
Index: test/Import/call-expr/Inputs/F.cpp
===
--- /dev/null
+++ test/Import/call-expr/Inputs/F.cpp
@@ -0,0 +1,10 @@
+namespace NS {
+struct X {};
+void f(X) {}
+void operator+(X, X) {}
+} // namespace NS
+void f() {
+  NS::X x;
+  f(x);
+  x + x;
+}
Index: test/AST/ast-dump-expr.cpp
===
--- test/AST/ast-dump-expr.cpp
+++ test/AST/ast-dump-expr.cpp
@@ -508,3 +508,46 @@
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'Ts...' lvalue ParmVar 0x{{[^ ]*}} 'a' 'Ts...'
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue Var 0x{{[^ ]*}} 'b' 'int'
 }
+
+
+namespace NS {
+struct X {};
+void f(X);
+void y(...);
+} // namespace NS
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
+void ADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
+void NonADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  NS::f(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
+void NonADLCall2() {
+  NS::X x;
+  using NS::f;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+namespace test_adl_call_three {
+using namespace NS;
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
+void NonADLCall3() {
+  X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+}
+} // namespace test_adl_call_three
\ No newline at end of file
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -651,6 +651,7 @@
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg)
 Record.AddStmt(*Arg);
+  Record

[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-11 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked an inline comment as done.
EricWF added a comment.

I think this is good to go. Any more comments?




Comment at: include/clang/Sema/Sema.h:2758
 bool AllowExplicit = false,
+bool IsADLCandidate = false,
 ConversionSequenceList EarlyConversions = None);

EricWF wrote:
> rsmith wrote:
> > Long lists of bool arguments make me nervous, especially with default 
> > arguments. Can you introduce an enum for the new param at least?
> Ack. I was thinking the same thing. 
And you were right to be nervous. The change found bugs.


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

https://reviews.llvm.org/D55534



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


[PATCH] D55566: [analyzer] LiveVariables: Fix a zombie expression problem, add testing infrastructure.

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 177753.
NoQ added a comment.

Add documentation, fix checker help message.


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

https://reviews.llvm.org/D55566

Files:
  docs/analyzer/DebugChecks.rst
  include/clang/Analysis/Analyses/LiveVariables.h
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/Analysis/LiveVariables.cpp
  lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  test/Analysis/live-stmts.cpp
  test/Analysis/use-after-move.cpp

Index: test/Analysis/use-after-move.cpp
===
--- test/Analysis/use-after-move.cpp
+++ test/Analysis/use-after-move.cpp
@@ -784,6 +784,45 @@
   }
 }
 
+void checkMoreLoopZombies1(bool flag) {
+  while (flag) {
+Empty e{};
+if (true)
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
+bool coin();
+
+void checkMoreLoopZombies2(bool flag) {
+  while (flag) {
+Empty e{};
+while (coin())
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
+void checkMoreLoopZombies3(bool flag) {
+  while (flag) {
+Empty e{};
+do
+  e; // expected-warning {{expression result unused}}
+while (coin());
+Empty f = std::move(e); // no-warning
+  }
+}
+
+void checkMoreLoopZombies4(bool flag) {
+  while (flag) {
+Empty e{};
+for (; coin();)
+  e; // expected-warning {{expression result unused}}
+Empty f = std::move(e); // no-warning
+  }
+}
+
 struct MoveOnlyWithDestructor {
   MoveOnlyWithDestructor();
   ~MoveOnlyWithDestructor();
Index: test/Analysis/live-stmts.cpp
===
--- /dev/null
+++ test/Analysis/live-stmts.cpp
@@ -0,0 +1,167 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=debug.DumpLiveStmts %s 2>&1\
+// RUN:   | FileCheck %s
+
+int coin();
+
+
+int testThatDumperWorks(int x, int y, int z) {
+  return x ? y : z;
+}
+// CHECK: [ B0 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B1 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B2 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 
+// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 
+// CHECK-NEXT:   `-DeclRefExpr {{.*}} 'x' 'int'
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B3 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 
+// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 
+// CHECK-NEXT:   `-DeclRefExpr {{.*}} 'x' 'int'
+// CHECK: [ B4 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 
+// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 
+// CHECK-NEXT:   `-DeclRefExpr {{.*}} 'x' 'int'
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B5 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
+// CHECK-EMPTY:
+// CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+
+
+void testIfBranchExpression(bool flag) {
+  // No expressions should be carried over from one block to another here.
+  while (flag) {
+int e = 1;
+if (true)
+  e;
+  }
+}
+// CHECK: [ B0 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B1 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B2 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B3 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B4 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B5 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+
+
+void testWhileBodyExpression(bool flag) {
+  // No expressions should be carried over from one block to another here.
+  while (flag) {
+int e = 1;
+while (coin())
+  e;
+  }
+}
+// CHECK: [ B0 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B1 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B2 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B3 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B4 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+// CHECK: [ B5 (live statements at block exit) ]
+// CHECK-EMPTY:
+// CHECK-EMPTY:
+
+
+void testDoWhileBodyExpression(bool flag) {
+  // No expressions should be carried over from one block to another here.
+  while (flag) {
+int e = 1;
+do
+  

[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/tools/libclang/CXType.cpp:132
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);

leonardchan wrote:
> aaron.ballman wrote:
> > leonardchan wrote:
> > > aaron.ballman wrote:
> > > > This change seems surprising -- if the parsing options say the caller 
> > > > does not want attributed types, why are we returning one anyway for 
> > > > address space?
> > > This has to do with ensuring `clang_getAddressSpace` still returns the 
> > > proper address_space. It does this by essentially checking the qualifiers 
> > > of the type, which we now attach to the `AttributedType` whereas before 
> > > it was attached to the modified type.
> > > 
> > > This extra condition is necessary for ensuring that calling 
> > > `clang_getAddressSpace` points to the qualified AttributedType instead of 
> > > the unqualified modified type.
> > My fear is that this will be breaking assumptions in third-party code. If 
> > someone disables `CXTranslationUnit_IncludeAttributedTypes`, they are 
> > unlikely to expect to receive an `AttributedType` and may react poorly to 
> > it.
> Instead check if the type is address_space attributed and apply the 
> qualifiers the modified type.
Sure, they can always modify their code to handle it gracefully, but it's a 
silent, breaking change to a somewhat stable API which is why I was prodding 
about it.

After talking with @rsmith, we're thinking the correct change here is to return 
the attributed type when the user asks for it, but return the equivalent type 
rather than the modified type if the user doesn't want attribute sugar (for all 
attributes, not just address spaces). This way, when a user asks for CXType for 
one of these, they always get a correct type but sometimes it has attribute 
type sugar and sometimes it doesn't, depending on the parsing options.

This is still a silent, breaking change in behavior, which is unfortunate. It 
should probably come with a mention in the release notes about the change to 
the API and some unit tests as well.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55447



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


[PATCH] D55410: [clang-tidy] check for flagging using declarations in headers

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: docs/clang-tidy/checks/abseil-alias-free-headers.rst:13
+The style guide  http://google.github.io/styleguide/cppguide.html#Aliases 
discusses this
+issue in more detail

Eugene.Zelenko wrote:
> Naysh wrote:
> > Eugene.Zelenko wrote:
> > > Missing link to guidelines,
> > @Eugene.Zelenko: Sorry, I'm not sure what you mean. Could you clarify what 
> > guidelines you're referring to? 
> Please see documentation in other using-related checks.
I think he's talking about the fact that this is text and not a hyperlink. It 
should look something more like
```
The `Abseil Style Guide 
`_ discusses this 
issue in more detail.
```


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55410



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


[PATCH] D54921: [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Hmm, i think i get it. `Cached` is a reference. Changing `Memoization` will 
invalidate references because `DenseMap` doesn't provide the respective 
guarantee.

Here's how the code should have looked:

  ~  77 Optional Cached = Memoization[C];
  ~  78 if (!Cached) {
 79   Cached = seenBeforeRec(C, A, B, Memoization);
  +  80   Memoization[C] = Cached;
  +  81 }


Repository:
  rC Clang

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

https://reviews.llvm.org/D54921



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


[PATCH] D54921: [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-11 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@NoQ thanks, interesting! But I thought the underlying map is not actually 
modified while the reference is alive?


Repository:
  rC Clang

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

https://reviews.llvm.org/D54921



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


[PATCH] D54921: [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think that it is modified, at least, when `Memoization[C]` is evaluated. The 
object needs to be created and put into the map in order to obtain a reference 
to it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54921



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


[PATCH] D54921: [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

That is, it is modified within the recursive call.


Repository:
  rC Clang

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

https://reviews.llvm.org/D54921



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


[PATCH] D55483: Introduce the callback attribute and emit !callback metadata

2018-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/Attr.td:1204
+  VariadicUnsignedArgument<"PayloadIndices">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];

jdoerfert wrote:
> aaron.ballman wrote:
> > Should this also apply to Objective-C methods?
> > 
> > Why should the user specify this attribute on the function as opposed to on 
> > the parameter? e.g.,
> > ```
> > // Why this:
> > __attribute__((callback (1, 2, 3)))
> > void* broker0(void* (*callee)(void *), void *payload, int otherPayload) {
> >   return callee(payload);
> > }
> > 
> > // Instead of this:
> > void* broker0(void* (*callee)(void *) __attribute__((callback (2, 3))), 
> > void *payload, int otherPayload) {
> >   return callee(payload);
> > }
> > 
> > // Or this:
> > void* broker0(void* (*callee)(void *) __attribute__((callback (payload, 
> > otherPayload))), void *payload, int otherPayload) {
> >   return callee(payload);
> > }
> > ```
> > I ask because these "use an index" attributes are really hard for users to 
> > use in practice. They have to account for 0-vs-1 based indexing, implicit 
> > this parameters, etc and if we can avoid that, it may be worth the effort.
> > Should this also apply to Objective-C methods?
> 
> I don't need it to and unless somebody does, I'd say no.
> 
> 
> > I ask because these "use an index" attributes are really hard for users to 
> > use in practice. They have to account for 0-vs-1 based indexing, implicit 
> > this parameters, etc and if we can avoid that, it may be worth the effort.
> 
> I was thinking that the function notation makes it clear that there is *only 
> one callback per function* allowed right now. I don't expect many manual 
> users of this feature until we improve the middle-end support, so it is 
> unclear to me if this requirement needs to be removed as well.
> 
> Other than that, some thoughts: 
> - I do not feel strongly about this.
> - The middle requirement seems not much better n the first, we would still 
> need to deal with index numbers (callbacks without arguments are not really 
> interesting for now). 
> - The last encoding requires us to define a symbol for "unknown argument" 
> (maybe _ or ?).
> I was thinking that the function notation makes it clear that there is *only 
> one callback per function* allowed right now.

I don't see how that follows. Users may still try writing:
```
__attribute__((callback (1, 3, 4)))
__attribute__((callback (2, 3, 4)))
void broker0(void (*cb1)(void *, int), void (*cb2)(void *, int), void *payload, 
int otherPayload) {
  cb1(payload, otherPayload);
  cb2(payload, otherPayload);
}
```
and reasonably expect that to work (we should have this as a test case, and 
probably warn on it).

I'm not strongly opposed to the current way this is exposed to users, just 
wondering if we can find a better way to surface the feature.

> The last encoding requires us to define a symbol for "unknown argument" 
> (maybe _ or ?).

Ah, I wasn't aware that this was part of the feature, but the documentation you 
wrote helped to clarify for me. Personal preference is for `?`, but any symbol 
will do (so long as we aren't hoping users can count commas, e.g., 
`callback(frobble,,,foo)`).



Comment at: include/clang/Basic/AttrDocs.td:3711
+The ``callback`` attribute specifies that the annotated function may invoke the
+specified callback callee zero or more times. The callback callee, as well as
+the passed arguments, are identified by their parameter position (starting with

I'd remove `callee` here in both places.



Comment at: include/clang/Basic/AttrDocs.td:3714
+1!) in the annotated function. The first position identifies the callback 
callee,
+the following indices the forwarded arguments. The callback callee is required
+to be callable with the number, and order, of the specified arguments. To

and the following indicies are the forwarded arguments.



Comment at: include/clang/Basic/AttrDocs.td:3716
+to be callable with the number, and order, of the specified arguments. To
+represent unknown arguments a zero shall be used.
+

The index '0' is used to represent a callback callee argument which is not 
present in the declared parameter list.



Comment at: include/clang/Basic/AttrDocs.td:3718
+
+The ``callback`` attributes, which are directly translated to ``callback``
+metadata , allow to make

attributes -> attribute



Comment at: include/clang/Basic/AttrDocs.td:3719
+The ``callback`` attributes, which are directly translated to ``callback``
+metadata , allow to make
+the connection between the call to the annotated function and the callback

, allow to make the connection -> , make the con

  1   2   >